From 901c5be5d7d917f0ba95526e8f61ce72188aa010 Mon Sep 17 00:00:00 2001 From: Vadim Lopatin Date: Wed, 21 May 2014 15:27:53 +0400 Subject: [PATCH] window icon support for win32 api backend --- examples/example1/res/mdpi/dlangui-logo1.png | Bin 1970 -> 956 bytes src/dlangui/graphics/drawbuf.d | 8 ++- src/dlangui/platforms/windows/win32drawbuf.d | 62 ++++++++++++++++++- src/dlangui/platforms/windows/winapp.d | 28 ++++++++- 4 files changed, 91 insertions(+), 7 deletions(-) diff --git a/examples/example1/res/mdpi/dlangui-logo1.png b/examples/example1/res/mdpi/dlangui-logo1.png index 84593ee72490a84f89215cf8bc5f9465d8d66839..da4f1f5694c5b72d0f373a30feb712feb0ec1ea6 100644 GIT binary patch delta 898 zcmV-|1AY9m54;DEBr*YWQb$4nuFf3k00009a7bBm000XU000XU0RWnu7ytkO2XskI zMF-vm6$=^^?PWe?ky|H!11U*FK~z}7y_Zc$R8bVif1^?+QM{*SjU^GtP-K4L$3%k- zwJH}vo7#j6qn0y*tB7>dE}g9)Wi1P4A=pB&(Qy$G#n3=#Uzo{6D))(vGV08{7WuAk zCPy57&VMs=&;Pu8|L?qW&$-t|8a|#mgVnh3{d-2PAl)#kY5E?2*7^kud4#x^Vzt>a zKJXvYrzpCGFW(Q0cs0$x;|Lh=2$6BtL@dTyG|Kw&GAr}*h^Z;&!eM@lj-q}0W_G>1 z@$1hz0^1451U-@9XD~?k*)zTj4W-j=j}T-3zR2dXc~&NyEkB~K(4TZ`T4q^!19`c$^HQF87aFI!t#Sy(X4 zr+ung2*k4b1nB}Y!QRw_tEYz(jg8VaJ28R(#toA3xM8~J)wDNRMZkbp(=zU-K1INZ^_@Fr*URQX zp2bD4#}E;G@BlrL06?j%AD7%Imuvq8_*69?n3Q$- z-8;#Z)zs|2fDPO?q7Zo_lbyrmZUy*M)s|A_ z@;0Z}bv-wKIp7f@1}p&-m6l5T+R{>X?Rb}{@TqFEOgy_?5~~>mSRDZyaMq}H;wiM8JuZK|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C@nTMT!x{SH|?+S_?bdGIugYhFQOP9O|e!UWwMBS}?0;O_Xg$q!Be2MO!Le9WzBl ze-P3C1E6b#Nd;lnW7^@S9btta6ZAE=M{M_i2t^jV&nu}KpzEhqSXOlqw@Kwg+q$vMNas_u z3}kUi3`D8L%T@riqGa{`q%wZt1?@&pf4KFyd0zoU5Ed0ctO79ak)o((a%Y3VDoKUh8C85z(0>&Ev5ZN}j>n2TOTKK7tgjDNr zw+;v-s*t=9lRKMIBvGP6ORb_~OQ_Z(kj8^${!B+@RJE2P9P@=hd5^W~l`LbTe>`rw z#_JokP?-(E+GLFqX{?}Md+pd}`E}fcu3y_s@>@J3YGd5jdpB}HD-l}r;1jx*FwT7c zX`_)R_8*|@+BaXL>( zdHJQIk#GO_7yR|HCs?0l);BVLe|u~n-}~tUTMwpOJo-c>tx@b`Z_&hH=I!{L`+=EiS*=M77>%Pu^hD=xbPQEkrO9tCQ) znWPqp$b3P* zV+_UW5!tLWL~90=nyN(|*A92@A=f;fn%1k>xVT2D$~OWjwIqqfeOW(cY*K4&P|H2h zR`RK1tzcQyk8UVB~n`>pzkC{+hyvv-K4@?C1Dii!fY#8a(a ekntF5Nd6C>`jEmqu>^kr0000= 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,9 +77,11 @@ class Win32ColorDrawBuf : ColorDrawBufBase { clear(); } override void clear() { - if (_drawbmp !is null) { - DeleteObject( _drawbmp ); - DeleteObject( _drawdc ); + if (_drawbmp !is null || _drawdc !is null) { + if (_drawbmp) + DeleteObject(_drawbmp); + if (_drawdc) + DeleteObject(_drawdc); _drawbmp = null; _drawdc = null; _pixels = null; diff --git a/src/dlangui/platforms/windows/winapp.d b/src/dlangui/platforms/windows/winapp.d index 143fb29e..b2c3870b 100644 --- a/src/dlangui/platforms/windows/winapp.d +++ b/src/dlangui/platforms/windows/winapp.d @@ -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() {