From dfb8b428eb1535a12b61d4131c4f72f78c48bf26 Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Wed, 23 Nov 2011 14:35:16 -0200 Subject: [PATCH] implement window icon for win --- modules/otclient/otcicon.png | Bin 248 -> 518 bytes src/framework/platform/win32platform.cpp | 42 +++++++++++++++++++++++ src/framework/platform/x11platform.cpp | 11 ++++-- 3 files changed, 51 insertions(+), 2 deletions(-) diff --git a/modules/otclient/otcicon.png b/modules/otclient/otcicon.png index e804eb1f666a4866d33f22203698e8d86ebf61ad..4200fb528102b39cd52768fe6aeb4c26db339aab 100644 GIT binary patch delta 427 zcmV;c0aX6@0fq!2iBL{Q4GJ0x0000DNk~Le0000W0000W2nGNE0CReJ^pPPy2p13^ z0x?0ERLtqy<2jgAGW^fBv61QPG}*m!C_uTj5H<#0>3J z27gZ%#}JFt$q5St42%p63@lhu|ERlvZY(vHh)kICH+%WyB{vN%CO3ir>+A>rwqEAk zl-SUD$w0z1;R-{~6c3-Gwv~-bJ-UpAm)a#TFwBvXQmpNnSq8L^!PC{xWt~$(69D9e BGim?; diff --git a/src/framework/platform/win32platform.cpp b/src/framework/platform/win32platform.cpp index 62110e4d..025bcec2 100644 --- a/src/framework/platform/win32platform.cpp +++ b/src/framework/platform/win32platform.cpp @@ -27,6 +27,9 @@ #include #include +#include +#include + LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); struct Win32PlatformPrivate { @@ -424,6 +427,45 @@ bool Platform::createWindow(int x, int y, int width, int height, int minWidth, i return true; } +void Platform::setWindowIcon(const std::string& pngIcon) +{ + apng_data apng; + std::stringstream fin; + g_resources.loadFile(pngIcon, fin); + if(load_apng(fin, &apng) == 0) { + if(apng.bpp != 4) + logError("could not set app icon, icon image must have 4 channels"); + + int n = apng.width * apng.height; + std::vector iconData(n); + for(int i=0; i < n;++i) { + uint8 *pixel = (uint8*)&iconData[i]; + pixel[2] = *(apng.pdata + (i * 4) + 0); + pixel[1] = *(apng.pdata + (i * 4) + 1); + pixel[0] = *(apng.pdata + (i * 4) + 2); + pixel[3] = *(apng.pdata + (i * 4) + 3); + } + + HBITMAP hbmColor = CreateBitmap(apng.width, apng.height, 1, 32, &iconData[0]); + HBITMAP hbmMask = CreateCompatibleBitmap(GetDC(NULL), apng.width, apng.height); + + ICONINFO ii; + ii.fIcon = TRUE; + ii.hbmColor = hbmColor; + ii.hbmMask = hbmMask; + ii.xHotspot = 0; + ii.yHotspot = 0; + + HICON icon = CreateIconIndirect(&ii); + DeleteObject(hbmMask); + DeleteObject(hbmColor); + + SendMessage(win32.window, WM_SETICON, ICON_SMALL, (LPARAM)icon); + SendMessage(win32.window, WM_SETICON, ICON_BIG, (LPARAM)icon); + } else + logError("could not load app icon"); +} + void Platform::destroyWindow() { if(win32.hrc) { diff --git a/src/framework/platform/x11platform.cpp b/src/framework/platform/x11platform.cpp index 40b13a84..8604007d 100644 --- a/src/framework/platform/x11platform.cpp +++ b/src/framework/platform/x11platform.cpp @@ -704,12 +704,19 @@ void Platform::setWindowIcon(const std::string& pngIcon) std::stringstream fin; g_resources.loadFile(pngIcon, fin); if(load_apng(fin, &apng) == 0) { + if(apng.bpp != 4) + logError("could not set app icon, icon image must have 4 channels"); int n = apng.width * apng.height; std::vector iconData(n + 2); iconData[0] = apng.width; iconData[1] = apng.height; - for(int i=0; i < n;++i) - iconData[2 + i] = *(uint32_t*)(apng.pdata + (i * 4)); + for(int i=0; i < n;++i) { + uint8 *pixel = (uint8*)&iconData[2 + i]; + pixel[2] = *(apng.pdata + (i * 4) + 0); + pixel[1] = *(apng.pdata + (i * 4) + 1); + pixel[0] = *(apng.pdata + (i * 4) + 2); + pixel[3] = *(apng.pdata + (i * 4) + 3); + } Atom property = XInternAtom(x11.display, "_NET_WM_ICON", 0); if(!XChangeProperty(x11.display, x11.window, property, XA_CARDINAL, 32, PropModeReplace, (const unsigned char*)&iconData[0], iconData.size()))