From 6496d7253319b330cb076cec2089eed2ae42128f Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Wed, 24 Mar 2010 10:10:56 +0000 Subject: [PATCH] Updates related to win32 camera zoom compile fixes --- .../include/platform/win32/platform_util.h | 3 +- .../include/platform/win32/window.h | 75 +++++- .../sources/platform/win32/platform_util.cpp | 2 + .../sources/platform/win32/window.cpp | 234 ++++++++++++++++++ 4 files changed, 304 insertions(+), 10 deletions(-) diff --git a/source/shared_lib/include/platform/win32/platform_util.h b/source/shared_lib/include/platform/win32/platform_util.h index bb6340186..8c36255c7 100755 --- a/source/shared_lib/include/platform/win32/platform_util.h +++ b/source/shared_lib/include/platform/win32/platform_util.h @@ -59,7 +59,8 @@ class Chrono{ private: int64 startCount; int64 accumCount; - int64 freq; + static int64 freq; + bool stopped; public: diff --git a/source/shared_lib/include/platform/win32/window.h b/source/shared_lib/include/platform/win32/window.h index ff6116ede..2e2d9f4a9 100644 --- a/source/shared_lib/include/platform/win32/window.h +++ b/source/shared_lib/include/platform/win32/window.h @@ -8,18 +8,20 @@ // by the Free Software Foundation; either version 2 of the // License, or (at your option) any later version // ============================================================== - #ifndef _SHARED_PLATFORM_WINDOW_H_ #define _SHARED_PLATFORM_WINDOW_H_ #include #include +#include #include "types.h" +#include "vec.h" #include "platform_menu.h" using std::map; using std::string; +using Shared::Graphics::Vec2i; namespace Shared{ namespace Platform{ @@ -27,9 +29,16 @@ class Timer; class PlatformContextGl; enum MouseButton{ - mbLeft, - mbRight, - mbCenter + mbUnknown, + mbLeft, + mbCenter, + mbRight, + mbWheelUp, + mbWheelDown, + mbButtonX1, + mbButtonX2, + + mbCount }; enum SizeState{ @@ -53,11 +62,29 @@ const int vkBack= VK_BACK; const int vkDelete= VK_DELETE; const int vkF1= VK_F1; -struct MouseState{ - bool leftMouse; - bool rightMouse; - bool centerMouse; -}; +class MouseState { +private: + bool states[mbCount]; + + +public: + MouseState() { + clear(); + } + //MouseState(const MouseState &); + //MouseState &operator=(const MouseState &); + void clear() { memset(this, 0, sizeof(MouseState)); } + + bool get(MouseButton b) const { + assert(b > 0 && b < mbCount); + return states[b]; + } + + void set(MouseButton b, bool state) { + assert(b > 0 && b < mbCount); + states[b] = state; + } +}; enum WindowStyle{ wsFullscreen, @@ -81,6 +108,19 @@ private: static int nextClassName; static WindowMap createdWindows; + static unsigned int lastMouseEvent; /** for use in mouse hover calculations */ + static MouseState mouseState; + static Vec2i mousePos; + + static void setLastMouseEvent(unsigned int lastMouseEvent) {Window::lastMouseEvent = lastMouseEvent;} + static unsigned int getLastMouseEvent() {return Window::lastMouseEvent;} + + static const MouseState &getMouseState() {return Window::mouseState;} + static void setMouseState(MouseButton b, bool state) {Window::mouseState.set(b, state);} + + static const Vec2i &getMousePos() {return Window::mousePos;} + static void setMousePos(const Vec2i &mousePos) {Window::mousePos = mousePos;} + protected: WindowHandle handle; WindowStyle windowStyle; @@ -152,6 +192,23 @@ private: static int getNextClassName(); void registerWindow(WNDPROC wndProc= NULL); void createWindow(LPVOID creationData= NULL); + void mouseyVent(int asdf, MouseButton mouseButton) { + const Vec2i &mousePos = getMousePos(); + switch(asdf) { + case 0: + setMouseState(mouseButton, true); + eventMouseDown(mousePos.x, mousePos.y, mouseButton); + break; + case 1: + setMouseState(mouseButton, false); + eventMouseUp(mousePos.x, mousePos.y, mouseButton); + break; + case 2: + eventMouseDoubleClick(mousePos.x, mousePos.y, mouseButton); + break; + } + } + }; }}//end namespace diff --git a/source/shared_lib/sources/platform/win32/platform_util.cpp b/source/shared_lib/sources/platform/win32/platform_util.cpp index 48906ca7c..61f3f0961 100644 --- a/source/shared_lib/sources/platform/win32/platform_util.cpp +++ b/source/shared_lib/sources/platform/win32/platform_util.cpp @@ -73,6 +73,8 @@ void PerformanceTimer::reset(){ // class Chrono // ===================================================== +int64 Chrono::freq; + Chrono::Chrono(){ if(!QueryPerformanceFrequency((LARGE_INTEGER*) &freq)){ throw runtime_error("Performance counters not supported"); diff --git a/source/shared_lib/sources/platform/win32/window.cpp b/source/shared_lib/sources/platform/win32/window.cpp index 3360cdde0..58d04715f 100644 --- a/source/shared_lib/sources/platform/win32/window.cpp +++ b/source/shared_lib/sources/platform/win32/window.cpp @@ -34,6 +34,10 @@ const DWORD Window::windowedResizeableStyle= WS_SIZEBOX | WS_CAPTION | WS_MINIMI int Window::nextClassName= 0; Window::WindowMap Window::createdWindows; +unsigned int Window::lastMouseEvent = 0; /** for use in mouse hover calculations */ +Vec2i Window::mousePos; +MouseState Window::mouseState; + // ===================== PUBLIC ======================== Window::Window(){ @@ -45,6 +49,11 @@ Window::Window(){ y= 0; w= 100; h= 100; + + lastMouseEvent = 0; + mousePos = Vec2i(0); + mouseState.clear(); + } Window::~Window(){ @@ -220,6 +229,230 @@ void Window::destroy(){ LRESULT CALLBACK Window::eventRouter(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam){ + Window *eventWindow; + WindowMap::iterator it; + + it = createdWindows.find(hwnd); + if (it == createdWindows.end()) { + return DefWindowProc(hwnd, msg, wParam, lParam); + } + eventWindow = it->second; + + switch (msg) { + case WM_CREATE: + eventWindow->eventCreate(); + break; + + case WM_LBUTTONDOWN: + case WM_LBUTTONUP: + case WM_LBUTTONDBLCLK: + case WM_RBUTTONDOWN: + case WM_RBUTTONUP: + case WM_RBUTTONDBLCLK: + case WM_MBUTTONDOWN: + case WM_MBUTTONUP: + case WM_MBUTTONDBLCLK: + case WM_XBUTTONDOWN: + case WM_XBUTTONUP: + case WM_XBUTTONDBLCLK: + case WM_MOUSEWHEEL: + case WM_MOUSEHWHEEL: + case WM_MOUSEMOVE: { + RECT windowRect; + POINT mousePos; + + GetWindowRect(eventWindow->getHandle(), &windowRect); + mousePos.x = LOWORD(lParam) - windowRect.left; + mousePos.y = HIWORD(lParam) - windowRect.top; + ClientToScreen(eventWindow->getHandle(), &mousePos); + + eventWindow->setLastMouseEvent(Chrono::getCurMillis()); + eventWindow->setMousePos(Vec2i(mousePos.x, mousePos.y)); + switch(msg) { + case WM_LBUTTONDOWN: + eventWindow->mouseyVent(0, mbLeft); + return 0; + + case WM_LBUTTONUP: + eventWindow->mouseyVent(1, mbLeft); + return 0; + + case WM_LBUTTONDBLCLK: + eventWindow->mouseyVent(2, mbLeft); + return 0; + + case WM_RBUTTONDOWN: + eventWindow->mouseyVent(0, mbRight); + return 0; + + case WM_RBUTTONUP: + eventWindow->mouseyVent(1, mbRight); + return 0; + + case WM_RBUTTONDBLCLK: + eventWindow->mouseyVent(2, mbRight); + return 0; + + case WM_MBUTTONDOWN: + eventWindow->mouseyVent(0, mbCenter); + return 0; + + case WM_MBUTTONUP: + eventWindow->mouseyVent(1, mbCenter); + return 0; + + case WM_MBUTTONDBLCLK: + eventWindow->mouseyVent(2, mbCenter); + return 0; + + case WM_XBUTTONDOWN: + // we only know about XBUTTON1 and XBUTTON2, but there may be more later, let + // DefWindowProc take these. + switch(HIWORD(wParam)) { + case XBUTTON1: + eventWindow->mouseyVent(0, mbButtonX1); + return TRUE;// don't ask me why it wants TRUE instead of zero like + // everything else + case XBUTTON2: + eventWindow->mouseyVent(0, mbButtonX2); + return TRUE; + } + break; + + case WM_XBUTTONUP: + switch(HIWORD(wParam)) { + case XBUTTON1: + eventWindow->mouseyVent(1, mbButtonX1); + return TRUE;// don't ask me why it wants TRUE instead of zero like + // everything else + case XBUTTON2: + eventWindow->mouseyVent(1, mbButtonX2); + return TRUE; + } + break; + + case WM_XBUTTONDBLCLK: + switch(HIWORD(wParam)) { + case XBUTTON1: + eventWindow->mouseyVent(2, mbButtonX1); + return TRUE;// don't ask me why it wants TRUE instead of zero like + // everything else + case XBUTTON2: + eventWindow->mouseyVent(2, mbButtonX2); + return TRUE; + } + break; + + case WM_MOUSEWHEEL: + eventWindow->eventMouseWheel(mousePos.x, mousePos.y, GET_WHEEL_DELTA_WPARAM(wParam)); + return 0; + + case WM_MOUSEHWHEEL: + //eventWindow->eventMouseHWheel(mousePos.x, mousePos.y, GET_WHEEL_DELTA_WPARAM(wParam)); + break; // not handled, send to DefWindowProc + + case WM_MOUSEMOVE: + eventWindow->setMouseState(mbLeft, wParam & MK_LBUTTON); + eventWindow->setMouseState(mbRight, wParam & MK_RBUTTON); + eventWindow->setMouseState(mbCenter, wParam & MK_MBUTTON); + eventWindow->setMouseState(mbButtonX1, wParam & MK_XBUTTON1); + eventWindow->setMouseState(mbButtonX2, wParam & MK_XBUTTON2); + eventWindow->eventMouseMove(mousePos.x, mousePos.y, &eventWindow->getMouseState()); + return 0; + } + break; + } + + case WM_KEYDOWN: { + + eventWindow->eventKeyDown(static_cast(wParam)); + break; + /* + Key key(Input::getKeyCode(wParam), static_cast(wParam)); + // bottom 16 bits is repeat acount, and I only care if it's zero or non-zero + bool isRepeat = (lParam << 16); + // I don't want repeats of modifier keys posting + if(!isRepeat || !key.isModifier()) { + eventWindow->input.updateKeyModifiers(key.getCode(), true); + eventWindow->eventKeyDown(key); + } + break; + */ + } + + case WM_KEYUP: { + + eventWindow->eventKeyUp(static_cast(wParam)); + break; + + /* + Key key(Input::getKeyCode(wParam), static_cast(wParam)); + eventWindow->input.updateKeyModifiers(key.getCode(), false); + eventWindow->eventKeyUp(key); + break; + */ + } + + case WM_CHAR: + eventWindow->eventKeyPress(static_cast(wParam)); + break; + + case WM_COMMAND: + if (HIWORD(wParam) == 0) { + eventWindow->eventMenu(LOWORD(wParam)); + } + break; + + case WM_ACTIVATE: + eventWindow->eventActivate(wParam != WA_INACTIVE); + break; + + case WM_MOVE: { + RECT rect; + + GetWindowRect(eventWindow->getHandle(), &rect); + eventWindow->x = rect.left; + eventWindow->y = rect.top; + eventWindow->w = rect.right - rect.left; + eventWindow->h = rect.bottom - rect.top; + } + break; + + case WM_SIZE: { + RECT rect; + + GetWindowRect(eventWindow->getHandle(), &rect); + eventWindow->x = rect.left; + eventWindow->y = rect.top; + eventWindow->w = rect.right - rect.left; + eventWindow->h = rect.bottom - rect.top; + + eventWindow->eventResize(static_cast(wParam)); + } + break; + + case WM_SIZING: + eventWindow->eventResize(); + break; + + case WM_PAINT: + eventWindow->eventPaint(); + break; + + case WM_CLOSE: + eventWindow->eventClose(); + break; + + case WM_DESTROY: + eventWindow->eventDestroy(); + PostQuitMessage(0); + return 0; + } + + return DefWindowProc(hwnd, msg, wParam, lParam); + + +/* Window *eventWindow; WindowMap::iterator it; @@ -353,6 +586,7 @@ LRESULT CALLBACK Window::eventRouter(HWND hwnd, UINT msg, WPARAM wParam, LPARAM } return DefWindowProc(hwnd, msg, wParam, lParam); +*/ } int Window::getNextClassName(){