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.
This commit is contained in:
gambas 2021-06-10 02:10:09 +02:00
parent c42a80d20f
commit 8a191771ec
4 changed files with 42 additions and 35 deletions

View file

@ -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

View file

@ -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)

View file

@ -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,

View file

@ -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