mirror of
https://github.com/love2d/love.git
synced 2026-08-17 19:23:38 +02:00
Replaced the mouse button constants ("l", "r", "m", etc.) with button numbers. 1 is the primary button, 2 is the secondary button, 3 is middle-mouse, etc. Resolves issue #1019.
This commit is contained in:
@@ -176,12 +176,27 @@ void Mouse::setVisible(bool visible)
|
||||
SDL_ShowCursor(visible ? SDL_ENABLE : SDL_DISABLE);
|
||||
}
|
||||
|
||||
bool Mouse::isDown(Button *buttonlist) const
|
||||
bool Mouse::isDown(const std::vector<int> &buttons) const
|
||||
{
|
||||
Uint32 buttonstate = SDL_GetMouseState(nullptr, nullptr);
|
||||
|
||||
for (Button button = *buttonlist; button != BUTTON_MAX_ENUM; button = *(++buttonlist))
|
||||
for (int button : buttons)
|
||||
{
|
||||
if (button <= 0)
|
||||
continue;
|
||||
|
||||
// We use button index 2 to represent the right mouse button, but SDL
|
||||
// uses 2 to represent the middle mouse button.
|
||||
switch (button)
|
||||
{
|
||||
case 2:
|
||||
button = SDL_BUTTON_RIGHT;
|
||||
break;
|
||||
case 3:
|
||||
button = SDL_BUTTON_MIDDLE;
|
||||
break;
|
||||
}
|
||||
|
||||
if (buttonstate & SDL_BUTTON(button))
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ class Mouse : public love::mouse::Mouse
|
||||
public:
|
||||
|
||||
// Implements Module.
|
||||
const char *getName() const;
|
||||
const char *getName() const override;
|
||||
|
||||
Mouse();
|
||||
~Mouse();
|
||||
@@ -62,7 +62,7 @@ public:
|
||||
void setY(double y);
|
||||
void setPosition(double x, double y);
|
||||
void setVisible(bool visible);
|
||||
bool isDown(Button *buttonlist) const;
|
||||
bool isDown(const std::vector<int> &buttons) const;
|
||||
bool isVisible() const;
|
||||
void setGrabbed(bool grab);
|
||||
bool isGrabbed() const;
|
||||
|
||||
Reference in New Issue
Block a user