diff --git a/modules/otclient/otcicon.png b/modules/otclient/otcicon.png index e804eb1f..4200fb52 100644 Binary files a/modules/otclient/otcicon.png and b/modules/otclient/otcicon.png differ 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()))