From 8a191771ecb12a4ee6dd3d3fc3afa7adc3e6a64e Mon Sep 17 00:00:00 2001 From: gambas Date: Thu, 10 Jun 2021 02:10:09 +0200 Subject: [PATCH] Fix Mouse.Button and Mouse.State, especially for mouses having more than 3 buttons. [GB.GTK] * BUG: Now Mouse.Button returns the button number, between 1 and 5. * BUG: Mouse.State returns the same thing as with Qt components, except that apparently GTK+ cannot tell if button 4 and 5 are pressed all the time. [GB.GTK3] * BUG: Now Mouse.Button returns the button number, between 1 and 5. * BUG: Mouse.State returns the same thing as with Qt components, except that apparently GTK+ cannot tell if button 4 and 5 are pressed all the time. [GB.QT4] * BUG: Now Mouse.Button returns the button number, between 1 and 5. [GB.QT5] * BUG: Now Mouse.Button returns the button number, between 1 and 5. --- gb.gtk/src/CMouse.cpp | 21 +------------------ gb.gtk/src/gmouse.cpp | 40 +++++++++++++++++++++++------------- gb.qt4/share/gb.form.const.h | 2 ++ gb.qt4/src/CMouse.cpp | 14 ++++++++++++- 4 files changed, 42 insertions(+), 35 deletions(-) diff --git a/gb.gtk/src/CMouse.cpp b/gb.gtk/src/CMouse.cpp index 7d676c614..c0cc536b8 100644 --- a/gb.gtk/src/CMouse.cpp +++ b/gb.gtk/src/CMouse.cpp @@ -130,26 +130,7 @@ END_PROPERTY BEGIN_PROPERTY(Mouse_State) CHECK_VALID(); - - int state = gMouse::state(); - int result = 0; - - if (state & GDK_BUTTON1_MASK) - result |= MOUSE_LEFT; - if (state & GDK_BUTTON2_MASK) - result |= MOUSE_MIDDLE; - if (state & GDK_BUTTON3_MASK) - result |= MOUSE_RIGHT; - if (state & GDK_SHIFT_MASK) - result |= MOUSE_SHIFT; - if (state & GDK_CONTROL_MASK) - result |= MOUSE_CTRL; - if (state & GDK_MOD1_MASK) - result |= MOUSE_ALT; - if (state & GDK_MOD2_MASK) - result |= MOUSE_META; - - GB.ReturnInteger(result); + GB.ReturnInteger(gMouse::state()); END_PROPERTY diff --git a/gb.gtk/src/gmouse.cpp b/gb.gtk/src/gmouse.cpp index 2cbef1b33..ec4dd0888 100644 --- a/gb.gtk/src/gmouse.cpp +++ b/gb.gtk/src/gmouse.cpp @@ -71,12 +71,36 @@ void gMouse::move(int x, int y) int gMouse::button() { - return _isValid ? _button : 0; + int button = 0; + + if (_isValid) + { + button = _button; + if (_button >= 4) + button -= 4; + } + + return button; } int gMouse::state() { - return _isValid ? _state : 0; + int state = 0; + + if (_isValid) + { + if ((_state & GDK_BUTTON1_MASK) || _button == 1) state |= MOUSE_LEFT; + if ((_state & GDK_BUTTON2_MASK) || _button == 2) state |= MOUSE_MIDDLE; + if ((_state & GDK_BUTTON3_MASK) || _button == 3) state |= MOUSE_RIGHT; + if ((_state & GDK_BUTTON4_MASK) || _button == 8) state |= MOUSE_BUTTON4; + if ((_state & GDK_BUTTON5_MASK) || _button == 9) state |= MOUSE_BUTTON5; + if (_state & GDK_SHIFT_MASK) state |= MOUSE_SHIFT; + if (_state & GDK_CONTROL_MASK) state |= MOUSE_CTRL; + if (_state & GDK_MOD1_MASK) state |= MOUSE_ALT; + if (_state & GDK_MOD2_MASK) state |= MOUSE_META; + } + + return state; } bool gMouse::left() @@ -207,18 +231,6 @@ void gMouse::setMouse(int x, int y, int sx, int sy, int button, int state) _button = button; _screen_x = sx; _screen_y = sy; - - /*switch(button) - { - case 1: _button = 1; break; - case 2: _button = 4; break; - case 3: _button = 2; break; - default: - _button = 0; - if (_state & GDK_BUTTON1_MASK) _button += 1; - if (_state & GDK_BUTTON2_MASK) _button += 4; - if (_state & GDK_BUTTON3_MASK) _button += 2; - }*/ } static GdkDevice *get_event_device(GdkEvent *event) diff --git a/gb.qt4/share/gb.form.const.h b/gb.qt4/share/gb.form.const.h index eba6d6564..0f7f54b80 100644 --- a/gb.qt4/share/gb.form.const.h +++ b/gb.qt4/share/gb.form.const.h @@ -102,6 +102,8 @@ enum { MOUSE_LEFT = 1, MOUSE_MIDDLE = 2, MOUSE_RIGHT = 4, + MOUSE_BUTTON4 = 8, + MOUSE_BUTTON5 = 16, MOUSE_SHIFT = 256, MOUSE_CTRL = 512, MOUSE_ALT = 1024, diff --git a/gb.qt4/src/CMouse.cpp b/gb.qt4/src/CMouse.cpp index f1c7ad9ed..1b88344c4 100644 --- a/gb.qt4/src/CMouse.cpp +++ b/gb.qt4/src/CMouse.cpp @@ -262,8 +262,20 @@ END_PROPERTY BEGIN_PROPERTY(Mouse_Button) + int i; + CHECK_VALID(); - GB.ReturnInteger((int)MOUSE_info.button); + + for (i = 0; i < 5; i++) + { + if ((int)MOUSE_info.button & (1 << i)) + { + GB.ReturnInteger(i + 1); + return; + } + } + + GB.ReturnInteger(0); END_PROPERTY