diff options
Diffstat (limited to 'platform/windows/os_windows.cpp')
-rw-r--r-- | platform/windows/os_windows.cpp | 151 |
1 files changed, 125 insertions, 26 deletions
diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index 64219d6c17..5e57827c68 100644 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -206,6 +206,54 @@ bool OS_Windows::can_draw() const { return !minimized; }; +#define MI_WP_SIGNATURE 0xFF515700 +#define SIGNATURE_MASK 0xFFFFFF00 +#define IsPenEvent(dw) (((dw) & SIGNATURE_MASK) == MI_WP_SIGNATURE) + + +void OS_Windows::_touch_event(int idx, UINT uMsg, WPARAM wParam, LPARAM lParam) { + + InputEvent event; + event.type = InputEvent::SCREEN_TOUCH; + event.ID=++last_id; + event.screen_touch.index = idx; + + switch (uMsg) { + case WM_LBUTTONDOWN: + case WM_MBUTTONDOWN: + case WM_RBUTTONDOWN: { + + event.screen_touch.pressed = true; + } break; + + case WM_LBUTTONUP: + case WM_MBUTTONUP: + case WM_RBUTTONUP: { + event.screen_touch.pressed = false; + } break; + }; + + event.screen_touch.x=GET_X_LPARAM(lParam); + event.screen_touch.y=GET_Y_LPARAM(lParam); + + if (main_loop) { + input->parse_input_event(event); + } +}; + +void OS_Windows::_drag_event(int idx,UINT uMsg, WPARAM wParam, LPARAM lParam) { + + InputEvent event; + event.type = InputEvent::SCREEN_DRAG; + event.ID=++last_id; + event.screen_drag.index = idx; + + event.screen_drag.x=GET_X_LPARAM(lParam); + event.screen_drag.y=GET_Y_LPARAM(lParam); + + if (main_loop) + input->parse_input_event(event); +}; LRESULT OS_Windows::WndProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam) { @@ -270,28 +318,41 @@ LRESULT OS_Windows::WndProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam) { } case WM_MOUSELEAVE: { - old_invalid=true; - outside=true; + old_invalid=true; + outside=true; } break; case WM_MOUSEMOVE: { - if (outside) { + if (outside) { - CursorShape c=cursor_shape; - cursor_shape=CURSOR_MAX; - set_cursor_shape(c); - outside=false; + CursorShape c=cursor_shape; + cursor_shape=CURSOR_MAX; + set_cursor_shape(c); + outside=false; + + //Once-Off notification, must call again.... + TRACKMOUSEEVENT tme; + tme.cbSize=sizeof(TRACKMOUSEEVENT); + tme.dwFlags=TME_LEAVE; + tme.hwndTrack=hWnd; + tme.dwHoverTime=HOVER_DEFAULT; + TrackMouseEvent(&tme); + + } + + LPARAM extra = GetMessageExtraInfo(); + if (IsPenEvent(extra)) { + + int idx = extra & 0x7f; + _drag_event(idx, uMsg, wParam, lParam); + if (idx != 0) { + return 0; + }; + // fallthrough for mouse event + }; - //Once-Off notification, must call again.... - TRACKMOUSEEVENT tme; - tme.cbSize=sizeof(TRACKMOUSEEVENT); - tme.dwFlags=TME_LEAVE; - tme.hwndTrack=hWnd; - tme.dwHoverTime=HOVER_DEFAULT; - TrackMouseEvent(&tme); - } InputEvent event; event.type=InputEvent::MOUSE_MOTION; event.ID=++last_id; @@ -360,6 +421,17 @@ LRESULT OS_Windows::WndProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam) { /*case WM_XBUTTONDOWN: case WM_XBUTTONUP: */{ + LPARAM extra = GetMessageExtraInfo(); + if (IsPenEvent(extra)) { + + int idx = extra & 0x7f; + _touch_event(idx, uMsg, wParam, lParam); + if (idx != 0) { + return 0; + }; + // fallthrough for mouse event + }; + InputEvent event; event.type=InputEvent::MOUSE_BUTTON; event.ID=++last_id; @@ -574,6 +646,8 @@ LRESULT CALLBACK WndProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam) { void OS_Windows::probe_joysticks() { + static uint32_t last_attached = 0; + int device_count = joyGetNumDevs(); JOYINFOEX jinfo; @@ -582,21 +656,40 @@ void OS_Windows::probe_joysticks() { for (int i=0; i<JOYSTICKS_MAX; i++) { - joysticks[i].attached = (device_count > 0) && (joyGetPosEx(JOYSTICKID1 + i, &jinfo) == JOYERR_NOERROR); - - if (!joysticks[i].attached) { + Joystick joy; + joy.id = i; + joy.attached = (device_count > 0) && (joyGetPosEx(JOYSTICKID1 + i, &jinfo) == JOYERR_NOERROR); + if (joy.attached == (last_attached & (1 << i) != 0)) { continue; }; - joysticks[i].last_buttons = jinfo.dwButtons; + // there's been a change since last call + + if (joy.attached) + last_attached = last_attached | (1 << i); + else + last_attached &= ~(1 << i); + + if (joy.attached) { + + joy.last_buttons = jinfo.dwButtons; - joysticks[i].last_axis[0] = jinfo.dwXpos; - joysticks[i].last_axis[1] = jinfo.dwYpos; - joysticks[i].last_axis[2] = jinfo.dwZpos; - joysticks[i].last_axis[3] = jinfo.dwRpos; - joysticks[i].last_axis[4] = jinfo.dwUpos; - joysticks[i].last_axis[5] = jinfo.dwVpos; + joy.last_axis[0] = jinfo.dwXpos; + joy.last_axis[1] = jinfo.dwYpos; + joy.last_axis[2] = jinfo.dwZpos; + joy.last_axis[3] = jinfo.dwRpos; + joy.last_axis[4] = jinfo.dwUpos; + joy.last_axis[5] = jinfo.dwVpos; + + JOYCAPS jcaps; + MMRESULT res = joyGetDevCaps(JOYSTICKID1 + i, &jcaps, sizeof(jcaps)); + if (res == JOYERR_NOERROR) { + joy.name = jcaps.szPname; + }; + }; + + joystick_change_queue.push_back(joy); }; }; @@ -998,7 +1091,13 @@ void OS_Windows::initialize(const VideoMode& p_desired,int p_video_driver,int p_ spatial_sound_2d_server = memnew( SpatialSound2DServerSW ); spatial_sound_2d_server->init(); - probe_joysticks(); + probe_joysticks(); // todo: move this to a thread + while (joystick_change_queue.size() > 0) { + Joystick joy = joystick_change_queue.front()->get(); + joystick_change_queue.pop_front(); + joysticks[joy.id] = joy; + input->joy_connection_changed(joy.id, joy.attached, joy.name); + }; TRACKMOUSEEVENT tme; tme.cbSize=sizeof(TRACKMOUSEEVENT); |