]> git.tdb.fi Git - libs/gui.git/blobdiff - source/input/mouse.cpp
Include the matching header first in .cpp files
[libs/gui.git] / source / input / mouse.cpp
index fce870f23aaf367b54155b55f5b9af82b0b51ac3..e379576363a3d29bff734fcf341036334e89c035 100644 (file)
@@ -1,14 +1,12 @@
-#ifdef WIN32
-#include <windowsx.h>
-#endif
-#include <msp/graphics/window.h>
-#include <msp/graphics/window_priv.h>
 #include "mouse.h"
+#include <msp/graphics/window.h>
+#include "keys.h"
 
 namespace Msp {
 namespace Input {
 
 Mouse::Mouse(Graphics::Window &w):
+       Device(MOUSE),
        window(w)
 {
        name = "Mouse";
@@ -23,15 +21,15 @@ std::string Mouse::get_button_name(unsigned btn) const
 {
        switch(btn)
        {
-       case 1:
+       case MOUSE_LEFT:
                return "Left";
-       case 2:
+       case MOUSE_MIDDLE:
                return "Middle";
-       case 3:
+       case MOUSE_RIGHT:
                return "Right";
-       case 4:
+       case MOUSE_WHEEL_UP:
                return "Wheel Up";
-       case 5:
+       case MOUSE_WHEEL_DOWN:
                return "Wheel Down";
        default:
                return Device::get_button_name(btn);
@@ -42,58 +40,14 @@ std::string Mouse::get_axis_name(unsigned axis) const
 {
        switch(axis)
        {
-       case 0:
+       case MOUSE_X_AXIS:
                return "X axis";
-       case 1:
+       case MOUSE_Y_AXIS:
                return "Y axis";
        default:
                return Device::get_axis_name(axis);
        };
 }
 
-void Mouse::input_event(const Graphics::Window::Event &event)
-{
-#ifdef WIN32
-       switch(event.msg)
-       {
-       case WM_LBUTTONDOWN:
-       case WM_LBUTTONUP:
-               set_button_state(1, event.msg==WM_LBUTTONDOWN, true);
-               break;
-       case WM_MBUTTONDOWN:
-       case WM_MBUTTONUP:
-               set_button_state(2, event.msg==WM_LBUTTONDOWN, true);
-               break;
-       case WM_RBUTTONDOWN:
-       case WM_RBUTTONUP:
-               set_button_state(3, event.msg==WM_LBUTTONDOWN, true);
-               break;
-       case WM_MOUSEWHEEL:
-               {
-                       unsigned btn = (HIWORD(event.wparam)&0x8000) ? 5 : 4;
-                       set_button_state(btn, true, true);
-                       set_button_state(btn, false, true);
-               }
-               break;
-       case WM_MOUSEMOVE:
-               set_axis_value(0, GET_X_LPARAM(event.lparam)*2.0/window.get_width()-1.0, true);
-               set_axis_value(1, 1.0-GET_Y_LPARAM(event.lparam)*2.0/window.get_height(), true);
-               break;
-       }
-#else
-       switch(event.xevent.type)
-       {
-       case ButtonPress:
-       case ButtonRelease:
-               set_button_state(event.xevent.xbutton.button, event.xevent.type==ButtonPress, true);
-               break;
-       case MotionNotify:
-               set_axis_value(0, event.xevent.xmotion.x*2.0/window.get_width()-1.0, true);
-               set_axis_value(1, 1.0-event.xevent.xmotion.y*2.0/window.get_height(), true);
-               break;
-       }
-#endif
-}
-
 } // namespace Input
 } // namespace Msp