mirror of
https://github.com/love2d/love.git
synced 2026-08-16 00:02:12 +02:00
Add love.window.getIcon, and reset it after setMode, so it doesn't get reset (issue #667 and issue #513)
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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 },
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user