diff options
author | mm <40793342+moiman100@users.noreply.github.com> | 2018-07-08 16:12:13 +0300 |
---|---|---|
committer | unknown <40793342+moiman100@users.noreply.github.com> | 2018-07-11 01:15:03 +0300 |
commit | bd9c592c528034a58f4ede0bd2ba06760dd360b5 (patch) | |
tree | 4b8e95c7b69af6b1609bf5ee846f314312baa8ec | |
parent | a184126e8b2a74b47137b47001c1d11a092ccdaa (diff) |
Fixed button mask behavior
-rw-r--r-- | platform/javascript/os_javascript.cpp | 5 | ||||
-rw-r--r-- | platform/osx/os_osx.mm | 6 | ||||
-rw-r--r-- | platform/windows/os_windows.cpp | 27 | ||||
-rw-r--r-- | platform/x11/os_x11.cpp | 44 | ||||
-rw-r--r-- | platform/x11/os_x11.h | 2 |
5 files changed, 32 insertions, 52 deletions
diff --git a/platform/javascript/os_javascript.cpp b/platform/javascript/os_javascript.cpp index c05ae03ec6..6d34b0da1f 100644 --- a/platform/javascript/os_javascript.cpp +++ b/platform/javascript/os_javascript.cpp @@ -461,7 +461,6 @@ EM_BOOL OS_JavaScript::wheel_callback(int p_event_type, const EmscriptenWheelEve InputDefault *input = get_singleton()->input; Ref<InputEventMouseButton> ev; ev.instance(); - ev->set_button_mask(input->get_mouse_button_mask()); ev->set_position(input->get_mouse_position()); ev->set_global_position(ev->get_position()); @@ -484,10 +483,14 @@ EM_BOOL OS_JavaScript::wheel_callback(int p_event_type, const EmscriptenWheelEve // Different browsers give wildly different delta values, and we can't // interpret deltaMode, so use default value for wheel events' factor. + int button_flag = 1 << (ev->get_button_index() - 1); + ev->set_pressed(true); + ev->set_button_mask(input->get_mouse_button_mask() | button_flag); input->parse_input_event(ev); ev->set_pressed(false); + ev->set_button_mask(input->get_mouse_button_mask() & ~button_flag); input->parse_input_event(ev); return true; diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm index 41a19ac992..3fce7ed4ad 100644 --- a/platform/osx/os_osx.mm +++ b/platform/osx/os_osx.mm @@ -1047,6 +1047,8 @@ static int remapKey(unsigned int key) { inline void sendScrollEvent(int button, double factor, int modifierFlags) { + unsigned int mask = 1 << (button - 1); + Ref<InputEventMouseButton> sc; sc.instance(); @@ -1057,9 +1059,13 @@ inline void sendScrollEvent(int button, double factor, int modifierFlags) { Vector2 mouse_pos = Vector2(mouse_x, mouse_y); sc->set_position(mouse_pos); sc->set_global_position(mouse_pos); + button_mask |= mask; sc->set_button_mask(button_mask); OS_OSX::singleton->push_input(sc); + sc->set_pressed(false); + button_mask &= ~mask; + sc->set_button_mask(button_mask); OS_OSX::singleton->push_input(sc); } diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index 05d16a5964..6eb87e4f50 100644 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -430,15 +430,7 @@ LRESULT OS_Windows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) mm->set_shift((wParam & MK_SHIFT) != 0); mm->set_alt(alt_mem); - int bmask = 0; - bmask |= (wParam & MK_LBUTTON) ? (1 << 0) : 0; - bmask |= (wParam & MK_RBUTTON) ? (1 << 1) : 0; - bmask |= (wParam & MK_MBUTTON) ? (1 << 2) : 0; - bmask |= (wParam & MK_XBUTTON1) ? (1 << 7) : 0; - bmask |= (wParam & MK_XBUTTON2) ? (1 << 8) : 0; - mm->set_button_mask(bmask); - - last_button_state = mm->get_button_mask(); + mm->set_button_mask(last_button_state); mm->set_position(Vector2(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))); mm->set_global_position(Vector2(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))); @@ -607,15 +599,12 @@ LRESULT OS_Windows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) mb->set_shift((wParam & MK_SHIFT) != 0); mb->set_alt(alt_mem); //mb->get_alt()=(wParam&MK_MENU)!=0; - int bmask = 0; - bmask |= (wParam & MK_LBUTTON) ? (1 << 0) : 0; - bmask |= (wParam & MK_RBUTTON) ? (1 << 1) : 0; - bmask |= (wParam & MK_MBUTTON) ? (1 << 2) : 0; - bmask |= (wParam & MK_XBUTTON1) ? (1 << 7) : 0; - bmask |= (wParam & MK_XBUTTON2) ? (1 << 8) : 0; - mb->set_button_mask(bmask); - - last_button_state = mb->get_button_mask(); + if (mb->is_pressed()) + last_button_state |= (1 << (mb->get_button_index() - 1)); + else + last_button_state &= ~(1 << (mb->get_button_index() - 1)); + mb->set_button_mask(last_button_state); + mb->set_position(Vector2(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam))); if (mouse_mode == MOUSE_MODE_CAPTURED) { @@ -653,6 +642,8 @@ LRESULT OS_Windows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) if (mb->is_pressed() && mb->get_button_index() > 3 && mb->get_button_index() < 8) { //send release for mouse wheel Ref<InputEventMouseButton> mbd = mb->duplicate(); + last_button_state &= ~(1 << (mbd->get_button_index() - 1)); + mbd->set_button_mask(last_button_state); mbd->set_pressed(false); input->parse_input_event(mbd); } diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index 2bc85f76c9..98aa7c8e48 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -1350,37 +1350,17 @@ void OS_X11::get_key_modifier_state(unsigned int p_x11_state, Ref<InputEventWith state->set_metakey((p_x11_state & Mod4Mask)); } -unsigned int OS_X11::get_mouse_button_state(unsigned int p_x11_state) { +unsigned int OS_X11::get_mouse_button_state(unsigned int p_x11_button, int p_x11_type) { - unsigned int state = 0; + unsigned int mask = 1 << (p_x11_button - 1); - if (p_x11_state & Button1Mask) { - - state |= 1 << 0; - } - - if (p_x11_state & Button3Mask) { - - state |= 1 << 1; - } - - if (p_x11_state & Button2Mask) { - - state |= 1 << 2; - } - - if (p_x11_state & Button4Mask) { - - state |= 1 << 3; - } - - if (p_x11_state & Button5Mask) { - - state |= 1 << 4; + if (p_x11_type == ButtonPress) { + last_button_state |= mask; + } else { + last_button_state &= ~mask; } - last_button_state = state; - return state; + return last_button_state; } void OS_X11::handle_key_event(XKeyEvent *p_event, bool p_echo) { @@ -1885,14 +1865,14 @@ void OS_X11::process_xevents() { mb.instance(); get_key_modifier_state(event.xbutton.state, mb); - mb->set_button_mask(get_mouse_button_state(event.xbutton.state)); - mb->set_position(Vector2(event.xbutton.x, event.xbutton.y)); - mb->set_global_position(mb->get_position()); - mb->set_button_index(event.xbutton.button); if (mb->get_button_index() == 2) mb->set_button_index(3); else if (mb->get_button_index() == 3) mb->set_button_index(2); + mb->set_button_mask(get_mouse_button_state(event.xbutton.button, event.xbutton.type)); + mb->set_position(Vector2(event.xbutton.x, event.xbutton.y)); + mb->set_global_position(mb->get_position()); + mb->set_button_index(event.xbutton.button); mb->set_pressed((event.type == ButtonPress)); @@ -1996,7 +1976,7 @@ void OS_X11::process_xevents() { mm.instance(); get_key_modifier_state(event.xmotion.state, mm); - mm->set_button_mask(get_mouse_button_state(event.xmotion.state)); + mm->set_button_mask(get_mouse_button_state()); mm->set_position(pos); mm->set_global_position(pos); input->set_mouse_position(pos); diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h index 8cab23fe63..da7e0e3e4b 100644 --- a/platform/x11/os_x11.h +++ b/platform/x11/os_x11.h @@ -135,7 +135,7 @@ class OS_X11 : public OS_Unix { } touch; #endif - unsigned int get_mouse_button_state(unsigned int p_x11_state); + unsigned int get_mouse_button_state(unsigned int p_x11_button, int p_x11_type); void get_key_modifier_state(unsigned int p_x11_state, Ref<InputEventWithModifiers> state); MouseMode mouse_mode; |