Merge pull request #20063 from moiman100/fix-button-mask

Unified button mask behavior across platforms
This commit is contained in:
Rémi Verschelde 2018-12-14 23:31:52 +01:00 committed by GitHub
commit 57c3f6a94b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 31 additions and 51 deletions

View File

@ -452,7 +452,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());
@ -475,10 +474,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;

View File

@ -1075,6 +1075,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();
@ -1085,9 +1087,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);
}

View File

@ -496,15 +496,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)));
@ -673,15 +665,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);
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);
last_button_state = mb->get_button_mask();
mb->set_position(Vector2(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)));
if (mouse_mode == MOUSE_MODE_CAPTURED && !use_raw_input) {
@ -721,6 +710,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);
}

View File

@ -1433,37 +1433,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_type == ButtonPress) {
last_button_state |= mask;
} else {
last_button_state &= ~mask;
}
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;
}
last_button_state = state;
return state;
return last_button_state;
}
void OS_X11::handle_key_event(XKeyEvent *p_event, bool p_echo) {
@ -1967,14 +1947,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));
@ -2076,7 +2056,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);

View File

@ -136,7 +136,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;