Added love.window.setScreenSaverEnabled and love.window.isScreenSaverEnabled (resolves issue #1088.)

This commit is contained in:
Alex Szpakowski
2015-11-24 22:16:40 -04:00
parent 151c7eca4f
commit 7ebef76b24
7 changed files with 40 additions and 22 deletions
-6
View File
@@ -556,12 +556,6 @@ Message *Event::convertWindowEvent(const SDL_Event &e) const
{
case SDL_WINDOWEVENT_FOCUS_GAINED:
case SDL_WINDOWEVENT_FOCUS_LOST:
// Users won't expect the screensaver to activate if a game is in
// focus. Also, joystick input may not delay the screensaver timer.
if (e.window.event == SDL_WINDOWEVENT_FOCUS_GAINED)
SDL_DisableScreenSaver();
else
SDL_EnableScreenSaver();
vargs.push_back(new Variant(e.window.event == SDL_WINDOWEVENT_FOCUS_GAINED));
msg = new Message("focus", vargs);
break;
+2 -16
View File
@@ -53,23 +53,9 @@ SpriteBatch::SpriteBatch(Texture *texture, int size, Mesh::Usage usage)
throw love::Exception("Invalid SpriteBatch size.");
GLenum gl_usage = Mesh::getGLBufferUsage(usage);
size_t vertex_size = sizeof(Vertex) * 4 * size;
const size_t vertex_size = sizeof(Vertex) * 4 * size;
try
{
array_buf = new GLBuffer(vertex_size, nullptr, GL_ARRAY_BUFFER, gl_usage, GLBuffer::MAP_EXPLICIT_RANGE_MODIFY);
}
catch (love::Exception &)
{
delete array_buf;
throw;
}
catch (std::bad_alloc &)
{
delete array_buf;
throw love::Exception("Out of memory.");
}
array_buf = new GLBuffer(vertex_size, nullptr, GL_ARRAY_BUFFER, gl_usage, GLBuffer::MAP_EXPLICIT_RANGE_MODIFY);
}
SpriteBatch::~SpriteBatch()
+3
View File
@@ -137,6 +137,9 @@ public:
virtual bool setIcon(love::image::ImageData *imgd) = 0;
virtual love::image::ImageData *getIcon() = 0;
virtual void setScreenSaverEnabled(bool enable) = 0;
virtual bool isScreenSaverEnabled() const = 0;
virtual void minimize() = 0;
virtual void maximize() = 0;
+16
View File
@@ -67,6 +67,9 @@ Window::Window()
if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0)
throw love::Exception("Could not initialize SDL video subsystem (%s)", SDL_GetError());
// Make sure the screensaver doesn't activate by default.
setScreenSaverEnabled(false);
SDL_version version = {};
SDL_GetVersion(&version);
hasSDL203orEarlier = (version.major == 2 && version.minor == 0 && version.patch <= 3);
@@ -842,6 +845,19 @@ love::image::ImageData *Window::getIcon()
return curMode.icon.get();
}
void Window::setScreenSaverEnabled(bool enable)
{
if (enable)
SDL_EnableScreenSaver();
else
SDL_DisableScreenSaver();
}
bool Window::isScreenSaverEnabled() const
{
return SDL_IsScreenSaverEnabled() != SDL_FALSE;
}
void Window::minimize()
{
if (window != nullptr)
+3
View File
@@ -70,6 +70,9 @@ public:
bool setIcon(love::image::ImageData *imgd);
love::image::ImageData *getIcon();
void setScreenSaverEnabled(bool enable);
bool isScreenSaverEnabled() const;
void minimize();
void maximize();
+14
View File
@@ -329,6 +329,18 @@ int w_getIcon(lua_State *L)
return 1;
}
int w_setScreenSaverEnabled(lua_State *L)
{
instance()->setScreenSaverEnabled(luax_toboolean(L, 1));
return 0;
}
int w_isScreenSaverEnabled(lua_State *L)
{
luax_pushboolean(L, instance()->isScreenSaverEnabled());
return 1;
}
int w_setTitle(lua_State *L)
{
std::string title = luax_checkstring(L, 1);
@@ -509,6 +521,8 @@ static const luaL_Reg functions[] =
{ "getPosition", w_getPosition },
{ "setIcon", w_setIcon },
{ "getIcon", w_getIcon },
{ "setScreenSaverEnabled", w_setScreenSaverEnabled },
{ "isScreenSaverEnabled", w_isScreenSaverEnabled },
{ "setTitle", w_setTitle },
{ "getTitle", w_getTitle },
{ "hasFocus", w_hasFocus },
+2
View File
@@ -43,6 +43,8 @@ int w_setPosition(lua_State *L);
int w_getPosition(lua_State *L);
int w_setIcon(lua_State *L);
int w_getIcon(lua_State *L);
int w_setScreenSaverEnabled(lua_State *L);
int w_isScreenSaverEnabled(lua_State *L);
int w_setTitle(lua_State *L);
int w_getTitle(lua_State *L);
int w_hasFocus(lua_State *L);