From eec8610817d7c967710e1e4001207cd07fefa43f Mon Sep 17 00:00:00 2001 From: Yves Rizoud Date: Sun, 30 May 2010 15:35:33 +0000 Subject: [PATCH] Fix issue 351: Ugly status bar icon on Windows git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1493 416bcca6-2ee7-4201-b75f-2eb2f807beb1 --- share/grafx2/gfx2def.ini | 5 ++ src/init.c | 164 +++++++++++++++++++++++++++++++++++++++ src/init.h | 3 + src/main.c | 37 +-------- 4 files changed, 173 insertions(+), 36 deletions(-) diff --git a/share/grafx2/gfx2def.ini b/share/grafx2/gfx2def.ini index 8375b3bb..e0b122f6 100644 --- a/share/grafx2/gfx2def.ini +++ b/share/grafx2/gfx2def.ini @@ -356,4 +356,9 @@ ; Menubars_visible = 255; (Default 255) + ; This enables a mode where right mouse buttons acts as + ; a color picker, with most tools. + ; + Right_click_colorpick = NO; (Default NO) + ; end of configuration diff --git a/src/init.c b/src/init.c index aca44a04..176fd14b 100644 --- a/src/init.c +++ b/src/init.c @@ -50,6 +50,10 @@ #if defined(__WIN32__) #include // GetLogicalDrives(), GetDriveType(), DRIVE_* #endif +#ifndef __GP2X__ + #include +#endif + #ifdef GRAFX2_CATCHES_SIGNALS #include #endif @@ -2693,4 +2697,164 @@ void Init_paintbrushes(void) Paintbrush[index].Offset_X=(Paintbrush[index].Width>>1); Paintbrush[index].Offset_Y=(Paintbrush[index].Height>>1); } +} + +/// Set application icon(s) +void Define_icon(void) +{ +#ifdef WIN32 + // Specific code for Win32: + // Load icon from embedded resource. + // This will provide both the 16x16 and 32x32 versions. + do + { + HICON hicon; + HRSRC hresource; + HINSTANCE hInstance; + LPVOID lpResIconDir; + LPVOID lpResIcon16; + LPVOID lpResIcon32; + HGLOBAL hMem; + WORD nID; + SDL_SysWMinfo info; + + hInstance = (HINSTANCE)GetModuleHandle(NULL); + if (hInstance==NULL) + break; + + // Icon is resource #1 + hresource = FindResource(hInstance, + MAKEINTRESOURCE(1), + RT_GROUP_ICON); + if (hresource==NULL) + break; + + // Load and lock the icon directory. + hMem = LoadResource(hInstance, hresource); + if (hMem==NULL) + break; + + lpResIconDir = LockResource(hMem); + if (lpResIconDir==NULL) + break; + + SDL_VERSION(&info.version); + SDL_GetWMInfo(&info); + + // + // 16x16 + // + + // Get the identifier of the 16x16 icon + nID = LookupIconIdFromDirectoryEx((PBYTE) lpResIconDir, TRUE, + 16, 16, LR_DEFAULTCOLOR); + if (nID==0) + break; + + // Find the bits for the nID icon. + hresource = FindResource(hInstance, + MAKEINTRESOURCE(nID), + MAKEINTRESOURCE(RT_ICON)); + if (hresource==NULL) + break; + + // Load and lock the icon. + hMem = LoadResource(hInstance, hresource); + if (hMem==NULL) + break; + lpResIcon16 = LockResource(hMem); + if (lpResIcon16==NULL) + break; + + // Create a handle to the icon. + hicon = CreateIconFromResourceEx((PBYTE) lpResIcon16, + SizeofResource(hInstance, hresource), TRUE, 0x00030000, + 16, 16, LR_DEFAULTCOLOR); + if (hicon==NULL) + break; + + // Set it + SetClassLongPtr(info.window, GCL_HICONSM, (LONG_PTR)hicon); + + + // + // 32x32 + // + + // Get the identifier of the 32x32 icon + nID = LookupIconIdFromDirectoryEx((PBYTE) lpResIconDir, TRUE, + 32, 32, LR_DEFAULTCOLOR); + if (nID==0) + break; + + // Find the bits for the nID icon. + hresource = FindResource(hInstance, + MAKEINTRESOURCE(nID), + MAKEINTRESOURCE(RT_ICON)); + if (hresource==NULL) + break; + + // Load and lock the icon. + hMem = LoadResource(hInstance, hresource); + if (hMem==NULL) + break; + lpResIcon32 = LockResource(hMem); + if (lpResIcon32==NULL) + break; + + // Create a handle to the icon. + hicon = CreateIconFromResourceEx((PBYTE) lpResIcon32, + SizeofResource(hInstance, hresource), TRUE, 0x00030000, + 32, 32, LR_DEFAULTCOLOR); + if (hicon==NULL) + break; + + // Set it + SetClassLongPtr(info.window, GCL_HICON, (LONG_PTR)hicon); + + + // Success + return; + } while (0); + // Failure: fall back on normal SDL version: + +#endif + // General version: Load icon from the file gfx2.gif + { + char icon_path[MAX_PATH_CHARACTERS]; + SDL_Surface * icon; + sprintf(icon_path, "%s%s", Data_directory, "gfx2.gif"); + icon = IMG_Load(icon_path); + if (icon && icon->w == 32 && icon->h == 32) + { + Uint32 pink; + pink = SDL_MapRGB(icon->format, 255, 0, 255); + + if (icon->format->BitsPerPixel == 8) + { + // 8bit image: use color key + + SDL_SetColorKey(icon, SDL_SRCCOLORKEY, pink); + SDL_WM_SetIcon(icon,NULL); + } + else + { + // 24bit image: need to build a mask on magic pink + + byte *icon_mask; + int x,y; + + icon_mask=malloc(128); + memset(icon_mask,0,128); + for (y=0;y<32;y++) + for (x=0;x<32;x++) + if (Get_SDL_pixel_hicolor(icon, x, y) != pink) + icon_mask[(y*32+x)/8] |=0x80>>(x&7); + SDL_WM_SetIcon(icon,icon_mask); + free(icon_mask); + icon_mask = NULL; + } + SDL_FreeSurface(icon); + } + } } \ No newline at end of file diff --git a/src/init.h b/src/init.h index 177b1886..d6da1bdf 100644 --- a/src/init.h +++ b/src/init.h @@ -36,6 +36,9 @@ void Set_config_defaults(void); void Init_sighandler(void); void Init_paintbrushes(void); +/// Set application icon(s) +void Define_icon(void); + extern char Gui_loading_error_message[512]; /// diff --git a/src/main.c b/src/main.c index 89152178..5b1dff35 100644 --- a/src/main.c +++ b/src/main.c @@ -517,42 +517,7 @@ int Init_program(int argc,char * argv[]) SDL_EnableKeyRepeat(250, 32); SDL_EnableUNICODE(SDL_ENABLE); SDL_WM_SetCaption("GrafX2","GrafX2"); - - { - // Routine pour définir l'icone. - char icon_path[MAX_PATH_CHARACTERS]; - SDL_Surface * icon; - sprintf(icon_path, "%s%s", Data_directory, "gfx2.gif"); - icon = IMG_Load(icon_path); - if (icon && icon->w == 32 && icon->h == 32) - { - Uint32 pink; - pink = SDL_MapRGB(icon->format, 255, 0, 255); - - if (icon->format->BitsPerPixel == 8) - { - SDL_SetColorKey(icon, SDL_SRCCOLORKEY, pink); - SDL_WM_SetIcon(icon,NULL); - } - else - { - byte *icon_mask; - int x,y; - - icon_mask=malloc(128); - memset(icon_mask,0,128); - for (y=0;y<32;y++) - for (x=0;x<32;x++) - if (Get_SDL_pixel_hicolor(icon, x, y) != pink) - icon_mask[(y*32+x)/8] |=0x80>>(x&7); - SDL_WM_SetIcon(icon,icon_mask); - free(icon_mask); - icon_mask = NULL; - } - - SDL_FreeSurface(icon); - } - } + Define_icon(); // Texte Init_text();