mirror of
https://github.com/love2d/love.git
synced 2026-08-16 00:02:12 +02:00
Removed the system cursor variant of love.mouse.newCursor and added love.mouse.getSystemCursor. love.mouse.newCursor can now take a file(path). Resolves issue #741.
This commit is contained in:
@@ -52,7 +52,7 @@ public:
|
||||
virtual ~Mouse() {};
|
||||
|
||||
virtual Cursor *newCursor(love::image::ImageData *data, int hotx, int hoty) = 0;
|
||||
virtual Cursor *newCursor(Cursor::SystemCursor cursortype) = 0;
|
||||
virtual Cursor *getSystemCursor(Cursor::SystemCursor cursortype) = 0;
|
||||
|
||||
virtual void setCursor(Cursor *cursor) = 0;
|
||||
virtual void setCursor() = 0;
|
||||
|
||||
@@ -46,6 +46,9 @@ Mouse::~Mouse()
|
||||
{
|
||||
if (curCursor)
|
||||
setCursor();
|
||||
|
||||
for (auto it = systemCursors.begin(); it != systemCursors.end(); ++it)
|
||||
it->second->release();
|
||||
}
|
||||
|
||||
love::mouse::Cursor *Mouse::newCursor(love::image::ImageData *data, int hotx, int hoty)
|
||||
@@ -53,9 +56,20 @@ love::mouse::Cursor *Mouse::newCursor(love::image::ImageData *data, int hotx, in
|
||||
return new Cursor(data, hotx, hoty);
|
||||
}
|
||||
|
||||
love::mouse::Cursor *Mouse::newCursor(love::mouse::Cursor::SystemCursor cursortype)
|
||||
love::mouse::Cursor *Mouse::getSystemCursor(Cursor::SystemCursor cursortype)
|
||||
{
|
||||
return new Cursor(cursortype);
|
||||
Cursor *cursor = NULL;
|
||||
auto it = systemCursors.find(cursortype);
|
||||
|
||||
if (it != systemCursors.end())
|
||||
cursor = it->second;
|
||||
else
|
||||
{
|
||||
cursor = new Cursor(cursortype);
|
||||
systemCursors[cursortype] = cursor;
|
||||
}
|
||||
|
||||
return cursor;
|
||||
}
|
||||
|
||||
void Mouse::setCursor(love::mouse::Cursor *cursor)
|
||||
|
||||
@@ -25,6 +25,9 @@
|
||||
#include "mouse/Mouse.h"
|
||||
#include "Cursor.h"
|
||||
|
||||
// C++
|
||||
#include <map>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace mouse
|
||||
@@ -43,7 +46,7 @@ public:
|
||||
~Mouse();
|
||||
|
||||
love::mouse::Cursor *newCursor(love::image::ImageData *data, int hotx, int hoty);
|
||||
love::mouse::Cursor *newCursor(love::mouse::Cursor::SystemCursor cursortype);
|
||||
love::mouse::Cursor *getSystemCursor(Cursor::SystemCursor cursortype);
|
||||
|
||||
void setCursor(love::mouse::Cursor *cursor);
|
||||
void setCursor();
|
||||
@@ -66,6 +69,8 @@ private:
|
||||
|
||||
love::mouse::Cursor *curCursor;
|
||||
|
||||
std::map<Cursor::SystemCursor, Cursor *> systemCursors;
|
||||
|
||||
}; // Mouse
|
||||
|
||||
} // sdl
|
||||
|
||||
@@ -20,16 +20,20 @@
|
||||
|
||||
// LOVE
|
||||
#include "wrap_Cursor.h"
|
||||
#include "Cursor.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace mouse
|
||||
{
|
||||
|
||||
int w_getType(lua_State *L)
|
||||
Cursor *luax_checkcursor(lua_State *L, int idx)
|
||||
{
|
||||
mouse::Cursor *cursor = luax_checktype<mouse::Cursor>(L, 1, "Cursor", MOUSE_CURSOR_T);
|
||||
return luax_checktype<Cursor>(L, idx, "Cursor", MOUSE_CURSOR_T);
|
||||
}
|
||||
|
||||
int w_Cursor_getType(lua_State *L)
|
||||
{
|
||||
Cursor *cursor = luax_checkcursor(L, 1);
|
||||
|
||||
Cursor::CursorType ctype = cursor->getType();
|
||||
const char *typestr = 0;
|
||||
@@ -51,7 +55,7 @@ int w_getType(lua_State *L)
|
||||
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
{ "getType", w_getType },
|
||||
{ "getType", w_Cursor_getType },
|
||||
{ 0, 0 },
|
||||
};
|
||||
|
||||
|
||||
@@ -23,13 +23,15 @@
|
||||
|
||||
// LOVE
|
||||
#include "common/runtime.h"
|
||||
#include "Cursor.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace mouse
|
||||
{
|
||||
|
||||
int w_getType(lua_State *L);
|
||||
Cursor *luax_checkcursor(lua_State *L, int idx);
|
||||
int w_Cursor_getType(lua_State *L);
|
||||
extern "C" int luaopen_cursor(lua_State *L);
|
||||
|
||||
} // mouse
|
||||
|
||||
@@ -36,27 +36,31 @@ int w_newCursor(lua_State *L)
|
||||
{
|
||||
Cursor *cursor = 0;
|
||||
|
||||
if (lua_isstring(L, 1))
|
||||
{
|
||||
// System cursor type.
|
||||
const char *str = luaL_checkstring(L, 1);
|
||||
Cursor::SystemCursor systemCursor;
|
||||
if (lua_isstring(L, 1) || luax_istype(L, 1, FILESYSTEM_FILE_T) || luax_istype(L, 1, FILESYSTEM_FILE_DATA_T))
|
||||
luax_convobj(L, 1, "image", "newImageData");
|
||||
|
||||
if (!Cursor::getConstant(str, systemCursor))
|
||||
return luaL_error(L, "Invalid cursor type %s", str);
|
||||
love::image::ImageData *data = luax_checktype<love::image::ImageData>(L, 1, "ImageData", IMAGE_IMAGE_DATA_T);
|
||||
int hotx = luaL_optint(L, 2, 0);
|
||||
int hoty = luaL_optint(L, 3, 0);
|
||||
|
||||
EXCEPT_GUARD(cursor = instance->newCursor(systemCursor);)
|
||||
}
|
||||
else
|
||||
{
|
||||
// Custom image.
|
||||
love::image::ImageData *data = luax_checktype<love::image::ImageData>(L, 1, "ImageData", IMAGE_IMAGE_DATA_T);
|
||||
int hotx = luaL_optint(L, 2, 0);
|
||||
int hoty = luaL_optint(L, 3, 0);
|
||||
EXCEPT_GUARD(cursor = instance->newCursor(data, hotx, hoty);)
|
||||
|
||||
EXCEPT_GUARD(cursor = instance->newCursor(data, hotx, hoty);)
|
||||
}
|
||||
luax_pushtype(L, "Cursor", MOUSE_CURSOR_T, cursor);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_getSystemCursor(lua_State *L)
|
||||
{
|
||||
const char *str = luaL_checkstring(L, 1);
|
||||
Cursor::SystemCursor systemCursor;
|
||||
|
||||
if (!Cursor::getConstant(str, systemCursor))
|
||||
return luaL_error(L, "Invalid system cursor type: %s", str);
|
||||
|
||||
Cursor *cursor = 0;
|
||||
EXCEPT_GUARD(cursor = instance->getSystemCursor(systemCursor);)
|
||||
|
||||
cursor->retain();
|
||||
luax_pushtype(L, "Cursor", MOUSE_CURSOR_T, cursor);
|
||||
return 1;
|
||||
}
|
||||
@@ -70,7 +74,7 @@ int w_setCursor(lua_State *L)
|
||||
return 0;
|
||||
}
|
||||
|
||||
Cursor *cursor = luax_checktype<Cursor>(L, 1, "Cursor", MOUSE_CURSOR_T);
|
||||
Cursor *cursor = luax_checkcursor(L, 1);
|
||||
instance->setCursor(cursor);
|
||||
return 0;
|
||||
}
|
||||
@@ -182,6 +186,7 @@ int w_isGrabbed(lua_State *L)
|
||||
static const luaL_Reg functions[] =
|
||||
{
|
||||
{ "newCursor", w_newCursor },
|
||||
{ "getSystemCursor", w_getSystemCursor },
|
||||
{ "setCursor", w_setCursor },
|
||||
{ "getCursor", w_getCursor },
|
||||
{ "getX", w_getX },
|
||||
|
||||
@@ -31,6 +31,7 @@ namespace mouse
|
||||
{
|
||||
|
||||
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_getX(lua_State *L);
|
||||
|
||||
Reference in New Issue
Block a user