mirror of
https://github.com/love2d/love.git
synced 2026-08-12 16:40:57 +02:00
Make love.mouse.isDown accept a list too
Credits go to Boolsheet for making this patch (imported unmodified!)
This commit is contained in:
@@ -63,14 +63,17 @@ namespace sdl
|
||||
SDL_ShowCursor(visible ? SDL_ENABLE : SDL_DISABLE);
|
||||
}
|
||||
|
||||
bool Mouse::isDown(Button button) const
|
||||
bool Mouse::isDown(Button * buttonlist) const
|
||||
{
|
||||
unsigned b = 0;
|
||||
Uint8 buttonstate = SDL_GetMouseState(0, 0);
|
||||
|
||||
if(!buttons.find(button, b))
|
||||
return false;
|
||||
for (Button button = *buttonlist; button != BUTTON_MAX_ENUM; button = *(++buttonlist))
|
||||
{
|
||||
if (buttonstate & SDL_BUTTON(button))
|
||||
return true;
|
||||
}
|
||||
|
||||
return (SDL_GetMouseState(0, 0) & SDL_BUTTON(b)) != 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Mouse::isVisible() const
|
||||
|
||||
@@ -43,7 +43,7 @@ namespace sdl
|
||||
void getPosition(int & x, int & y) const;
|
||||
void setPosition(int x, int y);
|
||||
void setVisible(bool visible);
|
||||
bool isDown(Button button) const;
|
||||
bool isDown(Button * buttonlist) const;
|
||||
bool isVisible() const;
|
||||
void setGrab(bool grab);
|
||||
bool isGrabbed() const;
|
||||
@@ -59,4 +59,4 @@ namespace sdl
|
||||
} // mouse
|
||||
} // love
|
||||
|
||||
#endif // LOVE_MOUSE_SDL_MOUSE_H
|
||||
#endif // LOVE_MOUSE_SDL_MOUSE_H
|
||||
|
||||
@@ -59,13 +59,20 @@ namespace sdl
|
||||
|
||||
int w_isDown(lua_State * L)
|
||||
{
|
||||
Mouse::Button button;
|
||||
|
||||
if(!Mouse::getConstant(luaL_checkstring(L, 1), button))
|
||||
luax_pushboolean(L, false);
|
||||
else
|
||||
luax_pushboolean(L, instance->isDown(button));
|
||||
|
||||
Mouse::Button b;
|
||||
unsigned int num = lua_gettop(L);
|
||||
Mouse::Button * buttonlist = new Mouse::Button[num+1];
|
||||
unsigned int counter = 0;
|
||||
|
||||
for (unsigned int i = 0; i < num; i++)
|
||||
{
|
||||
if(Mouse::getConstant(luaL_checkstring(L, i+1), b))
|
||||
buttonlist[counter++] = b;
|
||||
}
|
||||
buttonlist[counter] = Mouse::BUTTON_MAX_ENUM;
|
||||
|
||||
luax_pushboolean(L, instance->isDown(buttonlist));
|
||||
delete[] buttonlist;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user