mirror of
https://github.com/love2d/love.git
synced 2026-08-20 12:40:20 +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 ~Mouse() {};
|
||||||
|
|
||||||
virtual Cursor *newCursor(love::image::ImageData *data, int hotx, int hoty) = 0;
|
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(Cursor *cursor) = 0;
|
||||||
virtual void setCursor() = 0;
|
virtual void setCursor() = 0;
|
||||||
|
|||||||
@@ -46,6 +46,9 @@ Mouse::~Mouse()
|
|||||||
{
|
{
|
||||||
if (curCursor)
|
if (curCursor)
|
||||||
setCursor();
|
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)
|
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);
|
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)
|
void Mouse::setCursor(love::mouse::Cursor *cursor)
|
||||||
|
|||||||
@@ -25,6 +25,9 @@
|
|||||||
#include "mouse/Mouse.h"
|
#include "mouse/Mouse.h"
|
||||||
#include "Cursor.h"
|
#include "Cursor.h"
|
||||||
|
|
||||||
|
// C++
|
||||||
|
#include <map>
|
||||||
|
|
||||||
namespace love
|
namespace love
|
||||||
{
|
{
|
||||||
namespace mouse
|
namespace mouse
|
||||||
@@ -43,7 +46,7 @@ public:
|
|||||||
~Mouse();
|
~Mouse();
|
||||||
|
|
||||||
love::mouse::Cursor *newCursor(love::image::ImageData *data, int hotx, int hoty);
|
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(love::mouse::Cursor *cursor);
|
||||||
void setCursor();
|
void setCursor();
|
||||||
@@ -66,6 +69,8 @@ private:
|
|||||||
|
|
||||||
love::mouse::Cursor *curCursor;
|
love::mouse::Cursor *curCursor;
|
||||||
|
|
||||||
|
std::map<Cursor::SystemCursor, Cursor *> systemCursors;
|
||||||
|
|
||||||
}; // Mouse
|
}; // Mouse
|
||||||
|
|
||||||
} // sdl
|
} // sdl
|
||||||
|
|||||||
@@ -20,16 +20,20 @@
|
|||||||
|
|
||||||
// LOVE
|
// LOVE
|
||||||
#include "wrap_Cursor.h"
|
#include "wrap_Cursor.h"
|
||||||
#include "Cursor.h"
|
|
||||||
|
|
||||||
namespace love
|
namespace love
|
||||||
{
|
{
|
||||||
namespace mouse
|
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();
|
Cursor::CursorType ctype = cursor->getType();
|
||||||
const char *typestr = 0;
|
const char *typestr = 0;
|
||||||
@@ -51,7 +55,7 @@ int w_getType(lua_State *L)
|
|||||||
|
|
||||||
static const luaL_Reg functions[] =
|
static const luaL_Reg functions[] =
|
||||||
{
|
{
|
||||||
{ "getType", w_getType },
|
{ "getType", w_Cursor_getType },
|
||||||
{ 0, 0 },
|
{ 0, 0 },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -23,13 +23,15 @@
|
|||||||
|
|
||||||
// LOVE
|
// LOVE
|
||||||
#include "common/runtime.h"
|
#include "common/runtime.h"
|
||||||
|
#include "Cursor.h"
|
||||||
|
|
||||||
namespace love
|
namespace love
|
||||||
{
|
{
|
||||||
namespace mouse
|
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);
|
extern "C" int luaopen_cursor(lua_State *L);
|
||||||
|
|
||||||
} // mouse
|
} // mouse
|
||||||
|
|||||||
@@ -36,27 +36,31 @@ int w_newCursor(lua_State *L)
|
|||||||
{
|
{
|
||||||
Cursor *cursor = 0;
|
Cursor *cursor = 0;
|
||||||
|
|
||||||
if (lua_isstring(L, 1))
|
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");
|
||||||
// System cursor type.
|
|
||||||
const char *str = luaL_checkstring(L, 1);
|
|
||||||
Cursor::SystemCursor systemCursor;
|
|
||||||
|
|
||||||
if (!Cursor::getConstant(str, systemCursor))
|
love::image::ImageData *data = luax_checktype<love::image::ImageData>(L, 1, "ImageData", IMAGE_IMAGE_DATA_T);
|
||||||
return luaL_error(L, "Invalid cursor type %s", str);
|
int hotx = luaL_optint(L, 2, 0);
|
||||||
|
int hoty = luaL_optint(L, 3, 0);
|
||||||
|
|
||||||
EXCEPT_GUARD(cursor = instance->newCursor(systemCursor);)
|
EXCEPT_GUARD(cursor = instance->newCursor(data, hotx, hoty);)
|
||||||
}
|
|
||||||
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);)
|
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);
|
luax_pushtype(L, "Cursor", MOUSE_CURSOR_T, cursor);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -70,7 +74,7 @@ int w_setCursor(lua_State *L)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Cursor *cursor = luax_checktype<Cursor>(L, 1, "Cursor", MOUSE_CURSOR_T);
|
Cursor *cursor = luax_checkcursor(L, 1);
|
||||||
instance->setCursor(cursor);
|
instance->setCursor(cursor);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -182,6 +186,7 @@ int w_isGrabbed(lua_State *L)
|
|||||||
static const luaL_Reg functions[] =
|
static const luaL_Reg functions[] =
|
||||||
{
|
{
|
||||||
{ "newCursor", w_newCursor },
|
{ "newCursor", w_newCursor },
|
||||||
|
{ "getSystemCursor", w_getSystemCursor },
|
||||||
{ "setCursor", w_setCursor },
|
{ "setCursor", w_setCursor },
|
||||||
{ "getCursor", w_getCursor },
|
{ "getCursor", w_getCursor },
|
||||||
{ "getX", w_getX },
|
{ "getX", w_getX },
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ namespace mouse
|
|||||||
{
|
{
|
||||||
|
|
||||||
int w_newCursor(lua_State *L);
|
int w_newCursor(lua_State *L);
|
||||||
|
int w_getSystemCursor(lua_State *L);
|
||||||
int w_setCursor(lua_State *L);
|
int w_setCursor(lua_State *L);
|
||||||
int w_getCursor(lua_State *L);
|
int w_getCursor(lua_State *L);
|
||||||
int w_getX(lua_State *L);
|
int w_getX(lua_State *L);
|
||||||
|
|||||||
Reference in New Issue
Block a user