Windows refactors

This commit is contained in:
Jack Andersen
2015-08-30 17:40:58 -10:00
parent f9c4ed0761
commit 49771b0e15
13 changed files with 261 additions and 194 deletions

View File

@@ -1,41 +1,47 @@
#define _CRT_SECURE_NO_WARNINGS 1 /* STFU MSVC */
#define _WIN32_LEAN_AND_MEAN 1
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN 1
#endif
#include <windows.h>
#include <shellapi.h>
#include <initguid.h>
#include <Usbiodef.h>
#include <unordered_map>
#include "IRunLoop.hpp"
#include "inputdev/CDeviceFinder.hpp"
#include "boo/IApplication.hpp"
#include "boo/inputdev/DeviceFinder.hpp"
namespace boo
{
IWindow* _CWindowWin32New(const std::string& title);
IWindow* _WindowWin32New(const SystemString& title);
class CApplicationWin32 final : public IApplication
class ApplicationWin32 final : public IApplication
{
const IApplicationCallback& m_callback;
const std::string m_friendlyName;
const std::string m_pname;
const std::vector<std::string> m_args;
const SystemString m_uniqueName;
const SystemString m_friendlyName;
const SystemString m_pname;
const std::vector<SystemString> m_args;
std::unordered_map<HWND, IWindow*> m_allWindows;
bool m_singleInstance;
void _deletedWindow(IWindow* window)
{
m_allWindows.erase(window);
m_allWindows.erase(HWND(window->getPlatformHandle()));
}
public:
CApplicationWin32(const IApplicationCallback& callback,
const std::string& friendlyName,
const std::string& pname,
const std::vector<std::string>& args,
bool singleInstance)
ApplicationWin32(const IApplicationCallback& callback,
const SystemString& uniqueName,
const SystemString& friendlyName,
const SystemString& pname,
const std::vector<SystemString>& args,
bool singleInstance)
: m_callback(callback),
m_uniqueName(uniqueName),
m_friendlyName(friendlyName),
m_pname(pname),
m_args(args),
@@ -57,14 +63,14 @@ public:
return 0;
case WM_DEVICECHANGE:
return CDeviceFinder::winDevChangedHandler(wParam, lParam);
return DeviceFinder::winDevChangedHandler(wParam, lParam);
default:
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
}
void run()
void pump()
{
/* Pump messages */
MSG msg = {0};
@@ -75,40 +81,53 @@ public:
}
}
const std::string& getProcessName() const
const SystemString& getUniqueName() const
{
return m_uniqueName;
}
const SystemString& getFriendlyName() const
{
return m_friendlyName;
}
const SystemString& getProcessName() const
{
return m_pname;
}
const std::vector<std::string>& getArgs() const
const std::vector<SystemString>& getArgs() const
{
return m_args;
}
IWindow* newWindow(const std::string& title)
IWindow* newWindow(const SystemString& title)
{
IWindow* window = _CWindowWin32New(title);
HWND hwnd = window->getPlatformHandle();
IWindow* window = _WindowWin32New(title);
HWND hwnd = HWND(window->getPlatformHandle());
m_allWindows[hwnd] = window;
return 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)
std::unique_ptr<IApplication>
ApplicationBootstrap(IApplication::EPlatformType platform,
IApplicationCallback& cb,
const SystemString& uniqueName,
const SystemString& friendlyName,
const SystemString& pname,
const std::vector<SystemString>& args,
bool singleInstance)
{
if (!APP)
{
if (platform != IApplication::PLAT_WIN32 &&
platform != IApplication::PLAT_AUTO)
return NULL;
APP = new CApplicationWin32(cb, friendlyName, pname, args, singleInstance);
APP = new ApplicationWin32(cb, uniqueName, friendlyName, pname, args, singleInstance);
}
return APP;
return std::unique_ptr<IApplication>(APP);
}
}
@@ -123,16 +142,17 @@ static const DEV_BROADCAST_DEVICEINTERFACE_A HOTPLUG_CONF =
static bool HOTPLUG_REGISTERED = false;
static LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
if (!HOTPLUG_REGISTERED && hwnd == WM_CREATE)
if (!HOTPLUG_REGISTERED && uMsg == 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);
return static_cast<boo::ApplicationWin32*>(boo::APP)->winHwndHandler(hwnd, uMsg, wParam, lParam);
}
int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE, LPCWSTR lpCmdLine, int)
int wmain(int argc, wchar_t** argv);
int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE, LPWSTR lpCmdLine, int)
{
#if DEBUG
/* Debug console */
@@ -161,6 +181,6 @@ int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE, LPCWSTR lpCmdLine, int)
LPWSTR* argv = CommandLineToArgvW(lpCmdLine, &argc);
/* Call into the 'proper' entry point */
return main(argc, argv);
return wmain(argc, argv);
}

View File

@@ -1,83 +0,0 @@
#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)
{
}
}

View File

@@ -1,27 +1,98 @@
#include "windowsys/IWindow.hpp"
#include "windowsys/IGraphicsContext.hpp"
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN 1
#endif
#include <Windows.h>
#include "boo/IWindow.hpp"
#include "boo/IGraphicsContext.hpp"
namespace boo
{
IGraphicsContext* _CGraphicsContextWin32New(IGraphicsContext::EGraphicsAPI api,
IWindow* parentWindow);
struct GraphicsContextWin32 : IGraphicsContext
{
EGraphicsAPI m_api;
EPixelFormat m_pf;
IWindow* m_parentWindow;
public:
IWindowCallback* m_callback;
GraphicsContextWin32(EGraphicsAPI api, IWindow* parentWindow)
: m_api(api),
m_pf(PF_RGBA8),
m_parentWindow(parentWindow)
{}
~GraphicsContextWin32()
{
}
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()
{
}
};
class CWindowWin32 final : public IWindow
class WindowWin32 : public IWindow
{
HWND m_hwnd;
public:
CWindowWin32(const std::string& title)
WindowWin32(const SystemString& title)
{
m_hwnd = CreateWindowW(L"BooWindow", L"BooTest", WS_OVERLAPPEDWINDOW,
m_hwnd = CreateWindowW(L"BooWindow", title.c_str(), WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, hInstance, NULL);
NULL, NULL, NULL, NULL);
}
~CWindowWin32()
~WindowWin32()
{
}
@@ -41,14 +112,16 @@ public:
}
std::string getTitle()
SystemString getTitle()
{
wchar_t title[256];
int c = GetWindowTextW(m_hwnd, title, 256);
return SystemString(title, c);
}
void setTitle(const std::string& title)
void setTitle(const SystemString& title)
{
SetWindowTextW(m_hwnd, title.c_str());
}
void setWindowFrameDefault()
@@ -68,29 +141,38 @@ public:
float getVirtualPixelFactor() const
{
return 1.0;
}
bool isFullscreen() const
{
return false;
}
void setFullscreen(bool fs)
{
}
void waitForRetrace()
{
}
uintptr_t getPlatformHandle() const
{
return uintptr_t(m_hwnd);
}
ETouchType getTouchType() const
{
return TOUCH_NONE;
}
};
IWindow* _CWindowWin32New(const std::string& title)
IWindow* _WindowWin32New(const SystemString& title)
{
return new CWindowWin32(title);
return new WindowWin32(title);
}
}