2015-06-12 13:14:38 +00:00
|
|
|
#if defined(Hiro_Viewport)
|
2013-03-15 13:11:33 +00:00
|
|
|
|
2015-06-12 13:14:38 +00:00
|
|
|
namespace hiro {
|
|
|
|
|
|
|
|
static auto CALLBACK Viewport_windowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) -> LRESULT {
|
|
|
|
auto object = (mObject*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
|
|
|
|
if(!object) return DefWindowProc(hwnd, msg, wparam, lparam);
|
|
|
|
auto viewport = dynamic_cast<mViewport*>(object);
|
|
|
|
if(!viewport) return DefWindowProc(hwnd, msg, wparam, lparam);
|
2012-01-26 06:50:09 +00:00
|
|
|
|
2013-07-29 09:42:45 +00:00
|
|
|
if(msg == WM_DROPFILES) {
|
2015-06-12 13:14:38 +00:00
|
|
|
if(auto paths = DropPaths(wparam)) viewport->doDrop(paths);
|
|
|
|
return false;
|
2013-07-29 09:42:45 +00:00
|
|
|
}
|
|
|
|
|
2012-01-26 06:50:09 +00:00
|
|
|
if(msg == WM_GETDLGCODE) {
|
|
|
|
return DLGC_STATIC | DLGC_WANTCHARS;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(msg == WM_MOUSEMOVE) {
|
2015-06-12 13:14:38 +00:00
|
|
|
TRACKMOUSEEVENT tracker{sizeof(TRACKMOUSEEVENT), TME_LEAVE, hwnd};
|
2012-01-26 06:50:09 +00:00
|
|
|
TrackMouseEvent(&tracker);
|
2015-06-12 13:14:38 +00:00
|
|
|
viewport->doMouseMove({(int16_t)LOWORD(lparam), (int16_t)HIWORD(lparam)});
|
2012-01-26 06:50:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(msg == WM_MOUSELEAVE) {
|
2015-06-12 13:14:38 +00:00
|
|
|
viewport->doMouseLeave();
|
2012-01-26 06:50:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(msg == WM_LBUTTONDOWN || msg == WM_MBUTTONDOWN || msg == WM_RBUTTONDOWN) {
|
2015-06-12 13:14:38 +00:00
|
|
|
switch(msg) {
|
|
|
|
case WM_LBUTTONDOWN: viewport->doMousePress(Mouse::Button::Left); break;
|
|
|
|
case WM_MBUTTONDOWN: viewport->doMousePress(Mouse::Button::Middle); break;
|
|
|
|
case WM_RBUTTONDOWN: viewport->doMousePress(Mouse::Button::Right); break;
|
2012-01-26 06:50:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(msg == WM_LBUTTONUP || msg == WM_MBUTTONUP || msg == WM_RBUTTONUP) {
|
2015-06-12 13:14:38 +00:00
|
|
|
switch(msg) {
|
|
|
|
case WM_LBUTTONUP: viewport->doMouseRelease(Mouse::Button::Left); break;
|
|
|
|
case WM_MBUTTONUP: viewport->doMouseRelease(Mouse::Button::Middle); break;
|
|
|
|
case WM_RBUTTONUP: viewport->doMouseRelease(Mouse::Button::Right); break;
|
2012-01-26 06:50:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return DefWindowProc(hwnd, msg, wparam, lparam);
|
|
|
|
}
|
|
|
|
|
2015-06-12 13:14:38 +00:00
|
|
|
auto pViewport::construct() -> void {
|
|
|
|
hwnd = CreateWindow(L"hiroViewport", L"",
|
|
|
|
WS_CHILD | WS_DISABLED,
|
|
|
|
0, 0, 0, 0, _parentHandle(), nullptr, GetModuleHandle(0), 0);
|
|
|
|
SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)&reference);
|
|
|
|
pWidget::_setState();
|
|
|
|
setDroppable(state().droppable);
|
2011-02-24 09:25:20 +00:00
|
|
|
}
|
|
|
|
|
2015-06-12 13:14:38 +00:00
|
|
|
auto pViewport::destruct() -> void {
|
|
|
|
DestroyWindow(hwnd);
|
2013-07-29 09:42:45 +00:00
|
|
|
}
|
|
|
|
|
2015-06-12 13:14:38 +00:00
|
|
|
auto pViewport::handle() const -> uintptr_t {
|
|
|
|
return (uintptr_t)hwnd;
|
2011-02-24 09:25:20 +00:00
|
|
|
}
|
|
|
|
|
2015-06-12 13:14:38 +00:00
|
|
|
auto pViewport::setDroppable(bool droppable) -> void {
|
|
|
|
DragAcceptFiles(hwnd, droppable);
|
2011-09-05 03:48:23 +00:00
|
|
|
}
|
|
|
|
|
2013-03-15 13:11:33 +00:00
|
|
|
}
|
|
|
|
|
2015-06-12 13:14:38 +00:00
|
|
|
#endif
|