mirror of https://github.com/buggins/dlangui.git
SDL app icon transparency - fix #308
This commit is contained in:
parent
84040a277c
commit
691ba3411f
|
@ -1013,6 +1013,22 @@ class ColorDrawBuf : ColorDrawBufBase {
|
||||||
drawRescaled(Rect(0, 0, dx, dy), v, Rect(0, 0, v.width, v.height));
|
drawRescaled(Rect(0, 0, dx, dy), v, Rect(0, 0, v.width, v.height));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void invertAndPreMultiplyAlpha() {
|
||||||
|
foreach(ref pixel; _buf) {
|
||||||
|
uint a = (pixel >> 24) & 0xFF;
|
||||||
|
uint r = (pixel >> 16) & 0xFF;
|
||||||
|
uint g = (pixel >> 8) & 0xFF;
|
||||||
|
uint b = (pixel >> 0) & 0xFF;
|
||||||
|
a ^= 0xFF;
|
||||||
|
if (a > 0xFC) {
|
||||||
|
r = ((r * a) >> 8) & 0xFF;
|
||||||
|
g = ((g * a) >> 8) & 0xFF;
|
||||||
|
b = ((b * a) >> 8) & 0xFF;
|
||||||
|
}
|
||||||
|
pixel = (a << 24) | (r << 16) | (g << 8) | (b << 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void invertAlpha() {
|
void invertAlpha() {
|
||||||
foreach(ref pixel; _buf)
|
foreach(ref pixel; _buf)
|
||||||
pixel ^= 0xFF000000;
|
pixel ^= 0xFF000000;
|
||||||
|
|
|
@ -287,9 +287,9 @@ class SDLWindow : Window {
|
||||||
int iconw = 32;
|
int iconw = 32;
|
||||||
int iconh = 32;
|
int iconh = 32;
|
||||||
ColorDrawBuf iconDraw = new ColorDrawBuf(iconw, iconh);
|
ColorDrawBuf iconDraw = new ColorDrawBuf(iconw, iconh);
|
||||||
iconDraw.fill(0xE0E0E0);
|
iconDraw.fill(0xFF000000);
|
||||||
iconDraw.drawRescaled(Rect(0, 0, iconw, iconh), icon, Rect(0, 0, icon.width, icon.height));
|
iconDraw.drawRescaled(Rect(0, 0, iconw, iconh), icon, Rect(0, 0, icon.width, icon.height));
|
||||||
iconDraw.invertAlpha();
|
iconDraw.invertAndPreMultiplyAlpha();
|
||||||
SDL_Surface *surface = SDL_CreateRGBSurfaceFrom(iconDraw.scanLine(0), iconDraw.width, iconDraw.height, 32, iconDraw.width * 4, 0x00ff0000,0x0000ff00,0x000000ff,0xff000000);
|
SDL_Surface *surface = SDL_CreateRGBSurfaceFrom(iconDraw.scanLine(0), iconDraw.width, iconDraw.height, 32, iconDraw.width * 4, 0x00ff0000,0x0000ff00,0x000000ff,0xff000000);
|
||||||
if (surface) {
|
if (surface) {
|
||||||
// The icon is attached to the window pointer
|
// The icon is attached to the window pointer
|
||||||
|
|
Loading…
Reference in New Issue