From: <wil...@us...> - 2009-07-15 04:23:25
|
Revision: 425 http://hgengine.svn.sourceforge.net/hgengine/?rev=425&view=rev Author: willmurnane Date: 2009-07-15 04:23:04 +0000 (Wed, 15 Jul 2009) Log Message: ----------- Improved (?) X11 mouse handling: scroll wheel, buttons-by-name, stuff Modified Paths: -------------- Mercury2/src/MercuryInput.cpp Mercury2/src/MercuryInput.h Mercury2/src/X11Window.cpp Modified: Mercury2/src/MercuryInput.cpp =================================================================== --- Mercury2/src/MercuryInput.cpp 2009-07-15 02:37:35 UTC (rev 424) +++ Mercury2/src/MercuryInput.cpp 2009-07-15 04:23:04 UTC (rev 425) @@ -2,24 +2,25 @@ #include <MercuryMessageManager.h> MouseInput::MouseInput() - :MessageData(), dx(0), dy(0), buttonMasks(0) + :MessageData(), dx(0), dy(0) { + buttons.data = 0; } -void MouseInput::ProcessMouseInput(int dx, int dy, bool leftButton, bool rightButton, bool centerButton) +void MouseInput::ProcessMouseInput(int dx, int dy, bool leftButton, bool rightButton, bool centerButton, bool scrollUpButton, bool scrollDownButton) { MouseInput* mi = new MouseInput(); mi->dx = dx; mi->dy = dy; + buttonMask buttons = {0}; + buttons.left = leftButton; + buttons.right = rightButton; + buttons.center = centerButton; + buttons.scrollup = scrollUpButton; + buttons.scrolldown = scrollDownButton; + mi->buttons = buttons; + currentButtonMasks = buttons; - uint8_t buttonMasks = 0; - buttonMasks |= (leftButton << MOUSE_LEFT); //enable if true - buttonMasks |= (rightButton << MOUSE_RIGHT); //enable if true - buttonMasks |= (centerButton << MOUSE_CENTER); //enable if true - mi->buttonMasks = buttonMasks; - - currentButtonMasks = buttonMasks; - POST_MESSAGE( INPUTEVENT_MOUSE, mi, 0 ); } @@ -65,7 +66,7 @@ uint8_t KeyboardInput::m_keyStates[512]; -uint8_t MouseInput::currentButtonMasks; +MouseInput::buttonMask MouseInput::currentButtonMasks; /**************************************************************************** Modified: Mercury2/src/MercuryInput.h =================================================================== --- Mercury2/src/MercuryInput.h 2009-07-15 02:37:35 UTC (rev 424) +++ Mercury2/src/MercuryInput.h 2009-07-15 04:23:04 UTC (rev 425) @@ -10,22 +10,25 @@ class MouseInput : public MessageData { public: - static void ProcessMouseInput(int dx, int dy, bool leftButton, bool rightButton, bool centerButton); + typedef union + { + uint8_t data; + struct { + unsigned int left: 1; + unsigned int right: 1; + unsigned int center: 1; + unsigned int scrollup: 1; + unsigned int scrolldown: 1; + }; + } buttonMask; + static void ProcessMouseInput(int dx, int dy, bool leftButton, bool rightButton, bool centerButton, bool scrollUpButton, bool scrollDownButton); MouseInput(); int32_t dx, dy; - uint8_t buttonMasks; + buttonMask buttons; - enum MouseButton - { - MOUSE_NONE = 0, - MOUSE_LEFT = 1, - MOUSE_RIGHT = 2, - MOUSE_CENTER = 3 - }; - private: - static uint8_t currentButtonMasks; + static buttonMask currentButtonMasks; }; class KeyboardInput : public MessageData Modified: Mercury2/src/X11Window.cpp =================================================================== --- Mercury2/src/X11Window.cpp 2009-07-15 02:37:35 UTC (rev 424) +++ Mercury2/src/X11Window.cpp 2009-07-15 04:23:04 UTC (rev 425) @@ -3,6 +3,18 @@ #include <MercuryInput.h> #include <MercuryPrefs.h> +#define MOUSE_BTN_LEFT 1 +#define MOUSE_BTN_RIGHT 3 +#define MOUSE_BTN_CENTER 2 +#define MOUSE_BTN_SCROLL_UP 4 +#define MOUSE_BTN_SCROLL_DOWN 5 + +// Use X11_MASK(MOUSE_BTN_SCROLL_UP) to generate the token Button4Mask +#define X11_MASK(x) _X11_MASK(x) +// Sigh... second #define needed, because otherwise x doesn't get evaluated. +// That is, instead of giving you Button4Mask this would give ButtonMOUSE_BTN_SCROLL_UPMask +#define _X11_MASK(x) Button##x##Mask + Callback0R< MercuryWindow* > MercuryWindow::genWindowClbk(X11Window::GenX11Window); //Register window generation callback //XXX: THIS SECTION IS INCOMPLETE! IT NEEDS The right half of the keyboard (Bar arrow keys) + it needs the windows keys/sel keys mapped @@ -236,7 +248,19 @@ case ButtonRelease: { XButtonEvent* e = (XButtonEvent*)&event; - MouseInput::ProcessMouseInput(0, 0, e->button & Button1, e->button & Button3, e->button & Button2); + uint8_t left, right, center, su, sd; + left = (e->state & X11_MASK(MOUSE_BTN_LEFT)) ^ (e->button == MOUSE_BTN_LEFT); + right = (e->state & X11_MASK(MOUSE_BTN_RIGHT)) ^ (e->button == MOUSE_BTN_RIGHT); + center = (e->state & X11_MASK(MOUSE_BTN_CENTER)) ^ (e->button == MOUSE_BTN_CENTER); + su = (e->state & X11_MASK(MOUSE_BTN_SCROLL_UP)) ^ (e->button == MOUSE_BTN_SCROLL_UP); + sd = (e->state & X11_MASK(MOUSE_BTN_SCROLL_DOWN)) ^ (e->button == MOUSE_BTN_SCROLL_DOWN); + + MouseInput::ProcessMouseInput(0, 0, + e->state & X11_MASK(MOUSE_BTN_LEFT), + e->state & X11_MASK(MOUSE_BTN_RIGHT), + e->state & X11_MASK(MOUSE_BTN_CENTER), + e->state & X11_MASK(MOUSE_BTN_SCROLL_UP), + e->state & X11_MASK(MOUSE_BTN_SCROLL_DOWN)); break; } case KeyPress: @@ -257,25 +281,28 @@ } case MotionNotify: { + XMotionEvent* e = (XMotionEvent*)&event; int x, y; - bool left, right, center; - left = e->state & Button1Mask; - right = e->state & Button3Mask; - center = e->state & Button2Mask; + bool left, right, center, su, sd; + left = e->state & X11_MASK(MOUSE_BTN_LEFT); + right = e->state & X11_MASK(MOUSE_BTN_RIGHT); + center = e->state & X11_MASK(MOUSE_BTN_CENTER); + su = e->state & X11_MASK(MOUSE_BTN_SCROLL_UP); + sd = e->state & X11_MASK(MOUSE_BTN_SCROLL_DOWN); if( m_bGrabbed ) { x = m_width/2 - e->x; y = m_height/2 - e->y; if (x!=0 || y!=0) //prevent recursive XWarp { - MouseInput::ProcessMouseInput(x, y, left, right, center); + MouseInput::ProcessMouseInput(x, y, left, right, center, su, sd); XWarpPointer(m_display, None, m_window, 0,0,0,0,m_width/2,m_height/2); } } else { - MouseInput::ProcessMouseInput(e->x, e->y, left, right, center); + MouseInput::ProcessMouseInput(e->x, e->y, left, right, center, su, sd); } break; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |