From 25d0d8724793aa8d5801bbedb295bba259d3791a Mon Sep 17 00:00:00 2001 From: Bart van Strien Date: Tue, 9 Jul 2013 15:19:49 +0200 Subject: [PATCH] Add love.window.getIcon, and reset it after setMode, so it doesn't get reset (issue #667 and issue #513) --- src/modules/window/Window.h | 1 + src/modules/window/sdl/Window.cpp | 15 +++++++++++++++ src/modules/window/sdl/Window.h | 2 ++ src/modules/window/wrap_Window.cpp | 11 +++++++++++ src/modules/window/wrap_Window.h | 1 + 5 files changed, 30 insertions(+) diff --git a/src/modules/window/Window.h b/src/modules/window/Window.h index 06e30f75f..1a18d06e4 100644 --- a/src/modules/window/Window.h +++ b/src/modules/window/Window.h @@ -71,6 +71,7 @@ public: virtual std::string getWindowTitle() const = 0; virtual bool setIcon(love::image::ImageData *imgd) = 0; + virtual love::image::ImageData *getIcon() = 0; // default no-op implementation virtual void swapBuffers(); diff --git a/src/modules/window/sdl/Window.cpp b/src/modules/window/sdl/Window.cpp index e65b184b9..210b2339d 100644 --- a/src/modules/window/sdl/Window.cpp +++ b/src/modules/window/sdl/Window.cpp @@ -52,6 +52,7 @@ Window::_currentMode::_currentMode() : width(800) , height(600) , flags() + , icon(0) { } @@ -111,6 +112,7 @@ bool Window::setWindow(int width, int height, graphics::Graphics *graphics, Wind // Set caption. setWindowTitle(windowTitle); setMouseVisible(mouseVisible); + setIcon(currentMode.icon); SDL_EnableKeyRepeat(keyrepeatDelay, keyrepeatInterval); // Set GL attributes @@ -302,9 +304,22 @@ bool Window::setIcon(love::image::ImageData *imgd) SDL_WM_SetIcon(icon, NULL); SDL_FreeSurface(icon); + imgd->retain(); + if (currentMode.icon) + currentMode.icon->release(); + currentMode.icon = imgd; + return true; } +love::image::ImageData *Window::getIcon() +{ + if (currentMode.icon) + currentMode.icon->retain(); + + return currentMode.icon; +} + void Window::swapBuffers() { SDL_GL_SwapBuffers(); diff --git a/src/modules/window/sdl/Window.h b/src/modules/window/sdl/Window.h index 052890800..51615e7c0 100644 --- a/src/modules/window/sdl/Window.h +++ b/src/modules/window/sdl/Window.h @@ -53,6 +53,7 @@ public: std::string getWindowTitle() const; bool setIcon(love::image::ImageData *imgd); + love::image::ImageData *getIcon(); void swapBuffers(); @@ -79,6 +80,7 @@ private: int width; int height; WindowFlags flags; + love::image::ImageData *icon; } currentMode; diff --git a/src/modules/window/wrap_Window.cpp b/src/modules/window/wrap_Window.cpp index 80c3d45c4..2299be24c 100644 --- a/src/modules/window/wrap_Window.cpp +++ b/src/modules/window/wrap_Window.cpp @@ -189,6 +189,16 @@ int w_setIcon(lua_State *L) return 0; } +int w_getIcon(lua_State *L) +{ + image::ImageData *i = instance->getIcon(); + if (i) + luax_newtype(L, "ImageData", IMAGE_IMAGE_DATA_T, (void*) i); + else + lua_pushnil(L); + return 1; +} + int w_setCaption(lua_State *L) { std::string title = luax_checkstring(L, 1); @@ -232,6 +242,7 @@ static const luaL_Reg functions[] = { "getHeight", w_getHeight }, { "getDimensions", w_getDimensions }, { "setIcon", w_setIcon }, + { "getIcon", w_getIcon }, { "setCaption", w_setCaption }, { "getCaption", w_getCaption }, { "hasFocus", w_hasFocus }, diff --git a/src/modules/window/wrap_Window.h b/src/modules/window/wrap_Window.h index b47bc6de4..4d6525c61 100644 --- a/src/modules/window/wrap_Window.h +++ b/src/modules/window/wrap_Window.h @@ -39,6 +39,7 @@ int w_getWidth(lua_State *L); int w_getHeight(lua_State *L); int w_getDimensions(lua_State *L); int w_setIcon(lua_State *L); +int w_getIcon(lua_State *L); int w_setCaption(lua_State *L); int w_getCaption(lua_State *L); int w_hasFocus(lua_State *L);