-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathicon_map.cpp
More file actions
114 lines (84 loc) · 3.68 KB
/
icon_map.cpp
File metadata and controls
114 lines (84 loc) · 3.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include "stdafx.h"
#include "CGdiPlusBitmap.h"
#include "icon_map.h"
HBITMAP LoadDpiBitmapResource(Icon icon, bool isDark) {
HBITMAP h_bitmap;
CGdiPlusBitmapResource rec_image;
auto hInst = core_api::get_my_instance();
const CSize DPI = QueryScreenDPIEx();
t_uint32 dpiX = DPI.cx;
t_uint32 dpiY = DPI.cy;
int iconWidth = 16;
int iconHeight = 16;
int scaledIconWidth = MulDiv(iconWidth, dpiX, USER_DEFAULT_SCREEN_DPI);
int scaledIconHeight = MulDiv(iconHeight, dpiY, USER_DEFAULT_SCREEN_DPI);
const IconMapping* mapping = nullptr;
mapping = &ICON_RESOURCE_MAPPINGS_COLOR;
const auto& iconSizeMappins = mapping->at(icon);
auto match = std::find_if(
iconSizeMappins.begin(), iconSizeMappins.end(), [scaledIconWidth, scaledIconHeight](auto entry) {
return scaledIconWidth <= entry.first && scaledIconHeight <= entry.first;
});
if (match == iconSizeMappins.end())
{
match = std::prev(iconSizeMappins.end());
}
rec_image.Load(MAKEINTRESOURCE(match->second/*IDB_PNG_REC16*/), L"PNG", hInst);
if (match->first == scaledIconWidth && match->first == scaledIconHeight)
{
Gdiplus::Status res_get = rec_image.m_pBitmap->GetHBITMAP(Gdiplus::Color(255, 255, 255)/*Color::Black*/, &h_bitmap);
DeleteObject(rec_image);
}
else {
auto scaledBitmap = std::make_unique<Gdiplus::Bitmap>(scaledIconWidth, scaledIconHeight);
scaledBitmap->SetResolution(rec_image.m_pBitmap->GetHorizontalResolution(), rec_image.m_pBitmap->GetVerticalResolution());
Gdiplus::Graphics graphics(scaledBitmap.get());
float scalingFactorX = static_cast<float>(scaledIconWidth) / static_cast<float>(match->first);
float scalingFactorY = static_cast<float>(scaledIconHeight) / static_cast<float>(match->first);
graphics.ScaleTransform(scalingFactorX, scalingFactorY);
graphics.DrawImage(rec_image.m_pBitmap, 0, 0);
DeleteObject(rec_image);
Gdiplus::Status res_get = scaledBitmap->GetHBITMAP(Gdiplus::Color(255, 255, 255), &h_bitmap);
}
return h_bitmap;
}
HICON LoadDpiIconResource(Icon icon, bool isDark) {
HICON h_icon;
CGdiPlusBitmapResource rec_image;
auto hInst = core_api::get_my_instance();
const CSize DPI = QueryScreenDPIEx();
t_uint32 dpiX = DPI.cx;
t_uint32 dpiY = DPI.cy;
int iconWidth = 16;
int iconHeight = 16;
int scaledIconWidth = MulDiv(iconWidth, dpiX, USER_DEFAULT_SCREEN_DPI);
int scaledIconHeight = MulDiv(iconHeight, dpiY, USER_DEFAULT_SCREEN_DPI);
const IconMapping* mapping = nullptr;
mapping = &ICON_RESOURCE_MAPPINGS_COLOR;
const auto& iconSizeMappins = mapping->at(icon);
auto match = std::find_if(
iconSizeMappins.begin(), iconSizeMappins.end(), [scaledIconWidth, scaledIconHeight](auto entry) {
return scaledIconWidth <= entry.first && scaledIconHeight <= entry.first;
});
if (match == iconSizeMappins.end())
{
match = std::prev(iconSizeMappins.end());
}
rec_image.Load(MAKEINTRESOURCE(match->second/*IDB_PNG_REC16*/), L"PNG", hInst);
if (match->first == scaledIconWidth && match->first == scaledIconHeight)
{
Gdiplus::Status res_get = rec_image.m_pBitmap->GetHICON(&h_icon);
}
else {
auto scaledBitmap = std::make_unique<Gdiplus::Bitmap>(scaledIconWidth, scaledIconHeight);
scaledBitmap->SetResolution(rec_image.m_pBitmap->GetHorizontalResolution(), rec_image.m_pBitmap->GetVerticalResolution());
Gdiplus::Graphics graphics(scaledBitmap.get());
float scalingFactorX = static_cast<float>(scaledIconWidth) / static_cast<float>(match->first);
float scalingFactorY = static_cast<float>(scaledIconHeight) / static_cast<float>(match->first);
graphics.ScaleTransform(scalingFactorX, scalingFactorY);
graphics.DrawImage(rec_image.m_pBitmap, 0, 0);
DeleteObject(rec_image);
Gdiplus::Status res_get = scaledBitmap->GetHICON(&h_icon);
}
return h_icon;
}