From 176645e25d9dee4c1541294b930244a3a3ae6e41 Mon Sep 17 00:00:00 2001 From: Bill Meltsner Date: Sun, 1 Aug 2010 08:56:05 -0500 Subject: [PATCH] added love.graphics.setIcon --- changes.txt | 2 +- src/modules/graphics/opengl/Graphics.cpp | 19 +++++++++++++++++++ src/modules/graphics/opengl/Graphics.h | 8 ++++++-- src/modules/graphics/opengl/wrap_Graphics.cpp | 9 +++++++++ src/modules/graphics/opengl/wrap_Graphics.h | 1 + 5 files changed, 36 insertions(+), 3 deletions(-) diff --git a/changes.txt b/changes.txt index abe836652..3703d19a5 100644 --- a/changes.txt +++ b/changes.txt @@ -9,6 +9,7 @@ LOVE 0.7.0 * Added identity field to love.conf. * Added love.quit callback. * Added extra meter parameter to love.physics.newWorld. + * Added love.graphics.setIcon. * Enabled love.filesystem.FileData. * Fixed bug where the debug module was not an upvalue of the error handlers. (you can now override debug) * Fixed bug where love.audio.pause and friends were acting on everything, not just the passed Source. @@ -20,7 +21,6 @@ LOVE 0.7.0 * Moved fonts to love.font (from love.graphics), only rendering remains in love.graphics. * Switched font origin to top-left. * OS X now properly uses UTIs for .love files. - * Dropped the OS X version requirement to 10.4. * Fewer compiler warnings. LOVE 0.6.2 diff --git a/src/modules/graphics/opengl/Graphics.cpp b/src/modules/graphics/opengl/Graphics.cpp index dfd9eea3f..4a958a7f1 100644 --- a/src/modules/graphics/opengl/Graphics.cpp +++ b/src/modules/graphics/opengl/Graphics.cpp @@ -306,6 +306,25 @@ namespace opengl { SDL_GL_SwapBuffers(); } + + void Graphics::setIcon(Image * image) + { + Uint32 rmask, gmask, bmask, amask; +#ifdef LOVE_BIG_ENDIAN + rmask = 0xFF000000; + gmask = 0x00FF0000; + bmask = 0x0000FF00; + amask = 0x000000FF; +#else + rmask = 0x000000FF; + gmask = 0x0000FF00; + bmask = 0x00FF0000; + amask = 0xFF000000; +#endif + SDL_Surface * icon = SDL_CreateRGBSurfaceFrom(image->getData()->getData(), image->getWidth(), image->getHeight(), 32, image->getWidth() * 4, rmask, gmask, bmask, amask); + SDL_WM_SetIcon(icon, NULL); + SDL_FreeSurface(icon); + } void Graphics::setCaption(const char * caption) { diff --git a/src/modules/graphics/opengl/Graphics.h b/src/modules/graphics/opengl/Graphics.h index a3a1b4789..2eaeb80fd 100644 --- a/src/modules/graphics/opengl/Graphics.h +++ b/src/modules/graphics/opengl/Graphics.h @@ -176,9 +176,14 @@ namespace opengl * presented on screen). **/ void present(); + + /** + * Sets the window's icon. + **/ + void setIcon(Image * image); /** - * Sets the windows caption. + * Sets the window's caption. **/ void setCaption(const char * caption); @@ -505,7 +510,6 @@ namespace opengl * @param ... Vertex components (x1, y1, x2, y2, etc). **/ int polygon(lua_State * L); - int polygong(lua_State * L); /** * Creates a screenshot of the view and saves it to the default folder. diff --git a/src/modules/graphics/opengl/wrap_Graphics.cpp b/src/modules/graphics/opengl/wrap_Graphics.cpp index 50c739907..8b146f04b 100644 --- a/src/modules/graphics/opengl/wrap_Graphics.cpp +++ b/src/modules/graphics/opengl/wrap_Graphics.cpp @@ -78,6 +78,13 @@ namespace opengl return 0; } + int w_setIcon(lua_State * L) + { + Image * image = luax_checktype(L, 1, "Image", GRAPHICS_IMAGE_T); + instance->setIcon(image); + return 0; + } + int w_setCaption(lua_State * L) { const char * str = luaL_checkstring(L, 1); @@ -859,6 +866,8 @@ namespace opengl { "setCaption", w_setCaption }, { "getCaption", w_getCaption }, + + { "setIcon", w_setIcon }, { "getWidth", w_getWidth }, { "getHeight", w_getHeight }, diff --git a/src/modules/graphics/opengl/wrap_Graphics.h b/src/modules/graphics/opengl/wrap_Graphics.h index 244121680..2ad3a95f7 100644 --- a/src/modules/graphics/opengl/wrap_Graphics.h +++ b/src/modules/graphics/opengl/wrap_Graphics.h @@ -42,6 +42,7 @@ namespace opengl int w_reset(lua_State * L); int w_clear(lua_State * L); int w_present(lua_State * L); + int w_setIcon(lua_State * L); int w_setCaption(lua_State * L); int w_getCaption(lua_State * L); int w_getWidth(lua_State * L);