mirror of
https://github.com/love2d/love-android.git
synced 2026-08-19 20:20:25 +02:00
updated to latest mobile-common (0cf55b7da58e), removed libtiff, libpng, libmng, devil, jasper, jpeg-8d, added libturbo-jpeg
This commit is contained in:
@@ -51,6 +51,9 @@ public:
|
||||
|
||||
virtual ~Mouse() {}
|
||||
|
||||
// Implements Module.
|
||||
virtual ModuleType getModuleType() const { return M_MOUSE; }
|
||||
|
||||
virtual Cursor *newCursor(love::image::ImageData *data, int hotx, int hoty) = 0;
|
||||
virtual Cursor *getSystemCursor(Cursor::SystemCursor cursortype) = 0;
|
||||
|
||||
@@ -59,6 +62,8 @@ public:
|
||||
|
||||
virtual Cursor *getCursor() const = 0;
|
||||
|
||||
virtual bool hasCursor() const = 0;
|
||||
|
||||
virtual int getX() const = 0;
|
||||
virtual int getY() const = 0;
|
||||
virtual void getPosition(int &x, int &y) const = 0;
|
||||
|
||||
@@ -81,11 +81,11 @@ Mouse::Mouse()
|
||||
|
||||
Mouse::~Mouse()
|
||||
{
|
||||
if (curCursor)
|
||||
if (curCursor.get())
|
||||
setCursor();
|
||||
|
||||
for (auto it = systemCursors.begin(); it != systemCursors.end(); ++it)
|
||||
it->second->release();
|
||||
for (auto &c : systemCursors)
|
||||
c.second->release();
|
||||
}
|
||||
|
||||
love::mouse::Cursor *Mouse::newCursor(love::image::ImageData *data, int hotx, int hoty)
|
||||
@@ -95,7 +95,7 @@ love::mouse::Cursor *Mouse::newCursor(love::image::ImageData *data, int hotx, in
|
||||
|
||||
love::mouse::Cursor *Mouse::getSystemCursor(Cursor::SystemCursor cursortype)
|
||||
{
|
||||
Cursor *cursor = NULL;
|
||||
Cursor *cursor = nullptr;
|
||||
auto it = systemCursors.find(cursortype);
|
||||
|
||||
if (it != systemCursors.end())
|
||||
@@ -111,25 +111,24 @@ love::mouse::Cursor *Mouse::getSystemCursor(Cursor::SystemCursor cursortype)
|
||||
|
||||
void Mouse::setCursor(love::mouse::Cursor *cursor)
|
||||
{
|
||||
Object::AutoRelease cursorrelease(curCursor);
|
||||
|
||||
curCursor = cursor;
|
||||
curCursor->retain();
|
||||
|
||||
curCursor.set(cursor);
|
||||
SDL_SetCursor((SDL_Cursor *) cursor->getHandle());
|
||||
}
|
||||
|
||||
void Mouse::setCursor()
|
||||
{
|
||||
Object::AutoRelease cursorrelease(curCursor);
|
||||
curCursor = NULL;
|
||||
|
||||
curCursor.set(nullptr);
|
||||
SDL_SetCursor(SDL_GetDefaultCursor());
|
||||
}
|
||||
|
||||
love::mouse::Cursor *Mouse::getCursor() const
|
||||
{
|
||||
return curCursor;
|
||||
return curCursor.get();
|
||||
}
|
||||
|
||||
bool Mouse::hasCursor() const
|
||||
{
|
||||
return SDL_GetDefaultCursor() != nullptr;
|
||||
}
|
||||
|
||||
int Mouse::getX() const
|
||||
|
||||
@@ -53,6 +53,8 @@ public:
|
||||
|
||||
love::mouse::Cursor *getCursor() const;
|
||||
|
||||
bool hasCursor() const;
|
||||
|
||||
int getX() const;
|
||||
int getY() const;
|
||||
void getPosition(int &x, int &y) const;
|
||||
@@ -67,7 +69,7 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
love::mouse::Cursor *curCursor;
|
||||
Object::StrongRef<love::mouse::Cursor> curCursor;
|
||||
|
||||
std::map<Cursor::SystemCursor, Cursor *> systemCursors;
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace love
|
||||
namespace mouse
|
||||
{
|
||||
|
||||
static Mouse *instance = nullptr;
|
||||
#define instance() (Module::getInstance<Mouse>(Module::M_MOUSE))
|
||||
|
||||
int w_newCursor(lua_State *L)
|
||||
{
|
||||
@@ -43,9 +43,10 @@ int w_newCursor(lua_State *L)
|
||||
int hotx = luaL_optint(L, 2, 0);
|
||||
int hoty = luaL_optint(L, 3, 0);
|
||||
|
||||
EXCEPT_GUARD(cursor = instance->newCursor(data, hotx, hoty);)
|
||||
luax_catchexcept(L, [&](){ cursor = instance()->newCursor(data, hotx, hoty); });
|
||||
|
||||
luax_pushtype(L, "Cursor", MOUSE_CURSOR_T, cursor);
|
||||
cursor->release();
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -58,9 +59,8 @@ int w_getSystemCursor(lua_State *L)
|
||||
return luaL_error(L, "Invalid system cursor type: %s", str);
|
||||
|
||||
Cursor *cursor = 0;
|
||||
EXCEPT_GUARD(cursor = instance->getSystemCursor(systemCursor);)
|
||||
luax_catchexcept(L, [&](){ cursor = instance()->getSystemCursor(systemCursor); });
|
||||
|
||||
cursor->retain();
|
||||
luax_pushtype(L, "Cursor", MOUSE_CURSOR_T, cursor);
|
||||
return 1;
|
||||
}
|
||||
@@ -70,46 +70,49 @@ int w_setCursor(lua_State *L)
|
||||
// Revert to the default system cursor if no argument is given.
|
||||
if (lua_isnoneornil(L, 1))
|
||||
{
|
||||
instance->setCursor();
|
||||
instance()->setCursor();
|
||||
return 0;
|
||||
}
|
||||
|
||||
Cursor *cursor = luax_checkcursor(L, 1);
|
||||
instance->setCursor(cursor);
|
||||
instance()->setCursor(cursor);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_getCursor(lua_State *L)
|
||||
{
|
||||
Cursor *cursor = instance->getCursor();
|
||||
Cursor *cursor = instance()->getCursor();
|
||||
|
||||
if (cursor)
|
||||
{
|
||||
cursor->retain();
|
||||
luax_pushtype(L, "Cursor", MOUSE_CURSOR_T, cursor);
|
||||
}
|
||||
else
|
||||
lua_pushnil(L);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_hasCursor(lua_State *L)
|
||||
{
|
||||
luax_pushboolean(L, instance()->hasCursor());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_getX(lua_State *L)
|
||||
{
|
||||
lua_pushnumber(L, instance->getX());
|
||||
lua_pushnumber(L, instance()->getX());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_getY(lua_State *L)
|
||||
{
|
||||
lua_pushnumber(L, instance->getY());
|
||||
lua_pushnumber(L, instance()->getY());
|
||||
return 1;
|
||||
}
|
||||
|
||||
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;
|
||||
@@ -118,14 +121,14 @@ int w_getPosition(lua_State *L)
|
||||
int w_setX(lua_State *L)
|
||||
{
|
||||
int x = luaL_checkint(L, 1);
|
||||
instance->setX(x);
|
||||
instance()->setX(x);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_setY(lua_State *L)
|
||||
{
|
||||
int y = luaL_checkint(L, 1);
|
||||
instance->setY(y);
|
||||
instance()->setY(y);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -133,7 +136,7 @@ int w_setPosition(lua_State *L)
|
||||
{
|
||||
int x = luaL_checkint(L, 1);
|
||||
int y = luaL_checkint(L, 2);
|
||||
instance->setPosition(x, y);
|
||||
instance()->setPosition(x, y);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -151,7 +154,7 @@ int w_isDown(lua_State *L)
|
||||
}
|
||||
buttonlist[counter] = Mouse::BUTTON_MAX_ENUM;
|
||||
|
||||
luax_pushboolean(L, instance->isDown(buttonlist));
|
||||
luax_pushboolean(L, instance()->isDown(buttonlist));
|
||||
delete[] buttonlist;
|
||||
return 1;
|
||||
}
|
||||
@@ -159,26 +162,26 @@ int w_isDown(lua_State *L)
|
||||
int w_setVisible(lua_State *L)
|
||||
{
|
||||
bool b = luax_toboolean(L, 1);
|
||||
instance->setVisible(b);
|
||||
instance()->setVisible(b);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_isVisible(lua_State *L)
|
||||
{
|
||||
luax_pushboolean(L, instance->isVisible());
|
||||
luax_pushboolean(L, instance()->isVisible());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_setGrabbed(lua_State *L)
|
||||
{
|
||||
bool b = luax_toboolean(L, 1);
|
||||
instance->setGrabbed(b);
|
||||
instance()->setGrabbed(b);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_isGrabbed(lua_State *L)
|
||||
{
|
||||
luax_pushboolean(L, instance->isGrabbed());
|
||||
luax_pushboolean(L, instance()->isGrabbed());
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -189,6 +192,7 @@ static const luaL_Reg functions[] =
|
||||
{ "getSystemCursor", w_getSystemCursor },
|
||||
{ "setCursor", w_setCursor },
|
||||
{ "getCursor", w_getCursor },
|
||||
{ "hasCursor", w_hasCursor },
|
||||
{ "getX", w_getX },
|
||||
{ "getY", w_getY },
|
||||
{ "setX", w_setX },
|
||||
@@ -212,9 +216,10 @@ static const lua_CFunction types[] =
|
||||
|
||||
extern "C" int luaopen_love_mouse(lua_State *L)
|
||||
{
|
||||
Mouse *instance = instance();
|
||||
if (instance == nullptr)
|
||||
{
|
||||
EXCEPT_GUARD(instance = new love::mouse::sdl::Mouse();)
|
||||
luax_catchexcept(L, [&](){ instance = new love::mouse::sdl::Mouse(); });
|
||||
}
|
||||
else
|
||||
instance->retain();
|
||||
|
||||
@@ -34,6 +34,7 @@ int w_newCursor(lua_State *L);
|
||||
int w_getSystemCursor(lua_State *L);
|
||||
int w_setCursor(lua_State *L);
|
||||
int w_getCursor(lua_State *L);
|
||||
int w_hasCursor(lua_State *L);
|
||||
int w_getX(lua_State *L);
|
||||
int w_getY(lua_State *L);
|
||||
int w_getPosition(lua_State *L);
|
||||
|
||||
Reference in New Issue
Block a user