]> git.tdb.fi Git - libs/gui.git/blob - source/input/windows/touchscreen.cpp
Touchscreen input device
[libs/gui.git] / source / input / windows / touchscreen.cpp
1 #define _WIN32_WINNT 0x0601
2 #include <windows.h>
3 #include <msp/graphics/window_private.h>
4 #include "touchscreen.h"
5
6 using namespace std;
7
8 namespace Msp {
9 namespace Input {
10
11 void Touchscreen::input_event(const Graphics::Window::Event &event)
12 {
13         if(event.msg==WM_TOUCHMOVE)
14         {
15                 HTOUCHINPUT handle = reinterpret_cast<HTOUCHINPUT>(event.lparam);
16                 unsigned n_points = LOWORD(event.wparam);
17                 /* If I ever invent a legitimate use case for more touch points than an
18                 average human has fingers, I'll come up with something else here. */
19                 TOUCHINPUT touch_buffer[10];
20                 if(!GetTouchInputInfo(handle, 10, touch_buffer, sizeof(TOUCHINPUT)))
21                         return;
22
23                 for(unsigned i=0; i<n_points; ++i)
24                 {
25                         const TOUCHINPUT &point = touch_buffer[i];
26
27                         POINT screen_pt = { point.x/100, point.y/100 };
28                         POINT client_pt = screen_pt;
29                         ScreenToClient(window.get_private().window, &client_pt);
30                         float x = (point.x/100.0f-screen_pt.x+client_pt.x)*2.0f/window.get_width()-1.0f;
31                         float y = 1.0f-(point.y/100.0f-screen_pt.y+client_pt.y)*2.0f/window.get_height();
32
33                         touch_move(point.dwID, x, y);
34                         if(point.dwFlags&TOUCHEVENTF_DOWN)
35                                 touch_down(point.dwID);
36                         else if(point.dwFlags&TOUCHEVENTF_UP)
37                                 touch_up(point.dwID);
38                 }
39
40                 CloseTouchInputHandle(handle);
41         }
42 }
43
44
45
46 } // namespace Input
47 } // namespace Msp