Repository navigation
Expand file tree
/
Copy pathgui_controls.cpp
More file actions
543 lines (495 loc) · 22.5 KB
/
Copy pathgui_controls.cpp
File metadata and controls
543 lines (495 loc) · 22.5 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
// Shared themed buttons, check controls, and redraw helpers.
#include "gui_controls.hpp"
#include "gui_state.hpp"
#include "gui_theme.hpp"
#include "gui_ids.hpp"
#include "gui_text.hpp"
namespace gui {
COLORREF mix_color(COLORREF a, COLORREF b, int weight_b) {
weight_b = std::clamp(weight_b, 0, 255);
const int weight_a = 255 - weight_b;
const int r = (GetRValue(a) * weight_a + GetRValue(b) * weight_b) / 255;
const int g = (GetGValue(a) * weight_a + GetGValue(b) * weight_b) / 255;
const int bl = (GetBValue(a) * weight_a + GetBValue(b) * weight_b) / 255;
return RGB(r, g, bl);
}
void fill_rounded_rect(HDC dc, const RECT& r, COLORREF fill, COLORREF border, int radius) {
HBRUSH bg = CreateSolidBrush(fill);
HPEN pen = CreatePen(PS_SOLID, 1, border);
HGDIOBJ old_brush = SelectObject(dc, bg);
HGDIOBJ old_pen = SelectObject(dc, pen);
RoundRect(dc, r.left, r.top, r.right, r.bottom, radius, radius);
SelectObject(dc, old_pen);
SelectObject(dc, old_brush);
DeleteObject(pen);
DeleteObject(bg);
}
void draw_button_with_colors(HDC dc, const RECT& r, const wchar_t* txt,
COLORREF bg_col, COLORREF border_col, COLORREF text_col,
bool pressed) {
fill_rounded_rect(dc, r, bg_col, border_col, 6);
RECT inner = { r.left + 1, r.top + 1, r.right - 1, r.top + 10 };
HBRUSH gloss = CreateSolidBrush(mix_color(bg_col, RGB(255, 255, 255), pressed ? 8 : 20));
FillRect(dc, &inner, gloss);
DeleteObject(gloss);
SetBkMode(dc, TRANSPARENT);
SetTextColor(dc, text_col);
HFONT f = g.ui_font ? g.ui_font : reinterpret_cast<HFONT>(GetStockObject(DEFAULT_GUI_FONT));
HGDIOBJ old_font = SelectObject(dc, f);
RECT text_rect = { r.left + 6, r.top, r.right - 6, r.bottom };
if (pressed) OffsetRect(&text_rect, 0, 1);
DrawTextW(dc, txt, -1, &text_rect,
DT_CENTER | DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX | DT_END_ELLIPSIS);
SelectObject(dc, old_font);
}
namespace {
constexpr UINT_PTR kThemedComboSubclassId = 0x414D4342; // "AMCB"
constexpr UINT_PTR kThemedEditSubclassId = 0x414D4544; // "AMED"
constexpr wchar_t kThemedComboPressedProperty[] = L"AMSignalThemedComboPressed";
std::wstring combo_selection_text(HWND combo) {
const int index = static_cast<int>(SendMessageW(combo, CB_GETCURSEL, 0, 0));
if (index == CB_ERR) return L"";
const LRESULT len = SendMessageW(combo, CB_GETLBTEXTLEN, index, 0);
if (len <= 0) return L"";
std::wstring text(static_cast<std::size_t>(len), L'\0');
SendMessageW(combo, CB_GETLBTEXT, index, reinterpret_cast<LPARAM>(text.data()));
return text;
}
std::wstring themed_combo_closed_text(HWND combo) {
return combo_selection_text(combo);
}
void paint_themed_combo(HWND combo) {
RECT window{};
GetWindowRect(combo, &window);
const int width = window.right - window.left;
const int height = window.bottom - window.top;
if (width <= 0 || height <= 0) return;
HDC dc = GetWindowDC(combo);
if (!dc) return;
const RECT r = {0, 0, width, height};
const bool enabled = IsWindowEnabled(combo) != FALSE;
const bool focused = GetFocus() == combo;
const bool pressed = GetPropW(combo, kThemedComboPressedProperty) != nullptr ||
SendMessageW(combo, CB_GETDROPPEDSTATE, 0, 0) != FALSE;
const COLORREF surface = enabled ? (pressed ? g_theme->btn_hover : g_theme->bg_plot)
: mix_color(g_theme->bg_plot, g_theme->bg_panel, 104);
const COLORREF border = focused || pressed ? g_theme->accent : g_theme->btn_border;
fill_rounded_rect(dc, r, surface, border, 6);
const int arrow_width = min(28, max(22, width / 5));
RECT divider = {r.right - arrow_width, r.top + 5, r.right - arrow_width + 1, r.bottom - 5};
HBRUSH divider_brush = CreateSolidBrush(mix_color(border, surface, 112));
FillRect(dc, ÷r, divider_brush);
DeleteObject(divider_brush);
const COLORREF arrow = enabled ? (pressed ? g_theme->accent_hover : g_theme->text_secondary)
: g_theme->text_secondary;
const int cx = r.right - arrow_width / 2;
const int cy = (r.top + r.bottom) / 2 + (pressed ? 1 : 0);
HPEN arrow_pen = CreatePen(PS_SOLID, 2, arrow);
HGDIOBJ old_pen = SelectObject(dc, arrow_pen);
MoveToEx(dc, cx - 4, cy - 2, nullptr);
LineTo(dc, cx, cy + 2);
LineTo(dc, cx + 4, cy - 2);
SelectObject(dc, old_pen);
DeleteObject(arrow_pen);
const std::wstring text = themed_combo_closed_text(combo);
RECT text_rect = {r.left + 9, r.top + 1, r.right - arrow_width - 7, r.bottom - 1};
SetBkMode(dc, TRANSPARENT);
SetTextColor(dc, enabled ? g_theme->text_primary : g_theme->text_secondary);
HFONT font = g.ui_font ? g.ui_font : reinterpret_cast<HFONT>(GetStockObject(DEFAULT_GUI_FONT));
HGDIOBJ old_font = SelectObject(dc, font);
DrawTextW(dc, text.c_str(), -1, &text_rect,
DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX | DT_END_ELLIPSIS);
SelectObject(dc, old_font);
ReleaseDC(combo, dc);
}
LRESULT CALLBACK themed_combo_proc(HWND combo, UINT msg, WPARAM wp, LPARAM lp,
UINT_PTR, DWORD_PTR) {
switch (msg) {
case WM_LBUTTONDOWN:
SetPropW(combo, kThemedComboPressedProperty, reinterpret_cast<HANDLE>(1));
InvalidateRect(combo, nullptr, FALSE);
break;
case WM_LBUTTONUP:
case WM_KILLFOCUS:
RemovePropW(combo, kThemedComboPressedProperty);
InvalidateRect(combo, nullptr, FALSE);
break;
case WM_SETFOCUS:
case WM_ENABLE:
case CB_SETCURSEL:
InvalidateRect(combo, nullptr, FALSE);
break;
case WM_NCDESTROY:
RemovePropW(combo, kThemedComboPressedProperty);
RemoveWindowSubclass(combo, themed_combo_proc, kThemedComboSubclassId);
break;
case WM_PAINT: {
const LRESULT result = DefSubclassProc(combo, msg, wp, lp);
paint_themed_combo(combo);
return result;
}
default:
break;
}
return DefSubclassProc(combo, msg, wp, lp);
}
void paint_compact_edit_frame(HWND edit) {
RECT window{};
GetWindowRect(edit, &window);
const int width = window.right - window.left;
const int height = window.bottom - window.top;
if (width <= 2 || height <= 2) return;
HDC dc = GetWindowDC(edit);
if (!dc) return;
const bool enabled = IsWindowEnabled(edit) != FALSE;
const COLORREF border = !enabled ? mix_color(g_theme->btn_border, g_theme->bg_panel, 96)
: (GetFocus() == edit ? g_theme->accent : g_theme->btn_border);
HPEN pen = CreatePen(PS_SOLID, 1, border);
HGDIOBJ old_pen = SelectObject(dc, pen);
HGDIOBJ old_brush = SelectObject(dc, GetStockObject(NULL_BRUSH));
RoundRect(dc, 0, 0, width, height, 6, 6);
SelectObject(dc, old_brush);
SelectObject(dc, old_pen);
DeleteObject(pen);
ReleaseDC(edit, dc);
}
LRESULT CALLBACK themed_edit_proc(HWND edit, UINT msg, WPARAM wp, LPARAM lp,
UINT_PTR, DWORD_PTR) {
switch (msg) {
case WM_SETFOCUS:
case WM_KILLFOCUS:
case WM_ENABLE:
RedrawWindow(edit, nullptr, nullptr, RDW_INVALIDATE | RDW_FRAME);
break;
case WM_NCPAINT: {
const LRESULT result = DefSubclassProc(edit, msg, wp, lp);
paint_compact_edit_frame(edit);
return result;
}
case WM_NCDESTROY:
RemoveWindowSubclass(edit, themed_edit_proc, kThemedEditSubclassId);
break;
default:
break;
}
return DefSubclassProc(edit, msg, wp, lp);
}
} // namespace
void install_themed_combo(HWND combo) {
if (!combo || !IsWindow(combo)) return;
SetWindowSubclass(combo, themed_combo_proc, kThemedComboSubclassId, 0);
InvalidateRect(combo, nullptr, TRUE);
}
void install_compact_themed_edit(HWND edit) {
if (!edit || !IsWindow(edit)) return;
const LONG_PTR ex_style = GetWindowLongPtrW(edit, GWL_EXSTYLE) & ~static_cast<LONG_PTR>(WS_EX_CLIENTEDGE);
const LONG_PTR style = GetWindowLongPtrW(edit, GWL_STYLE) | WS_BORDER;
SetWindowLongPtrW(edit, GWL_EXSTYLE, ex_style);
SetWindowLongPtrW(edit, GWL_STYLE, style);
SetWindowSubclass(edit, themed_edit_proc, kThemedEditSubclassId, 0);
SetWindowPos(edit, nullptr, 0, 0, 0, 0,
SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED);
}
LRESULT draw_themed_trackbar(const NMCUSTOMDRAW& draw) {
const HWND track=draw.hdr.hwndFrom;
if(draw.dwDrawStage!=CDDS_PREPAINT)return CDRF_DODEFAULT;
// Trackbars may omit channel/item callbacks on incremental redraws. Paint
// the complete control in one stage so clearing the background never
// erases a channel or thumb that native code elects to leave cached.
const int saved=SaveDC(draw.hdc);
RECT client{};GetClientRect(track,&client);
IntersectClipRect(draw.hdc,client.left,client.top,client.right,client.bottom);
HBRUSH background=CreateSolidBrush(g_theme->bg_panel);
FillRect(draw.hdc,&client,background);DeleteObject(background);
const bool enabled=IsWindowEnabled(track)!=FALSE;
const bool focused=GetFocus()==track;
const bool pressed=GetCapture()==track || (draw.uItemState&CDIS_SELECTED)!=0;
POINT cursor{};GetCursorPos(&cursor);ScreenToClient(track,&cursor);
RECT thumb{};SendMessageW(track,TBM_GETTHUMBRECT,0,reinterpret_cast<LPARAM>(&thumb));
const bool hot=PtInRect(&thumb,cursor)!=FALSE;
const COLORREF accent=enabled ? g_theme->accent : mix_color(g_theme->btn_border,g_theme->bg_panel,80);
RECT rail{};SendMessageW(track,TBM_GETCHANNELRECT,0,reinterpret_cast<LPARAM>(&rail));
const int center=(thumb.top+thumb.bottom)/2;
rail.top=center-2;rail.bottom=center+3;
const COLORREF base=mix_color(g_theme->btn_border,g_theme->bg_panel,64);
fill_rounded_rect(draw.hdc,rail,base,base,5);
RECT filled=rail;filled.right=std::clamp((thumb.left+thumb.right)/2,rail.left,rail.right);
if(filled.right>filled.left)fill_rounded_rect(draw.hdc,filled,accent,accent,5);
const COLORREF surface=!enabled ? mix_color(g_theme->btn_bg,g_theme->bg_panel,128)
: (pressed ? g_theme->btn_active : hot ? g_theme->btn_hover : g_theme->bg_plot);
const COLORREF border=enabled && (focused || pressed || hot) ? g_theme->accent_hover : accent;
fill_rounded_rect(draw.hdc,thumb,surface,border,6);
if(enabled && focused && thumb.right-thumb.left>6 && thumb.bottom-thumb.top>6) {
RECT inner=thumb;InflateRect(&inner,-3,-3);
fill_rounded_rect(draw.hdc,inner,accent,accent,3);
}
RestoreDC(draw.hdc,saved);
return CDRF_SKIPDEFAULT;
}
namespace {
constexpr UINT_PTR kThemedTrackbarSubclassId=0x54524143;
void paint_themed_track(HWND track,HDC dc) {
NMCUSTOMDRAW draw{};draw.hdr.hwndFrom=track;draw.hdc=dc;draw.dwDrawStage=CDDS_PREPAINT;
draw_themed_trackbar(draw);
}
LRESULT CALLBACK themed_track_proc(HWND track,UINT msg,WPARAM wp,LPARAM lp,UINT_PTR,DWORD_PTR) {
if(msg==WM_ERASEBKGND)return 1;
if(msg==WM_PRINTCLIENT) {paint_themed_track(track,reinterpret_cast<HDC>(wp));return 0;}
if(msg==WM_PAINT) {
// Native drag painting clips to old/new thumb fragments and can leave
// stale filled-channel pixels. Own the complete paint and its clip.
InvalidateRect(track,nullptr,FALSE);
PAINTSTRUCT ps{};HDC dc=BeginPaint(track,&ps);RECT client{};GetClientRect(track,&client);
HDC buffer=CreateCompatibleDC(dc);
HBITMAP bitmap=CreateCompatibleBitmap(dc,std::max(1L,client.right),std::max(1L,client.bottom));
if(buffer && bitmap) {
const auto old=SelectObject(buffer,bitmap);paint_themed_track(track,buffer);
BitBlt(dc,0,0,client.right,client.bottom,buffer,0,0,SRCCOPY);SelectObject(buffer,old);
} else paint_themed_track(track,dc);
if(bitmap)DeleteObject(bitmap);
if(buffer)DeleteDC(buffer);
EndPaint(track,&ps);return 0;
}
if(msg==WM_NCDESTROY)RemoveWindowSubclass(track,themed_track_proc,kThemedTrackbarSubclassId);
const bool drag_move=msg==WM_MOUSEMOVE && GetCapture()==track;
const LRESULT result=DefSubclassProc(track,msg,wp,lp);
if(drag_move || msg==WM_LBUTTONDOWN || msg==WM_LBUTTONUP || msg==WM_KEYDOWN || msg==WM_CAPTURECHANGED ||
(msg==TBM_SETPOS && wp) || (msg==TBM_SETRANGE && wp)) {
// Finish every input event with a full frame, even while capture is held.
RedrawWindow(track,nullptr,nullptr,RDW_INVALIDATE|RDW_UPDATENOW|RDW_NOERASE);
}
return result;
}
}
void install_themed_trackbar(HWND track) {
if(track)SetWindowSubclass(track,themed_track_proc,kThemedTrackbarSubclassId,0);
}
bool is_channel_checkbox_id(int id) {
return id >= IDC_CHAN_BASE && id < IDC_CHAN_BASE + static_cast<int>(g.visible.size());
}
bool is_side_toggle_id(int id) {
return id == IDC_SIDE_PT_NUM ||
id == IDC_SIDE_PT_X ||
id == IDC_SIDE_PT_Y ||
id == IDC_SIDE_PT_DX ||
id == IDC_SIDE_PT_DY ||
id == IDC_SIDE_PT_INVDT ||
id == IDC_SIDE_PT_DIST ||
id == IDC_SIDE_FILTER_ENABLE ||
id == IDC_SIDE_STITCH_GAPS ||
id == IDC_SIDE_POINT_GROUP_VISIBLE;
}
bool is_settings_toggle_button_id(int id) {
return id == IDC_SET_LANG_RU ||
id == IDC_SET_LANG_EN ||
id == IDW_THEME_LIGHT ||
id == IDW_THEME_DARK ||
id == IDC_SET_HOTKEY_CTRL ||
id == IDC_SET_HOTKEY_SHIFT ||
id == IDC_SET_HOTKEY_ALT;
}
bool is_settings_hotkey_modifier_id(int id) {
return id == IDC_SET_HOTKEY_CTRL ||
id == IDC_SET_HOTKEY_SHIFT ||
id == IDC_SET_HOTKEY_ALT;
}
bool is_settings_checkbox_id(int id) {
return id == IDC_SET_GAP_MARKERS ||
id == IDC_SET_MEMORY_AUTO ||
id == IDC_SET_DISK_UNLIMITED;
}
bool uses_manual_toggle_state(HWND hwnd) {
if (!hwnd) return false;
const int id = GetDlgCtrlID(hwnd);
return is_channel_checkbox_id(id) ||
is_side_toggle_id(id) ||
id == IDC_SET_GAP_MARKERS ||
id == IDC_SET_MEMORY_AUTO ||
id == IDC_SET_DISK_UNLIMITED ||
id == IDC_EXPORT_APPLY_SETTINGS ||
id == IDC_EXPORT_APPLY_DATA ||
id == IDC_EXPORT_INCLUDE_CHANNEL_NAMES ||
id == IDC_EXPORT_INCLUDE_HIDDEN_CHANNELS ||
id == IDC_EXPORT_INCLUDE_POINTS ||
id == IDC_EXPORT_INCLUDE_MARKERS ||
id == IDC_EXPORT_INCLUDE_GUIDES ||
id == IDC_EXPORT_INCLUDE_FORMULAS ||
id == IDC_EXPORT_INCLUDE_FILTER ||
id == IDC_EXPORT_INCLUDE_GRAPH_SETTINGS ||
id == IDC_SET_HOTKEY_CTRL ||
id == IDC_SET_HOTKEY_SHIFT ||
id == IDC_SET_HOTKEY_ALT;
}
bool is_toggle_checked(HWND hwnd) {
if (!hwnd) return false;
if (uses_manual_toggle_state(hwnd)) {
return GetPropW(hwnd, L"LvmToggleChecked") != nullptr;
}
return SendMessageW(hwnd, BM_GETCHECK, 0, 0) == BST_CHECKED;
}
void set_toggle_checked(HWND hwnd, bool checked) {
if (!hwnd) return;
if (uses_manual_toggle_state(hwnd)) {
if (checked) SetPropW(hwnd, L"LvmToggleChecked", reinterpret_cast<HANDLE>(1));
else RemovePropW(hwnd, L"LvmToggleChecked");
}
SendMessageW(hwnd, BM_SETCHECK, checked ? BST_CHECKED : BST_UNCHECKED, 0);
InvalidateRect(hwnd, nullptr, FALSE);
}
void toggle_checked_state(HWND hwnd) {
set_toggle_checked(hwnd, !is_toggle_checked(hwnd));
}
void draw_themed_check_control(HDC dc, const RECT& r, const wchar_t* txt,
bool checked, bool pressed, bool enabled,
bool radio, bool compact,
COLORREF surface_bg) {
const COLORREF base_bg = (surface_bg == CLR_INVALID) ? g_theme->bg_panel : surface_bg;
HBRUSH bg = CreateSolidBrush(base_bg);
FillRect(dc, &r, bg);
DeleteObject(bg);
const int box_size = compact ? 14 : 16;
const int box_left = compact ? (r.left + ((r.right - r.left - box_size) / 2)) : (r.left + 4);
const int box_top = r.top + ((r.bottom - r.top - box_size) / 2);
RECT box = { box_left, box_top, box_left + box_size, box_top + box_size };
COLORREF fill = checked ? (pressed ? g_theme->accent_hover : g_theme->accent)
: (pressed ? g_theme->btn_hover : g_theme->bg_plot);
COLORREF border = checked ? g_theme->accent : g_theme->btn_border;
COLORREF text = enabled ? g_theme->text_primary : g_theme->text_secondary;
if (!enabled) {
fill = mix_color(fill, base_bg, 96);
border = mix_color(border, base_bg, 96);
}
if (radio) {
HBRUSH outer = CreateSolidBrush(fill);
HPEN pen = CreatePen(PS_SOLID, 1, border);
HGDIOBJ old_brush = SelectObject(dc, outer);
HGDIOBJ old_pen = SelectObject(dc, pen);
Ellipse(dc, box.left, box.top, box.right, box.bottom);
SelectObject(dc, old_pen);
SelectObject(dc, old_brush);
DeleteObject(pen);
DeleteObject(outer);
if (checked) {
RECT dot = { box.left + 4, box.top + 4, box.right - 4, box.bottom - 4 };
HBRUSH dot_brush = CreateSolidBrush(RGB(255, 255, 255));
HGDIOBJ old_dot = SelectObject(dc, dot_brush);
HPEN dot_pen = CreatePen(PS_SOLID, 1, RGB(255, 255, 255));
HGDIOBJ old_dot_pen = SelectObject(dc, dot_pen);
Ellipse(dc, dot.left, dot.top, dot.right, dot.bottom);
SelectObject(dc, old_dot_pen);
SelectObject(dc, old_dot);
DeleteObject(dot_pen);
DeleteObject(dot_brush);
}
} else {
fill_rounded_rect(dc, box, fill, border, 4);
if (checked) {
HPEN check_pen = CreatePen(PS_SOLID, 2, RGB(255, 255, 255));
HGDIOBJ old_pen = SelectObject(dc, check_pen);
MoveToEx(dc, box.left + 3, box.top + 8, nullptr);
LineTo(dc, box.left + 6, box.bottom - 4);
LineTo(dc, box.right - 3, box.top + 4);
SelectObject(dc, old_pen);
DeleteObject(check_pen);
}
}
if (!compact && txt && txt[0]) {
SetBkMode(dc, TRANSPARENT);
SetTextColor(dc, text);
HFONT font = g.ui_font ? g.ui_font : reinterpret_cast<HFONT>(GetStockObject(DEFAULT_GUI_FONT));
HGDIOBJ old_font = SelectObject(dc, font);
RECT text_rect = { box.right + 10, r.top, r.right - 4, r.bottom };
if (pressed) OffsetRect(&text_rect, 0, 1);
DrawTextW(dc, txt, -1, &text_rect, DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX | DT_END_ELLIPSIS);
SelectObject(dc, old_font);
}
}
void draw_welcome_action_button(HDC dc, const RECT& r, const wchar_t* txt,
bool pressed, bool primary, bool outlined) {
COLORREF bg_col = g_theme->btn_bg;
COLORREF border_col = g_theme->btn_border;
COLORREF text_col = g_theme->text_primary;
if (primary) {
bg_col = pressed ? g_theme->accent_hover : g_theme->accent;
border_col = pressed ? g_theme->accent_hover : g_theme->accent;
text_col = RGB(255, 255, 255);
} else if (outlined) {
if (g_theme == &kDarkTheme) {
bg_col = pressed ? mix_color(g_theme->btn_hover, g_theme->accent, 26)
: mix_color(g_theme->btn_bg, g_theme->accent, 18);
border_col = mix_color(g_theme->btn_border, g_theme->accent, 72);
text_col = RGB(235, 240, 248);
} else {
bg_col = pressed ? g_theme->btn_hover : g_theme->bg_panel;
border_col = g_theme->accent;
text_col = g_theme->text_primary;
}
} else {
if (g_theme == &kDarkTheme) {
bg_col = pressed ? g_theme->btn_hover : mix_color(g_theme->btn_bg, g_theme->bg_panel, 70);
border_col = mix_color(g_theme->btn_border, g_theme->separator, 48);
text_col = g_theme->text_primary;
} else {
bg_col = pressed ? g_theme->btn_hover : g_theme->btn_bg;
border_col = g_theme->btn_border;
text_col = g_theme->text_primary;
}
}
fill_rounded_rect(dc, r, bg_col, border_col, 6);
if (g_theme != &kDarkTheme) {
RECT inner = { r.left + 1, r.top + 1, r.right - 1, r.top + 10 };
HBRUSH gloss = CreateSolidBrush(mix_color(bg_col, RGB(255, 255, 255), pressed ? 8 : 20));
FillRect(dc, &inner, gloss);
DeleteObject(gloss);
} else if (!primary) {
RECT inner = { r.left + 1, r.top + 1, r.right - 1, min(r.bottom - 1, r.top + 8) };
HBRUSH sheen = CreateSolidBrush(mix_color(bg_col, RGB(255, 255, 255), pressed ? 4 : 10));
FillRect(dc, &inner, sheen);
DeleteObject(sheen);
}
SetBkMode(dc, TRANSPARENT);
SetTextColor(dc, text_col);
HFONT f = g.ui_font ? g.ui_font : reinterpret_cast<HFONT>(GetStockObject(DEFAULT_GUI_FONT));
HGDIOBJ old_font = SelectObject(dc, f);
RECT text_rect = r;
if (pressed) OffsetRect(&text_rect, 0, 1);
DrawTextW(dc, txt, -1, &text_rect, DT_CENTER | DT_VCENTER | DT_SINGLELINE | DT_NOPREFIX);
SelectObject(dc, old_font);
}
void redraw_button(HWND btn) {
if (!btn || !IsWindow(btn)) return;
RedrawWindow(btn, nullptr, nullptr, RDW_INVALIDATE | RDW_ERASE | RDW_UPDATENOW);
}
void redraw_window_with_children(HWND hwnd) {
if (!hwnd || !IsWindow(hwnd)) return;
RedrawWindow(hwnd, nullptr, nullptr, RDW_INVALIDATE | RDW_ERASE | RDW_UPDATENOW | RDW_ALLCHILDREN);
}
void redraw_toolbar_buttons() {
for (HWND btn : g.buttons) redraw_button(btn);
}
void draw_themed_button(HDC dc, const RECT& r, const wchar_t* txt, bool pressed, bool active, bool hover) {
COLORREF bg_col, border_col, text_col;
if (active && pressed) {
bg_col = g_theme->accent_hover;
border_col = g_theme->accent_hover;
text_col = (g_theme == &kDarkTheme) ? RGB(255, 255, 255) : RGB(12, 42, 78);
} else if (active) {
bg_col = mix_color(g_theme->btn_bg, g_theme->accent, hover ? 64 : 42);
border_col = g_theme->accent;
text_col = (g_theme == &kDarkTheme) ? RGB(255, 255, 255) : RGB(12, 42, 78);
} else if (pressed) {
bg_col = mix_color(g_theme->btn_hover, g_theme->separator, 68);
border_col = g_theme->separator;
text_col = g_theme->text_primary;
} else if (hover) {
bg_col = g_theme->btn_hover;
border_col = g_theme->btn_border;
text_col = g_theme->text_primary;
} else {
bg_col = g_theme->btn_bg;
border_col = g_theme->btn_border;
text_col = g_theme->text_primary;
}
draw_button_with_colors(dc, r, txt, bg_col, border_col, text_col, pressed);
}
} // namespace gui