diff --git a/engine/backend/driver.h b/engine/backend/driver.h index 41a569c6074..fe2ed8cb3e4 100644 --- a/engine/backend/driver.h +++ b/engine/backend/driver.h @@ -68,6 +68,8 @@ public: virtual bool isHardwareAccelerated() = 0; + virtual void setupIcon() = 0; + virtual void setupCamera(float fov, float nclip, float fclip, float roll) = 0; virtual void positionCamera(Vector3d pos, Vector3d interest) = 0; diff --git a/engine/backend/sdl/driver_sdl.cpp b/engine/backend/sdl/driver_sdl.cpp index 01eb25dd59b..c7fdf9f5dfb 100644 --- a/engine/backend/sdl/driver_sdl.cpp +++ b/engine/backend/sdl/driver_sdl.cpp @@ -34,6 +34,8 @@ #include #endif +#include "icons/residual.xpm" + #define SAMPLES_PER_SEC 22050 // NOTE: This is not a complete driver, it needs to be subclassed @@ -309,6 +311,10 @@ DriverSDL::~DriverSDL() { void DriverSDL::init() { _timer = new DefaultTimerManager(); _timerID = SDL_AddTimer(10, &timer_handler, _timer); + +#if !defined(MACOSX) + setupIcon(); +#endif } char *DriverSDL::getVideoDeviceName() { @@ -482,6 +488,52 @@ void DriverSDL::quit() { error("Unable to push exit event!"); } +void DriverSDL::setupIcon() { + int w, h, ncols, nbytes, i; + unsigned int rgba[256], icon[32 * 32]; + unsigned char mask[32][4]; + + sscanf(residual_icon[0], "%d %d %d %d", &w, &h, &ncols, &nbytes); + if ((w != 32) || (h != 32) || (ncols > 255) || (nbytes > 1)) { + warning("Could not load the icon (%d %d %d %d)", w, h, ncols, nbytes); + return; + } + for (i = 0; i < ncols; i++) { + unsigned char code; + char color[32]; + unsigned int col; + + sscanf(residual_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 { + warning("Could not load the icon (%d %s - %s) ", code, color, residual_icon[1 + i]); + return; + } + + rgba[code] = col; + } + memset(mask, 0, sizeof(mask)); + for (h = 0; h < 32; h++) { + const char *line = residual_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 *sdl_surf = SDL_CreateRGBSurfaceFrom(icon, 32, 32, 32, 32 * 4, 0xFF0000, 0x00FF00, 0x0000FF, 0xFF000000); + SDL_WM_SetIcon(sdl_surf, (unsigned char *)mask); + SDL_FreeSurface(sdl_surf); +} + #if defined (WIN32) int __stdcall WinMain(HINSTANCE /*hInst*/, HINSTANCE /*hPrevInst*/, LPSTR /*lpCmdLine*/, int /*iShowCmd*/) { SDL_SetModuleHandle(GetModuleHandle(NULL)); @@ -494,4 +546,3 @@ int main(int argc, char *argv[]) { return res; } - diff --git a/engine/backend/sdl/driver_sdl.h b/engine/backend/sdl/driver_sdl.h index 896414c6dd7..20daad3757e 100644 --- a/engine/backend/sdl/driver_sdl.h +++ b/engine/backend/sdl/driver_sdl.h @@ -50,7 +50,9 @@ public: DriverSDL(); virtual ~DriverSDL(); - virtual void init(); + void init(); + + void setupIcon(); char *getVideoDeviceName(); diff --git a/icons/residual.xpm b/icons/residual.xpm index cf968454e82..de0aa20e269 100644 --- a/icons/residual.xpm +++ b/icons/residual.xpm @@ -1,5 +1,5 @@ /* XPM */ -static char *residual[] = { +static char *residual_icon[] = { /* columns rows colors chars-per-pixel */ "32 32 236 2", " c #000000",