Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
3175 lines (3063 loc) · 132 KB
/
Copy pathmain.cpp
File metadata and controls
3175 lines (3063 loc) · 132 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
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <windows.h>
#include <windowsx.h>
#include <dwmapi.h>
#include <shlobj.h>
#include <shobjidl.h>
#include <shellapi.h>
#include <uxtheme.h>
#include <commctrl.h>
#include <commdlg.h>
#include <gdiplus.h>
#include <cwctype>
#include <algorithm>
#include <filesystem>
#include <fstream>
#include <string>
#include <vector>
#include <utility>
#include "platform.h"
#include "backdrop.h"
#ifdef FLOATNOTE_GLASS_LAB
#include "liquid_backdrop.h"
#include "glass_editor_layout.h"
#endif
#include "localization.h"
#include "version.h"
#include "markdown_preview.h"
namespace {
#ifdef FLOATNOTE_GLASS_LAB
#ifdef FLOATNOTE_LOCAL_DESKTOP
constexpr wchar_t kWindowClass[] = L"FloatNote.MainWindow";
constexpr wchar_t kWindowTitle[] = L"FloatNote";
constexpr wchar_t kMutexName[] = L"Local\\FloatNote.Singleton";
#else
constexpr wchar_t kWindowClass[] = L"FloatNote.GlassLab.MainWindow";
constexpr wchar_t kWindowTitle[] = L"FloatNote · Glass Lab";
constexpr wchar_t kMutexName[] = L"Local\\FloatNote.GlassLab.Singleton";
#endif
void OpenGlassLabControls();
void LoadGlassLabPreferences();
void RefreshGlassLabGeometry();
void CreateExperienceUI();
void DestroyExperienceUI();
void SyncExperienceUI();
void ToggleExperienceMenu();
void CloseExperienceMenu();
void RequestExperienceClose();
constexpr UINT kExperienceCloseRequest=WM_APP+75;
void ChooseExperienceColor(bool background);
void SaveExperienceMaterial();
constexpr UINT kExperienceChooseColor=WM_APP+76;
void BeginExperienceResize();
void FinishExperienceResize(const RECT* original=nullptr);
void MaybeAbsorbExperienceResize();
void TickExperienceAbsorb();
bool ExperienceAbsorbing();
bool ExperienceInputBlocked();
float ExperienceAbsorbOpacity();
void ExperienceSavedGeometry(RECT& rectangle);
void SyncExperienceCapture();
bool HandleExperienceKey(const MSG& message);
bool ExperienceCompact();
void ExpandExperienceNote();
void ApplyWindowStacking(bool force=false);
constexpr int kMinimumNoteWidth=76,kMinimumNoteHeight=24;
#else
constexpr wchar_t kWindowClass[] = L"FloatNote.MainWindow";
constexpr wchar_t kWindowTitle[] = L"FloatNote";
constexpr wchar_t kMutexName[] = L"Local\\FloatNote.Singleton";
constexpr int kMinimumNoteWidth=180,kMinimumNoteHeight=90;
#endif
constexpr UINT kTrayMessage = WM_APP + 1;
constexpr UINT kShowEditMessage = WM_APP + 2;
constexpr UINT kRenderMessage = WM_APP + 3;
constexpr UINT kMarkdownPreviewMessage = WM_APP + 4;
constexpr UINT_PTR kCaretTimer = 3;
constexpr UINT_PTR kSaveTimer = 1;
constexpr UINT_PTR kPillHoverTimer = 4;
constexpr UINT_PTR kMenuFadeTimer = 5;
constexpr UINT kHotkeyToggleMode = 1;
constexpr UINT kHotkeyToggleVisibility = 2;
constexpr UINT kHotkeyPassThrough = 3;
constexpr int kControlEdit = 101;
constexpr int kControlPill = 108;
constexpr int kControlGrip = 109;
constexpr int kControlOpacitySlider = 110;
constexpr int kMenuEditMode = 200;
constexpr int kMenuTopmost = 201;
constexpr int kMenuToggleVisible = 202;
constexpr int kMenuGlass = 203;
constexpr int kMenuAutostart = 204;
constexpr int kMenuExit = 205;
constexpr int kMenuPassThrough = 206;
constexpr int kMenuTheme = 207;
constexpr int kMenuLanguage = 208;
constexpr int kMenuLanguageAutomatic = 209;
constexpr int kMenuLanguageChinese = 210;
constexpr int kMenuLanguageEnglish = 211;
constexpr int kMenuTextColor = 212;
constexpr int kMenuAutoTextColor = 213;
constexpr int kMenuShadow = 214;
constexpr int kMenuThemeBase = 500;
constexpr int kMenuOpacityBase = 300;
struct Settings {
int x = CW_USEDEFAULT;
int y = CW_USEDEFAULT;
int width = 320;
int height = 160;
int fontSize = 13;
int opacityPercent = 88;
bool glass = false;
bool topmost = false;
bool passThrough = false;
COLORREF themeColor = RGB(248, 247, 243);
bool autoTextColor = true;
COLORREF textColor = RGB(30, 32, 36);
bool shadow = true;
UiLanguage language = UiLanguage::Automatic;
};
HINSTANCE g_instance = nullptr;
HWND g_window = nullptr;
HWND g_edit = nullptr;
HWND g_canvas = nullptr;
bool g_nativeGlass = false;
#ifdef FLOATNOTE_GLASS_LAB
GlassLabBackdrop g_backdrop;
#else
NativeBackdrop g_backdrop;
#endif
HWND g_pill = nullptr;
HWND g_grip = nullptr;
HWND g_menu = nullptr;
HWND g_slider = nullptr;
HWND g_menuTopmost = nullptr;
HWND g_menuAutostart = nullptr;
HWND g_menuHide = nullptr;
HWND g_menuExit = nullptr;
HWND g_menuGlass = nullptr;
HWND g_menuPassThrough = nullptr;
HWND g_menuTheme = nullptr;
HWND g_menuLanguage = nullptr;
HWND g_menuTextColor = nullptr;
HWND g_menuAutoTextColor = nullptr;
HWND g_menuShadow = nullptr;
HWND g_tooltip = nullptr;
int g_menuScroll = 0;
int g_menuWheel = 0;
int g_menuLayoutMode = -1;
bool g_pillHover = false;
float g_pillHoverMix = 0;
RECT g_menuRest{};
bool g_menuClosing = false;
int g_menuAlpha = 0;
int g_menuFadeFrom = 0;
ULONGLONG g_menuFadeStart = 0;
bool g_pointerDown = false;
bool g_pointerDragged = false;
POINT g_pointerStart{};
RECT g_pointerWindow{};
int g_wheelRemainder = 0;
int g_scrollRemainder = 0;
ULONGLONG g_menuDismissedAt = 0;
COLORREF kBackground = RGB(248, 247, 243);
COLORREF kText = RGB(30, 32, 36);
COLORREF kNoteText = RGB(30, 32, 36);
int g_textMask = 0;
constexpr int kCornerRadius = 14;
const COLORREF kThemeColors[] = {RGB(248, 247, 243), RGB(220, 233, 219), RGB(221, 233, 245), RGB(243, 222, 227),
RGB(38, 42, 48)};
struct SmoothGraphicsRuntime {
ULONG_PTR token = 0;
SmoothGraphicsRuntime() {
Gdiplus::GdiplusStartupInput input;
Gdiplus::GdiplusStartup(&token, &input, nullptr);
}
~SmoothGraphicsRuntime() {
if (token)
Gdiplus::GdiplusShutdown(token);
}
};
Gdiplus::Color DrawingColor(COLORREF color) {
return Gdiplus::Color(255, GetRValue(color), GetGValue(color), GetBValue(color));
}
void SmoothRoundRect(HDC dc, RECT rect, float radius, COLORREF color, bool outline = false) {
static SmoothGraphicsRuntime runtime;
Gdiplus::Graphics graphics(dc);
graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
graphics.SetPixelOffsetMode(Gdiplus::PixelOffsetModeHalf);
const float x = static_cast<float>(rect.left) + (outline ? 0.5f : 0.0f);
const float y = static_cast<float>(rect.top) + (outline ? 0.5f : 0.0f);
const float width = static_cast<float>(rect.right - rect.left) - (outline ? 1.0f : 0.0f);
const float height = static_cast<float>(rect.bottom - rect.top) - (outline ? 1.0f : 0.0f);
const float diameter = std::min(radius * 2.0f, std::min(width, height));
if (diameter <= 0)
return;
Gdiplus::GraphicsPath path;
path.AddArc(x, y, diameter, diameter, 180.0f, 90.0f);
path.AddArc(x + width - diameter, y, diameter, diameter, 270.0f, 90.0f);
path.AddArc(x + width - diameter, y + height - diameter, diameter, diameter, 0.0f, 90.0f);
path.AddArc(x, y + height - diameter, diameter, diameter, 90.0f, 90.0f);
path.CloseFigure();
if (outline) {
Gdiplus::Pen pen(DrawingColor(color), 1.0f);
graphics.DrawPath(&pen, &path);
} else {
Gdiplus::SolidBrush brush(DrawingColor(color));
graphics.FillPath(&brush, &path);
}
}
HFONT g_textFont = nullptr;
HFONT g_uiFont = nullptr;
HBRUSH g_editBrush = nullptr;
HANDLE g_singleInstanceMutex = nullptr;
HICON g_trayIcon = nullptr;
HICON g_appIcon = nullptr;
UINT g_taskbarCreatedMessage = 0;
Settings g_settings;
std::filesystem::path g_dataDirectory;
std::filesystem::path g_notePath;
std::filesystem::path g_settingsPath;
bool g_loadingText = false;
bool g_isVisible = true;
bool g_closing = false;
bool g_dirty = false;
bool g_saveFailed = false;
bool g_modeHotkey = false;
bool g_hideHotkey = false;
bool g_passHotkey = false;
bool g_settingsFailed = false;
bool g_loadFailed = false;
bool g_highContrast = false;
bool g_glassActive = false;
bool g_rendering = false;
bool g_renderPosted = false;
bool g_caretVisible = true;
#ifdef FLOATNOTE_DIAGNOSTICS
unsigned long long g_renderCount = 0;
#endif
std::wstring g_glassStatus;
std::wstring g_hitText;
bool g_hitTextDirty = true;
Markdown::Preview g_markdownPreview;
bool g_markdownEditing = false, g_markdownDirty = true;
bool g_markdownComposing = false, g_markdownBlurPending = false;
void RequestRender();
void RenderLayeredWindow();
void RefreshTheme();
void UpdateMenuLabels();
void RecoverWindowPosition();
void SetPassThrough(bool enabled);
void ResetCaret();
void ScrollMenuTo(int position);
void EnsureMenuFocusVisible(HWND control);
void LayoutMenuForMode();
void RefreshLocalizedUi();
const LocalizedStrings& Text() {
return StringsFor(g_settings.language);
}
int MenuLogicalHeight() {
return 584;
}
int MenuLogicalWidth() {
return ResolveUiLanguage(g_settings.language) == UiLanguage::English ? 360 : 280;
}
int EffectiveOpacityPercent() {
return g_settings.opacityPercent;
}
#ifdef FLOATNOTE_GLASS_LAB
int NoteMaximumCornerRadius() {
RECT rect{0,0,g_settings.width,g_settings.height};
if(g_window)GetClientRect(g_window,&rect);
const float scale=(g_window?GetDpiForWindow(g_window):GetDpiForSystem())/96.0f;
return GlassGeometry::MaximumRadius(float(rect.right),float(rect.bottom),scale);
}
#endif
int NoteCornerRadius() {
#ifdef FLOATNOTE_GLASS_LAB
return std::clamp(static_cast<int>(std::lround(g_backdrop.cornerRadius)),std::min(8,NoteMaximumCornerRadius()),NoteMaximumCornerRadius());
#else
return g_nativeGlass ? 8 : kCornerRadius;
#endif
}
int ScaleForDpi(HWND window, int value) {
const UINT dpi = window ? GetDpiForWindow(window) : GetDpiForSystem();
return MulDiv(value, static_cast<int>(dpi), 96);
}
std::filesystem::path ExecutableDirectory() {
std::vector<wchar_t> buffer(32768);
const DWORD length = GetModuleFileNameW(nullptr, buffer.data(), static_cast<DWORD>(buffer.size()));
return std::filesystem::path(std::wstring(buffer.data(), length)).parent_path();
}
std::wstring ReadIniString(const wchar_t* key, const wchar_t* fallback) {
wchar_t buffer[128]{};
GetPrivateProfileStringW(L"FloatNote", key, fallback, buffer, ARRAYSIZE(buffer), g_settingsPath.c_str());
return buffer;
}
int ReadIniInt(const wchar_t* key, int fallback) {
const std::wstring value = ReadIniString(key, L"");
if (value.empty()) {
return fallback;
}
wchar_t* end = nullptr;
errno = 0;
const long parsed = wcstol(value.c_str(), &end, 10);
return errno == ERANGE || end == value.c_str() || *end != L'\0' ? fallback : static_cast<int>(parsed);
}
bool ReadIniBool(const wchar_t* key, bool fallback) {
return ReadIniInt(key, fallback ? 1 : 0) != 0;
}
void LoadSettings() {
g_settings.x = ReadIniInt(L"x", CW_USEDEFAULT);
g_settings.y = ReadIniInt(L"y", CW_USEDEFAULT);
const bool compactLayout = ReadIniInt(L"layoutVersion", 0) >= 2;
g_settings.width = compactLayout ? std::clamp(ReadIniInt(L"width", 320), kMinimumNoteWidth, 16384) : ScaleForDpi(nullptr, 320);
g_settings.height = compactLayout ? std::clamp(ReadIniInt(L"height", 160), kMinimumNoteHeight, 16384) : ScaleForDpi(nullptr, 160);
g_settings.fontSize = std::clamp(ReadIniInt(L"fontSize", 13), 8, 40);
g_settings.opacityPercent = std::clamp(ReadIniInt(L"opacity", 88), 0, 100);
g_settings.glass = ReadIniInt(L"visualVersion", 0) >= 3 ? ReadIniBool(L"glass", true) : true;
g_settings.topmost = ReadIniBool(L"topmost", false);
g_settings.passThrough = ReadIniBool(L"passThrough", false);
g_settings.themeColor =
static_cast<COLORREF>(std::clamp(ReadIniInt(L"themeColor", RGB(248, 247, 243)), 0, 0xffffff));
g_settings.autoTextColor = ReadIniBool(L"autoTextColor", true);
g_settings.textColor = static_cast<COLORREF>(std::clamp(ReadIniInt(L"textColor", RGB(30, 32, 36)), 0, 0xffffff));
g_settings.shadow = ReadIniBool(L"shadow", true);
g_settings.language = static_cast<UiLanguage>(std::clamp(ReadIniInt(L"language", 0), 0, 2));
}
void SaveSettings() {
if (g_window && !IsIconic(g_window) && !g_closing) {
RECT rectangle{};
if (GetWindowRect(g_window, &rectangle)) {
#ifdef FLOATNOTE_GLASS_LAB
ExperienceSavedGeometry(rectangle);
#endif
g_settings.x = rectangle.left;
g_settings.y = rectangle.top;
g_settings.width = rectangle.right - rectangle.left;
g_settings.height = rectangle.bottom - rectangle.top;
}
}
std::string values = "[FloatNote]\r\n";
auto add = [&](const char* key, int value) { values += std::string(key) + "=" + std::to_string(value) + "\r\n"; };
add("x", g_settings.x);
add("y", g_settings.y);
add("width", g_settings.width);
add("height", g_settings.height);
add("opacity", g_settings.opacityPercent);
add("glass", g_settings.glass);
add("topmost", g_settings.topmost);
add("fontSize", g_settings.fontSize);
add("passThrough", g_settings.passThrough);
add("themeColor", g_settings.themeColor);
add("autoTextColor", g_settings.autoTextColor);
add("textColor", g_settings.textColor);
add("shadow", g_settings.shadow);
add("language", static_cast<int>(g_settings.language));
add("layoutVersion", 2);
add("visualVersion", 4);
g_settingsFailed = !AtomicWrite(g_settingsPath, values);
RequestRender();
}
std::wstring ConvertToWide(const std::string& value, UINT codePage, DWORD flags) {
if (value.empty())
return {};
const int characters =
MultiByteToWideChar(codePage, flags, value.data(), static_cast<int>(value.size()), nullptr, 0);
if (characters <= 0)
return {};
std::wstring output(static_cast<size_t>(characters), L'\0');
const int written =
MultiByteToWideChar(codePage, flags, value.data(), static_cast<int>(value.size()), output.data(), characters);
if (written <= 0)
return {};
output.resize(static_cast<size_t>(std::min(written, characters)));
return output;
}
std::string WideToUtf8(const std::wstring& value) {
if (value.empty())
return {};
const int bytes =
WideCharToMultiByte(CP_UTF8, 0, value.data(), static_cast<int>(value.size()), nullptr, 0, nullptr, nullptr);
if (bytes <= 0)
return {};
std::string output(static_cast<size_t>(bytes), '\0');
const int written = WideCharToMultiByte(CP_UTF8, 0, value.data(), static_cast<int>(value.size()), output.data(),
bytes, nullptr, nullptr);
if (written <= 0)
return {};
// Drop the unwritten tail. It is still the NUL used to size the buffer.
output.resize(static_cast<size_t>(std::min(written, bytes)));
return output;
}
std::wstring Utf8ToWide(const std::string& value) {
const std::wstring utf8 = ConvertToWide(value, CP_UTF8, MB_ERR_INVALID_CHARS);
return utf8.empty() && !value.empty() ? ConvertToWide(value, CP_ACP, 0) : utf8;
}
bool SaveNote();
// `copied` is GetWindowText's return, not the length reported beforehand.
// The spare tail of a length-sized buffer is L'\0'; keeping it makes the next
// launch reject the note as unsupported binary.
std::wstring AdoptWindowText(std::wstring text, int copied) {
if (copied < 0)
copied = 0;
if (static_cast<size_t>(copied) < text.size())
text.resize(static_cast<size_t>(copied));
const auto embedded = text.find(L'\0');
if (embedded != std::wstring::npos)
text.resize(embedded);
return text;
}
std::wstring EditorText() {
const int length = GetWindowTextLengthW(g_edit);
if (length <= 0)
return {};
std::wstring text(static_cast<size_t>(length) + 1, L'\0');
const int copied = GetWindowTextW(g_edit, text.data(), length + 1);
return AdoptWindowText(std::move(text), copied);
}
bool EnsureMarkdownPreview() {
RECT bounds{};GetClientRect(g_edit,&bounds);
const float size=static_cast<float>(MulDiv(g_settings.fontSize,GetDpiForWindow(g_edit),72));
if(!g_markdownDirty && g_markdownPreview.Matches(bounds.right,bounds.bottom,size))return true;
if(!g_markdownPreview.Build(EditorText(),bounds.right,bounds.bottom,size))return false;
g_markdownDirty=false;return true;
}
bool PaintMarkdownPreview(HDC dc) {
if(!EnsureMarkdownPreview())return false;
RECT bounds{};GetClientRect(g_edit,&bounds);
return g_markdownPreview.Paint(dc,bounds,g_textMask?RGB(255,255,255):kNoteText,
g_textMask?(g_textMask==1?RGB(0,0,0):RGB(255,255,255)):kBackground);
}
std::wstring NormalizeNewlines(const std::wstring& input) {
std::wstring output;
output.reserve(input.size());
for (size_t i = 0; i < input.size(); ++i) {
if (input[i] == L'\r') {
output += L"\r\n";
if (i + 1 < input.size() && input[i + 1] == L'\n')
++i;
} else if (input[i] == L'\n')
output += L"\r\n";
else
output += input[i];
}
return output;
}
void LoadNote() {
g_loadingText = true;
g_loadFailed = false;
std::ifstream input(g_notePath, std::ios::binary);
const bool noteExists = input.good();
std::error_code error;
const bool existsOnDisk = std::filesystem::exists(g_notePath, error);
const auto byteCount = existsOnDisk && !error ? std::filesystem::file_size(g_notePath, error) : 0;
if (error || (!noteExists && existsOnDisk) || byteCount > 4 * 1024 * 1024) {
g_loadFailed = true;
SetWindowTextW(g_edit, byteCount > 4 * 1024 * 1024 && !error ? Text().readTooLarge : Text().readFailed);
SendMessageW(g_edit, EM_SETREADONLY, TRUE, 0);
g_loadingText = false;
return;
}
std::string bytes((std::istreambuf_iterator<char>(input)), std::istreambuf_iterator<char>());
if (bytes.size() >= 3 && bytes.compare(0, 3, "\xef\xbb\xbf") == 0)
bytes.erase(0, 3);
if (bytes.find('\0') != std::string::npos || bytes.size() > 4 * 1024 * 1024 || input.bad()) {
g_loadFailed = true;
SetWindowTextW(g_edit, Text().unsupportedText);
SendMessageW(g_edit, EM_SETREADONLY, TRUE, 0);
g_loadingText = false;
return;
}
const std::wstring text = input ? NormalizeNewlines(Utf8ToWide(bytes)) : Text().defaultNote;
if (text.size() > 1024 * 1024) {
g_loadFailed = true;
SetWindowTextW(g_edit, Text().tooManyCharacters);
SendMessageW(g_edit, EM_SETREADONLY, TRUE, 0);
g_loadingText = false;
return;
}
SendMessageW(g_edit, EM_SETREADONLY, FALSE, 0);
SetWindowTextW(g_edit, text.c_str());
SendMessageW(g_edit, EM_SETSEL, 0, 0);
g_loadingText = false;
if (!noteExists) {
g_saveFailed = !SaveNote();
g_dirty = g_saveFailed;
}
g_hitTextDirty = true;
}
bool SaveNote() {
if (!IsWindow(g_edit) || g_loadFailed)
return false;
const int reported = GetWindowTextLengthW(g_edit);
const std::wstring text = EditorText();
// A failed read must not replace the note with an empty or NUL-padded file.
if (reported > 0 && text.empty())
return false;
const std::string utf8 = WideToUtf8(text);
if (!text.empty() && (utf8.empty() || utf8.find('\0') != std::string::npos))
return false;
return AtomicWrite(g_notePath, utf8);
}
void CloseMenu();
void TogglePillMenu();
void RecreateFonts(HWND window) {
const int dpi = static_cast<int>(GetDpiForWindow(window));
HFONT oldText = g_textFont;
HFONT oldUi = g_uiFont;
g_textFont = CreateFontW(-MulDiv(g_settings.fontSize, dpi, 72), 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY,
DEFAULT_PITCH | FF_DONTCARE, L"Microsoft YaHei UI");
g_uiFont =
CreateFontW(-MulDiv(10, dpi, 72), 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS, CLEARTYPE_QUALITY, DEFAULT_PITCH | FF_DONTCARE, L"Microsoft YaHei UI");
SendMessageW(g_edit, WM_SETFONT, reinterpret_cast<WPARAM>(g_textFont), TRUE);
for (HWND control : {g_pill, g_grip, g_menuTopmost, g_menuAutostart, g_menuHide, g_menuExit, g_menuGlass,
g_menuPassThrough, g_menuTheme, g_menuLanguage, g_menuTextColor, g_menuAutoTextColor,
g_menuShadow})
if (control)
SendMessageW(control, WM_SETFONT, reinterpret_cast<WPARAM>(g_uiFont), TRUE);
if (oldText)
DeleteObject(oldText);
if (oldUi)
DeleteObject(oldUi);
RequestRender();
}
void RoundWindow(HWND window, int radius) {
#ifdef FLOATNOTE_GLASS_LAB
if (window == g_window) {
// Text/tint and shader share the visible silhouette; the custom shader
// gets a conservative HWND scissor so binary clipping cannot remove AA.
// DWM's fixed small corner must not override the lab radius.
const int corners = 1;
DwmSetWindowAttribute(window, static_cast<DWMWINDOWATTRIBUTE>(33), &corners, sizeof(corners));
radius = NoteCornerRadius();
}
#else
if (window == g_window) {
// DWM's forced rounding also requests its shadow. Opt out and retain
// our own rounded region when the user disables the shadow.
const int corners = g_settings.shadow ? 2 : 1;
DwmSetWindowAttribute(window, static_cast<DWMWINDOWATTRIBUTE>(33), &corners, sizeof(corners));
}
if (window == g_window && g_nativeGlass && g_settings.shadow) {
SetWindowRgn(window, nullptr, TRUE);
return;
}
if (window == g_window && g_nativeGlass)
radius = NoteCornerRadius();
#endif
RECT rect{};
GetWindowRect(window, &rect);
#ifdef FLOATNOTE_GLASS_LAB
if(window==g_window && g_nativeGlass && g_backdrop.mode>0) {
HRGN sampling=CreateGlassSamplingClip(rect.right-rect.left,rect.bottom-rect.top,ScaleForDpi(window,radius));
if(sampling){if(!SetWindowRgn(window,sampling,TRUE))DeleteObject(sampling);return;}
}
#endif
HRGN region = CreateRoundRectRgn(0, 0, rect.right - rect.left + 1, rect.bottom - rect.top + 1,
ScaleForDpi(window, radius * 2), ScaleForDpi(window, radius * 2));
if (!SetWindowRgn(window, region, TRUE))
DeleteObject(region);
}
void UpdateLayout(HWND window) {
if (!g_edit || IsIconic(window))
return;
RECT rect{};
GetClientRect(window, &rect);
if (g_canvas)
SetWindowPos(g_canvas, HWND_BOTTOM, 0, 0, rect.right, rect.bottom, SWP_NOACTIVATE);
g_backdrop.Resize(rect.right, rect.bottom);
SetWindowPos(g_pill, nullptr, (rect.right - ScaleForDpi(window, 46)) / 2, ScaleForDpi(window, 5),
ScaleForDpi(window, 46), ScaleForDpi(window, 18), SWP_NOZORDER | SWP_NOACTIVATE);
#ifdef FLOATNOTE_GLASS_LAB
const auto layout=GlassEditorLayout::Calculate(rect.right,rect.bottom,float(NoteCornerRadius()),
GetDpiForWindow(window)/96.0f);
const bool compact=ExperienceCompact() || ExperienceAbsorbing() || rect.bottom<=ScaleForDpi(window,44);
ShowWindow(g_pill,SW_HIDE);
if(compact && GetFocus()==g_edit)SetFocus(g_window);
ShowWindow(g_edit,compact?SW_HIDE:SW_SHOWNOACTIVATE);
if(compact)SetWindowPos(g_edit,nullptr,0,0,1,1,SWP_NOZORDER|SWP_NOACTIVATE);
else SetWindowPos(g_edit,nullptr,layout.editor.left,layout.editor.top,
layout.editor.Width(),layout.editor.Height(),SWP_NOZORDER|SWP_NOACTIVATE);
SendMessageW(g_edit, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, 0);
// EDIT's formatting rectangle is separate from its HWND size. Refresh it
// explicitly after resizing; this does not replace text or clear undo.
RECT formatting{};GetClientRect(g_edit,&formatting);
SendMessageW(g_edit,EM_SETRECTNP,0,reinterpret_cast<LPARAM>(&formatting));
SetWindowPos(g_grip,HWND_TOP,layout.grip.left,layout.grip.top,
layout.grip.Width(),layout.grip.Height(),SWP_NOACTIVATE);
ShowWindow(g_grip,ExperienceCompact() || ExperienceAbsorbing()?SW_HIDE:SW_SHOWNOACTIVATE);
#else
const int margin=ScaleForDpi(window,12),top=ScaleForDpi(window,29);
SetWindowPos(g_edit,nullptr,margin,top,std::max(1L,rect.right-2*margin),
std::max(1L,rect.bottom-top-margin),SWP_NOZORDER|SWP_NOACTIVATE);
SendMessageW(g_edit,EM_SETMARGINS,EC_LEFTMARGIN|EC_RIGHTMARGIN,0);
SetWindowPos(g_grip,HWND_TOP,rect.right-ScaleForDpi(window,22),rect.bottom-ScaleForDpi(window,22),
ScaleForDpi(window,18),ScaleForDpi(window,18),SWP_NOACTIVATE);
#endif
RoundWindow(window, kCornerRadius);
#ifdef FLOATNOTE_GLASS_LAB
RefreshGlassLabGeometry();
SyncExperienceUI();
#endif
InvalidateRect(window, nullptr, TRUE);
RequestRender();
}
void RequestRender() {
if (!g_window || g_rendering || g_renderPosted || g_closing)
return;
g_renderPosted = PostMessageW(g_window, kRenderMessage, 0, 0) != FALSE;
}
#ifdef FLOATNOTE_GLASS_LAB
void SyncAdaptiveInk() {
static bool timer=false;
static bool fadeTimer=false;
static GlassAutoInk::Fade fade;
static double lastInkPaint=0;
const bool motion=ExperienceAbsorbing();
const bool active=g_window && g_settings.autoTextColor && !g_highContrast && g_nativeGlass && g_glassActive &&
g_backdrop.mode==2 && EffectiveOpacityPercent()<100 && g_isVisible && !IsIconic(g_window) && !ExperienceCompact();
if(active && !motion && !timer){SetTimer(g_window,82,100,nullptr);timer=true;}
else if((!active || motion) && timer){KillTimer(g_window,82);timer=false;}
if(motion) {
if(fadeTimer){KillTimer(g_window,83);fadeTimer=false;}
fade.Reset(kNoteText);return; // Freeze ink through the cached-surface animation.
}
const int alpha=std::max(g_settings.passThrough?0:1,MulDiv(EffectiveOpacityPercent(),255,100));
const int choice=g_backdrop.UpdateAutoInk(active,kBackground,alpha,kText==GlassAutoInk::Light);
const COLORREF next=g_highContrast?kText:!g_settings.autoTextColor?g_settings.textColor:
choice<0?kText:choice?GlassAutoInk::Light:GlassAutoInk::Dark;
const double now=GlassClockMs();
if(active && choice>=0)fade.Aim(next,kNoteText,now);
else fade.Reset(next); // Explicit colours and accessibility changes apply immediately.
const bool animating=active && fade.Running(now);
if(animating && !fadeTimer){SetTimer(g_window,83,16,nullptr);fadeTimer=true;}
else if(!animating && fadeTimer){KillTimer(g_window,83);fadeTimer=false;}
// Capture and render-completion events also enter here. Cap fade updates
// so they cannot turn a short animation into a self-posting repaint loop.
const COLORREF presented=animating && now-lastInkPaint<16?kNoteText:fade.Sample(now);
if(presented!=kNoteText) {
lastInkPaint=now;
kNoteText=presented;
if(g_edit)InvalidateRect(g_edit,nullptr,FALSE);
RequestRender();
}
}
#endif
void RefreshTheme() {
g_highContrast = SystemHighContrast();
kBackground = g_highContrast ? GetSysColor(COLOR_WINDOW) : g_settings.themeColor;
kText = g_highContrast ? GetSysColor(COLOR_WINDOWTEXT) : ContrastText(kBackground);
kNoteText = g_highContrast || g_settings.autoTextColor ? kText : g_settings.textColor;
#ifdef FLOATNOTE_GLASS_LAB
SyncAdaptiveInk();
#endif
HBRUSH oldBrush = g_editBrush;
g_editBrush = CreateSolidBrush(kBackground);
if (oldBrush)
DeleteObject(oldBrush);
if (g_window)
RedrawWindow(g_window, nullptr, nullptr, RDW_INVALIDATE | RDW_ALLCHILDREN);
if (g_menu)
RedrawWindow(g_menu, nullptr, nullptr, RDW_INVALIDATE | RDW_ALLCHILDREN);
RequestRender();
}
void ApplyVisuals(HWND window) {
const bool wasGlassActive = g_glassActive;
g_glassActive = false;
g_glassStatus = Text().glassOff;
const int none = 1;
DwmSetWindowAttribute(window, static_cast<DWMWINDOWATTRIBUTE>(38), &none, sizeof(none));
#ifdef FLOATNOTE_GLASS_LAB
if (g_backdrop.mode>=0 && !ExperienceCompact()) {
#else
if (g_settings.glass) {
#endif
if (g_highContrast)
g_glassStatus = Text().glassHighContrast;
else if (GetSystemMetrics(SM_REMOTESESSION))
g_glassStatus = Text().glassRemoteDesktop;
else if (SystemEnergySaver())
g_glassStatus = Text().glassEnergySaver;
else if (!SystemTransparencyEnabled())
g_glassStatus = Text().glassTransparencyOff;
else if (!SystemComposition())
g_glassStatus = Text().glassCompositionOff;
else {
g_glassActive = g_backdrop.Enable(window, true);
g_glassStatus = g_glassActive ? Text().glassOn : Text().glassFallback;
}
}
if (wasGlassActive && !g_glassActive)
g_backdrop.Enable(window, false);
const int rounded = g_settings.shadow ? 2 : 1;
if (g_glassActive &&
FAILED(DwmSetWindowAttribute(window, static_cast<DWMWINDOWATTRIBUTE>(33), &rounded, sizeof(rounded)))) {
g_backdrop.Enable(window, false);
g_glassActive = false;
g_glassStatus = Text().glassUnsupported;
}
if (g_nativeGlass != g_glassActive) {
g_nativeGlass = g_glassActive;
LONG_PTR ex = GetWindowLongPtrW(window, GWL_EXSTYLE);
SetWindowLongPtrW(window, GWL_EXSTYLE, ex & ~WS_EX_LAYERED);
SetWindowLongPtrW(window, GWL_EXSTYLE,
g_nativeGlass && !g_settings.passThrough ? ex & ~WS_EX_LAYERED : ex | WS_EX_LAYERED);
LONG_PTR style = GetWindowLongPtrW(window, GWL_STYLE);
SetWindowLongPtrW(window, GWL_STYLE,
g_nativeGlass ? (style | WS_THICKFRAME) & ~WS_CLIPCHILDREN
: (style & ~WS_THICKFRAME) | WS_CLIPCHILDREN);
if (g_nativeGlass && g_settings.passThrough)
SetLayeredWindowAttributes(window, 0, 254, LWA_ALPHA);
SetWindowPos(window, nullptr, 0, 0, 0, 0,
SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED);
ShowWindow(g_canvas, g_nativeGlass ? SW_SHOWNOACTIVATE : SW_HIDE);
}
const int policy = g_nativeGlass && g_settings.shadow ? DWMNCRP_ENABLED : DWMNCRP_DISABLED;
const COLORREF noBorder = 0xfffffffe;
DwmSetWindowAttribute(window, DWMWA_NCRENDERING_POLICY, &policy, sizeof(policy));
DwmSetWindowAttribute(window, static_cast<DWMWINDOWATTRIBUTE>(34), &noBorder, sizeof(noBorder));
const BOOL dark = Luminance(kBackground) < 0.18;
DwmSetWindowAttribute(window, static_cast<DWMWINDOWATTRIBUTE>(20), &dark, sizeof(dark));
const auto frameStyle = GetWindowLongPtrW(window, GWL_STYLE);
const auto desiredStyle =
g_nativeGlass && g_settings.shadow ? frameStyle | WS_THICKFRAME : frameStyle & ~WS_THICKFRAME;
if (frameStyle != desiredStyle) {
SetWindowLongPtrW(window, GWL_STYLE, desiredStyle);
SetWindowPos(window, nullptr, 0, 0, 0, 0,
SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED);
}
MARGINS margins{g_nativeGlass && g_settings.shadow ? -1 : 0, 0, 0, 0};
DwmExtendFrameIntoClientArea(window, &margins);
RoundWindow(window, kCornerRadius);
RedrawWindow(window, nullptr, nullptr, RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN);
RequestRender();
#ifdef FLOATNOTE_GLASS_LAB
ApplyWindowStacking();
SyncExperienceUI();
#endif
if (g_menu && IsWindowVisible(g_menu)) {
SetLayeredWindowAttributes(g_menu, 0, 255, LWA_ALPHA);
SetWindowPos(g_menu, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
}
}
void ChangeFontSize(int delta) {
const int size = std::clamp(g_settings.fontSize + delta, 8, 40);
if (size == g_settings.fontSize)
return;
g_settings.fontSize = size;
RecreateFonts(g_window);
// Font changes never call SetWindowPos or change the outer window bounds.
SaveSettings();
if (g_menu)
InvalidateRect(g_menu, nullptr, FALSE);
}
void ZoomFromWheel(WPARAM value) {
g_wheelRemainder += GET_WHEEL_DELTA_WPARAM(value);
const int steps = g_wheelRemainder / WHEEL_DELTA;
g_wheelRemainder %= WHEEL_DELTA;
if (steps)
ChangeFontSize(steps);
}
void UpdateTrayTip();
void SavePendingNote() {
KillTimer(g_window, kSaveTimer);
if (g_dirty) {
g_saveFailed = !SaveNote();
if (!g_saveFailed)
g_dirty = false;
}
InvalidateRect(g_window, nullptr, FALSE);
if (g_menu)
InvalidateRect(g_menu, nullptr, FALSE);
RequestRender();
}
void BeginMarkdownEditing(size_t source=std::wstring::npos) {
if(g_loadFailed || g_settings.passThrough)return;
g_markdownEditing=true;g_markdownBlurPending=false;
SetFocus(g_edit);
if(source!=std::wstring::npos) {
const auto caret=static_cast<WPARAM>(std::min(source,size_t(GetWindowTextLengthW(g_edit))));
SendMessageW(g_edit,EM_SETSEL,caret,caret);
SendMessageW(g_edit,EM_SCROLLCARET,0,0);
}
InvalidateRect(g_edit,nullptr,FALSE);ResetCaret();
}
void FinishMarkdownEditing() {
if(!g_markdownEditing)return;
if(g_markdownComposing){g_markdownBlurPending=true;return;}
const auto line=SendMessageW(g_edit,EM_GETFIRSTVISIBLELINE,0,0);
const auto source=SendMessageW(g_edit,EM_LINEINDEX,line,0);
g_markdownEditing=false;g_markdownBlurPending=false;g_caretVisible=false;
KillTimer(g_window,kCaretTimer);
if(EnsureMarkdownPreview() && source>=0)g_markdownPreview.ScrollToSource(static_cast<size_t>(source));
SavePendingNote();InvalidateRect(g_edit,nullptr,FALSE);RequestRender();
}
void LeaveMarkdownEditor() {
// Native focus handling commits/cancels IME composition before we display
// the preview. No source text is replaced, so native undo survives.
if(GetFocus()==g_edit)SetFocus(g_window);
FinishMarkdownEditing();
}
void ApplyInteractionMode(bool = false) {
if (!g_window || g_closing)
return;
LONG_PTR style = GetWindowLongPtrW(g_window, GWL_EXSTYLE);
style |= WS_EX_LAYERED | WS_EX_TOOLWINDOW;
if (g_nativeGlass && !g_settings.passThrough)
style &= ~WS_EX_LAYERED;
if (g_settings.passThrough)
style |= WS_EX_TRANSPARENT | WS_EX_NOACTIVATE;
else
style &= ~(WS_EX_TRANSPARENT | WS_EX_NOACTIVATE);
SetWindowLongPtrW(g_window, GWL_EXSTYLE, style);
if (g_nativeGlass && g_settings.passThrough)
SetLayeredWindowAttributes(g_window, 0, 254, LWA_ALPHA);
if (g_isVisible) {
#ifdef FLOATNOTE_GLASS_LAB
if(!ExperienceCompact())ShowWindow(g_window,SW_SHOWNOACTIVATE);
#else
SetWindowPos(g_window, (g_settings.topmost || g_settings.passThrough) ? HWND_TOPMOST : HWND_NOTOPMOST, 0, 0, 0,
0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_SHOWWINDOW);
#endif
}
UpdateLayout(g_window);
ApplyVisuals(g_window);
#ifdef FLOATNOTE_GLASS_LAB
ApplyWindowStacking(true);
SyncExperienceUI();
#endif
UpdateTrayTip();
}
void EnterEditor() {
#ifdef FLOATNOTE_GLASS_LAB
if(ExperienceInputBlocked())return;
if(ExperienceCompact()) {
if(g_settings.passThrough)SetPassThrough(false);
ExpandExperienceNote();return;
}
#endif
if (g_settings.passThrough) {
g_settings.passThrough = false;
SaveSettings();
}
RecoverWindowPosition();
g_isVisible = true;
ShowWindow(g_window, SW_SHOWNORMAL);
ApplyInteractionMode();
SetForegroundWindow(g_window);
BeginMarkdownEditing();
}
void SetPassThrough(bool enabled) {
#ifndef FLOATNOTE_GLASS_LAB
CloseMenu();
#endif
SavePendingNote();
if (enabled && (g_saveFailed || g_loadFailed)) {
EnterEditor();
return;
}
// Without a hotkey, the tray and second launch still provide a way back.
g_settings.passThrough = enabled;
if (enabled) {
SetFocus(nullptr);
FinishMarkdownEditing();
KillTimer(g_window, kCaretTimer);
}
ApplyInteractionMode();
SaveSettings();
UpdateMenuLabels();
}
void SetTopmost(bool enabled) {
g_settings.topmost = enabled;
ApplyInteractionMode();
SaveSettings();
}
void SetOpacityPercent(int opacity, bool persist = true) {
g_settings.opacityPercent = std::clamp(opacity, 0, 100);
ApplyVisuals(g_window);
if (persist)
SaveSettings();
else
SetTimer(g_window, 2, 300, nullptr);
}
std::filesystem::path StartupShortcutPath() {
PWSTR startupFolder = nullptr;
if (FAILED(SHGetKnownFolderPath(FOLDERID_Startup, KF_FLAG_DEFAULT, nullptr, &startupFolder))) {
return {};
}
std::filesystem::path result = std::filesystem::path(startupFolder) / L"FloatNote.lnk";
CoTaskMemFree(startupFolder);
return result;
}
bool IsAutostartEnabled() {
const auto shortcut = StartupShortcutPath();
return !shortcut.empty() && GetFileAttributesW(shortcut.c_str()) != INVALID_FILE_ATTRIBUTES;
}
bool SetAutostartEnabled(bool enabled) {
#if defined(FLOATNOTE_GLASS_LAB) && !defined(FLOATNOTE_LOCAL_DESKTOP)
(void)enabled;
return false;
#else
const auto shortcut = StartupShortcutPath();
if (shortcut.empty()) {
return false;
}
if (!enabled) {
return DeleteFileW(shortcut.c_str()) != FALSE || GetLastError() == ERROR_FILE_NOT_FOUND;
}
IShellLinkW* shellLink = nullptr;
HRESULT result = CoCreateInstance(CLSID_ShellLink, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&shellLink));
if (FAILED(result)) {
return false;
}
const std::filesystem::path executable = ExecutableDirectory() / L"FloatNote.exe";
shellLink->SetPath(executable.c_str());
shellLink->SetWorkingDirectory(ExecutableDirectory().c_str());
shellLink->SetArguments(L"--startup");
shellLink->SetDescription(Text().autostartDescription);
IPersistFile* persistFile = nullptr;
result = shellLink->QueryInterface(IID_PPV_ARGS(&persistFile));
if (SUCCEEDED(result)) {
result = persistFile->Save(shortcut.c_str(), TRUE);
persistFile->Release();
}
shellLink->Release();
return SUCCEEDED(result);
#endif
}
HICON CreateNoteIcon(int size) {
static SmoothGraphicsRuntime runtime;
// Draw large, then downsample once so the tray-size outline stays smooth.
size = std::clamp(size, 16, 128);
Gdiplus::Bitmap canvas(size * 4, size * 4, PixelFormat32bppARGB);
{
Gdiplus::Graphics graphics(&canvas);
graphics.Clear(Gdiplus::Color(0, 0, 0, 0));
graphics.SetSmoothingMode(Gdiplus::SmoothingModeAntiAlias);
graphics.ScaleTransform(size / 8.0f, size / 8.0f);
Gdiplus::GraphicsPath note;
note.AddArc(4.0f, 2.0f, 10.0f, 10.0f, 180.0f, 90.0f);
note.AddArc(18.0f, 2.0f, 10.0f, 10.0f, 270.0f, 90.0f);
note.AddArc(18.0f, 20.0f, 10.0f, 10.0f, 0.0f, 90.0f);
note.AddArc(4.0f, 20.0f, 10.0f, 10.0f, 90.0f, 90.0f);
note.CloseFigure();
Gdiplus::SolidBrush paper(Gdiplus::Color(255, 248, 247, 239));
Gdiplus::Pen outline(Gdiplus::Color(255, 87, 89, 88), 1.4f);