From eaa92d3fafeab0bcb9e80f37fc36e1e93d92761b Mon Sep 17 00:00:00 2001 From: stephena Date: Wed, 3 Dec 2003 18:11:25 +0000 Subject: [PATCH] Moved some redundant code into the parent FrameBufferSDL class. Added the Cyberstella icon to the SDL port. No more ugly looking 'X' icon for Stella in Linux. git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@224 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba --- stella/src/ui/sdl/FrameBufferGL.cxx | 6 +-- stella/src/ui/sdl/FrameBufferSDL.cxx | 66 ++++++++++++++++++++++++++- stella/src/ui/sdl/FrameBufferSDL.hxx | 9 +++- stella/src/ui/sdl/FrameBufferSoft.cxx | 6 +-- stella/src/ui/sdl/stella.xpm | 38 +++++++++++++++ 5 files changed, 114 insertions(+), 11 deletions(-) create mode 100644 stella/src/ui/sdl/stella.xpm diff --git a/stella/src/ui/sdl/FrameBufferGL.cxx b/stella/src/ui/sdl/FrameBufferGL.cxx index 35375442c..2dd18f5ea 100644 --- a/stella/src/ui/sdl/FrameBufferGL.cxx +++ b/stella/src/ui/sdl/FrameBufferGL.cxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: FrameBufferGL.cxx,v 1.10 2003-12-02 01:46:40 stephena Exp $ +// $Id: FrameBufferGL.cxx,v 1.11 2003-12-03 18:11:25 stephena Exp $ //============================================================================ #include @@ -134,9 +134,7 @@ bool FrameBufferGL::init() mySDLFlags |= myConsole->settings().getBool("fullscreen") ? SDL_FULLSCREEN : 0; // Set the window title and icon - ostringstream name; - name << "Stella: \"" << myConsole->properties().get("Cartridge.Name") << "\""; - SDL_WM_SetCaption(name.str().c_str(), "stella"); + setWindowAttributes(); // Set up the OpenGL attributes myDepth = SDL_GetVideoInfo()->vfmt->BitsPerPixel; diff --git a/stella/src/ui/sdl/FrameBufferSDL.cxx b/stella/src/ui/sdl/FrameBufferSDL.cxx index 17b5c785c..d812a086b 100644 --- a/stella/src/ui/sdl/FrameBufferSDL.cxx +++ b/stella/src/ui/sdl/FrameBufferSDL.cxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: FrameBufferSDL.cxx,v 1.7 2003-11-30 22:50:15 stephena Exp $ +// $Id: FrameBufferSDL.cxx,v 1.8 2003-12-03 18:11:25 stephena Exp $ //============================================================================ #include @@ -26,6 +26,8 @@ #include "MediaSrc.hxx" #include "Settings.hxx" +#include "stella.xpm" // The Stella icon + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - FrameBufferSDL::FrameBufferSDL() : x11Available(false), @@ -185,3 +187,65 @@ uInt32 FrameBufferSDL::maxWindowSizeForScreen() return 1; #endif } + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +void FrameBufferSDL::setWindowAttributes() +{ + // Set the window title + ostringstream name; + name << "Stella: \"" << myConsole->properties().get("Cartridge.Name") << "\""; + SDL_WM_SetCaption(name.str().c_str(), "stella"); + + // Set the window icon + uInt32 w, h, ncols, nbytes; + uInt32 rgba[256], icon[32 * 32]; + uInt8 mask[32][4]; + + sscanf(stella_icon[0], "%d %d %d %d", &w, &h, &ncols, &nbytes); + if((w != 32) || (h != 32) || (ncols > 255) || (nbytes > 1)) + { + cerr << "ERROR: Couldn't load the icon.\n"; + return; + } + + for(uInt32 i = 0; i < ncols; i++) + { + unsigned char code; + char color[32]; + uInt32 col; + + sscanf(stella_icon[1 + i], "%c c %s", &code, color); + if(!strcmp(color, "None")) + col = 0x00000000; + else if(!strcmp(color, "black")) + col = 0xFF000000; + else if (color[0] == '#') + { + sscanf(color + 1, "%06x", &col); + col |= 0xFF000000; + } + else + { + cerr << "ERROR: Couldn't load the icon.\n"; + return; + } + rgba[code] = col; + } + + memset(mask, 0, sizeof(mask)); + for(h = 0; h < 32; h++) + { + const char* line = stella_icon[1 + ncols + h]; + for(w = 0; w < 32; w++) + { + icon[w + 32 * h] = rgba[(int)line[w]]; + if(rgba[(int)line[w]] & 0xFF000000) + mask[h][w >> 3] |= 1 << (7 - (w & 0x07)); + } + } + + SDL_Surface *surface = SDL_CreateRGBSurfaceFrom(icon, 32, 32, 32, + 32 * 4, 0xFF0000, 0x00FF00, 0x0000FF, 0xFF000000); + SDL_WM_SetIcon(surface, (unsigned char *) mask); + SDL_FreeSurface(surface); +} diff --git a/stella/src/ui/sdl/FrameBufferSDL.hxx b/stella/src/ui/sdl/FrameBufferSDL.hxx index 63f032172..b0adf85ba 100644 --- a/stella/src/ui/sdl/FrameBufferSDL.hxx +++ b/stella/src/ui/sdl/FrameBufferSDL.hxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: FrameBufferSDL.hxx,v 1.7 2003-11-24 14:51:06 stephena Exp $ +// $Id: FrameBufferSDL.hxx,v 1.8 2003-12-03 18:11:25 stephena Exp $ //============================================================================ #ifndef FRAMEBUFFER_SDL_HXX @@ -34,7 +34,7 @@ the core FrameBuffer. @author Stephen Anthony - @version $Id: FrameBufferSDL.hxx,v 1.7 2003-11-24 14:51:06 stephena Exp $ + @version $Id: FrameBufferSDL.hxx,v 1.8 2003-12-03 18:11:25 stephena Exp $ */ class FrameBufferSDL : public FrameBuffer { @@ -92,6 +92,11 @@ class FrameBufferSDL : public FrameBuffer */ uInt32 maxWindowSizeForScreen(); + /** + Set the title and icon for the main SDL window. + */ + void setWindowAttributes(); + ////////////////////////////////////////////////////////////////////// // The following methods are derived from FrameBuffer.hxx ////////////////////////////////////////////////////////////////////// diff --git a/stella/src/ui/sdl/FrameBufferSoft.cxx b/stella/src/ui/sdl/FrameBufferSoft.cxx index 0408a7290..c213a2f43 100644 --- a/stella/src/ui/sdl/FrameBufferSoft.cxx +++ b/stella/src/ui/sdl/FrameBufferSoft.cxx @@ -13,7 +13,7 @@ // See the file "license" for information on usage and redistribution of // this file, and for a DISCLAIMER OF ALL WARRANTIES. // -// $Id: FrameBufferSoft.cxx,v 1.3 2003-11-30 22:50:15 stephena Exp $ +// $Id: FrameBufferSoft.cxx,v 1.4 2003-12-03 18:11:25 stephena Exp $ //============================================================================ #include @@ -116,9 +116,7 @@ bool FrameBufferSoft::init() } // Set the window title and icon - ostringstream name; - name << "Stella: \"" << myConsole->properties().get("Cartridge.Name") << "\""; - SDL_WM_SetCaption(name.str().c_str(), "stella"); + setWindowAttributes(); // Create the screen if(!createScreen()) diff --git a/stella/src/ui/sdl/stella.xpm b/stella/src/ui/sdl/stella.xpm new file mode 100644 index 000000000..5b4875975 --- /dev/null +++ b/stella/src/ui/sdl/stella.xpm @@ -0,0 +1,38 @@ +/* XPM */ +static char * stella_icon[] = { +"32 32 3 1", +" c None", +". c #000000", +"+ c #FFFFFF", +" ", +" ", +" ", +" ", +" .............. ", +" .............. ", +" ..++..++..++.. ", +" ..++..++..++.. ", +" ..++..++..++.. ", +" ..++..++..++.. ", +" ..++..++..++.. ", +" ..++..++..++.. ", +" ..++..++..++.. ", +" ..++..++..++.. ", +" ....++..++..++.... ", +" ....++..++..++.... ", +" ....++++..++..++++.... ", +" ....++++..++..++++.... ", +" ..++++....++....++++.. ", +" ..++++....++....++++.. ", +" ......++......++......++...... ", +" ......++......++......++...... ", +" ..++++++.. ..++.. ..++++++.. ", +" ..++++++.. ..++.. ..++++++.. ", +" ..++++.... ..++.. ....++++.. ", +" ..++++.... ..++.. ....++++.. ", +" ........ ...... ........ ", +" ........ ...... ........ ", +" ", +" ", +" ", +" "};