implement window icon for win

master
Eduardo Bart 13 years ago
parent c8d5ca1cfb
commit dfb8b428eb

Binary file not shown.

Before

Width:  |  Height:  |  Size: 248 B

After

Width:  |  Height:  |  Size: 518 B

@ -27,6 +27,9 @@
#include <dir.h>
#include <physfs.h>
#include <framework/thirdparty/apngloader.h>
#include <framework/core/resourcemanager.h>
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<uint32> 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) {

@ -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<unsigned long int> 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()))

Loading…
Cancel
Save