1 module dlangui.platforms.windows.win32drawbuf;
2 
3 version (Windows) {
4 
5 import win32.windows;
6 import dlangui.core.logger;
7 import dlangui.graphics.drawbuf;
8 
9 class Win32ColorDrawBuf : ColorDrawBufBase {
10     uint * _pixels;
11     HDC _drawdc;
12     HBITMAP _drawbmp;
13     @property HDC dc() { return _drawdc; }
14     this(int width, int height) {
15         resize(width, height);
16     }
17     override uint * scanLine(int y) {
18         if (y >= 0 && y < _dy)
19             return _pixels + _dx * (_dy - 1 - y);
20         return null;
21     }
22     ~this() {
23         clear();
24     }
25     override void clear() {
26         if (_drawbmp !is null) {
27             DeleteObject( _drawbmp );
28             DeleteObject( _drawdc );
29             _drawbmp = null;
30             _drawdc = null;
31             _pixels = null;
32             _dx = 0;
33             _dy = 0;
34         }
35     }
36     override void resize(int width, int height) {
37         if (width< 0)
38             width = 0;
39         if (height < 0)
40             height = 0;
41         if (_dx == width && _dy == height)
42             return;
43         clear();
44         _dx = width;
45         _dy = height;
46         if (_dx > 0 && _dy > 0) {
47             BITMAPINFO bmi;
48             //memset( &bmi, 0, sizeof(bmi) );
49             bmi.bmiHeader.biSize = (bmi.bmiHeader.sizeof);
50             bmi.bmiHeader.biWidth = _dx;
51             bmi.bmiHeader.biHeight = _dy;
52             bmi.bmiHeader.biPlanes = 1;
53             bmi.bmiHeader.biBitCount = 32;
54             bmi.bmiHeader.biCompression = BI_RGB;
55             bmi.bmiHeader.biSizeImage = 0;
56             bmi.bmiHeader.biXPelsPerMeter = 1024;
57             bmi.bmiHeader.biYPelsPerMeter = 1024;
58             bmi.bmiHeader.biClrUsed = 0;
59             bmi.bmiHeader.biClrImportant = 0;
60             _drawbmp = CreateDIBSection( NULL, &bmi, DIB_RGB_COLORS, cast(void**)(&_pixels), NULL, 0 );
61             _drawdc = CreateCompatibleDC(NULL);
62             SelectObject(_drawdc, _drawbmp);
63         }
64     }
65     override void fill(uint color) {
66         int len = _dx * _dy;
67         for (int i = 0; i < len; i++)
68             _pixels[i] = color;
69     }
70     void drawTo(HDC dc, int x, int y) {
71         BitBlt(dc, x, y, _dx, _dy, _drawdc, 0, 0, SRCCOPY);
72     }
73 }
74 
75 }