mirror of
https://github.com/AxioDL/boo.git
synced 2025-12-09 21:47:57 +00:00
Major refactor for better modularity
This commit is contained in:
166
lib/win/ApplicationWin32.cpp
Normal file
166
lib/win/ApplicationWin32.cpp
Normal file
@@ -0,0 +1,166 @@
|
||||
#define _CRT_SECURE_NO_WARNINGS 1 /* STFU MSVC */
|
||||
#define _WIN32_LEAN_AND_MEAN 1
|
||||
#include <windows.h>
|
||||
#include <initguid.h>
|
||||
#include <Usbiodef.h>
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
#include "IRunLoop.hpp"
|
||||
#include "inputdev/CDeviceFinder.hpp"
|
||||
|
||||
namespace boo
|
||||
{
|
||||
|
||||
IWindow* _CWindowWin32New(const std::string& title);
|
||||
|
||||
class CApplicationWin32 final : public IApplication
|
||||
{
|
||||
const IApplicationCallback& m_callback;
|
||||
const std::string m_friendlyName;
|
||||
const std::string m_pname;
|
||||
const std::vector<std::string> m_args;
|
||||
std::unordered_map<HWND, IWindow*> m_allWindows;
|
||||
bool m_singleInstance;
|
||||
|
||||
void _deletedWindow(IWindow* window)
|
||||
{
|
||||
m_allWindows.erase(window);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
CApplicationWin32(const IApplicationCallback& callback,
|
||||
const std::string& friendlyName,
|
||||
const std::string& pname,
|
||||
const std::vector<std::string>& args,
|
||||
bool singleInstance)
|
||||
: m_callback(callback),
|
||||
m_friendlyName(friendlyName),
|
||||
m_pname(pname),
|
||||
m_args(args),
|
||||
m_singleInstance(singleInstance)
|
||||
{}
|
||||
|
||||
EPlatformType getPlatformType() const
|
||||
{
|
||||
return PLAT_WIN32;
|
||||
}
|
||||
|
||||
LRESULT winHwndHandler(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
/* Lookup boo window instance */
|
||||
IWindow* window = m_allWindows[hwnd];
|
||||
switch (uMsg)
|
||||
{
|
||||
case WM_CREATE:
|
||||
return 0;
|
||||
|
||||
case WM_DEVICECHANGE:
|
||||
return CDeviceFinder::winDevChangedHandler(wParam, lParam);
|
||||
|
||||
default:
|
||||
return DefWindowProc(hwnd, uMsg, wParam, lParam);
|
||||
}
|
||||
}
|
||||
|
||||
void run()
|
||||
{
|
||||
/* Pump messages */
|
||||
MSG msg = {0};
|
||||
while (GetMessage(&msg, NULL, 0, 0))
|
||||
{
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
}
|
||||
}
|
||||
|
||||
const std::string& getProcessName() const
|
||||
{
|
||||
return m_pname;
|
||||
}
|
||||
|
||||
const std::vector<std::string>& getArgs() const
|
||||
{
|
||||
return m_args;
|
||||
}
|
||||
|
||||
IWindow* newWindow(const std::string& title)
|
||||
{
|
||||
IWindow* window = _CWindowWin32New(title);
|
||||
HWND hwnd = window->getPlatformHandle();
|
||||
m_allWindows[hwnd] = window;
|
||||
}
|
||||
};
|
||||
|
||||
IApplication* APP = NULL;
|
||||
IApplication* IApplicationBootstrap(IApplication::EPlatformType platform,
|
||||
IApplicationCallback& cb,
|
||||
const std::string& friendlyName,
|
||||
const std::string& pname,
|
||||
const std::vector<std::string>& args,
|
||||
bool singleInstance)
|
||||
{
|
||||
if (!APP)
|
||||
{
|
||||
if (platform != IApplication::PLAT_WIN32 &&
|
||||
platform != IApplication::PLAT_AUTO)
|
||||
return NULL;
|
||||
APP = new CApplicationWin32(cb, friendlyName, pname, args, singleInstance);
|
||||
}
|
||||
return APP;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static const DEV_BROADCAST_DEVICEINTERFACE_A HOTPLUG_CONF =
|
||||
{
|
||||
sizeof(DEV_BROADCAST_DEVICEINTERFACE_A),
|
||||
DBT_DEVTYP_DEVICEINTERFACE,
|
||||
0,
|
||||
GUID_DEVINTERFACE_USB_DEVICE
|
||||
};
|
||||
static bool HOTPLUG_REGISTERED = false;
|
||||
static LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
if (!HOTPLUG_REGISTERED && hwnd == WM_CREATE)
|
||||
{
|
||||
/* Register hotplug notification with windows */
|
||||
RegisterDeviceNotificationA(hwnd, (LPVOID)&HOTPLUG_CONF, DEVICE_NOTIFY_WINDOW_HANDLE);
|
||||
HOTPLUG_REGISTERED = true;
|
||||
}
|
||||
return IRunLoopInstance()->winHwndHandler(hwnd, uMsg, wParam, lParam);
|
||||
}
|
||||
|
||||
int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE, LPCWSTR lpCmdLine, int)
|
||||
{
|
||||
#if DEBUG
|
||||
/* Debug console */
|
||||
AllocConsole();
|
||||
freopen("CONOUT$", "w", stdout);
|
||||
#endif
|
||||
|
||||
/* One class for *all* boo windows */
|
||||
WNDCLASS wndClass =
|
||||
{
|
||||
0,
|
||||
WindowProc,
|
||||
0,
|
||||
0,
|
||||
hInstance,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
L"BooWindow"
|
||||
};
|
||||
|
||||
RegisterClassW(&wndClass);
|
||||
|
||||
int argc = 0;
|
||||
LPWSTR* argv = CommandLineToArgvW(lpCmdLine, &argc);
|
||||
|
||||
/* Call into the 'proper' entry point */
|
||||
return main(argc, argv);
|
||||
|
||||
}
|
||||
83
lib/win/GraphicsContextWin32.cpp
Normal file
83
lib/win/GraphicsContextWin32.cpp
Normal file
@@ -0,0 +1,83 @@
|
||||
#include "windowsys/IGraphicsContext.hpp"
|
||||
#include "windowsys/IWindow.hpp"
|
||||
|
||||
namespace boo
|
||||
{
|
||||
|
||||
class CGraphicsContextWin32 final : public IGraphicsContext
|
||||
{
|
||||
|
||||
EGraphicsAPI m_api;
|
||||
EPixelFormat m_pf;
|
||||
IWindow* m_parentWindow;
|
||||
|
||||
public:
|
||||
IWindowCallback* m_callback;
|
||||
|
||||
CGraphicsContextWin32(EGraphicsAPI api, IWindow* parentWindow)
|
||||
: m_api(api),
|
||||
m_pf(PF_RGBA8),
|
||||
m_parentWindow(parentWindow)
|
||||
{}
|
||||
|
||||
~CGraphicsContextWin32()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void _setCallback(IWindowCallback* cb)
|
||||
{
|
||||
m_callback = cb;
|
||||
}
|
||||
|
||||
EGraphicsAPI getAPI() const
|
||||
{
|
||||
return m_api;
|
||||
}
|
||||
|
||||
EPixelFormat getPixelFormat() const
|
||||
{
|
||||
return m_pf;
|
||||
}
|
||||
|
||||
void setPixelFormat(EPixelFormat pf)
|
||||
{
|
||||
if (pf > PF_RGBAF32_Z24)
|
||||
return;
|
||||
m_pf = pf;
|
||||
}
|
||||
|
||||
void initializeContext()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
IGraphicsContext* makeShareContext() const
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void makeCurrent()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void clearCurrent()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void swapBuffer()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
IGraphicsContext* _CGraphicsContextWin32New(IGraphicsContext::EGraphicsAPI api,
|
||||
IWindow* parentWindow)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
#ifdef _WIN32
|
||||
#include "win/CWGLContext.hpp"
|
||||
|
||||
#endif
|
||||
96
lib/win/WindowWin32.cpp
Normal file
96
lib/win/WindowWin32.cpp
Normal file
@@ -0,0 +1,96 @@
|
||||
#include "windowsys/IWindow.hpp"
|
||||
#include "windowsys/IGraphicsContext.hpp"
|
||||
|
||||
namespace boo
|
||||
{
|
||||
|
||||
IGraphicsContext* _CGraphicsContextWin32New(IGraphicsContext::EGraphicsAPI api,
|
||||
IWindow* parentWindow);
|
||||
|
||||
class CWindowWin32 final : public IWindow
|
||||
{
|
||||
|
||||
HWND m_hwnd;
|
||||
|
||||
public:
|
||||
|
||||
CWindowWin32(const std::string& title)
|
||||
{
|
||||
m_hwnd = CreateWindowW(L"BooWindow", L"BooTest", WS_OVERLAPPEDWINDOW,
|
||||
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
|
||||
NULL, NULL, hInstance, NULL);
|
||||
}
|
||||
|
||||
~CWindowWin32()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void setCallback(IWindowCallback* cb)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void showWindow()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void hideWindow()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
std::string getTitle()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void setTitle(const std::string& title)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void setWindowFrameDefault()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void getWindowFrame(float& xOut, float& yOut, float& wOut, float& hOut) const
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void setWindowFrame(float x, float y, float w, float h)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
float getVirtualPixelFactor() const
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool isFullscreen() const
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void setFullscreen(bool fs)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
ETouchType getTouchType() const
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
IWindow* _CWindowWin32New(const std::string& title)
|
||||
{
|
||||
return new CWindowWin32(title);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user