]> git.tdb.fi Git - libs/gui.git/blobdiff - source/input/windows/touchscreen.cpp
Touchscreen input device
[libs/gui.git] / source / input / windows / touchscreen.cpp
diff --git a/source/input/windows/touchscreen.cpp b/source/input/windows/touchscreen.cpp
new file mode 100644 (file)
index 0000000..180f1c0
--- /dev/null
@@ -0,0 +1,47 @@
+#define _WIN32_WINNT 0x0601
+#include <windows.h>
+#include <msp/graphics/window_private.h>
+#include "touchscreen.h"
+
+using namespace std;
+
+namespace Msp {
+namespace Input {
+
+void Touchscreen::input_event(const Graphics::Window::Event &event)
+{
+       if(event.msg==WM_TOUCHMOVE)
+       {
+               HTOUCHINPUT handle = reinterpret_cast<HTOUCHINPUT>(event.lparam);
+               unsigned n_points = LOWORD(event.wparam);
+               /* If I ever invent a legitimate use case for more touch points than an
+               average human has fingers, I'll come up with something else here. */
+               TOUCHINPUT touch_buffer[10];
+               if(!GetTouchInputInfo(handle, 10, touch_buffer, sizeof(TOUCHINPUT)))
+                       return;
+
+               for(unsigned i=0; i<n_points; ++i)
+               {
+                       const TOUCHINPUT &point = touch_buffer[i];
+
+                       POINT screen_pt = { point.x/100, point.y/100 };
+                       POINT client_pt = screen_pt;
+                       ScreenToClient(window.get_private().window, &client_pt);
+                       float x = (point.x/100.0f-screen_pt.x+client_pt.x)*2.0f/window.get_width()-1.0f;
+                       float y = 1.0f-(point.y/100.0f-screen_pt.y+client_pt.y)*2.0f/window.get_height();
+
+                       touch_move(point.dwID, x, y);
+                       if(point.dwFlags&TOUCHEVENTF_DOWN)
+                               touch_down(point.dwID);
+                       else if(point.dwFlags&TOUCHEVENTF_UP)
+                               touch_up(point.dwID);
+               }
+
+               CloseTouchInputHandle(handle);
+       }
+}
+
+
+
+} // namespace Input
+} // namespace Msp