|
1
|
1 #include "stdafx.h"
|
|
|
2
|
|
|
3 #include "GDIUtils.h"
|
|
|
4
|
|
|
5 HBITMAP CreateDIB24(CSize size) {
|
|
|
6 struct {
|
|
|
7 BITMAPINFOHEADER bmi;
|
|
|
8 } bi = {};
|
|
|
9 bi.bmi.biSize = sizeof(bi.bmi);
|
|
|
10 bi.bmi.biWidth = size.cx;
|
|
|
11 bi.bmi.biHeight = size.cy;
|
|
|
12 bi.bmi.biPlanes = 1;
|
|
|
13 bi.bmi.biBitCount = 24;
|
|
|
14 bi.bmi.biCompression = BI_RGB;
|
|
|
15 void* bitsPtr;
|
|
|
16 return CreateDIBSection(NULL, reinterpret_cast<const BITMAPINFO*>(&bi), DIB_RGB_COLORS, &bitsPtr, 0, 0);
|
|
|
17 }
|
|
|
18
|
|
|
19 HBITMAP CreateDIB16(CSize size) {
|
|
|
20 struct {
|
|
|
21 BITMAPINFOHEADER bmi;
|
|
|
22 } bi = {};
|
|
|
23 bi.bmi.biSize = sizeof(bi.bmi);
|
|
|
24 bi.bmi.biWidth = size.cx;
|
|
|
25 bi.bmi.biHeight = size.cy;
|
|
|
26 bi.bmi.biPlanes = 1;
|
|
|
27 bi.bmi.biBitCount = 16;
|
|
|
28 bi.bmi.biCompression = BI_RGB;
|
|
|
29 void* bitsPtr;
|
|
|
30 return CreateDIBSection(NULL, reinterpret_cast<const BITMAPINFO*>(&bi), DIB_RGB_COLORS, &bitsPtr, 0, 0);
|
|
|
31 }
|
|
|
32
|
|
|
33 HBITMAP CreateDIB8(CSize size, const COLORREF palette[256]) {
|
|
|
34 struct {
|
|
|
35 BITMAPINFOHEADER bmi;
|
|
|
36 COLORREF colors[256];
|
|
|
37 } bi = { };
|
|
|
38 for (int c = 0; c < 256; ++c) bi.colors[c] = palette[c];
|
|
|
39 bi.bmi.biSize = sizeof(bi.bmi);
|
|
|
40 bi.bmi.biWidth = size.cx;
|
|
|
41 bi.bmi.biHeight = size.cy;
|
|
|
42 bi.bmi.biPlanes = 1;
|
|
|
43 bi.bmi.biBitCount = 8;
|
|
|
44 bi.bmi.biCompression = BI_RGB;
|
|
|
45 bi.bmi.biClrUsed = 256;
|
|
|
46 void* bitsPtr;
|
|
|
47 return CreateDIBSection(NULL, reinterpret_cast<const BITMAPINFO*>(&bi), DIB_RGB_COLORS, &bitsPtr, 0, 0);
|
|
|
48 }
|
|
|
49
|
|
|
50 void CreateScaledFont(CFont& out, CFontHandle in, double scale) {
|
|
|
51 LOGFONT lf;
|
|
|
52 WIN32_OP_D(in.GetLogFont(lf));
|
|
|
53 int temp = pfc::rint32(scale * lf.lfHeight);
|
|
|
54 if (temp == 0) temp = pfc::sgn_t(lf.lfHeight);
|
|
|
55 lf.lfHeight = temp;
|
|
|
56 WIN32_OP_D(out.CreateFontIndirect(&lf) != NULL);
|
|
|
57 }
|
|
|
58
|
|
|
59 void CreateScaledFontEx(CFont& out, CFontHandle in, double scale, int weight) {
|
|
|
60 LOGFONT lf;
|
|
|
61 WIN32_OP_D(in.GetLogFont(lf));
|
|
|
62 int temp = pfc::rint32(scale * lf.lfHeight);
|
|
|
63 if (temp == 0) temp = pfc::sgn_t(lf.lfHeight);
|
|
|
64 lf.lfHeight = temp;
|
|
|
65 lf.lfWeight = weight;
|
|
|
66 WIN32_OP_D(out.CreateFontIndirect(&lf) != NULL);
|
|
|
67 }
|
|
|
68
|
|
|
69 void CreatePreferencesHeaderFont(CFont& out, CWindow source) {
|
|
|
70 CreateScaledFontEx(out, source.GetFont(), 1.3, FW_BOLD);
|
|
|
71 }
|
|
|
72
|
|
|
73 void CreatePreferencesHeaderFont2(CFont& out, CWindow source) {
|
|
|
74 CreateScaledFontEx(out, source.GetFont(), 1.1, FW_BOLD);
|
|
|
75 }
|
|
|
76
|
|
|
77 CSize GetBitmapSize(HBITMAP bmp) {
|
|
|
78 PFC_ASSERT(bmp != NULL);
|
|
|
79 CBitmapHandle h(bmp);
|
|
|
80 BITMAP bm = {};
|
|
|
81 WIN32_OP_D(h.GetBitmap(bm));
|
|
|
82 return CSize(bm.bmWidth, bm.bmHeight);
|
|
|
83 }
|
|
|
84
|
|
|
85 CSize GetIconSize(HICON icon) {
|
|
|
86 PFC_ASSERT(icon != NULL);
|
|
|
87 CIconHandle h(icon);
|
|
|
88 ICONINFO info = {};
|
|
|
89 WIN32_OP_D( h.GetIconInfo(&info) );
|
|
|
90 CSize ret;
|
|
|
91 if (info.hbmColor != NULL) ret = GetBitmapSize(info.hbmColor);
|
|
|
92 else if (info.hbmMask != NULL) ret = GetBitmapSize(info.hbmMask);
|
|
|
93 else { PFC_ASSERT(!"???"); }
|
|
|
94 if (info.hbmColor != NULL) DeleteObject(info.hbmColor);
|
|
|
95 if (info.hbmMask != NULL) DeleteObject(info.hbmMask);
|
|
|
96 return ret;
|
|
|
97 }
|
|
|
98
|
|
|
99 HBRUSH MakeTempBrush(HDC dc, COLORREF color) noexcept {
|
|
|
100 SetDCBrushColor(dc, color); return (HBRUSH)GetStockObject(DC_BRUSH);
|
|
|
101 }
|