]> git.tdb.fi Git - libs/gui.git/blob - source/input/windows/mouse.cpp
Add constants for mouse axes and buttons
[libs/gui.git] / source / input / windows / mouse.cpp
1 #include <windowsx.h>
2 #include <msp/graphics/window_private.h>
3 #include "keys.h"
4 #include "mouse.h"
5
6 namespace Msp {
7 namespace Input {
8
9 void Mouse::input_event(const Graphics::Window::Event &event)
10 {
11         // http://msdn.microsoft.com/en-us/library/windows/desktop/ms703320.aspx
12         if(window.get_touch_input() && (event.extra&0xFFFFFF00)==0xFF515700)
13                 return;
14
15         switch(event.msg)
16         {
17         case WM_LBUTTONDOWN:
18         case WM_LBUTTONUP:
19                 set_button_state(MOUSE_LEFT, event.msg==WM_LBUTTONDOWN, true);
20                 break;
21         case WM_MBUTTONDOWN:
22         case WM_MBUTTONUP:
23                 set_button_state(MOUSE_MIDDLE, event.msg==WM_MBUTTONDOWN, true);
24                 break;
25         case WM_RBUTTONDOWN:
26         case WM_RBUTTONUP:
27                 set_button_state(MOUSE_RIGHT, event.msg==WM_RBUTTONDOWN, true);
28                 break;
29         case WM_MOUSEWHEEL:
30                 {
31                         unsigned btn = (HIWORD(event.wparam)&0x8000) ? MOUSE_WHEEL_DOWN : MOUSE_WHEEL_UP;
32                         set_button_state(btn, true, true);
33                         set_button_state(btn, false, true);
34                 }
35                 break;
36         case WM_MOUSEMOVE:
37                 set_axis_value(MOUSE_X_AXIS, GET_X_LPARAM(event.lparam)*2.0/window.get_width()-1.0, true);
38                 set_axis_value(MOUSE_Y_AXIS, 1.0-GET_Y_LPARAM(event.lparam)*2.0/window.get_height(), true);
39                 break;
40         }
41 }
42
43 } // namespace Input
44 } // namepsace Msp