From 8edea22179482e7afca1f29de5ed8b6f438be214 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Mon, 16 Feb 2015 00:21:39 -0400 Subject: [PATCH] Added love.mouse.hasCursor. Returns true if mouse cursors are available. --HG-- branch : minor --- src/modules/mouse/Mouse.h | 2 ++ src/modules/mouse/sdl/Mouse.cpp | 6 ++++++ src/modules/mouse/sdl/Mouse.h | 2 ++ src/modules/mouse/wrap_Mouse.cpp | 7 +++++++ src/modules/mouse/wrap_Mouse.h | 1 + 5 files changed, 18 insertions(+) diff --git a/src/modules/mouse/Mouse.h b/src/modules/mouse/Mouse.h index e3e06db9b..05f50f473 100644 --- a/src/modules/mouse/Mouse.h +++ b/src/modules/mouse/Mouse.h @@ -60,6 +60,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; diff --git a/src/modules/mouse/sdl/Mouse.cpp b/src/modules/mouse/sdl/Mouse.cpp index 5f912ec46..0116365df 100644 --- a/src/modules/mouse/sdl/Mouse.cpp +++ b/src/modules/mouse/sdl/Mouse.cpp @@ -112,6 +112,12 @@ love::mouse::Cursor *Mouse::getCursor() const return curCursor.get(); } + +bool Mouse::hasCursor() const +{ + return SDL_GetDefaultCursor() != nullptr; +} + int Mouse::getX() const { int x; diff --git a/src/modules/mouse/sdl/Mouse.h b/src/modules/mouse/sdl/Mouse.h index 93db09440..f63239d1b 100644 --- a/src/modules/mouse/sdl/Mouse.h +++ b/src/modules/mouse/sdl/Mouse.h @@ -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; diff --git a/src/modules/mouse/wrap_Mouse.cpp b/src/modules/mouse/wrap_Mouse.cpp index bf46149ba..d45fe41a4 100644 --- a/src/modules/mouse/wrap_Mouse.cpp +++ b/src/modules/mouse/wrap_Mouse.cpp @@ -91,6 +91,12 @@ int w_getCursor(lua_State *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()); @@ -199,6 +205,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 }, diff --git a/src/modules/mouse/wrap_Mouse.h b/src/modules/mouse/wrap_Mouse.h index f08e430b3..4963494b3 100644 --- a/src/modules/mouse/wrap_Mouse.h +++ b/src/modules/mouse/wrap_Mouse.h @@ -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);