]> git.tdb.fi Git - libs/gui.git/blobdiff - source/input/mouse.cpp
Fix windows compilation
[libs/gui.git] / source / input / mouse.cpp
index 0fbc940f144b23537495cf99825db4b3e09fbc8b..cd89f94ad348a48efc7676fcfb52d9d4154a0b65 100644 (file)
@@ -1,11 +1,9 @@
-/* $Id$
-
-This file is part of libmspgbase
-Copyright © 2007 Mikko Rasa, Mikkosoft Productions
-Distributed under the LGPL
-*/
-
-#include <msp/strings/formatter.h>
+#ifdef WIN32
+#include <windowsx.h>
+#endif
+#include <msp/graphics/window.h>
+#include <msp/graphics/window_priv.h>
+#include <msp/strings/format.h>
 #include "mouse.h"
 
 namespace Msp {
@@ -14,14 +12,12 @@ namespace Input {
 Mouse::Mouse(Graphics::Window &w):
        window(w)
 {
-       name="Mouse";
+       name = "Mouse";
 
        buttons.resize(3);
        axes.resize(2);
 
-       window.signal_button_press.connect(sigc::mem_fun(this, &Mouse::button_press));
-       window.signal_button_release.connect(sigc::mem_fun(this, &Mouse::button_release));
-       window.signal_pointer_motion.connect(sigc::mem_fun(this, &Mouse::pointer_motion));
+       window.signal_input_event.connect(sigc::mem_fun(this, &Mouse::input_event));
 }
 
 std::string Mouse::get_button_name(unsigned btn) const
@@ -56,20 +52,48 @@ std::string Mouse::get_axis_name(unsigned axis) const
        };
 }
 
-void Mouse::button_press(int, int, unsigned btn, unsigned)
-{
-       set_button_state(btn, true, true);
-}
-
-void Mouse::button_release(int, int, unsigned btn, unsigned)
-{
-       set_button_state(btn, false, true);
-}
-
-void Mouse::pointer_motion(int x, int y)
+void Mouse::input_event(const Graphics::Window::Event &event)
 {
-       set_axis_value(0, x*2.0f/window.get_width()-1.0f, true);
-       set_axis_value(1, 1.0f-y*2.0f/window.get_height(), true);
+#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