mirror of
https://github.com/love2d/love.git
synced 2026-08-17 11:00:31 +02:00
Finally abstracted constants properly. Changed how the event module works; wasn't really abstract before. Removed libs we're not going to use: native, signal.
This commit is contained in:
@@ -48,9 +48,9 @@ namespace sdl
|
||||
return y;
|
||||
}
|
||||
|
||||
void Mouse::getPosition(int * x, int * y) const
|
||||
void Mouse::getPosition(int & x, int & y) const
|
||||
{
|
||||
SDL_GetMouseState(x, y);
|
||||
SDL_GetMouseState(&x, &y);
|
||||
}
|
||||
|
||||
void Mouse::setPosition(int x, int y)
|
||||
@@ -63,9 +63,14 @@ namespace sdl
|
||||
SDL_ShowCursor(visible ? SDL_ENABLE : SDL_DISABLE);
|
||||
}
|
||||
|
||||
bool Mouse::isDown(int button) const
|
||||
bool Mouse::isDown(Button button) const
|
||||
{
|
||||
return (SDL_GetMouseState(0, 0) & SDL_BUTTON(button)) != 0;
|
||||
unsigned b = 0;
|
||||
|
||||
if(!buttons.find(button, b))
|
||||
return false;
|
||||
|
||||
return (SDL_GetMouseState(0, 0) & SDL_BUTTON(b)) != 0;
|
||||
}
|
||||
|
||||
bool Mouse::isVisible() const
|
||||
@@ -83,6 +88,19 @@ namespace sdl
|
||||
return (SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_ON ? true : false);
|
||||
}
|
||||
|
||||
EnumMap<Mouse::Button, unsigned, Mouse::BUTTON_MAX_ENUM>::Entry Mouse::buttonEntries[] =
|
||||
{
|
||||
{ Mouse::BUTTON_LEFT, SDL_BUTTON_LEFT},
|
||||
{ Mouse::BUTTON_MIDDLE, SDL_BUTTON_MIDDLE},
|
||||
{ Mouse::BUTTON_RIGHT, SDL_BUTTON_RIGHT},
|
||||
{ Mouse::BUTTON_WHEELUP, SDL_BUTTON_WHEELUP},
|
||||
{ Mouse::BUTTON_WHEELDOWN, SDL_BUTTON_WHEELDOWN},
|
||||
{ Mouse::BUTTON_X1, SDL_BUTTON_X1},
|
||||
{ Mouse::BUTTON_X2, SDL_BUTTON_X2},
|
||||
};
|
||||
|
||||
EnumMap<Mouse::Button, unsigned, Mouse::BUTTON_MAX_ENUM> Mouse::buttons(Mouse::buttonEntries, sizeof(Mouse::buttonEntries));
|
||||
|
||||
} // sdl
|
||||
} // mouse
|
||||
} // love
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
|
||||
// LOVE
|
||||
#include <mouse/Mouse.h>
|
||||
#include <common/EnumMap.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
@@ -39,14 +40,19 @@ namespace sdl
|
||||
|
||||
int getX() const;
|
||||
int getY() const;
|
||||
void getPosition(int * x, int * y) const;
|
||||
void getPosition(int & x, int & y) const;
|
||||
void setPosition(int x, int y);
|
||||
void setVisible(bool visible);
|
||||
bool isDown(int button) const;
|
||||
bool isDown(Button button) const;
|
||||
bool isVisible() const;
|
||||
void setGrab(bool grab);
|
||||
bool isGrabbed() const;
|
||||
|
||||
public:
|
||||
|
||||
static EnumMap<Button, unsigned, BUTTON_MAX_ENUM>::Entry buttonEntries[];
|
||||
static EnumMap<Button, unsigned, BUTTON_MAX_ENUM> buttons;
|
||||
|
||||
}; // Mouse
|
||||
|
||||
} // sdl
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace love
|
||||
namespace mouse
|
||||
{
|
||||
namespace sdl
|
||||
{
|
||||
{
|
||||
static Mouse * instance = 0;
|
||||
|
||||
int w_getX(lua_State * L)
|
||||
@@ -43,7 +43,7 @@ namespace sdl
|
||||
int w_getPosition(lua_State * L)
|
||||
{
|
||||
int x, y;
|
||||
instance->getPosition(&x, &y);
|
||||
instance->getPosition(x, y);
|
||||
lua_pushinteger(L, x);
|
||||
lua_pushinteger(L, y);
|
||||
return 2;
|
||||
@@ -59,8 +59,13 @@ namespace sdl
|
||||
|
||||
int w_isDown(lua_State * L)
|
||||
{
|
||||
int b = luaL_checkint(L, 1);
|
||||
luax_pushboolean(L, instance->isDown(b));
|
||||
Mouse::Button button;
|
||||
|
||||
if(!Mouse::getConstant(luaL_checkstring(L, 1), button))
|
||||
luax_pushboolean(L, false);
|
||||
else
|
||||
luax_pushboolean(L, instance->isDown(button));
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -104,17 +109,6 @@ namespace sdl
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
// List of constants.
|
||||
static const Constant constants[] = {
|
||||
{ "mouse_left", Mouse::MOUSE_LEFT },
|
||||
{ "mouse_middle", Mouse::MOUSE_MIDDLE },
|
||||
{ "mouse_right", Mouse::MOUSE_RIGHT },
|
||||
{ "mouse_wheelup", Mouse::MOUSE_WHEELUP },
|
||||
{ "mouse_wheeldown", Mouse::MOUSE_WHEELDOWN },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
|
||||
int luaopen_love_mouse(lua_State * L)
|
||||
{
|
||||
if(instance == 0)
|
||||
@@ -135,7 +129,6 @@ namespace sdl
|
||||
w.flags = MODULE_T;
|
||||
w.functions = functions;
|
||||
w.types = 0;
|
||||
w.constants = constants;
|
||||
|
||||
return luax_register_module(L, w);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user