mirror of https://github.com/buggins/dlangui.git
window icon support for win32 api backend
This commit is contained in:
parent
c564bb67a2
commit
901c5be5d7
Binary file not shown.
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 956 B |
|
@ -830,10 +830,16 @@ class ColorDrawBuf : ColorDrawBufBase {
|
|||
/// create copy of ColorDrawBuf
|
||||
this(ColorDrawBuf v) {
|
||||
this(v.width, v.height);
|
||||
_buf.length = v._buf.length;
|
||||
//_buf.length = v._buf.length;
|
||||
for (int i = 0; i < _buf.length; i++)
|
||||
_buf[i] = v._buf[i];
|
||||
}
|
||||
/// create resized copy of ColorDrawBuf
|
||||
this(ColorDrawBuf v, int dx, int dy) {
|
||||
this(dx, dy);
|
||||
fill(0xFFFFFFFF);
|
||||
drawRescaled(Rect(0, 0, dx, dy), v, Rect(0, 0, v.width, v.height));
|
||||
}
|
||||
void invertAlpha() {
|
||||
foreach(pixel; _buf)
|
||||
pixel ^= 0xFF000000;
|
||||
|
|
|
@ -11,8 +11,62 @@ class Win32ColorDrawBuf : ColorDrawBufBase {
|
|||
HDC _drawdc;
|
||||
HBITMAP _drawbmp;
|
||||
@property HDC dc() { return _drawdc; }
|
||||
@property HBITMAP bmp() { return _drawdc; }
|
||||
this(int width, int height) {
|
||||
resize(width, height);
|
||||
}
|
||||
/// create resized copy of ColorDrawBuf
|
||||
this(ColorDrawBuf v, int dx, int dy) {
|
||||
this(dx, dy);
|
||||
fill(0xFFFFFFFF);
|
||||
if (_dx == dx && _dy == dy)
|
||||
drawImage(0, 0, v);
|
||||
else
|
||||
drawRescaled(Rect(0, 0, dx, dy), v, Rect(0, 0, v.width, v.height));
|
||||
}
|
||||
void invertAlpha() {
|
||||
for(int i = _dx * _dy - 1; i >= 0; i--)
|
||||
_pixels[i] ^= 0xFF000000;
|
||||
}
|
||||
/// returns HBITMAP for alpha
|
||||
HBITMAP createTransparencyBitmap() {
|
||||
int hbytes = (((_dx + 7) / 8) + 1) & 0xFFFFFFFE;
|
||||
static ubyte[] buf;
|
||||
buf.length = hbytes * _dy * 2;
|
||||
//for (int y = 0; y < _dy; y++) {
|
||||
// uint * src = scanLine(y);
|
||||
// ubyte * dst1 = buf.ptr + (_dy - 1 - y) * hbytes;
|
||||
// ubyte * dst2 = buf.ptr + (_dy - 1 - y) * hbytes + hbytes * _dy;
|
||||
// for (int x = 0; x < _dx; x++) {
|
||||
// ubyte pixel1 = 0x80; //(src[x] >> 24) > 0x80 ? 0 : 0x80;
|
||||
// ubyte pixel2 = (src[x] >> 24) < 0x80 ? 0 : 0x80;
|
||||
// int xi = x >> 3;
|
||||
// dst1[xi] |= (pixel1 >> (x & 7));
|
||||
// dst2[xi] |= (pixel2 >> (x & 7));
|
||||
// }
|
||||
//}
|
||||
// debug
|
||||
for(int i = 0; i < hbytes * _dy; i++)
|
||||
buf[i] = 0xFF;
|
||||
for(int i = hbytes * _dy; i < buf.length; i++)
|
||||
buf[i] = 0; //0xFF;
|
||||
|
||||
BITMAP b;
|
||||
b.bmWidth = _dx;
|
||||
b.bmHeight = _dy;
|
||||
b.bmWidthBytes = hbytes;
|
||||
b.bmPlanes = 1;
|
||||
b.bmBitsPixel = 1;
|
||||
b.bmBits = buf.ptr;
|
||||
return CreateBitmapIndirect(&b);
|
||||
//return CreateBitmap(_dx, _dy, 1, 1, buf.ptr);
|
||||
}
|
||||
/// destroy object, but leave bitmap as is
|
||||
HBITMAP destoryLeavingBitmap() {
|
||||
HBITMAP res = _drawbmp;
|
||||
_drawbmp = null;
|
||||
destroy(this);
|
||||
return res;
|
||||
}
|
||||
override uint * scanLine(int y) {
|
||||
if (y >= 0 && y < _dy)
|
||||
|
@ -23,8 +77,10 @@ class Win32ColorDrawBuf : ColorDrawBufBase {
|
|||
clear();
|
||||
}
|
||||
override void clear() {
|
||||
if (_drawbmp !is null) {
|
||||
if (_drawbmp !is null || _drawdc !is null) {
|
||||
if (_drawbmp)
|
||||
DeleteObject(_drawbmp);
|
||||
if (_drawdc)
|
||||
DeleteObject(_drawdc);
|
||||
_drawbmp = null;
|
||||
_drawdc = null;
|
||||
|
|
|
@ -325,16 +325,38 @@ class Win32Window : Window {
|
|||
_platform.closeWindow(this);
|
||||
}
|
||||
|
||||
HICON _icon;
|
||||
|
||||
/// sets window icon
|
||||
@property override void windowIcon(DrawBufRef buf) {
|
||||
if (_icon)
|
||||
DestroyIcon(_icon);
|
||||
_icon = null;
|
||||
ColorDrawBuf icon = cast(ColorDrawBuf)buf.get;
|
||||
if (!icon) {
|
||||
Log.e("Trying to set null icon for window");
|
||||
return;
|
||||
}
|
||||
//icon = new ColorDrawBuf(icon);
|
||||
//icon.invertAlpha();
|
||||
//destroy(icon);
|
||||
Win32ColorDrawBuf resizedicon = new Win32ColorDrawBuf(icon, 32, 32);
|
||||
resizedicon.invertAlpha();
|
||||
ICONINFO ii;
|
||||
HBITMAP mask = resizedicon.createTransparencyBitmap();
|
||||
HBITMAP color = resizedicon.destoryLeavingBitmap();
|
||||
ii.fIcon = TRUE;
|
||||
ii.xHotspot = 0;
|
||||
ii.yHotspot = 0;
|
||||
ii.hbmMask = mask;
|
||||
ii.hbmColor = color;
|
||||
_icon = CreateIconIndirect(&ii);
|
||||
if (_icon) {
|
||||
SendMessage(_hwnd, WM_SETICON, ICON_SMALL, cast(int)_icon);
|
||||
SendMessage(_hwnd, WM_SETICON, ICON_BIG, cast(int)_icon);
|
||||
} else {
|
||||
Log.e("failed to create icon");
|
||||
}
|
||||
if (mask)
|
||||
DeleteObject(mask);
|
||||
DeleteObject(color);
|
||||
}
|
||||
|
||||
private void paintUsingGDI() {
|
||||
|
|
Loading…
Reference in New Issue