Repository navigation
Expand file tree
/
Copy pathMonkeGUI.h
More file actions
2016 lines (1577 loc) · 65 KB
/
Copy pathMonkeGUI.h
File metadata and controls
2016 lines (1577 loc) · 65 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
#pragma once
#include "CoreMinimal.h"
#include "Engine/Canvas.h"
#include "Engine/Font.h"
#include "Engine/Texture.h"
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <vector>
#include <string>
namespace MonkeGUI
{
static inline float srgb_to_linear(float c)
{
if (c <= 0.04045f) return c / 12.92f;
return std::pow((c + 0.055f) / 1.055f, 2.4f);
}
static inline FLinearColor SRGB(int r, int g, int b, int a = 255)
{
const float rf = (float)r / 255.0f;
const float gf = (float)g / 255.0f;
const float bf = (float)b / 255.0f;
const float af = (float)a / 255.0f;
FLinearColor out;
out.R = srgb_to_linear(rf);
out.G = srgb_to_linear(gf);
out.B = srgb_to_linear(bf);
out.A = af;
return out;
}
namespace Style
{
inline float TitleH = 48.f;
inline FVector2D Pad = FVector2D{ 12.f, 12.f };
inline float ItemSpacingY = 8.f;
inline float TextLineH = 24.f;
inline float FrameH = 44.f;
inline float FrameR = 0.f;
inline float BorderT = 1.f;
inline float FontSize = 18.f;
inline float TextOffsetY = 8.f;
inline float RowH = 44.f;
inline float LabelW = 120.f;
inline FLinearColor Text = SRGB(230, 230, 230, 255);
inline FLinearColor TextDisabled = SRGB(150, 150, 150, 255);
inline FLinearColor WindowBg = SRGB(28, 28, 28, 230);
inline FLinearColor TitleBg = SRGB(45, 45, 45, 255);
inline FLinearColor TitleBgActive = SRGB(55, 55, 55, 255);
inline FLinearColor Tab = SRGB(45, 45, 45, 255);
inline FLinearColor TabHovered = SRGB(60, 60, 60, 255);
inline FLinearColor TabActive = SRGB(75, 75, 75, 255);
inline FLinearColor FrameBg = SRGB(42, 42, 42, 255);
inline FLinearColor FrameHovered = SRGB(60, 60, 60, 255);
inline FLinearColor FrameActive = SRGB(75, 75, 75, 255);
inline FLinearColor Button = SRGB(55, 55, 55, 255);
inline FLinearColor ButtonHovered = SRGB(70, 70, 70, 255);
inline FLinearColor ButtonActive = SRGB(90, 90, 90, 255);
inline FLinearColor Border = SRGB(0, 0, 0, 110);
inline FLinearColor Separator = SRGB(0, 0, 0, 80);
inline FLinearColor Accent = SRGB(66, 150, 250, 220);
inline FLinearColor Shadow = SRGB(0, 0, 0, 60);
inline FVector2D ShadowOff = FVector2D{ 1.f, 1.f };
}
namespace Post
{
enum : int { FILLED_RECT = 1, TEXT_L, TEXT_C, LINE };
struct Cmd
{
int type = -1;
FVector2D pos{};
FVector2D size{};
FLinearColor color{};
float thickness = 1.f;
char text[128]{};
FVector2D a{}, b{};
};
static Cmd q[2048];
static int n = 0;
static inline void Reset() { n = 0; }
static inline void RectFilled(const FVector2D& pos, const FVector2D& size, const FLinearColor& c)
{
if (n >= 2048) return;
q[n] = {}; q[n].type = FILLED_RECT; q[n].pos = pos; q[n].size = size; q[n].color = c; n++;
}
static inline void Line(const FVector2D& a, const FVector2D& b, float t, const FLinearColor& c)
{
if (n >= 2048) return;
q[n] = {}; q[n].type = LINE; q[n].a = a; q[n].b = b; q[n].thickness = t; q[n].color = c; n++;
}
static inline void RectBorder(const FVector2D& pos, const FVector2D& size, float t, const FLinearColor& c)
{
RectFilled(pos, FVector2D{ size.X, t }, c);
RectFilled(FVector2D{ pos.X, pos.Y + size.Y - t }, FVector2D{ size.X, t }, c);
RectFilled(pos, FVector2D{ t, size.Y }, c);
RectFilled(FVector2D{ pos.X + size.X - t, pos.Y }, FVector2D{ t, size.Y }, c);
}
static inline void TextL(const char* txt, const FVector2D& pos, const FLinearColor& c)
{
if (n >= 2048) return;
q[n] = {};
q[n].type = TEXT_L;
q[n].pos = pos;
q[n].color = c;
if (txt) { std::snprintf(q[n].text, sizeof(q[n].text), "%s", txt); }
n++;
}
static inline void TextC(const char* txt, const FVector2D& pos, const FLinearColor& c)
{
if (n >= 2048) return;
q[n] = {};
q[n].type = TEXT_C;
q[n].pos = pos;
q[n].color = c;
if (txt) { std::snprintf(q[n].text, sizeof(q[n].text), "%s", txt); }
n++;
}
}
static UCanvas* Canvas = nullptr;
static UTexture* WhiteTex = nullptr;
static UFont* Font = nullptr;
static FVector2D Mouse{ 0.f, 0.f };
static FVector2D PointerPosition{ 0.f, 0.f };
static bool PointerDown = false;
static bool MouseDown = false;
static bool MouseClicked = false;
static bool MouseReleased = false;
static int OpenComboId = -1;
static int Hot = -1;
static int Active = -1;
static int IdCounter = 0;
static FVector2D WinPos{ 200.f, 120.f };
static FVector2D WinSize{ 360.f, 260.f };
static FVector2D FullSize{};
static FVector2D Cursor{ 0.f, 0.f };
static int OpenColorId = -1;
static bool Resizing = false;
static FVector2D ResizeStartMouse{ 0.f, 0.f };
static FVector2D ResizeStartSize{ 0.f, 0.f };
static float MinWinW = 220.f;
static float MinWinH = 120.f;
static float ResizeGrip = 12.f;
static bool InWindow = false;
static bool Dragging = false;
static FVector2D DragOff{ 0.f, 0.f };
static inline void SetWhiteTexture(UTexture* T) { WhiteTex = T; }
static inline void SetFont(UFont* F) { Font = F; }
static inline void SetPointerState(const FVector2D& position, bool isDown)
{
PointerPosition = position;
PointerDown = isDown;
}
static inline void SetPointerState(float x, float y, bool isDown)
{
SetPointerState(FVector2D{ x, y }, isDown);
}
static std::string PendingTextInput;
static int PendingBackspaces = 0;
static bool PendingEscape = false;
static inline void QueueTextInput(const char* utf8Text)
{
if (utf8Text) PendingTextInput += utf8Text;
}
static inline void QueueTextBackspace() { ++PendingBackspaces; }
static inline void QueueTextEscape() { PendingEscape = true; }
static inline void ClearQueuedTextInput()
{
PendingTextInput.clear();
PendingBackspaces = 0;
PendingEscape = false;
}
struct PopupState
{
FVector2D pos{ 0.f, 0.f };
bool posInit = false;
bool dragging = false;
FVector2D dragOff{ 0.f, 0.f };
};
static int OpenPopupId = -1;
struct PopupData
{
FVector2D pos{};
bool posInit = false;
bool dragging = false;
FVector2D dragOff{};
float openT = 0.f;
};
static std::unordered_map<int, PopupData> gPopups;
static PopupState ColorPopup;
static inline void DrawFilledCircle(const FVector2D& pos, float r, const FLinearColor& color)
{
if (!Canvas) return;
const float PI = 3.14159265359f;
const int segments = max(12, (int)(r * 6.f));
const float step = 2.f * PI / segments;
for (int i = 0; i < segments; i++)
{
float a0 = i * step;
float a1 = (i + 1) * step;
FVector2D p0{
pos.X + std::cos(a0) * r,
pos.Y + std::sin(a0) * r
};
FVector2D p1{
pos.X + std::cos(a1) * r,
pos.Y + std::sin(a1) * r
};
Canvas->K2_DrawLine(pos, p0, 1.f, color);
Canvas->K2_DrawLine(p0, p1, 1.f, color);
}
}
namespace FX
{
struct SnowFlake
{
float x, y;
float vy;
float vx;
float size;
float phase;
};
static SnowFlake g_snow[180];
static bool g_inited = false;
static inline float frand01()
{
return (float)(std::rand() % 10000) / 10000.0f;
}
static inline void SnowInit(float w, float h)
{
static bool seeded = false;
if (!seeded) { std::srand((unsigned)std::time(nullptr)); seeded = true; }
for (auto& f : g_snow)
{
f.x = frand01() * w;
f.y = frand01() * h;
f.vy = 30.f + frand01() * 90.f;
f.vx = -10.f + frand01() * 20.f;
f.size = 0.8f + frand01() * 1.8f;
f.phase = frand01() * 6.28318f;
}
g_inited = true;
}
static inline void SnowRender(float dt, float alpha = 0.9f)
{
if (!Canvas) return;
const float w = Canvas->SizeX;
const float h = Canvas->SizeY;
if (!g_inited) SnowInit(w, h);
static float t = 0.f;
t += dt;
for (auto& f : g_snow)
{
const float sway = std::sin(t * 0.8f + f.phase) * 8.0f;
f.y += f.vy * dt;
f.x += (f.vx + sway * 0.05f) * dt;
if (f.y > h + 5.f)
{
f.y = -5.f - frand01() * 30.f;
f.x = frand01() * w;
}
if (f.x < -10.f) f.x = w + 10.f;
if (f.x > w + 10.f) f.x = -10.f;
DrawFilledCircle(
FVector2D{ f.x, f.y },
f.size,
SRGB(255, 255, 255, (int)(alpha * 255.f))
);
}
}
}
struct WidgetAnim
{
float hoverT = 0.f;
float activeT = 0.f;
float openT = 0.f;
};
static std::unordered_map<int, WidgetAnim> gAnim;
static float gDT = 1.f / 60.f;
static inline float Clamp01(float x) { return (x < 0.f) ? 0.f : (x > 1.f ? 1.f : x); }
static inline FLinearColor MulAlpha(FLinearColor c, float aMul)
{
c.A *= aMul;
return c;
}
static inline float EaseOutCubic(float t)
{
t = Clamp01(t);
float u = 1.f - t;
return 1.f - u * u * u;
}
static inline float EaseOutBack(float t)
{
t = Clamp01(t);
const float c1 = 1.70158f;
const float c3 = c1 + 1.f;
return 1.f + c3 * std::pow(t - 1.f, 3.f) + c1 * std::pow(t - 1.f, 2.f);
}
static inline WidgetAnim& Anim(int id) { return gAnim[id]; }
struct ComboAnimState
{
float openT = 0.f;
float chevronT = 0.f;
};
static std::unordered_map<int, ComboAnimState> gComboAnim;
static inline float ExpApproach(float current, float target, float speed, float dt)
{
const float k = 1.f - std::exp(-speed * dt);
return current + (target - current) * k;
}
static inline float Smooth01(float current, float target, float speed)
{
return ExpApproach(current, target, speed, gDT);
}
static inline FLinearColor LerpColor(const FLinearColor& a, const FLinearColor& b, float t)
{
return FLinearColor{
a.R + (b.R - a.R) * t,
a.G + (b.G - a.G) * t,
a.B + (b.B - a.B) * t,
a.A + (b.A - a.A) * t
};
}
static inline float PowfSafe(float x, float p)
{
x = Clamp01(x);
return std::pow(x, p);
}
static inline void UpdateMouse()
{
Mouse = PointerPosition;
MouseClicked = PointerDown && !MouseDown;
MouseReleased = !PointerDown && MouseDown;
MouseDown = PointerDown;
Hot = -1;
}
static inline uint32_t Hash32(const char* s)
{
uint32_t h = 2166136261u;
for (; s && *s; ++s) { h ^= (uint8_t)*s; h *= 16777619u; }
return h;
}
static inline int GetID(const char* label, int scope = 0)
{
return (int)(Hash32(label) ^ (uint32_t)scope);
}
static inline bool MouseInRect(const FVector2D& pos, const FVector2D& size)
{
return (Mouse.X >= pos.X && Mouse.Y >= pos.Y &&
Mouse.X <= pos.X + size.X && Mouse.Y <= pos.Y + size.Y);
}
static inline void DrawChevronDown(const FVector2D& center, float s, const FLinearColor& c)
{
Post::Line({ center.X - s, center.Y - s * 0.2f }, { center.X, center.Y + s }, 1.f, c);
Post::Line({ center.X, center.Y + s }, { center.X + s, center.Y - s * 0.2f }, 1.f, c);
}
static inline void DrawChevronRight(const FVector2D& center, float s, const FLinearColor& c)
{
Post::Line({ center.X - s * 0.2f, center.Y - s }, { center.X + s, center.Y }, 1.f, c);
Post::Line({ center.X + s, center.Y }, { center.X - s * 0.2f, center.Y + s }, 1.f, c);
}
static inline float ContentX() { return WinPos.X + Style::Pad.X; }
static inline float ControlX() { return ContentX() + Style::LabelW; }
static inline float TextY() { return Cursor.Y + Style::TextOffsetY; }
static inline float CenterY(float h) { return Cursor.Y + (Style::RowH - h) * 0.5f; }
static inline int NextID() { return ++IdCounter; }
static int IdScope = 0;
static inline void PushID(const char* s) { IdScope ^= (int)Hash32(s); }
static inline void PushID(int v) { IdScope ^= (v * 16777619); }
static inline void PopID(const char* s) { IdScope ^= (int)Hash32(s); }
static inline void PopID(int v) { IdScope ^= (v * 16777619); }
static inline float SnapHalfPx(float x) { return floorf(x) + 0.5f; }
static inline float SnapRadius(float r)
{
return SnapHalfPx(r);
}
static inline int CalcCircleSegments(float radiusPx, float maxErrorPx = 0.45f)
{
radiusPx = max(1.0f, radiusPx);
maxErrorPx = std::clamp(maxErrorPx, 0.25f, 1.5f);
float n = 3.14159265f * sqrtf(radiusPx / (2.0f * maxErrorPx));
int seg = (int)ceilf(n);
return std::clamp(seg, 32, 160);
}
static inline void DrawFilledRect(const FVector2D& pos, const FVector2D& size, const FLinearColor& col)
{
if (!Canvas || !WhiteTex) return;
Canvas->K2_DrawTexture(
WhiteTex,
pos,
size,
FVector2D{ 0.f, 0.f },
FVector2D{ 1.f, 1.f },
col,
EBlendMode::BLEND_Translucent,
0.f,
FVector2D{ 0.f, 0.f }
);
}
static inline void DimBackground(float alpha = 0.45f)
{
if (!Canvas) return;
const float w = Canvas->SizeX;
const float h = Canvas->SizeY;
Post::RectFilled(FVector2D{ 0.f, 0.f }, FVector2D{ w, h }, SRGB(0, 0, 0, (int)(alpha * 255.f)));
}
static inline void DrawX(const FVector2D& center, float s, const FLinearColor& c)
{
Post::Line({ center.X - s, center.Y - s }, { center.X + s, center.Y + s }, 1.f, c);
Post::Line({ center.X + s, center.Y - s }, { center.X - s, center.Y + s }, 1.f, c);
}
static inline void OpenPopup(const char* str_id)
{
OpenPopupId = GetID(str_id, IdScope);
}
static inline bool BeginPopup(const char* str_id, FVector2D size)
{
if (!Canvas) return false;
int id = GetID(str_id, IdScope);
if (OpenPopupId != id)
{
auto it = gPopups.find(id);
if (it != gPopups.end())
it->second.openT = 0.f;
return false;
}
auto& pop = gPopups[id];
if (!pop.posInit)
{
pop.pos = FVector2D{
Canvas->SizeX * 0.5f - size.X * 0.5f,
Canvas->SizeY * 0.5f - size.Y * 0.5f
};
pop.posInit = true;
pop.openT = 0.f;
}
pop.openT = ExpApproach(pop.openT, 1.f, 14.f, gDT);
const float t = EaseOutBack(pop.openT);
const float alpha = Clamp01(pop.openT * 2.f);
FVector2D pos = pop.pos;
const float titleH = 20.f;
FVector2D barPos = pos;
FVector2D barSz{ size.X, titleH };
bool hoverBar = MouseInRect(barPos, barSz);
if (hoverBar && MouseClicked)
{
pop.dragging = true;
pop.dragOff = FVector2D{ Mouse.X - pos.X, Mouse.Y - pos.Y };
}
if (!MouseDown)
pop.dragging = false;
if (pop.dragging)
{
pop.pos = FVector2D{ Mouse.X - pop.dragOff.X, Mouse.Y - pop.dragOff.Y };
pos = pop.pos;
}
if (MouseClicked && !MouseInRect(pos, size))
{
OpenPopupId = -1;
pop.posInit = false;
pop.openT = 0.f;
return false;
}
const FVector2D center{ pos.X + size.X * 0.5f, pos.Y + size.Y * 0.5f };
const FVector2D scaledSize{ size.X * t, size.Y * t };
const FVector2D scaledPos{ center.X - scaledSize.X * 0.5f, center.Y - scaledSize.Y * 0.5f };
const FVector2D scaledTitleSz{ scaledSize.X, titleH * t };
DimBackground(0.4f * alpha);
Post::RectFilled(
FVector2D{ scaledPos.X + 3.f, scaledPos.Y + 3.f },
scaledSize,
MulAlpha(Style::Shadow, alpha * 1.4f));
Post::RectFilled(scaledPos, scaledSize, MulAlpha(Style::WindowBg, alpha));
Post::RectBorder(scaledPos, scaledSize, Style::BorderT, MulAlpha(Style::Border, alpha));
Post::RectFilled(scaledPos, scaledTitleSz, MulAlpha(Style::TitleBgActive, alpha));
Post::RectBorder(scaledPos, scaledTitleSz, Style::BorderT, MulAlpha(Style::Border, alpha));
InWindow = true;
WinPos = scaledPos;
WinSize = scaledSize;
Cursor = FVector2D{ scaledPos.X + Style::Pad.X, scaledPos.Y + scaledTitleSz.Y + Style::Pad.Y };
return true;
}
static inline void EndPopup()
{
InWindow = false;
}
static inline bool PopupCloseButton(const FVector2D& pos, float size = 20.f)
{
FVector2D btnPos{ pos.X - size, pos.Y };
FVector2D btnSz{ size, size };
bool hovered = MouseInRect(btnPos, btnSz);
if (hovered && MouseClicked)
{
OpenPopupId = -1;
return true;
}
if (hovered)
Post::RectFilled(btnPos, btnSz, SRGB(255, 255, 255, 12));
DrawX(FVector2D{ btnPos.X + size * 0.5f, btnPos.Y + size * 0.5f }, 5.f, Style::Text);
return false;
}
static inline void DrawCircleWithLineTex(
const FVector2D& center,
float radius,
float thicknessPx,
int segments,
const FLinearColor& col,
int rings = 4,
float aaWidthPx = 1.25f,
float alphaGamma = 1.8f,
bool featherOutsideOnly = true
)
{
if (!Canvas || !WhiteTex) return;
if (segments < 8) segments = 8;
rings = std::clamp(rings, 1, 8);
const float TwoPi = 6.28318530717958647692f;
const float Step = TwoPi / (float)segments;
auto DrawRing = [&](float r, float thick, float aMul)
{
if (r <= 0.01f || thick <= 0.01f || aMul <= 0.0001f) return;
const float segLen = 2.0f * r * sinf(Step * 0.5f);
FLinearColor c = col;
c.A = Clamp01(c.A * aMul);
for (int i = 0; i < segments; i++)
{
const float a0 = Step * i;
const float a1 = a0 + Step;
const float am = (a0 + a1) * 0.5f;
FVector2D mid{
center.X + cosf(am) * r,
center.Y + sinf(am) * r
};
FVector2D size{ segLen, thick };
FVector2D pos{ mid.X - size.X * 0.5f, mid.Y - size.Y * 0.5f };
const float rotDeg = (am * 57.29577951308232f) + 90.0f;
const FVector2D pivot{ 0.5f, 0.5f };
Canvas->K2_DrawTexture(
WhiteTex,
pos,
size,
FVector2D{ 0.f, 0.f },
FVector2D{ 1.f, 1.f },
c,
EBlendMode::BLEND_Translucent,
rotDeg,
pivot
);
}
};
if (rings == 1 || aaWidthPx <= 0.01f)
{
DrawRing(radius, thicknessPx, 1.f);
return;
}
const float start = featherOutsideOnly ? radius : (radius - aaWidthPx * 0.5f);
const float end = featherOutsideOnly ? (radius + aaWidthPx) : (radius + aaWidthPx * 0.5f);
const float thicknessBoostMax = 0.35f;
for (int k = 0; k < rings; k++)
{
const float t = (float)k / (float)(rings - 1);
const float r = start + (end - start) * t;
float w = 1.f;
if (featherOutsideOnly)
{
w = std::pow(1.0f - t, alphaGamma);
}
else
{
const float d = fabsf(t - 0.5f) * 2.0f;
w = std::pow(1.0f - d, alphaGamma);
}
const float thick = thicknessPx + thicknessBoostMax * t;
DrawRing(r, thick, w);
}
}
static inline void DrawCircleStroke_AA_Final(
const FVector2D& center,
float radius,
float thicknessPx,
int segments,
const FLinearColor& col
)
{
if (!Canvas || !WhiteTex) return;
thicknessPx = max(1.0f, thicknessPx);
if (segments <= 0)
segments = CalcCircleSegments(radius, 0.8f);
DrawCircleWithLineTex(center, radius, thicknessPx, segments, col, 1, 0, 1, true);
const float halfT = thicknessPx * 0.5f;
const float featherPx = 1.0f;
FLinearColor featherCol = col;
featherCol.A = Clamp01(col.A * 0.32f);
DrawCircleWithLineTex(
center,
radius + halfT + featherPx * 0.5f,
featherPx,
segments,
featherCol,
1, 0, 1, true
);
if (radius - halfT - featherPx * 0.5f > 0.5f)
{
DrawCircleWithLineTex(
center,
radius - halfT - featherPx * 0.5f,
featherPx,
segments,
featherCol,
1, 0, 1, true
);
}
}
static inline void DrawBox(const FVector2D& pos, const FVector2D& size, float thickness, const FLinearColor& col, bool filled = false, float fillAlphaMul = 0.25f)
{
if (filled)
{
FLinearColor fillCol = col;
fillCol.A *= fillAlphaMul;
MonkeGUI::Post::RectFilled(pos, size, fillCol);
}
const FVector2D p0{ pos.X, pos.Y };
const FVector2D p1{ pos.X + size.X, pos.Y };
const FVector2D p2{ pos.X + size.X, pos.Y + size.Y };
const FVector2D p3{ pos.X, pos.Y + size.Y };
MonkeGUI::Post::Line(p0, p1, thickness, col);
MonkeGUI::Post::Line(p1, p2, thickness, col);
MonkeGUI::Post::Line(p2, p3, thickness, col);
MonkeGUI::Post::Line(p3, p0, thickness, col);
}
static inline void DrawLine(const FVector2D& a, const FVector2D& b, float t, const FLinearColor& col)
{
if (!Canvas) return;
Canvas->K2_DrawLine(a, b, t, col);
}
static inline void DrawText_Impl(const char* txt, const FVector2D& pos, const FLinearColor& col, bool center)
{
if (!Canvas || !Font || !txt) return;
const FString text(UTF8_TO_TCHAR(txt));
Canvas->K2_DrawText(
Font,
text,
pos,
FVector2D(1.0f, 1.0f),
col,
0.0f,
Style::Shadow,
Style::ShadowOff,
center,
true,
false,
SRGB(0, 0, 0, 0)
);
}
static bool TabsActiveRow = false;
static float TabsX = 0.f;
static float TabsY = 0.f;
static inline float EstimateTextW(const char* s)
{
if (!s) return 0.f;
return (float)std::strlen(s) * 7.0f;
}
static inline void StampRectLine(const FVector2D& a, const FVector2D& b, float thickness, const FLinearColor& col)
{
FVector2D d{ b.X - a.X, b.Y - a.Y };
float len = std::sqrt(d.X * d.X + d.Y * d.Y);
if (len <= 0.0001f) return;
float step = max(1.0f, thickness * 0.5f);
int steps = (int)std::ceil(len / step);
const float half = thickness * 0.5f;
for (int i = 0; i <= steps; i++)
{
float t = (steps == 0) ? 0.f : (float)i / (float)steps;
FVector2D p{ a.X + d.X * t, a.Y + d.Y * t };
Post::RectFilled(
FVector2D{ p.X - half, p.Y - half },
FVector2D{ thickness, thickness },
col
);
}
}
static inline void DrawCheckMark(const FVector2D& boxPos, float boxSz, const FLinearColor& col)
{
const float thickness = max(2.0f, boxSz * 0.14f);
FVector2D a{ boxPos.X + boxSz * 0.20f, boxPos.Y + boxSz * 0.55f };
FVector2D b{ boxPos.X + boxSz * 0.42f, boxPos.Y + boxSz * 0.75f };
FVector2D c{ boxPos.X + boxSz * 0.80f, boxPos.Y + boxSz * 0.28f };
StampRectLine(a, b, thickness, col);
StampRectLine(b, c, thickness, col);
}
static inline void TextLeft(const char* txt, const FVector2D& pos, const FLinearColor& col = Style::Text)
{
Post::TextL(txt ? txt : "", pos, col);
}
static inline void TextCenter(const char* txt, const FVector2D& centerPos, const FLinearColor& col = Style::Text)
{
Post::TextC(txt ? txt : "", centerPos, col);
}
static inline FLinearColor Lerp(const FLinearColor& a, const FLinearColor& b, float t)
{
t = Clamp01(t);
FLinearColor o;
o.R = a.R + (b.R - a.R) * t;
o.G = a.G + (b.G - a.G) * t;
o.B = a.B + (b.B - a.B) * t;
o.A = a.A + (b.A - a.A) * t;
return o;
}
static inline FLinearColor HSVtoRGB(float h, float s, float v, float a = 1.f)
{
h = h - floorf(h);
s = Clamp01(s);
v = Clamp01(v);
float r = v, g = v, b = v;
if (s > 0.f)
{
float hf = h * 6.f;
int i = (int)floorf(hf);
float f = hf - (float)i;
float p = v * (1.f - s);
float q = v * (1.f - s * f);
float t = v * (1.f - s * (1.f - f));
switch (i % 6)
{
case 0: r = v; g = t; b = p; break;
case 1: r = q; g = v; b = p; break;
case 2: r = p; g = v; b = t; break;
case 3: r = p; g = q; b = v; break;
case 4: r = t; g = p; b = v; break;
case 5: r = v; g = p; b = q; break;
}
}
FLinearColor out; out.R = r; out.G = g; out.B = b; out.A = a;
return out;
}
static inline void RGBtoHSV(const FLinearColor& c, float& outH, float& outS, float& outV)
{
float r = Clamp01(c.R), g = Clamp01(c.G), b = Clamp01(c.B);
float mx = max(r, max(g, b));
float mn = min(r, min(g, b));
float d = mx - mn;
outV = mx;
outS = (mx <= 0.f) ? 0.f : (d / mx);
if (d <= 0.f)
{
outH = 0.f;
return;
}
float h;
if (mx == r) h = (g - b) / d + (g < b ? 6.f : 0.f);
else if (mx == g) h = (b - r) / d + 2.f;
else h = (r - g) / d + 4.f;
outH = (h / 6.f);
}
static inline void DrawHueBar(const FVector2D& pos, const FVector2D& sz)
{
const int steps = 30;
const float stepH = sz.Y / (float)steps;
for (int i = 0; i < steps; i++)
{
float h0 = (float)i / (float)steps;
float h1 = (float)(i + 1) / (float)steps;
FLinearColor c0 = HSVtoRGB(h0, 1.f, 1.f, 1.f);
FLinearColor c1 = HSVtoRGB(h1, 1.f, 1.f, 1.f);
FVector2D p0{ pos.X, pos.Y + i * stepH };
Post::RectFilled(p0, FVector2D{ sz.X, stepH * 0.5f }, c0);
Post::RectFilled(FVector2D{ p0.X, p0.Y + stepH * 0.5f }, FVector2D{ sz.X, stepH * 0.5f }, c1);
}
Post::RectBorder(pos, sz, Style::BorderT, Style::Border);
}
static inline void DrawSVSquare(const FVector2D& pos, const FVector2D& sz, float hue)
{
const int stepsX = 40;
const int stepsY = 40;
FLinearColor hueCol = HSVtoRGB(hue, 1.f, 1.f, 1.f);
for (int y = 0; y < stepsY; y++)
{
float v = 1.f - (float)y / (float)(stepsY - 1);
float rowY = pos.Y + (sz.Y * y) / stepsY;
float rowH = sz.Y / stepsY + 1.f;
for (int x = 0; x < stepsX; x++)
{
float s = (float)x / (float)(stepsX - 1);
float colX = pos.X + (sz.X * x) / stepsX;
float colW = sz.X / stepsX + 1.f;
FLinearColor top = Lerp(FLinearColor{ 1,1,1,1 }, hueCol, s);
FLinearColor out = top;
out.R *= v; out.G *= v; out.B *= v;
Post::RectFilled(FVector2D{ colX, rowY }, FVector2D{ colW, rowH }, out);
}
}
Post::RectBorder(pos, sz, Style::BorderT, Style::Border);
}
static inline void DrawCheckerboard(const FVector2D& pos, const FVector2D& size, float cell = 6.f)
{