2015-11-03 04:19:41 +00:00
|
|
|
#include "Win32Common.hpp"
|
|
|
|
#include <Windowsx.h>
|
2015-08-31 03:40:58 +00:00
|
|
|
#include "boo/IWindow.hpp"
|
|
|
|
#include "boo/IGraphicsContext.hpp"
|
2015-11-03 04:19:41 +00:00
|
|
|
#include <LogVisor/LogVisor.hpp>
|
|
|
|
|
2015-11-06 03:20:58 +00:00
|
|
|
#include "boo/graphicsdev/D3D.hpp"
|
2015-11-07 01:43:12 +00:00
|
|
|
#include "boo/graphicsdev/GL.hpp"
|
2015-11-10 20:11:08 +00:00
|
|
|
#include "boo/graphicsdev/glew.h"
|
2015-11-07 01:43:12 +00:00
|
|
|
#include "boo/graphicsdev/wglew.h"
|
|
|
|
|
|
|
|
static const int ContextAttribs[] =
|
|
|
|
{
|
|
|
|
WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
|
|
|
|
WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
|
|
|
|
WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
|
|
|
|
//WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_DEBUG_BIT_ARB,
|
|
|
|
//WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
|
|
|
|
0, 0
|
|
|
|
};
|
2015-05-06 00:50:57 +00:00
|
|
|
|
|
|
|
namespace boo
|
|
|
|
{
|
2015-11-10 20:11:08 +00:00
|
|
|
static LogVisor::LogModule Log("boo::WindowWin32");
|
2015-11-06 03:20:58 +00:00
|
|
|
#if _WIN32_WINNT_WIN10
|
2015-11-05 00:00:29 +00:00
|
|
|
IGraphicsCommandQueue* _NewD3D12CommandQueue(D3D12Context* ctx, D3D12Context::Window* windowCtx, IGraphicsContext* parent,
|
|
|
|
ID3D12CommandQueue** cmdQueueOut);
|
2015-11-06 03:20:58 +00:00
|
|
|
IGraphicsDataFactory* _NewD3D12DataFactory(D3D12Context* ctx, IGraphicsContext* parent);
|
|
|
|
#endif
|
2015-11-04 00:27:32 +00:00
|
|
|
IGraphicsCommandQueue* _NewD3D11CommandQueue(D3D11Context* ctx, D3D11Context::Window* windowCtx, IGraphicsContext* parent);
|
2015-11-06 03:20:58 +00:00
|
|
|
IGraphicsDataFactory* _NewD3D11DataFactory(D3D11Context* ctx, IGraphicsContext* parent);
|
2015-11-07 01:43:12 +00:00
|
|
|
IGraphicsCommandQueue* _NewGLCommandQueue(IGraphicsContext* parent);
|
2015-11-03 04:19:41 +00:00
|
|
|
|
2015-08-31 03:40:58 +00:00
|
|
|
struct GraphicsContextWin32 : IGraphicsContext
|
|
|
|
{
|
|
|
|
EGraphicsAPI m_api;
|
|
|
|
EPixelFormat m_pf;
|
2015-11-05 00:00:29 +00:00
|
|
|
IWindow* m_parentWindow;
|
2015-11-07 01:43:12 +00:00
|
|
|
Boo3DAppContext& m_3dCtx;
|
|
|
|
ComPtr<IDXGIOutput> m_output;
|
|
|
|
GraphicsContextWin32(EGraphicsAPI api, IWindow* parentWindow, Boo3DAppContext& b3dCtx)
|
|
|
|
: m_api(api),
|
2015-11-21 02:58:56 +00:00
|
|
|
m_pf(EPixelFormat::RGBA8),
|
2015-11-07 01:43:12 +00:00
|
|
|
m_parentWindow(parentWindow),
|
|
|
|
m_3dCtx(b3dCtx) {}
|
|
|
|
};
|
2015-11-03 04:19:41 +00:00
|
|
|
|
2015-11-07 01:43:12 +00:00
|
|
|
struct GraphicsContextWin32D3D : GraphicsContextWin32
|
|
|
|
{
|
2015-11-03 04:19:41 +00:00
|
|
|
ComPtr<IDXGISwapChain1> m_swapChain;
|
|
|
|
|
|
|
|
IGraphicsCommandQueue* m_commandQueue = nullptr;
|
|
|
|
IGraphicsDataFactory* m_dataFactory = nullptr;
|
2015-08-31 03:40:58 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
IWindowCallback* m_callback;
|
|
|
|
|
2015-11-07 01:43:12 +00:00
|
|
|
GraphicsContextWin32D3D(EGraphicsAPI api, IWindow* parentWindow, HWND hwnd, Boo3DAppContext& b3dCtx)
|
|
|
|
: GraphicsContextWin32(api, parentWindow, b3dCtx)
|
2015-11-03 04:19:41 +00:00
|
|
|
{
|
|
|
|
/* Create Swap Chain */
|
|
|
|
DXGI_SWAP_CHAIN_DESC1 scDesc = {};
|
|
|
|
scDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
|
|
|
|
scDesc.SampleDesc.Count = 1;
|
|
|
|
scDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
|
|
|
|
scDesc.BufferCount = 2;
|
|
|
|
scDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
|
|
|
|
scDesc.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
|
|
|
|
|
|
|
|
#if _WIN32_WINNT_WIN10
|
2015-11-07 01:43:12 +00:00
|
|
|
if (b3dCtx.m_ctx12.m_dev)
|
2015-11-03 04:19:41 +00:00
|
|
|
{
|
2015-11-07 01:43:12 +00:00
|
|
|
auto insIt = b3dCtx.m_ctx12.m_windows.emplace(std::make_pair(parentWindow, D3D12Context::Window()));
|
2015-11-04 00:27:32 +00:00
|
|
|
D3D12Context::Window& w = insIt.first->second;
|
2015-11-05 00:00:29 +00:00
|
|
|
|
|
|
|
ID3D12CommandQueue* cmdQueue;
|
2015-11-07 01:43:12 +00:00
|
|
|
m_dataFactory = _NewD3D12DataFactory(&b3dCtx.m_ctx12, this);
|
|
|
|
m_commandQueue = _NewD3D12CommandQueue(&b3dCtx.m_ctx12, &w, this, &cmdQueue);
|
2015-11-05 00:00:29 +00:00
|
|
|
|
2015-11-06 03:20:58 +00:00
|
|
|
scDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD;
|
2015-11-07 01:43:12 +00:00
|
|
|
HRESULT hr = b3dCtx.m_ctx12.m_dxFactory->CreateSwapChainForHwnd(cmdQueue,
|
2015-11-05 00:00:29 +00:00
|
|
|
hwnd, &scDesc, nullptr, nullptr, &m_swapChain);
|
|
|
|
if (FAILED(hr))
|
|
|
|
Log.report(LogVisor::FatalError, "unable to create swap chain");
|
2015-11-07 01:43:12 +00:00
|
|
|
b3dCtx.m_ctx12.m_dxFactory->MakeWindowAssociation(hwnd, DXGI_MWA_NO_ALT_ENTER);
|
2015-11-05 00:00:29 +00:00
|
|
|
|
2015-11-04 00:27:32 +00:00
|
|
|
m_swapChain.As<IDXGISwapChain3>(&w.m_swapChain);
|
2015-11-05 04:57:48 +00:00
|
|
|
ComPtr<ID3D12Resource> fb;
|
|
|
|
m_swapChain->GetBuffer(0, __uuidof(ID3D12Resource), &fb);
|
2015-11-04 00:27:32 +00:00
|
|
|
w.m_backBuf = w.m_swapChain->GetCurrentBackBufferIndex();
|
2015-11-05 04:57:48 +00:00
|
|
|
D3D12_RESOURCE_DESC resDesc = fb->GetDesc();
|
2015-11-04 00:27:32 +00:00
|
|
|
w.width = resDesc.Width;
|
|
|
|
w.height = resDesc.Height;
|
2015-11-07 01:43:12 +00:00
|
|
|
|
|
|
|
if (FAILED(m_swapChain->GetContainingOutput(&m_output)))
|
|
|
|
Log.report(LogVisor::FatalError, "unable to get DXGI output");
|
2015-11-03 04:19:41 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
2015-11-07 01:43:12 +00:00
|
|
|
if (FAILED(b3dCtx.m_ctx11.m_dxFactory->CreateSwapChainForHwnd(b3dCtx.m_ctx11.m_dev.Get(),
|
2015-11-05 00:00:29 +00:00
|
|
|
hwnd, &scDesc, nullptr, nullptr, &m_swapChain)))
|
|
|
|
Log.report(LogVisor::FatalError, "unable to create swap chain");
|
2015-11-07 01:43:12 +00:00
|
|
|
b3dCtx.m_ctx11.m_dxFactory->MakeWindowAssociation(hwnd, DXGI_MWA_NO_ALT_ENTER);
|
2015-11-05 00:00:29 +00:00
|
|
|
|
2015-11-07 01:43:12 +00:00
|
|
|
auto insIt = b3dCtx.m_ctx11.m_windows.emplace(std::make_pair(parentWindow, D3D11Context::Window()));
|
2015-11-04 00:27:32 +00:00
|
|
|
D3D11Context::Window& w = insIt.first->second;
|
2015-11-06 03:20:58 +00:00
|
|
|
|
|
|
|
m_swapChain.As<IDXGISwapChain1>(&w.m_swapChain);
|
2015-11-04 00:27:32 +00:00
|
|
|
ComPtr<ID3D11Texture2D> fbRes;
|
|
|
|
m_swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), &fbRes);
|
|
|
|
D3D11_TEXTURE2D_DESC resDesc;
|
|
|
|
fbRes->GetDesc(&resDesc);
|
|
|
|
w.width = resDesc.Width;
|
|
|
|
w.height = resDesc.Height;
|
2015-11-07 01:43:12 +00:00
|
|
|
m_dataFactory = _NewD3D11DataFactory(&b3dCtx.m_ctx11, this);
|
|
|
|
m_commandQueue = _NewD3D11CommandQueue(&b3dCtx.m_ctx11, &insIt.first->second, this);
|
2015-11-05 00:00:29 +00:00
|
|
|
|
2015-11-07 01:43:12 +00:00
|
|
|
if (FAILED(m_swapChain->GetContainingOutput(&m_output)))
|
|
|
|
Log.report(LogVisor::FatalError, "unable to get DXGI output");
|
|
|
|
}
|
2015-11-03 04:19:41 +00:00
|
|
|
}
|
2015-08-31 03:40:58 +00:00
|
|
|
|
2015-11-07 01:43:12 +00:00
|
|
|
~GraphicsContextWin32D3D()
|
2015-08-31 03:40:58 +00:00
|
|
|
{
|
2015-11-04 00:27:32 +00:00
|
|
|
#if _WIN32_WINNT_WIN10
|
2015-11-07 01:43:12 +00:00
|
|
|
if (m_3dCtx.m_ctx12.m_dev)
|
|
|
|
m_3dCtx.m_ctx12.m_windows.erase(m_parentWindow);
|
2015-11-04 00:27:32 +00:00
|
|
|
else
|
|
|
|
#endif
|
2015-11-07 01:43:12 +00:00
|
|
|
m_3dCtx.m_ctx11.m_windows.erase(m_parentWindow);
|
2015-08-31 03:40:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void _setCallback(IWindowCallback* cb)
|
|
|
|
{
|
|
|
|
m_callback = cb;
|
|
|
|
}
|
|
|
|
|
|
|
|
EGraphicsAPI getAPI() const
|
|
|
|
{
|
|
|
|
return m_api;
|
|
|
|
}
|
|
|
|
|
|
|
|
EPixelFormat getPixelFormat() const
|
|
|
|
{
|
|
|
|
return m_pf;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setPixelFormat(EPixelFormat pf)
|
|
|
|
{
|
2015-11-21 02:58:56 +00:00
|
|
|
if (pf > EPixelFormat::RGBAF32_Z24)
|
2015-08-31 03:40:58 +00:00
|
|
|
return;
|
|
|
|
m_pf = pf;
|
|
|
|
}
|
|
|
|
|
2015-11-03 04:19:41 +00:00
|
|
|
void initializeContext() {}
|
2015-08-31 03:40:58 +00:00
|
|
|
|
2015-11-03 04:19:41 +00:00
|
|
|
void makeCurrent() {}
|
2015-08-31 03:40:58 +00:00
|
|
|
|
2015-11-03 04:19:41 +00:00
|
|
|
void postInit() {}
|
2015-08-31 03:40:58 +00:00
|
|
|
|
2015-11-03 04:19:41 +00:00
|
|
|
void present() {}
|
2015-08-31 03:40:58 +00:00
|
|
|
|
2015-11-03 04:19:41 +00:00
|
|
|
IGraphicsCommandQueue* getCommandQueue()
|
2015-08-31 03:40:58 +00:00
|
|
|
{
|
2015-11-05 00:00:29 +00:00
|
|
|
return m_commandQueue;
|
2015-08-31 03:40:58 +00:00
|
|
|
}
|
|
|
|
|
2015-11-03 04:19:41 +00:00
|
|
|
IGraphicsDataFactory* getDataFactory()
|
2015-08-31 03:40:58 +00:00
|
|
|
{
|
2015-11-05 00:00:29 +00:00
|
|
|
return m_dataFactory;
|
2015-08-31 03:40:58 +00:00
|
|
|
}
|
|
|
|
|
2015-11-18 06:14:49 +00:00
|
|
|
IGraphicsDataFactory* getMainContextDataFactory()
|
|
|
|
{
|
|
|
|
return m_dataFactory;
|
|
|
|
}
|
|
|
|
|
2015-11-07 01:43:12 +00:00
|
|
|
IGraphicsDataFactory* getLoadContextDataFactory()
|
|
|
|
{
|
|
|
|
return m_dataFactory;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct GraphicsContextWin32GL : GraphicsContextWin32
|
|
|
|
{
|
|
|
|
IGraphicsCommandQueue* m_commandQueue = nullptr;
|
|
|
|
IGraphicsDataFactory* m_dataFactory = nullptr;
|
|
|
|
|
|
|
|
public:
|
|
|
|
IWindowCallback* m_callback;
|
|
|
|
|
|
|
|
GraphicsContextWin32GL(EGraphicsAPI api, IWindow* parentWindow, HWND hwnd, Boo3DAppContext& b3dCtx)
|
|
|
|
: GraphicsContextWin32(api, parentWindow, b3dCtx)
|
|
|
|
{
|
|
|
|
|
|
|
|
HMONITOR testMon = MonitorFromWindow(hwnd, MONITOR_DEFAULTTOPRIMARY);
|
|
|
|
ComPtr<IDXGIAdapter1> adapter;
|
|
|
|
ComPtr<IDXGIOutput> foundOut;
|
|
|
|
int i=0;
|
|
|
|
while (b3dCtx.m_ctxOgl.m_dxFactory->EnumAdapters1(i, &adapter) != DXGI_ERROR_NOT_FOUND)
|
|
|
|
{
|
|
|
|
int j=0;
|
|
|
|
ComPtr<IDXGIOutput> out;
|
|
|
|
while (adapter->EnumOutputs(j, &out) != DXGI_ERROR_NOT_FOUND)
|
|
|
|
{
|
|
|
|
DXGI_OUTPUT_DESC desc;
|
|
|
|
out->GetDesc(&desc);
|
|
|
|
if (desc.Monitor == testMon)
|
|
|
|
{
|
|
|
|
out.As<IDXGIOutput>(&m_output);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++j;
|
|
|
|
}
|
|
|
|
if (m_output)
|
|
|
|
break;
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!m_output)
|
|
|
|
Log.report(LogVisor::FatalError, "unable to find window's IDXGIOutput");
|
|
|
|
|
|
|
|
auto insIt = b3dCtx.m_ctxOgl.m_windows.emplace(std::make_pair(parentWindow, OGLContext::Window()));
|
|
|
|
OGLContext::Window& w = insIt.first->second;
|
|
|
|
w.m_hwnd = hwnd;
|
|
|
|
w.m_deviceContext = GetDC(hwnd);
|
|
|
|
if (!w.m_deviceContext)
|
|
|
|
Log.report(LogVisor::FatalError, "unable to create window's device context");
|
|
|
|
|
|
|
|
if (!m_3dCtx.m_ctxOgl.m_lastContext)
|
|
|
|
{
|
|
|
|
PIXELFORMATDESCRIPTOR pfd =
|
|
|
|
{
|
|
|
|
sizeof(PIXELFORMATDESCRIPTOR),
|
|
|
|
1,
|
|
|
|
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, //Flags
|
|
|
|
PFD_TYPE_RGBA, //The kind of framebuffer. RGBA or palette.
|
|
|
|
32, //Colordepth of the framebuffer.
|
|
|
|
0, 0, 0, 0, 0, 0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0, 0, 0, 0,
|
|
|
|
24, //Number of bits for the depthbuffer
|
|
|
|
8, //Number of bits for the stencilbuffer
|
|
|
|
0, //Number of Aux buffers in the framebuffer.
|
|
|
|
PFD_MAIN_PLANE,
|
|
|
|
0,
|
|
|
|
0, 0, 0
|
|
|
|
};
|
|
|
|
|
|
|
|
int pf = ChoosePixelFormat(w.m_deviceContext, &pfd);
|
|
|
|
SetPixelFormat(w.m_deviceContext, pf, &pfd);
|
|
|
|
}
|
|
|
|
|
|
|
|
w.m_mainContext = wglCreateContext(w.m_deviceContext);
|
|
|
|
if (!w.m_mainContext)
|
|
|
|
Log.report(LogVisor::FatalError, "unable to create window's main context");
|
|
|
|
if (m_3dCtx.m_ctxOgl.m_lastContext)
|
|
|
|
if (!wglShareLists(w.m_mainContext, m_3dCtx.m_ctxOgl.m_lastContext))
|
|
|
|
Log.report(LogVisor::FatalError, "unable to share contexts");
|
|
|
|
m_3dCtx.m_ctxOgl.m_lastContext = w.m_mainContext;
|
|
|
|
|
|
|
|
m_dataFactory = new GLDataFactory(this);
|
|
|
|
m_commandQueue = _NewGLCommandQueue(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
~GraphicsContextWin32GL()
|
|
|
|
{
|
|
|
|
m_3dCtx.m_ctxOgl.m_windows.erase(m_parentWindow);
|
|
|
|
}
|
|
|
|
|
|
|
|
void _setCallback(IWindowCallback* cb)
|
|
|
|
{
|
|
|
|
m_callback = cb;
|
|
|
|
}
|
|
|
|
|
|
|
|
EGraphicsAPI getAPI() const
|
|
|
|
{
|
|
|
|
return m_api;
|
|
|
|
}
|
|
|
|
|
|
|
|
EPixelFormat getPixelFormat() const
|
|
|
|
{
|
|
|
|
return m_pf;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setPixelFormat(EPixelFormat pf)
|
|
|
|
{
|
2015-11-21 02:58:56 +00:00
|
|
|
if (pf > EPixelFormat::RGBAF32_Z24)
|
2015-11-07 01:43:12 +00:00
|
|
|
return;
|
|
|
|
m_pf = pf;
|
|
|
|
}
|
|
|
|
|
|
|
|
void initializeContext() {}
|
|
|
|
|
|
|
|
void makeCurrent()
|
|
|
|
{
|
|
|
|
OGLContext::Window& w = m_3dCtx.m_ctxOgl.m_windows[m_parentWindow];
|
|
|
|
if (!wglMakeCurrent(w.m_deviceContext, w.m_mainContext))
|
|
|
|
Log.report(LogVisor::FatalError, "unable to make WGL context current");
|
|
|
|
}
|
|
|
|
|
|
|
|
void postInit()
|
|
|
|
{
|
|
|
|
OGLContext::Window& w = m_3dCtx.m_ctxOgl.m_windows[m_parentWindow];
|
|
|
|
|
|
|
|
wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC)
|
|
|
|
wglGetProcAddress("wglCreateContextAttribsARB");
|
|
|
|
w.m_renderContext = wglCreateContextAttribsARB(w.m_deviceContext, w.m_mainContext, ContextAttribs);
|
|
|
|
if (!w.m_renderContext)
|
|
|
|
Log.report(LogVisor::FatalError, "unable to make new WGL context");
|
|
|
|
if (!wglMakeCurrent(w.m_deviceContext, w.m_renderContext))
|
|
|
|
Log.report(LogVisor::FatalError, "unable to make WGL context current");
|
|
|
|
|
|
|
|
if (!WGLEW_EXT_swap_control)
|
|
|
|
Log.report(LogVisor::FatalError, "WGL_EXT_swap_control not available");
|
|
|
|
wglSwapIntervalEXT(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void present()
|
|
|
|
{
|
|
|
|
OGLContext::Window& w = m_3dCtx.m_ctxOgl.m_windows[m_parentWindow];
|
|
|
|
if (!SwapBuffers(w.m_deviceContext))
|
|
|
|
Log.report(LogVisor::FatalError, "SwapBuffers err");
|
|
|
|
}
|
|
|
|
|
|
|
|
IGraphicsCommandQueue* getCommandQueue()
|
|
|
|
{
|
|
|
|
return m_commandQueue;
|
|
|
|
}
|
|
|
|
|
|
|
|
IGraphicsDataFactory* getDataFactory()
|
|
|
|
{
|
|
|
|
return m_dataFactory;
|
|
|
|
}
|
|
|
|
|
2015-11-18 06:14:49 +00:00
|
|
|
/* Creates a new context on current thread!! Call from client loading thread */
|
|
|
|
HGLRC m_mainCtx = 0;
|
|
|
|
IGraphicsDataFactory* getMainContextDataFactory()
|
|
|
|
{
|
|
|
|
OGLContext::Window& w = m_3dCtx.m_ctxOgl.m_windows[m_parentWindow];
|
|
|
|
if (!m_mainCtx)
|
|
|
|
{
|
|
|
|
m_mainCtx = wglCreateContextAttribsARB(w.m_deviceContext, w.m_mainContext, ContextAttribs);
|
|
|
|
if (!m_mainCtx)
|
|
|
|
Log.report(LogVisor::FatalError, "unable to make main WGL context");
|
|
|
|
}
|
|
|
|
if (!wglMakeCurrent(w.m_deviceContext, m_mainCtx))
|
|
|
|
Log.report(LogVisor::FatalError, "unable to make main WGL context current");
|
|
|
|
return m_dataFactory;
|
|
|
|
}
|
|
|
|
|
2015-11-03 04:19:41 +00:00
|
|
|
/* Creates a new context on current thread!! Call from client loading thread */
|
2015-11-07 01:43:12 +00:00
|
|
|
HGLRC m_loadCtx = 0;
|
2015-11-03 04:19:41 +00:00
|
|
|
IGraphicsDataFactory* getLoadContextDataFactory()
|
2015-08-31 03:40:58 +00:00
|
|
|
{
|
2015-11-07 01:43:12 +00:00
|
|
|
OGLContext::Window& w = m_3dCtx.m_ctxOgl.m_windows[m_parentWindow];
|
|
|
|
if (!m_loadCtx)
|
|
|
|
{
|
|
|
|
m_loadCtx = wglCreateContextAttribsARB(w.m_deviceContext, w.m_mainContext, ContextAttribs);
|
|
|
|
if (!m_loadCtx)
|
|
|
|
Log.report(LogVisor::FatalError, "unable to make load WGL context");
|
|
|
|
}
|
|
|
|
if (!wglMakeCurrent(w.m_deviceContext, m_loadCtx))
|
|
|
|
Log.report(LogVisor::FatalError, "unable to make load WGL context current");
|
2015-11-05 00:00:29 +00:00
|
|
|
return m_dataFactory;
|
2015-08-31 03:40:58 +00:00
|
|
|
}
|
|
|
|
};
|
2015-11-03 04:19:41 +00:00
|
|
|
|
|
|
|
static void genFrameDefault(MONITORINFO* screen, int& xOut, int& yOut, int& wOut, int& hOut)
|
|
|
|
{
|
|
|
|
float width = screen->rcMonitor.right * 2.0 / 3.0;
|
|
|
|
float height = screen->rcMonitor.bottom * 2.0 / 3.0;
|
|
|
|
xOut = (screen->rcMonitor.right - width) / 2.0;
|
|
|
|
yOut = (screen->rcMonitor.bottom - height) / 2.0;
|
|
|
|
wOut = width;
|
|
|
|
hOut = height;
|
|
|
|
}
|
|
|
|
|
2015-11-21 02:58:56 +00:00
|
|
|
static uint32_t translateKeysym(WPARAM sym, ESpecialKey& specialSym, EModifierKey& modifierSym)
|
2015-11-03 04:19:41 +00:00
|
|
|
{
|
2015-11-21 02:58:56 +00:00
|
|
|
specialSym = ESpecialKey::None;
|
|
|
|
modifierSym = EModifierKey::None;
|
2015-11-03 04:19:41 +00:00
|
|
|
if (sym >= VK_F1 && sym <= VK_F12)
|
2015-11-21 02:58:56 +00:00
|
|
|
specialSym = ESpecialKey(uint32_t(ESpecialKey::F1) + sym - VK_F1);
|
2015-11-03 04:19:41 +00:00
|
|
|
else if (sym == VK_ESCAPE)
|
2015-11-21 02:58:56 +00:00
|
|
|
specialSym = ESpecialKey::Esc;
|
2015-11-03 04:19:41 +00:00
|
|
|
else if (sym == VK_RETURN)
|
2015-11-21 02:58:56 +00:00
|
|
|
specialSym = ESpecialKey::Enter;
|
2015-11-03 04:19:41 +00:00
|
|
|
else if (sym == VK_BACK)
|
2015-11-21 02:58:56 +00:00
|
|
|
specialSym = ESpecialKey::Backspace;
|
2015-11-03 04:19:41 +00:00
|
|
|
else if (sym == VK_INSERT)
|
2015-11-21 02:58:56 +00:00
|
|
|
specialSym = ESpecialKey::Insert;
|
2015-11-03 04:19:41 +00:00
|
|
|
else if (sym == VK_DELETE)
|
2015-11-21 02:58:56 +00:00
|
|
|
specialSym = ESpecialKey::Delete;
|
2015-11-03 04:19:41 +00:00
|
|
|
else if (sym == VK_HOME)
|
2015-11-21 02:58:56 +00:00
|
|
|
specialSym = ESpecialKey::Home;
|
2015-11-03 04:19:41 +00:00
|
|
|
else if (sym == VK_END)
|
2015-11-21 02:58:56 +00:00
|
|
|
specialSym = ESpecialKey::End;
|
2015-11-03 04:19:41 +00:00
|
|
|
else if (sym == VK_PRIOR)
|
2015-11-21 02:58:56 +00:00
|
|
|
specialSym = ESpecialKey::PgUp;
|
2015-11-03 04:19:41 +00:00
|
|
|
else if (sym == VK_NEXT)
|
2015-11-21 02:58:56 +00:00
|
|
|
specialSym = ESpecialKey::PgDown;
|
2015-11-03 04:19:41 +00:00
|
|
|
else if (sym == VK_LEFT)
|
2015-11-21 02:58:56 +00:00
|
|
|
specialSym = ESpecialKey::Left;
|
2015-11-03 04:19:41 +00:00
|
|
|
else if (sym == VK_RIGHT)
|
2015-11-21 02:58:56 +00:00
|
|
|
specialSym = ESpecialKey::Right;
|
2015-11-03 04:19:41 +00:00
|
|
|
else if (sym == VK_UP)
|
2015-11-21 02:58:56 +00:00
|
|
|
specialSym = ESpecialKey::Up;
|
2015-11-03 04:19:41 +00:00
|
|
|
else if (sym == VK_DOWN)
|
2015-11-21 02:58:56 +00:00
|
|
|
specialSym = ESpecialKey::Down;
|
2015-11-03 04:19:41 +00:00
|
|
|
else if (sym == VK_LSHIFT || sym == VK_RSHIFT)
|
2015-11-21 02:58:56 +00:00
|
|
|
modifierSym = EModifierKey::Shift;
|
2015-11-03 04:19:41 +00:00
|
|
|
else if (sym == VK_LCONTROL || sym == VK_RCONTROL)
|
2015-11-21 02:58:56 +00:00
|
|
|
modifierSym = EModifierKey::Ctrl;
|
2015-11-03 04:19:41 +00:00
|
|
|
else if (sym == VK_MENU)
|
2015-11-21 02:58:56 +00:00
|
|
|
modifierSym = EModifierKey::Alt;
|
2015-11-03 04:19:41 +00:00
|
|
|
else
|
|
|
|
return MapVirtualKey(sym, MAPVK_VK_TO_CHAR);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-11-21 02:58:56 +00:00
|
|
|
static EModifierKey translateModifiers(UINT msg)
|
2015-11-03 04:19:41 +00:00
|
|
|
{
|
2015-11-21 02:58:56 +00:00
|
|
|
EModifierKey retval = EModifierKey::None;
|
2015-11-14 06:12:39 +00:00
|
|
|
if ((GetKeyState(VK_LSHIFT) & 0x8000) != 0 || (GetKeyState(VK_RSHIFT) & 0x8000) != 0)
|
2015-11-21 02:58:56 +00:00
|
|
|
retval |= EModifierKey::Shift;
|
2015-11-14 06:12:39 +00:00
|
|
|
if ((GetKeyState(VK_LCONTROL) & 0x8000) != 0 || (GetKeyState(VK_RCONTROL) & 0x8000) != 0)
|
2015-11-21 02:58:56 +00:00
|
|
|
retval |= EModifierKey::Ctrl;
|
2015-11-14 06:12:39 +00:00
|
|
|
if ((GetKeyState(VK_MENU) & 0x8000) != 0)
|
2015-11-21 02:58:56 +00:00
|
|
|
retval |= EModifierKey::Alt;
|
2015-11-06 03:20:58 +00:00
|
|
|
if (msg == WM_SYSKEYDOWN || msg == WM_SYSKEYUP)
|
2015-11-21 02:58:56 +00:00
|
|
|
retval |= EModifierKey::Alt;
|
2015-11-03 04:19:41 +00:00
|
|
|
return retval;
|
|
|
|
}
|
2015-05-06 00:50:57 +00:00
|
|
|
|
2015-08-31 03:40:58 +00:00
|
|
|
class WindowWin32 : public IWindow
|
2015-05-06 00:50:57 +00:00
|
|
|
{
|
2015-11-21 02:58:56 +00:00
|
|
|
friend struct GraphicsContextWin32;
|
2015-05-06 00:50:57 +00:00
|
|
|
HWND m_hwnd;
|
2015-11-03 04:19:41 +00:00
|
|
|
std::unique_ptr<GraphicsContextWin32> m_gfxCtx;
|
|
|
|
IWindowCallback* m_callback = nullptr;
|
2015-12-01 00:33:14 +00:00
|
|
|
EMouseCursor m_cursor = EMouseCursor::None;
|
|
|
|
bool m_cursorWait = false;
|
|
|
|
static HCURSOR GetWin32Cursor(EMouseCursor cur)
|
|
|
|
{
|
|
|
|
switch (cur)
|
|
|
|
{
|
|
|
|
case EMouseCursor::Pointer:
|
|
|
|
return WIN32_CURSORS.m_arrow;
|
|
|
|
case EMouseCursor::HorizontalArrow:
|
|
|
|
return WIN32_CURSORS.m_hResize;
|
|
|
|
case EMouseCursor::VerticalArrow:
|
|
|
|
return WIN32_CURSORS.m_vResize;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
return WIN32_CURSORS.m_arrow;
|
|
|
|
}
|
2015-11-07 07:49:53 +00:00
|
|
|
|
2015-05-06 00:50:57 +00:00
|
|
|
public:
|
2015-11-07 07:49:53 +00:00
|
|
|
|
2015-11-07 01:43:12 +00:00
|
|
|
WindowWin32(const SystemString& title, Boo3DAppContext& b3dCtx)
|
2015-05-06 00:50:57 +00:00
|
|
|
{
|
2015-08-31 03:40:58 +00:00
|
|
|
m_hwnd = CreateWindowW(L"BooWindow", title.c_str(), WS_OVERLAPPEDWINDOW,
|
2015-11-07 07:52:27 +00:00
|
|
|
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
|
|
|
|
NULL, NULL, NULL, NULL);
|
2015-11-21 02:58:56 +00:00
|
|
|
IGraphicsContext::EGraphicsAPI api = IGraphicsContext::EGraphicsAPI::D3D11;
|
2015-11-07 05:25:43 +00:00
|
|
|
#if _WIN32_WINNT_WIN10
|
2015-11-07 01:43:12 +00:00
|
|
|
if (b3dCtx.m_ctx12.m_dev)
|
2015-11-21 02:58:56 +00:00
|
|
|
api = IGraphicsContext::EGraphicsAPI::D3D12;
|
2015-11-07 05:25:43 +00:00
|
|
|
#endif
|
|
|
|
if (b3dCtx.m_ctxOgl.m_dxFactory)
|
2015-11-07 01:43:12 +00:00
|
|
|
{
|
2015-11-21 02:58:56 +00:00
|
|
|
m_gfxCtx.reset(new GraphicsContextWin32GL(IGraphicsContext::EGraphicsAPI::OpenGL3_3, this, m_hwnd, b3dCtx));
|
2015-11-07 01:43:12 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_gfxCtx.reset(new GraphicsContextWin32D3D(api, this, m_hwnd, b3dCtx));
|
2015-05-06 00:50:57 +00:00
|
|
|
}
|
2015-11-07 07:49:53 +00:00
|
|
|
|
2015-08-31 03:40:58 +00:00
|
|
|
~WindowWin32()
|
2015-05-06 00:50:57 +00:00
|
|
|
{
|
2015-11-07 07:49:53 +00:00
|
|
|
|
2015-05-06 00:50:57 +00:00
|
|
|
}
|
2015-11-07 07:49:53 +00:00
|
|
|
|
2015-05-06 00:50:57 +00:00
|
|
|
void setCallback(IWindowCallback* cb)
|
|
|
|
{
|
2015-11-03 04:19:41 +00:00
|
|
|
m_callback = cb;
|
2015-05-06 00:50:57 +00:00
|
|
|
}
|
2015-11-07 07:49:53 +00:00
|
|
|
|
2015-05-06 00:50:57 +00:00
|
|
|
void showWindow()
|
|
|
|
{
|
2015-11-03 04:19:41 +00:00
|
|
|
ShowWindow(m_hwnd, SW_SHOW);
|
2015-05-06 00:50:57 +00:00
|
|
|
}
|
2015-11-07 07:49:53 +00:00
|
|
|
|
2015-05-06 00:50:57 +00:00
|
|
|
void hideWindow()
|
|
|
|
{
|
2015-11-03 04:19:41 +00:00
|
|
|
ShowWindow(m_hwnd, SW_HIDE);
|
2015-05-06 00:50:57 +00:00
|
|
|
}
|
2015-11-07 07:49:53 +00:00
|
|
|
|
2015-08-31 03:40:58 +00:00
|
|
|
SystemString getTitle()
|
2015-05-06 00:50:57 +00:00
|
|
|
{
|
2015-11-07 07:49:53 +00:00
|
|
|
wchar_t title[256];
|
|
|
|
int c = GetWindowTextW(m_hwnd, title, 256);
|
|
|
|
return SystemString(title, c);
|
2015-05-06 00:50:57 +00:00
|
|
|
}
|
2015-11-07 07:49:53 +00:00
|
|
|
|
2015-08-31 03:40:58 +00:00
|
|
|
void setTitle(const SystemString& title)
|
2015-05-06 00:50:57 +00:00
|
|
|
{
|
2015-08-31 03:40:58 +00:00
|
|
|
SetWindowTextW(m_hwnd, title.c_str());
|
2015-05-06 00:50:57 +00:00
|
|
|
}
|
2015-11-07 07:49:53 +00:00
|
|
|
|
2015-12-01 00:33:14 +00:00
|
|
|
static void _setCursor(HCURSOR cur)
|
|
|
|
{
|
|
|
|
PostThreadMessageW(g_mainThreadId, WM_USER+2, WPARAM(cur), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setCursor(EMouseCursor cursor)
|
|
|
|
{
|
|
|
|
if (cursor == m_cursor && !m_cursorWait)
|
|
|
|
return;
|
|
|
|
m_cursor = cursor;
|
|
|
|
_setCursor(GetWin32Cursor(cursor));
|
|
|
|
}
|
|
|
|
|
|
|
|
void setWaitCursor(bool wait)
|
|
|
|
{
|
|
|
|
if (wait && !m_cursorWait)
|
|
|
|
{
|
|
|
|
_setCursor(WIN32_CURSORS.m_wait);
|
|
|
|
m_cursorWait = true;
|
|
|
|
}
|
|
|
|
else if (!wait && m_cursorWait)
|
|
|
|
{
|
|
|
|
setCursor(m_cursor);
|
|
|
|
m_cursorWait = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-06 00:50:57 +00:00
|
|
|
void setWindowFrameDefault()
|
|
|
|
{
|
2015-11-03 04:19:41 +00:00
|
|
|
MONITORINFO monInfo;
|
|
|
|
GetMonitorInfo(MonitorFromWindow(m_hwnd, MONITOR_DEFAULTTOPRIMARY), &monInfo);
|
|
|
|
int x, y, w, h;
|
|
|
|
genFrameDefault(&monInfo, x, y, w, h);
|
|
|
|
setWindowFrame(x, y, w, h);
|
2015-05-06 00:50:57 +00:00
|
|
|
}
|
2015-11-07 07:49:53 +00:00
|
|
|
|
2015-05-06 00:50:57 +00:00
|
|
|
void getWindowFrame(float& xOut, float& yOut, float& wOut, float& hOut) const
|
|
|
|
{
|
2015-11-03 04:19:41 +00:00
|
|
|
RECT rct;
|
2015-11-05 04:57:48 +00:00
|
|
|
GetClientRect(m_hwnd, &rct);
|
2015-11-07 07:49:53 +00:00
|
|
|
POINT pt;
|
|
|
|
pt.x = rct.left;
|
|
|
|
pt.y = rct.top;
|
|
|
|
MapWindowPoints(m_hwnd, HWND_DESKTOP, &pt, 1);
|
|
|
|
xOut = pt.x;
|
|
|
|
yOut = pt.y;
|
2015-11-03 04:19:41 +00:00
|
|
|
wOut = rct.right;
|
|
|
|
hOut = rct.bottom;
|
|
|
|
}
|
|
|
|
|
|
|
|
void getWindowFrame(int& xOut, int& yOut, int& wOut, int& hOut) const
|
|
|
|
{
|
|
|
|
RECT rct;
|
2015-11-05 04:57:48 +00:00
|
|
|
GetClientRect(m_hwnd, &rct);
|
2015-11-07 07:49:53 +00:00
|
|
|
POINT pt;
|
|
|
|
pt.x = rct.left;
|
|
|
|
pt.y = rct.top;
|
|
|
|
MapWindowPoints(m_hwnd, HWND_DESKTOP, &pt, 1);
|
|
|
|
xOut = pt.x;
|
|
|
|
yOut = pt.y;
|
2015-11-03 04:19:41 +00:00
|
|
|
wOut = rct.right;
|
|
|
|
hOut = rct.bottom;
|
2015-05-06 00:50:57 +00:00
|
|
|
}
|
2015-11-07 07:49:53 +00:00
|
|
|
|
2015-05-06 00:50:57 +00:00
|
|
|
void setWindowFrame(float x, float y, float w, float h)
|
|
|
|
{
|
2015-11-03 04:19:41 +00:00
|
|
|
MoveWindow(m_hwnd, x, y, w, h, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setWindowFrame(int x, int y, int w, int h)
|
|
|
|
{
|
|
|
|
MoveWindow(m_hwnd, x, y, w, h, true);
|
2015-05-06 00:50:57 +00:00
|
|
|
}
|
2015-11-07 07:49:53 +00:00
|
|
|
|
2015-05-06 00:50:57 +00:00
|
|
|
float getVirtualPixelFactor() const
|
|
|
|
{
|
2015-08-31 03:40:58 +00:00
|
|
|
return 1.0;
|
2015-05-06 00:50:57 +00:00
|
|
|
}
|
2015-11-07 07:49:53 +00:00
|
|
|
|
2015-05-06 00:50:57 +00:00
|
|
|
bool isFullscreen() const
|
|
|
|
{
|
2015-11-07 01:43:12 +00:00
|
|
|
return m_gfxCtx->m_3dCtx.isFullscreen(this);
|
2015-05-06 00:50:57 +00:00
|
|
|
}
|
2015-11-07 07:49:53 +00:00
|
|
|
|
2015-05-06 00:50:57 +00:00
|
|
|
void setFullscreen(bool fs)
|
|
|
|
{
|
2015-11-07 01:43:12 +00:00
|
|
|
m_gfxCtx->m_3dCtx.setFullscreen(this, fs);
|
2015-05-06 00:50:57 +00:00
|
|
|
}
|
2015-08-31 03:40:58 +00:00
|
|
|
|
|
|
|
void waitForRetrace()
|
|
|
|
{
|
2015-11-03 04:19:41 +00:00
|
|
|
m_gfxCtx->m_output->WaitForVBlank();
|
2015-08-31 03:40:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uintptr_t getPlatformHandle() const
|
|
|
|
{
|
|
|
|
return uintptr_t(m_hwnd);
|
|
|
|
}
|
2015-11-03 04:19:41 +00:00
|
|
|
|
|
|
|
void buttonDown(HWNDEvent& e, EMouseButton button)
|
|
|
|
{
|
|
|
|
if (m_callback)
|
|
|
|
{
|
|
|
|
int x, y, w, h;
|
|
|
|
getWindowFrame(x, y, w, h);
|
2015-11-21 02:58:56 +00:00
|
|
|
EModifierKey modifierMask = translateModifiers(e.uMsg);
|
2015-11-03 04:19:41 +00:00
|
|
|
SWindowCoord coord =
|
|
|
|
{
|
2015-12-04 01:54:48 +00:00
|
|
|
{GET_X_LPARAM(e.lParam), h-GET_Y_LPARAM(e.lParam)},
|
|
|
|
{GET_X_LPARAM(e.lParam), h-GET_Y_LPARAM(e.lParam)},
|
2015-12-01 00:33:14 +00:00
|
|
|
{float(GET_X_LPARAM(e.lParam)) / float(w), float(h-GET_Y_LPARAM(e.lParam)) / float(h)}
|
2015-11-03 04:19:41 +00:00
|
|
|
};
|
2015-11-21 02:58:56 +00:00
|
|
|
m_callback->mouseDown(coord, button, modifierMask);
|
2015-11-03 04:19:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void buttonUp(HWNDEvent& e, EMouseButton button)
|
|
|
|
{
|
|
|
|
if (m_callback)
|
|
|
|
{
|
|
|
|
int x, y, w, h;
|
|
|
|
getWindowFrame(x, y, w, h);
|
2015-11-21 02:58:56 +00:00
|
|
|
EModifierKey modifierMask = translateModifiers(e.uMsg);
|
2015-11-03 04:19:41 +00:00
|
|
|
SWindowCoord coord =
|
|
|
|
{
|
2015-12-04 01:54:48 +00:00
|
|
|
{GET_X_LPARAM(e.lParam), h-GET_Y_LPARAM(e.lParam)},
|
|
|
|
{GET_X_LPARAM(e.lParam), h-GET_Y_LPARAM(e.lParam)},
|
2015-12-01 00:33:14 +00:00
|
|
|
{float(GET_X_LPARAM(e.lParam)) / float(w), float(h-GET_Y_LPARAM(e.lParam)) / float(h)}
|
2015-11-03 04:19:41 +00:00
|
|
|
};
|
2015-11-21 02:58:56 +00:00
|
|
|
m_callback->mouseUp(coord, button, modifierMask);
|
2015-11-03 04:19:41 +00:00
|
|
|
}
|
|
|
|
}
|
2015-11-07 07:49:53 +00:00
|
|
|
|
|
|
|
void _trackMouse()
|
|
|
|
{
|
|
|
|
TRACKMOUSEEVENT tme;
|
|
|
|
tme.cbSize = sizeof(TRACKMOUSEEVENT);
|
|
|
|
tme.dwFlags = TME_NONCLIENT | TME_HOVER | TME_LEAVE;
|
|
|
|
tme.dwHoverTime = 500;
|
|
|
|
tme.hwndTrack = m_hwnd;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool mouseTracking = false;
|
2015-11-03 04:19:41 +00:00
|
|
|
void _incomingEvent(void* ev)
|
|
|
|
{
|
|
|
|
HWNDEvent& e = *static_cast<HWNDEvent*>(ev);
|
|
|
|
switch (e.uMsg)
|
|
|
|
{
|
2015-11-18 06:14:49 +00:00
|
|
|
case WM_CLOSE:
|
|
|
|
if (m_callback)
|
|
|
|
m_callback->destroyed();
|
|
|
|
return;
|
2015-11-07 20:12:47 +00:00
|
|
|
case WM_SIZE:
|
2015-11-03 04:19:41 +00:00
|
|
|
{
|
2015-11-05 04:57:48 +00:00
|
|
|
SWindowRect rect;
|
|
|
|
getWindowFrame(rect.location[0], rect.location[1], rect.size[0], rect.size[1]);
|
|
|
|
if (!rect.size[0] || !rect.size[1])
|
|
|
|
return;
|
2015-11-07 01:43:12 +00:00
|
|
|
m_gfxCtx->m_3dCtx.resize(this, rect.size[0], rect.size[1]);
|
2015-11-03 04:19:41 +00:00
|
|
|
if (m_callback)
|
|
|
|
m_callback->resized(rect);
|
|
|
|
return;
|
|
|
|
}
|
2015-11-07 07:49:53 +00:00
|
|
|
case WM_MOVING:
|
|
|
|
{
|
|
|
|
SWindowRect rect;
|
|
|
|
getWindowFrame(rect.location[0], rect.location[1], rect.size[0], rect.size[1]);
|
|
|
|
if (!rect.size[0] || !rect.size[1])
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (m_callback)
|
|
|
|
m_callback->windowMoved(rect);
|
|
|
|
return;
|
|
|
|
}
|
2015-11-03 04:19:41 +00:00
|
|
|
case WM_KEYDOWN:
|
2015-11-06 03:20:58 +00:00
|
|
|
case WM_SYSKEYDOWN:
|
2015-11-03 04:19:41 +00:00
|
|
|
{
|
|
|
|
if (m_callback)
|
|
|
|
{
|
2015-11-21 02:58:56 +00:00
|
|
|
ESpecialKey specialKey;
|
|
|
|
EModifierKey modifierKey;
|
2015-11-03 04:19:41 +00:00
|
|
|
uint32_t charCode = translateKeysym(e.wParam, specialKey, modifierKey);
|
2015-11-21 02:58:56 +00:00
|
|
|
EModifierKey modifierMask = translateModifiers(e.uMsg);
|
2015-11-03 04:19:41 +00:00
|
|
|
if (charCode)
|
2015-11-21 02:58:56 +00:00
|
|
|
m_callback->charKeyDown(charCode, modifierMask, (e.lParam & 0xffff) != 0);
|
|
|
|
else if (specialKey != ESpecialKey::None)
|
|
|
|
m_callback->specialKeyDown(specialKey, modifierMask, (e.lParam & 0xffff) != 0);
|
|
|
|
else if (modifierKey != EModifierKey::None)
|
|
|
|
m_callback->modKeyDown(modifierKey, (e.lParam & 0xffff) != 0);
|
2015-11-03 04:19:41 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
case WM_KEYUP:
|
2015-11-06 03:20:58 +00:00
|
|
|
case WM_SYSKEYUP:
|
2015-11-03 04:19:41 +00:00
|
|
|
{
|
|
|
|
if (m_callback)
|
|
|
|
{
|
2015-11-21 02:58:56 +00:00
|
|
|
ESpecialKey specialKey;
|
|
|
|
EModifierKey modifierKey;
|
2015-11-03 04:19:41 +00:00
|
|
|
uint32_t charCode = translateKeysym(e.wParam, specialKey, modifierKey);
|
2015-11-21 02:58:56 +00:00
|
|
|
EModifierKey modifierMask = translateModifiers(e.uMsg);
|
2015-11-03 04:19:41 +00:00
|
|
|
if (charCode)
|
2015-11-21 02:58:56 +00:00
|
|
|
m_callback->charKeyUp(charCode, modifierMask);
|
|
|
|
else if (specialKey != ESpecialKey::None)
|
|
|
|
m_callback->specialKeyUp(specialKey, modifierMask);
|
|
|
|
else if (modifierKey != EModifierKey::None)
|
|
|
|
m_callback->modKeyUp(modifierKey);
|
2015-11-03 04:19:41 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
case WM_LBUTTONDOWN:
|
|
|
|
{
|
2015-11-21 02:58:56 +00:00
|
|
|
buttonDown(e, EMouseButton::Primary);
|
2015-11-03 04:19:41 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
case WM_LBUTTONUP:
|
|
|
|
{
|
2015-11-21 02:58:56 +00:00
|
|
|
buttonUp(e, EMouseButton::Primary);
|
2015-11-03 04:19:41 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
case WM_RBUTTONDOWN:
|
|
|
|
{
|
2015-11-21 02:58:56 +00:00
|
|
|
buttonDown(e, EMouseButton::Secondary);
|
2015-11-03 04:19:41 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
case WM_RBUTTONUP:
|
|
|
|
{
|
2015-11-21 02:58:56 +00:00
|
|
|
buttonUp(e, EMouseButton::Secondary);
|
2015-11-03 04:19:41 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
case WM_MBUTTONDOWN:
|
|
|
|
{
|
2015-11-21 02:58:56 +00:00
|
|
|
buttonDown(e, EMouseButton::Middle);
|
2015-11-03 04:19:41 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
case WM_MBUTTONUP:
|
|
|
|
{
|
2015-11-21 02:58:56 +00:00
|
|
|
buttonUp(e, EMouseButton::Middle);
|
2015-11-03 04:19:41 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
case WM_XBUTTONDOWN:
|
|
|
|
{
|
|
|
|
if (HIWORD(e.wParam) == XBUTTON1)
|
2015-11-21 02:58:56 +00:00
|
|
|
buttonDown(e, EMouseButton::Aux1);
|
2015-11-03 04:19:41 +00:00
|
|
|
else if (HIWORD(e.wParam) == XBUTTON2)
|
2015-11-21 02:58:56 +00:00
|
|
|
buttonDown(e, EMouseButton::Aux2);
|
2015-11-03 04:19:41 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
case WM_XBUTTONUP:
|
|
|
|
{
|
|
|
|
if (HIWORD(e.wParam) == XBUTTON1)
|
2015-11-21 02:58:56 +00:00
|
|
|
buttonUp(e, EMouseButton::Aux1);
|
2015-11-03 04:19:41 +00:00
|
|
|
else if (HIWORD(e.wParam) == XBUTTON2)
|
2015-11-21 02:58:56 +00:00
|
|
|
buttonUp(e, EMouseButton::Aux2);
|
2015-11-03 04:19:41 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
case WM_MOUSEMOVE:
|
|
|
|
{
|
|
|
|
if (m_callback)
|
|
|
|
{
|
|
|
|
int x, y, w, h;
|
|
|
|
getWindowFrame(x, y, w, h);
|
|
|
|
SWindowCoord coord =
|
|
|
|
{
|
2015-12-04 01:54:48 +00:00
|
|
|
{GET_X_LPARAM(e.lParam), h-GET_Y_LPARAM(e.lParam)},
|
|
|
|
{GET_X_LPARAM(e.lParam), h-GET_Y_LPARAM(e.lParam)},
|
2015-12-01 00:33:14 +00:00
|
|
|
{float(GET_X_LPARAM(e.lParam)) / float(w), float(h-GET_Y_LPARAM(e.lParam)) / float(h)}
|
2015-11-03 04:19:41 +00:00
|
|
|
};
|
2015-11-07 07:49:53 +00:00
|
|
|
if (!mouseTracking)
|
|
|
|
{
|
|
|
|
_trackMouse();
|
|
|
|
mouseTracking = true;
|
|
|
|
m_callback->mouseEnter(coord);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
m_callback->mouseMove(coord);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
case WM_MOUSELEAVE:
|
|
|
|
case WM_NCMOUSELEAVE:
|
|
|
|
{
|
|
|
|
if (m_callback)
|
|
|
|
{
|
|
|
|
int x, y, w, h;
|
|
|
|
getWindowFrame(x, y, w, h);
|
|
|
|
SWindowCoord coord =
|
|
|
|
{
|
2015-12-04 01:54:48 +00:00
|
|
|
{ GET_X_LPARAM(e.lParam), h-GET_Y_LPARAM(e.lParam) },
|
|
|
|
{ GET_X_LPARAM(e.lParam), h-GET_Y_LPARAM(e.lParam) },
|
2015-12-01 00:33:14 +00:00
|
|
|
{ float(GET_X_LPARAM(e.lParam)) / float(w), float(h-GET_Y_LPARAM(e.lParam)) / float(h) }
|
2015-11-07 07:49:53 +00:00
|
|
|
};
|
|
|
|
m_callback->mouseLeave(coord);
|
|
|
|
mouseTracking = false;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
case WM_NCMOUSEHOVER:
|
|
|
|
case WM_MOUSEHOVER:
|
|
|
|
{
|
|
|
|
if (m_callback)
|
|
|
|
{
|
|
|
|
int x, y, w, h;
|
|
|
|
getWindowFrame(x, y, w, h);
|
|
|
|
SWindowCoord coord =
|
|
|
|
{
|
2015-12-04 01:54:48 +00:00
|
|
|
{ GET_X_LPARAM(e.lParam), h-GET_Y_LPARAM(e.lParam) },
|
|
|
|
{ GET_X_LPARAM(e.lParam), h-GET_Y_LPARAM(e.lParam) },
|
2015-12-01 00:33:14 +00:00
|
|
|
{ float(GET_X_LPARAM(e.lParam)) / float(w), float(h-GET_Y_LPARAM(e.lParam)) / float(h) }
|
2015-11-07 07:49:53 +00:00
|
|
|
};
|
|
|
|
m_callback->mouseEnter(coord);
|
2015-11-03 04:19:41 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-06 00:50:57 +00:00
|
|
|
ETouchType getTouchType() const
|
|
|
|
{
|
2015-11-21 02:58:56 +00:00
|
|
|
return ETouchType::None;
|
2015-05-06 00:50:57 +00:00
|
|
|
}
|
2015-11-03 04:19:41 +00:00
|
|
|
|
2015-11-06 03:20:58 +00:00
|
|
|
void setStyle(EWindowStyle style)
|
|
|
|
{
|
|
|
|
LONG sty = GetWindowLong(m_hwnd, GWL_STYLE);
|
|
|
|
|
2015-11-21 02:58:56 +00:00
|
|
|
if ((style & EWindowStyle::Titlebar) != EWindowStyle::None)
|
2015-11-06 03:20:58 +00:00
|
|
|
sty |= WS_CAPTION;
|
|
|
|
else
|
|
|
|
sty &= ~WS_CAPTION;
|
|
|
|
|
2015-11-21 02:58:56 +00:00
|
|
|
if ((style & EWindowStyle::Resize) != EWindowStyle::None)
|
2015-11-06 03:20:58 +00:00
|
|
|
sty |= WS_THICKFRAME;
|
|
|
|
else
|
|
|
|
sty &= ~WS_THICKFRAME;
|
|
|
|
|
2015-11-21 02:58:56 +00:00
|
|
|
if ((style & EWindowStyle::Close) != EWindowStyle::None)
|
2015-11-06 03:20:58 +00:00
|
|
|
sty |= (WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX);
|
|
|
|
else
|
|
|
|
sty &= ~(WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX);
|
|
|
|
|
|
|
|
SetWindowLong(m_hwnd, GWL_STYLE, sty);
|
|
|
|
}
|
|
|
|
|
|
|
|
EWindowStyle getStyle() const
|
|
|
|
{
|
|
|
|
LONG sty = GetWindowLong(m_hwnd, GWL_STYLE);
|
2015-11-21 02:58:56 +00:00
|
|
|
EWindowStyle retval = EWindowStyle::None;
|
2015-11-14 06:12:39 +00:00
|
|
|
if ((sty & WS_CAPTION) != 0)
|
2015-11-21 02:58:56 +00:00
|
|
|
retval |= EWindowStyle::Titlebar;
|
2015-11-14 06:12:39 +00:00
|
|
|
if ((sty & WS_THICKFRAME) != 0)
|
2015-11-21 02:58:56 +00:00
|
|
|
retval |= EWindowStyle::Resize;
|
2015-11-14 06:12:39 +00:00
|
|
|
if ((sty & WS_SYSMENU))
|
2015-11-21 02:58:56 +00:00
|
|
|
retval |= EWindowStyle::Close;
|
|
|
|
return retval;
|
2015-11-06 03:20:58 +00:00
|
|
|
}
|
|
|
|
|
2015-11-03 04:19:41 +00:00
|
|
|
IGraphicsCommandQueue* getCommandQueue()
|
|
|
|
{
|
|
|
|
return m_gfxCtx->getCommandQueue();
|
|
|
|
}
|
|
|
|
IGraphicsDataFactory* getDataFactory()
|
|
|
|
{
|
|
|
|
return m_gfxCtx->getDataFactory();
|
|
|
|
}
|
|
|
|
|
2015-11-18 06:14:49 +00:00
|
|
|
/* Creates a new context on current thread!! Call from main client thread */
|
|
|
|
IGraphicsDataFactory* getMainContextDataFactory()
|
|
|
|
{
|
|
|
|
return m_gfxCtx->getMainContextDataFactory();
|
|
|
|
}
|
|
|
|
|
2015-11-03 04:19:41 +00:00
|
|
|
/* Creates a new context on current thread!! Call from client loading thread */
|
|
|
|
IGraphicsDataFactory* getLoadContextDataFactory()
|
|
|
|
{
|
|
|
|
return m_gfxCtx->getLoadContextDataFactory();
|
|
|
|
}
|
2015-11-07 07:49:53 +00:00
|
|
|
|
2015-05-06 00:50:57 +00:00
|
|
|
};
|
|
|
|
|
2015-11-07 01:43:12 +00:00
|
|
|
IWindow* _WindowWin32New(const SystemString& title, Boo3DAppContext& d3dCtx)
|
2015-05-06 00:50:57 +00:00
|
|
|
{
|
2015-11-03 04:19:41 +00:00
|
|
|
return new WindowWin32(title, d3dCtx);
|
2015-05-06 00:50:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|