44 static const std::vector<Key> keys = []
46 std::vector<Key> result;
47 auto key = [&](
short code,
float column,
int row,
const wchar_t* caption,
48 float width = 1.0f,
int height = 1)
50 const LONG x = 20 +
static_cast<LONG
>(column * 78);
52 result.push_back({code, {x, y, x +
static_cast<LONG
>(width * 78) - 6, y + height *
KeyRowHeight - 8}, caption});
54 auto row = [&](
const std::vector<short>& codes,
float column,
int y)
56 for (
short code : codes)
57 key(code, column++, y,
nullptr);
59 key(DIK_ESCAPE, 0, 0, L
"Esc");
60 for (
int i = 0; i < 10; ++i)
61 key(
static_cast<short>(DIK_F1 + i), 2.0f + i + (i / 4) * 0.5f, 0,
nullptr);
62 key(DIK_F11, 13, 0, L
"F11");
63 key(DIK_F12, 14, 0, L
"F12");
64 row({DIK_GRAVE, DIK_1, DIK_2, DIK_3, DIK_4, DIK_5, DIK_6, DIK_7,
65 DIK_8, DIK_9, DIK_0, DIK_MINUS, DIK_EQUALS}, 0, 1);
66 key(DIK_BACK, 13, 1, L
"Backspace", 2);
67 key(DIK_TAB, 0, 2, L
"Tab", 1.5f);
68 row({DIK_Q, DIK_W, DIK_E, DIK_R, DIK_T, DIK_Y, DIK_U, DIK_I,
69 DIK_O, DIK_P, DIK_LBRACKET, DIK_RBRACKET}, 1.5f, 2);
70 key(DIK_BACKSLASH, 13.5f, 2,
nullptr, 1.5f);
71 key(DIK_CAPITAL, 0, 3, L
"Caps Lock", 1.75f);
72 row({DIK_A, DIK_S, DIK_D, DIK_F, DIK_G, DIK_H, DIK_J, DIK_K,
73 DIK_L, DIK_SEMICOLON, DIK_APOSTROPHE}, 1.75f, 3);
74 key(DIK_RETURN, 12.75f, 3, L
"Enter", 2.25f);
75 key(DIK_LSHIFT, 0, 4, L
"Shift", 1.25f);
76 key(DIK_OEM_102, 1.25f, 4,
nullptr);
77 row({DIK_Z, DIK_X, DIK_C, DIK_V, DIK_B, DIK_N, DIK_M, DIK_COMMA,
78 DIK_PERIOD, DIK_SLASH}, 2.25f, 4);
79 key(DIK_RSHIFT, 12.25f, 4, L
"Shift", 2.75f);
80 key(DIK_LCONTROL, 0, 5, L
"Ctrl", 1.25f);
81 key(DIK_LWIN, 1.25f, 5, L
"Win", 1.25f);
82 key(DIK_LALT, 2.5f, 5, L
"Alt", 1.25f);
83 key(DIK_SPACE, 3.75f, 5, L
"Space", 6.25f);
84 key(DIK_RALT, 10, 5, L
"Alt", 1.25f);
85 key(DIK_RWIN, 11.25f, 5, L
"Win", 1.25f);
86 key(DIK_APPS, 12.5f, 5, L
"Menu", 1.25f);
87 key(DIK_RCONTROL, 13.75f, 5, L
"Ctrl", 1.25f);
89 key(DIK_SYSRQ, 15.3f, 0, L
"PrtSc");
90 key(DIK_SCROLL, 16.3f, 0, L
"Scroll");
91 key(DIK_PAUSE, 17.3f, 0, L
"Pause");
92 key(DIK_INSERT, 15.3f, 1, L
"Insert");
93 key(DIK_HOME, 16.3f, 1, L
"Home");
94 key(DIK_PRIOR, 17.3f, 1, L
"Page Up");
95 key(DIK_DELETE, 15.3f, 2, L
"Delete");
96 key(DIK_END, 16.3f, 2, L
"End");
97 key(DIK_NEXT, 17.3f, 2, L
"Page Down");
98 key(DIK_UP, 16.3f, 4, L
"\x2191");
99 key(DIK_LEFT, 15.3f, 5, L
"\x2190");
100 key(DIK_DOWN, 16.3f, 5, L
"\x2193");
101 key(DIK_RIGHT, 17.3f, 5, L
"\x2192");
103 key(DIK_NUMLOCK, 18.6f, 1, L
"Num Lock");
104 key(DIK_DIVIDE, 19.6f, 1, L
"Num /");
105 key(DIK_MULTIPLY, 20.6f, 1, L
"Num *");
106 key(DIK_SUBTRACT, 21.6f, 1, L
"Num -");
107 key(DIK_NUMPAD7, 18.6f, 2, L
"Num 7");
108 key(DIK_NUMPAD8, 19.6f, 2, L
"Num 8");
109 key(DIK_NUMPAD9, 20.6f, 2, L
"Num 9");
110 key(DIK_ADD, 21.6f, 2, L
"Num +", 1, 2);
111 key(DIK_NUMPAD4, 18.6f, 3, L
"Num 4");
112 key(DIK_NUMPAD5, 19.6f, 3, L
"Num 5");
113 key(DIK_NUMPAD6, 20.6f, 3, L
"Num 6");
114 key(DIK_NUMPAD1, 18.6f, 4, L
"Num 1");
115 key(DIK_NUMPAD2, 19.6f, 4, L
"Num 2");
116 key(DIK_NUMPAD3, 20.6f, 4, L
"Num 3");
117 key(DIK_NUMPADENTER, 21.6f, 4, L
"Num Enter", 1, 2);
118 key(DIK_NUMPAD0, 18.6f, 5, L
"Num 0", 2);
119 key(DIK_DECIMAL, 20.6f, 5, L
"Num .");
203 const std::wstring& title,
int displayWidth,
int displayHeight)
205 if (!sprite || !
font || !
blankKeyboard || displayWidth <= 0 || displayHeight <= 0)
215 RECT previousScissor;
216 DWORD previousScissorEnabled = FALSE;
221 const float scale = (std::min)(displayWidth /
static_cast<float>(
Keychart::Width),
229 auto text = [&](
const std::wstring& value, RECT bounds,
DWORD color,
DWORD align,
230 bool marquee =
false,
const std::wstring& shortName = std::wstring())
232 if (value.empty())
return;
235 auto width = [&](
const std::wstring& string)
238 font->
DrawTextW(
nullptr,
string.c_str(), -1, &measured, DT_CALCRECT | DT_SINGLELINE, color);
239 return measured.right - measured.left;
241 const LONG available = bounds.right - bounds.left;
242 const auto cacheKey = std::make_tuple(value, shortName, available);
246 TextLayout layout = {width(value), value, value};
247 if (layout.
width > available && !shortName.empty() && shortName != L
"//")
249 const LONG shortWidth = width(shortName);
250 if (shortWidth < layout.
width)
252 layout.
width = shortWidth;
256 if (layout.
width > available)
258 const std::wstring ellipsis = L
"\x2026";
263 if (!layout.
fitted.empty() && layout.
fitted.back() >= 0xd800 && layout.
fitted.back() <= 0xdbff)
265 }
while (!layout.
fitted.empty() && width(layout.
fitted + ellipsis) > available);
266 layout.
fitted += ellipsis;
268 cached =
textLayouts.emplace(cacheKey, std::move(layout)).first;
270 const LONG textWidth = cached->second.width;
271 if (textWidth > available)
274 if (marquee && !position.showEllipsis)
279 static_cast<LONG
>(std::ceil(bounds.left * scale + transform._41)),
280 static_cast<LONG
>(std::ceil(bounds.top * scale + transform._42)),
281 static_cast<LONG
>(std::floor(bounds.right * scale + transform._41)),
282 static_cast<LONG
>(std::floor(bounds.bottom * scale + transform._42))};
283 if (previousScissorEnabled)
286 if (!IntersectRect(&intersection, &clip, &previousScissor))
return;
289 if (IsRectEmpty(&clip))
return;
294 RECT moving = bounds;
295 moving.left -=
static_cast<LONG
>(position.offset);
296 moving.right = moving.left + textWidth;
297 font->
DrawTextW(sprite, cached->second.selected.c_str(), -1, &moving,
298 DT_SINGLELINE | DT_VCENTER | DT_LEFT | DT_NOCLIP, color);
306 font->
DrawTextW(sprite, cached->second.fitted.c_str(), -1, &bounds, DT_SINGLELINE | DT_VCENTER | align, color);
309 text(title, {20, 14, 1045, 50}, colors[0], DT_LEFT);
310 text(L
"Key", {1070, 14, 1125, 50}, colors[0], DT_LEFT);
311 text(L
"Shift + Key", {1145, 14, 1280, 50}, colors[1], DT_LEFT);
312 text(L
"Control + Key", {1300, 14, 1490, 50}, colors[2], DT_LEFT);
313 text(L
"Control + Shift + Key", {1510, 14, 1795, 50}, colors[3], DT_LEFT);
316 wchar_t keyName[64] = {};
320 const LONG scan = ((key.scancode & 0x7f) << 16) | ((key.scancode & 0x80) ? (1 << 24) : 0);
321 if (!GetKeyNameTextW(scan, keyName, 64))
322 swprintf_s(keyName, L
"0x%02X", key.scancode);
324 RECT name = key.bounds;
325 name.left += 5; name.right -= 5; name.top += 2; name.bottom = name.top + 20;
326 text(key.caption ? key.caption : keyName, name, 0xFF9DB0BF, DT_LEFT);
329 RECT bounds = key.bounds;
330 bounds.left += 3; bounds.right -= 3;
333 const auto& label = labels[key.scancode][modifier];
334 text(label.full, bounds, colors[modifier], DT_CENTER,
true, label.shortName);