-
Notifications
You must be signed in to change notification settings - Fork 4
/
menu.h
1291 lines (1004 loc) · 36.5 KB
/
menu.h
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 "context.h"
#include "wrappers.h"
#include "string.h"
#include <functional>
// changes to improve and not make it 1:1 supremacy
// tabs at top with tiny bar underneath them
// skeet bar at top
// 3 columns
// hover/highlight animation on items
// colorpicker stays open
// textured background
// tab in animations: all controls fade in, sliders fill up to their position
// checkboes fill up from center when pressed
// dropdown closing animation
namespace UI
{
class c_cursor
{
int cursor_x{ }, cursor_y{ };
float hue_cycle{ };
public:
void handle( )
{
g_input.get_cursor_pos( cursor_x, cursor_y );
hue_cycle = std::clamp<float>( hue_cycle + 0.002f, 0.f, 1.f );
draw( );
}
void draw( )
{
const UIcolor_t outer_color( 3, 6, 26, 215 );
const UIcolor_t inner_color( 255, 255, 255, 255 ); //color_t::FromHSB( hue_cycle, 1.0f, 1.0f )
#pragma warning( push )
#pragma warning( disable : 4244 )
UI::_filled_rect( outer_color, cursor_x + 1.0f, cursor_y, 1, 17 );
for ( int i = 0; i < 11; i++ )
UI::_filled_rect( outer_color, cursor_x + 2 + i, cursor_y + 1 + i, 1, 1 );
UI::_filled_rect( outer_color, cursor_x + 8, cursor_y + 12, 5, 1 );
UI::_filled_rect( outer_color, cursor_x + 8, cursor_y + 13, 1, 1 );
UI::_filled_rect( outer_color, cursor_x + 9, cursor_y + 14, 1, 2 );
UI::_filled_rect( outer_color, cursor_x + 10, cursor_y + 16, 1, 2 );
UI::_filled_rect( outer_color, cursor_x + 8, cursor_y + 18, 2, 1 );
UI::_filled_rect( outer_color, cursor_x + 7, cursor_y + 16, 1, 2 );
UI::_filled_rect( outer_color, cursor_x + 6, cursor_y + 14, 1, 2 );
UI::_filled_rect( outer_color, cursor_x + 5, cursor_y + 13, 1, 1 );
UI::_filled_rect( outer_color, cursor_x + 4, cursor_y + 14, 1, 1 );
UI::_filled_rect( outer_color, cursor_x + 3, cursor_y + 15, 1, 1 );
UI::_filled_rect( outer_color, cursor_x + 2, cursor_y + 16, 1, 1 );
for ( int i = 0; i < 4; i++ )
UI::_filled_rect( inner_color, cursor_x + 2 + i, cursor_y + 2 + i, 1, 14 - ( i * 2 ) );
UI::_filled_rect( inner_color, cursor_x + 6, cursor_y + 6, 1, 8 );
UI::_filled_rect( inner_color, cursor_x + 7, cursor_y + 7, 1, 9 );
for ( int i = 0; i < 4; i++ )
UI::_filled_rect( inner_color, cursor_x + 8 + i, cursor_y + 8 + i, 1, 4 - i );
UI::_filled_rect( inner_color, cursor_x + 8, cursor_y + 14, 1, 4 );
UI::_filled_rect( inner_color, cursor_x + 9, cursor_y + 16, 1, 2 );
#pragma warning( pop )
}
};
class c_control
{
public:
vec2 m_start;
vec2 m_bounds;
vec2 m_end;
int m_cursor_x;
int m_cursor_y;
float m_drag_x;
float m_drag_y;
float m_alpha = 255;
bool m_dragging;
bool m_should_draw = true;
bool m_is_inside;
int m_tab;
size_t m_current_tab;
__forceinline bool is_inside( const float& x, const float& y, const float& w, const float& h )
{
return m_cursor_x > x && m_cursor_x < x + w && m_cursor_y > y && m_cursor_y < y + h + 1.0f;
}
__forceinline bool __is_inside( const float& x, const float& y, const float& w, const float& h )
{
return m_cursor_x > x && m_cursor_x < w && m_cursor_y > y && m_cursor_y < h + 1.0f;
}
};
class c_window_data
{
public:
bool m_first_click{ };
bool m_left_click{ };
bool m_right_click{ };
bool m_ignore{ };
float m_x{ };
float m_y{ };
UIcolor_t m_color = UIcolor_t( 181, 0, 41, 255 );
int m_alpha = 0;
float m_animation_progress = 0.f;
};
class c_window : public c_control
{
bool m_is_open{ };
bool m_was_open{ };
bool m_should_open = true;
vec2 m_window_size{ };
c_window_data m_data{ };
const float m_edge_size = 8.f;
bool m_is_inside_edge{ };
void draw_box( float x, float y, float w, float h ) const
{
// draw black background
UI::filled_rect( UIcolor_t( 1, 1, 1, m_data.m_alpha ), x, y, x + w, y + h );
// draw grey edge
UI::filled_rect( UIcolor_t( 44, 44, 44, m_data.m_alpha ), x + 1.f, y + 1.f, x + w - 1.f, y + h - 1.f );
// draw inner box
UI::filled_rect( UIcolor_t( 9, 9, 9, m_data.m_alpha ), x + 2.f, y + 2.f, x + w - 2.f, y + h - 2.f );
};
void draw_watermark( float x, float y, float w, float h )
{
const UIcolor_t text_shadow( 0, 0, 0, m_data.m_alpha );
const UIcolor_t text_color( 206, 206, 206, m_data.m_alpha );
std::string time = xor ( __DATE__ );
std::string username = xor ( "SenatorII" );
std::string watermark = time + xor ( " | " ) + username;
float text_w = UI::text_width( watermark.c_str( ) );
float text_x = x + w - text_w - 5.f;
float text_y = y + h - 16.f;
UI::string( text_shadow, text_x + 1.f, text_y + 1.f, false, watermark.c_str( ) );
UI::string( text_color, text_x, text_y, false, watermark.c_str( ) );
};
public:
c_window( float x = 100.f, float y = 100.f, float w = 482.f, float h = 500.f )
{
m_start = vec2( x, y );
m_window_size = vec2( w, h );
m_bounds = vec2( w + 40.f, h + 60.f );
m_end = m_start + m_bounds;
}
bool is_open( ) const { return m_is_open; }
bool handle( std::vector<std::string>& tabs, UIcolor_t color )
{
if ( g_input.is_key_pressed( KEYS_INSERT ) )
{
if ( !m_was_open )
{
m_should_open = !m_should_open;
UI::util::set_mouse_state( !m_should_open );
}
m_was_open = true;
}
else
m_was_open = false;
if ( g_ctx.m_settings.menu_fade_speed > 0 )
m_data.m_alpha = std::clamp<int>( m_should_open ? ( m_data.m_alpha + g_ctx.m_settings.menu_fade_speed ) : ( m_data.m_alpha - g_ctx.m_settings.menu_fade_speed ), 0, 255 );
else
m_data.m_alpha = std::clamp<int>( m_should_open ? ( m_data.m_alpha + 255 ) : ( m_data.m_alpha - 255 ), 0, 255 ); // sorry
if ( g_ctx.m_settings.menu_rainbow )
g_ctx.m_settings.menu_color( ) = ( m_data.m_color = UI::UIcolor_t::get_rainbow( m_data.m_alpha ) ).to_renderer_color( );
else
m_data.m_color = color;
m_data.m_color.A = m_data.m_alpha;
m_is_open = m_data.m_alpha > 0;
if ( !m_is_open )
return false;
g_input.get_cursor_pos( m_cursor_x, m_cursor_y );
m_is_inside = m_cursor_x > m_start.x && m_cursor_x < m_start.x + m_bounds.x && m_cursor_y > m_start.y && m_cursor_y < m_start.y + m_bounds.y;
m_is_inside_edge = m_is_inside && ( ( m_cursor_x > m_start.x + m_bounds.x - m_edge_size || m_cursor_x < m_start.x + m_edge_size ) || ( m_cursor_y > m_start.y + m_bounds.y - m_edge_size || m_cursor_y < m_start.y + m_edge_size ) );
// update data
m_data.m_first_click = !m_data.m_left_click && g_input.is_key_pressed( KEYS_MOUSE1 );
m_data.m_left_click = g_input.is_key_pressed( KEYS_MOUSE1 );
m_data.m_right_click = g_input.is_key_pressed( KEYS_MOUSE2 );
m_data.m_animation_progress = std::clamp<float>( m_data.m_animation_progress + 0.05f, 0.f, 1.f );
if ( !m_data.m_left_click )
m_data.m_ignore = false;
if ( m_dragging && !m_data.m_left_click )
m_dragging = false;
if ( m_data.m_first_click && m_is_inside_edge )
{
m_dragging = true;
m_drag_x = m_cursor_x - m_start.x;
m_drag_y = m_cursor_y - m_start.y;
}
if ( m_dragging )
{
m_start.x = std::clamp( static_cast< float >( m_cursor_x - m_drag_x ), 0.0f, static_cast< float >( UI::util::screen_width( ) ) - m_bounds.x );
m_start.y = std::clamp( static_cast< float >( m_cursor_y - m_drag_y ), 0.0f, static_cast< float >( UI::util::screen_height( ) ) - m_bounds.y );
}
m_end = m_start + m_bounds;
// draw black background
UI::filled_rect( UIcolor_t( 1, 1, 1, m_data.m_alpha ), m_start.x, m_start.y, m_end.x, m_end.y );
// draw outer light grey box
UI::filled_rect( UIcolor_t( 57, 57, 57, m_data.m_alpha ), m_start.x + 1.f, m_start.y + 1.f, m_end.x - 1.f, m_end.y - 1.f );
// draw dark grey box
UI::filled_rect( UIcolor_t( 35, 35, 35, m_data.m_alpha ), m_start.x + 2.f, m_start.y + 2.f, m_end.x - 2.f, m_end.y - 2.f );
// draw inner light grey box
UI::filled_rect( UIcolor_t( 57, 57, 57, m_data.m_alpha ), m_start.x + 5.f, m_start.y + 5.f, m_end.x - 5.f, m_end.y - 5.f );
// draw main menu background
UI::filled_rect( UIcolor_t( 4, 4, 4, m_data.m_alpha ), m_start.x + 6.f, m_start.y + 6.f, m_end.x - 6.f, m_end.y - 6.f );
// draw skeet bar
UI::skeet_rect( m_data.m_alpha, m_start.x + 6.0f, m_start.y + 6.0f, m_end.x - 6.0f, m_start.y + 8.0f );
// draw main box
draw_box( m_start.x + 20.f, m_start.y + 40.f, m_window_size.x, m_window_size.y );
// draw date/username
draw_watermark( m_start.x + 20.f, m_start.y + 40.f, m_window_size.x, m_window_size.y );
// tabz
const UIcolor_t text_color( 153, 153, 153, m_data.m_alpha );
const UIcolor_t text_color_shadow( 0, 0, 0, m_data.m_alpha );
const UIcolor_t tab_color( 36, 36, 36, m_data.m_alpha );
const UIcolor_t tab_color_shadow( 0, 0, 0, m_data.m_alpha / 2 );
const UIcolor_t tab_color_selected = m_data.m_color;
UIcolor_t tab_color_hovered = tab_color_selected;
tab_color_hovered.A /= 2;
// spacing per tab
float tab_spacing = 3.f;
// total used by spacing
float spacing = ( tabs.size( ) ) * tab_spacing;
// tab width
float tab_width = ( m_window_size.x - spacing ) / tabs.size( );
for ( size_t i = 0; i < tabs.size( ); i++ )
{
float tab_x = m_start.x + 20.f + ( tab_width + tab_spacing ) * i;
float tab_y = m_start.y + 30.f;
float text_x = tab_x + ( tab_width * 0.5f );
float text_y = tab_y - 14.f;
UI::string( text_color_shadow, text_x + 1.f, text_y + 1.f, true, tabs.at( i ).c_str( ) );
UI::string( text_color, text_x, text_y, true, tabs.at( i ).c_str( ) );
UI::filled_rect( m_current_tab == i ? tab_color_selected : tab_color, tab_x, tab_y, tab_x + tab_width, tab_y + 4.f );
UI::filled_rect( tab_color_shadow, tab_x, tab_y + 2.f, tab_x + tab_width, tab_y + 4.f );
if ( is_inside( tab_x, tab_y - 16.f, tab_width, 20.f ) && m_current_tab != i )
{
//select it if we are inside it and pressing
if ( m_data.m_first_click )
{
m_current_tab = i;
m_data.m_animation_progress = 0.f;
}
else
{
UI::filled_rect( tab_color_hovered, tab_x, tab_y, tab_x + tab_width, tab_y + 4.f );
UI::filled_rect( tab_color_shadow, tab_x, tab_y + 2.f, tab_x + tab_width, tab_y + 4.f );
}
}
}
return true;
}
void column_left( )
{
m_data.m_x = m_start.x + 50.f;
m_data.m_y = m_start.y + 60.f;
}
void column_right( )
{
m_data.m_x = m_start.x + 280.f;
m_data.m_y = m_start.y + 60.f;
}
c_window_data* data( )
{
return &m_data;
}
};
class c_groupbox : public c_control
{
const char* m_text{ };
public:
void start( c_window_data* data, const char* text )
{
m_text = text;
m_start = vec2( data->m_x - 10.f, data->m_y + 5.f );
// setup coord for next item
data->m_y += 15.f;
}
void end( c_window_data* data, const char* text )
{
m_text = text;
m_end = vec2( data->m_x - 10.f, data->m_y + 5.f );
// setup coord for next item
data->m_y += 15.f;
draw( data );
}
void draw( c_window_data* data )
{
UIcolor_t text_color( 206, 206, 206, data->m_alpha );
UIcolor_t shadow_color( 0, 0, 0, data->m_alpha );
UIcolor_t edge_color( 44, 44, 44, data->m_alpha );
float width = 211.f;
float text_width = UI::text_width( m_text );
// top
UI::line( edge_color, m_start.x, m_start.y, m_start.x + 8.f, m_start.y );
UI::line( edge_color, m_start.x + 12.f + text_width, m_start.y, m_start.x + width, m_start.y );
// left
UI::line( edge_color, m_start.x, m_start.y, m_end.x, m_end.y );
// right
UI::line( edge_color, m_start.x + width, m_start.y, m_end.x + width, m_end.y + 1.f );
UI::line( shadow_color, m_start.x + width + 1.f, m_start.y, m_end.x + width + 1.f, m_end.y + 1.f );
// bottom
UI::line( edge_color, m_end.x, m_end.y, m_end.x + width + 1.f, m_end.y );
UI::line( shadow_color, m_end.x, m_end.y + 1.f, m_end.x + width + 2.f, m_end.y + 1.f );
if ( m_text )
{
UI::string( shadow_color, m_start.x + 10.f + 1.f, m_start.y + 1.f - 6.f, false, m_text );
UI::string( text_color, m_start.x + 10.f, m_start.y - 6.f, false, m_text );
}
}
};
class c_label : public c_control
{
const char* m_text{ };
public:
c_label( )
{
}
void draw( c_window_data* data )
{
UIcolor_t text_color( 206, 206, 206, data->m_alpha );
UIcolor_t text_shadow( 0, 0, 0, data->m_alpha );
if ( m_text )
{
UI::string( text_shadow, m_start.x + 20.f + 1.f, m_start.y + 1.f - 3.f, false, m_text );
UI::string( text_color, m_start.x + 20.f, m_start.y - 3.f, false, m_text );
}
}
void handle( c_window_data* data, const char* text )
{
m_text = text;
m_start = vec2( data->m_x, data->m_y );
// setup coord for next item
data->m_y += 15.f;
draw( data );
}
};
class c_checkbox : public c_control
{
const char* m_text{ };
bool* m_value{ };
public:
c_checkbox( )
{
m_bounds = vec2( 8, 8 );
}
void draw( c_window_data* data )
{
UIcolor_t text_color( 206, 206, 206, data->m_alpha );
UIcolor_t text_shadow( 0, 0, 0, data->m_alpha );
if ( m_text )
{
UI::string( text_shadow, m_start.x + 20.f + 1.f, m_start.y + 1.f - 3.f, false, m_text );
UI::string( text_color, m_start.x + 20.f, m_start.y - 3.f, false, m_text );
}
// outer edge
UI::filled_rect( UIcolor_t( 0, 0, 0, data->m_alpha ), m_start.x, m_start.y, m_start.x + m_bounds.x, m_start.y + m_bounds.y );
// inner box empty
UIcolor_t empty_color_top = UIcolor_t( 69, 69, 69, data->m_alpha );
UIcolor_t empty_color_bottom
(
empty_color_top.R > 25 ? empty_color_top.R - 25 : 0,
empty_color_top.G > 25 ? empty_color_top.G - 25 : 0,
empty_color_top.B > 25 ? empty_color_top.B - 25 : 0,
data->m_alpha
);
UI::rect_gradient( empty_color_top, empty_color_bottom, m_start.x + 1.f, m_start.y + 1.f, m_bounds.x - 2.f, m_bounds.y - 2.f );
// inner box
if ( *m_value )
{
int anim_alpha = ( float( data->m_alpha ) * data->m_animation_progress );
UIcolor_t checkbox_color_top = data->m_color;
UIcolor_t checkbox_color_bottom
(
checkbox_color_top.R > 25 ? checkbox_color_top.R - 25 : 0,
checkbox_color_top.G > 25 ? checkbox_color_top.G - 25 : 0,
checkbox_color_top.B > 25 ? checkbox_color_top.B - 25 : 0,
anim_alpha
);
UI::rect_gradient( checkbox_color_top, checkbox_color_bottom, m_start.x + 1.f, m_start.y + 1.f, m_bounds.x - 2.f, m_bounds.y - 2.f );
}
}
void handle( c_window_data* data, const char* name, bool* setting )
{
g_input.get_cursor_pos( m_cursor_x, m_cursor_y );
m_text = name;
m_value = setting;
m_start = vec2( data->m_x, data->m_y );
m_end = m_start + m_bounds;
// setup coord for next item
data->m_y += 15.f;
float text_width = m_text ? UI::text_width( m_text ) : 0.f;
m_is_inside = m_cursor_x > m_start.x && m_cursor_x < m_start.x + 20.f + text_width + 5.f && m_cursor_y > m_start.y - 3.f && m_cursor_y < m_end.y + 3.f;
if ( m_value && data->m_left_click && !data->m_ignore && m_is_inside )
{
*m_value = !*m_value;
data->m_ignore = true;
}
draw( data );
}
};
class c_checkbox_smoll : public c_control
{
bool* m_value{ };
public:
c_checkbox_smoll( )
{
m_bounds = vec2( 8, 8 );
}
void draw( c_window_data* data )
{
// outer edge
UI::filled_rect( UIcolor_t( 0, 0, 0, data->m_alpha ), m_start.x, m_start.y, m_start.x + m_bounds.x, m_start.y + m_bounds.y );
// inner box empty
UIcolor_t empty_color_top = UIcolor_t( 69, 69, 69, data->m_alpha );
UIcolor_t empty_color_bottom
(
empty_color_top.R > 25 ? empty_color_top.R - 25 : 0,
empty_color_top.G > 25 ? empty_color_top.G - 25 : 0,
empty_color_top.B > 25 ? empty_color_top.B - 25 : 0,
data->m_alpha
);
UI::rect_gradient( empty_color_top, empty_color_bottom, m_start.x + 1.f, m_start.y + 1.f, m_bounds.x - 2.f, m_bounds.y - 2.f );
// inner box
if ( *m_value )
{
int anim_alpha = ( float( data->m_alpha ) * data->m_animation_progress );
UIcolor_t checkbox_color_top = data->m_color;
UIcolor_t checkbox_color_bottom
(
checkbox_color_top.R > 25 ? checkbox_color_top.R - 25 : 0,
checkbox_color_top.G > 25 ? checkbox_color_top.G - 25 : 0,
checkbox_color_top.B > 25 ? checkbox_color_top.B - 25 : 0,
anim_alpha
);
UI::rect_gradient( checkbox_color_top, checkbox_color_bottom, m_start.x + 1.f, m_start.y + 1.f, m_bounds.x - 2.f, m_bounds.y - 2.f );
}
}
void handle( c_window_data* data, bool* setting )
{
g_input.get_cursor_pos( m_cursor_x, m_cursor_y );
m_value = setting;
m_start = vec2( data->m_x, data->m_y );
m_end = m_start + m_bounds;
m_is_inside = m_cursor_x > m_start.x && m_cursor_x < m_start.x + 20.f + 100.f && m_cursor_y > m_start.y - 3.f && m_cursor_y < m_end.y + 3.f;
if ( m_value && data->m_left_click && !data->m_ignore && m_is_inside )
{
*m_value = !*m_value;
data->m_ignore = true;
}
draw( data );
}
};
class c_slider : public c_control
{
int* m_value;
int m_min;
int m_max;
const char* m_text;
const wchar_t* m_suffix;
vec2 m_slider_start;
float m_slider_pos;
float m_slider_width;
float m_slider_height;
public:
c_slider( )
{
m_slider_width = 150.f;
m_slider_height = 6.f;
m_bounds = vec2( m_slider_width, m_slider_height );
}
public:
void draw( c_window_data* data )
{
if ( m_text )
{
const UIcolor_t text_color( 206, 206, 206, data->m_alpha );
const UIcolor_t text_shadow( 0, 0, 0, data->m_alpha );
UI::string( text_shadow, m_start.x + 20.f + 1.f, m_start.y + 1.f - 3.f, false, m_text );
UI::string( text_color, m_start.x + 20.f, m_start.y - 3.f, false, m_text );
}
// outer edge
UI::filled_rect( UIcolor_t( 0, 0, 0, data->m_alpha ), m_slider_start.x - 1.f, m_slider_start.y - 1.f, m_end.x + 1.f, m_end.y + 1.f );
// inner background
UIcolor_t background_color_top( 69, 69, 69, data->m_alpha );
UIcolor_t background_color_bottom( 44, 44, 44, data->m_alpha );
UI::rect_gradient( background_color_top, background_color_bottom, m_slider_start.x, m_slider_start.y, m_bounds.x, m_bounds.y );
// slider bar
UIcolor_t slider_color_top = data->m_color; //should be menu colour setting
UIcolor_t slider_color_bottom
(
slider_color_top.R > 25 ? slider_color_top.R - 25 : 0,
slider_color_top.G > 25 ? slider_color_top.G - 25 : 0,
slider_color_top.B > 25 ? slider_color_top.B - 25 : 0
);
UI::rect_gradient( slider_color_top, slider_color_bottom, m_slider_start.x, m_slider_start.y, m_slider_pos, m_bounds.y );
std::wstring text_value( std::wstring( L"%d" ) + std::wstring( m_suffix ) );
UI::string( UIcolor_t( 0, 0, 0, data->m_alpha ), m_slider_start.x + m_slider_pos + 1.f, m_slider_start.y + 1.f, true, text_value.c_str( ), *m_value );
UI::string( UIcolor_t( 255, 255, 255, data->m_alpha ), m_slider_start.x + m_slider_pos, m_slider_start.y, true, text_value.c_str( ), *m_value );
}
void handle( c_window_data* data, const char* name, int* setting, int min, int max, const wchar_t* suffix = L"" )
{
g_input.get_cursor_pos( m_cursor_x, m_cursor_y );
m_text = strlen( name ) > 1 ? name : nullptr;
m_min = min;
m_max = max;
m_value = setting;
m_suffix = suffix;
m_start = vec2( data->m_x, data->m_y );
m_slider_start = vec2( m_start.x + 20.f, m_start.y );
m_end = m_slider_start + m_bounds;
data->m_y += 15.f;
if ( m_text )
{
m_slider_start.y += 15.f;
m_end.y += 15.f;
data->m_y += 15.f;
}
m_is_inside = m_cursor_x > m_slider_start.x - 1.0f && m_cursor_x < m_end.x + 1.0f && m_cursor_y > m_slider_start.y - 1.0f && m_cursor_y < m_end.y + 1.0f;
if ( m_dragging && !data->m_left_click )
m_dragging = false;
if ( m_value )
{
*m_value = std::clamp< int >( *m_value, m_min, m_max );
if ( m_dragging )
{
float dragged_pos = std::clamp< float >( m_cursor_x - m_slider_start.x, 0, m_slider_width );
*m_value = m_min + ( ( m_max - m_min ) * dragged_pos / m_slider_width );
}
if ( data->m_first_click && m_is_inside )
{
m_dragging = true;
data->m_ignore = true;
}
m_slider_pos = ( float( *m_value - m_min ) / float( m_max - m_min ) * m_slider_width );
m_slider_pos = std::clamp<float>( m_slider_pos, 0.f, m_slider_width * data->m_animation_progress );
}
draw( data );
}
};
class c_button : public c_control
{
const char* m_text{ };
public:
void draw( c_window_data* data )
{
filled_rect( UIcolor_t( 0, 0, 0, data->m_alpha ), m_start.x - 1.f, m_start.y - 1.f, m_end.x + 1.f, m_end.y + 1.f );
filled_rect( UIcolor_t( 36, 36, 36, data->m_alpha ), m_start.x, m_start.y, m_end.x, m_end.y );
if ( m_text )
string( UIcolor_t( 206, 206, 206, data->m_alpha ), m_start.x + m_bounds.x * 0.5f, m_start.y + ( m_bounds.y * 0.5f ) - 6.0f, true, m_text );
}
void handle( c_window_data* data, const char* text, std::function< void( ) > function )
{
g_input.get_cursor_pos( m_cursor_x, m_cursor_y );
m_text = text;
m_start = vec2( data->m_x + 20.f, data->m_y );
m_bounds = vec2( 150.f, 20.f );
m_end = m_start + m_bounds;
data->m_y += 25.f;
m_is_inside = m_cursor_x > m_start.x && m_cursor_x < m_end.x && m_cursor_y > m_start.y && m_cursor_y < m_end.y;
if ( data->m_left_click && !data->m_ignore && m_is_inside && function )
{
function( );
data->m_ignore = true;
}
draw( data );
}
};
class c_key_bind : public c_control
{
const char* m_text{ };
int* m_key{ };
vec2 m_box_start;
bool m_is_waiting{ };
public:
void handle( c_window_data* data, const char* text, int* key )
{
g_input.get_cursor_pos( m_cursor_x, m_cursor_y );
m_text = text;
m_key = key;
m_start = vec2( data->m_x + 20.f, data->m_y );
m_box_start = vec2( m_start.x, m_start.y + 12.f );
data->m_y += 40.f;
m_bounds = vec2( 150, 20 );
m_end = m_box_start + m_bounds;
m_is_inside = m_cursor_x > m_box_start.x && m_cursor_x < m_end.x && m_cursor_y > m_box_start.y && m_cursor_y < m_end.y;
if ( data->m_left_click && !data->m_ignore && m_is_inside )
{
m_is_waiting = true;
data->m_ignore = true;
}
if ( m_is_waiting )
{
*m_key = KEYS_NONE;
VirtualKeys_t start_key = data->m_ignore ? KEYS_MOUSE1 : KEYS_NONE;
if ( g_input.is_any_key_pressed( ) == KEYS_ESCAPE )
{
m_is_waiting = false;
*m_key = KEYS_NONE;
}
else if ( g_input.is_any_key_pressed( ) > start_key )
{
*m_key = g_input.is_any_key_pressed( );
m_is_waiting = false;
data->m_ignore = true;
}
}
draw( data );
}
void draw( c_window_data* data )
{
UIcolor_t text_color( 206, 206, 206, data->m_alpha );
UIcolor_t text_shadow( 0, 0, 0, data->m_alpha );
if ( m_text )
{
UI::string( text_shadow, m_start.x + 1.f, m_start.y + 1.f - 3.f, false, m_text ); //supwemacy dont have no shadow
UI::string( text_color, m_start.x, m_start.y - 3.f, false, m_text );
}
filled_rect( UIcolor_t( 0, 0, 0, data->m_alpha ), m_box_start.x - 1.f, m_box_start.y - 1.f, m_end.x + 1.f, m_end.y + 1.f );
filled_rect( UIcolor_t( 36, 36, 36, data->m_alpha ), m_box_start.x, m_box_start.y, m_end.x, m_end.y );
//supwemacy does m_box_start.y + 4.f, but it looks off (cuz it is off)
if ( m_is_waiting )
UI::string( data->m_color, m_box_start.x + 10.0f, m_box_start.y + 3.f, false, "press key" );
else if ( *m_key )
UI::string( UIcolor_t( 153, 153, 153, data->m_alpha ), m_box_start.x + 10.f, m_box_start.y + 3.f, false, g_input.get_key_name( *reinterpret_cast< VirtualKeys_t* >( m_key ) ) );
}
};
class c_dropdown : public c_control
{
const char* m_text{ };
std::vector<std::string> m_items{ };
int* m_setting{ };
bool m_is_open{ };
vec2 m_box_start;
vec2 m_box_end;
bool m_is_inside_items{ };
float m_dropdown_end{ };
const float m_item_height = 16.f;
public:
void handle( c_window_data* data, const char* text, const std::vector<std::string>& items, int* setting )
{
g_input.get_cursor_pos( m_cursor_x, m_cursor_y );
m_text = strlen( text ) > 1 ? text : nullptr;
m_items = items;
m_setting = setting;
m_start = vec2( data->m_x + 20.f, data->m_y );
m_box_start = vec2( m_start.x, m_start.y );
data->m_y += 25.f;
if ( m_text )
{
m_box_start.y += 15.f;
data->m_y += 15.f;
}
m_bounds = vec2( 150, 20 );
m_end = m_box_start + m_bounds;
m_box_end = m_end;
if ( m_is_open )
{
float h = items.size( ) * m_item_height;
m_box_end.y += h + 3.f;
}
m_is_inside = m_cursor_x > m_box_start.x && m_cursor_x < m_end.x && m_cursor_y > m_box_start.y && m_cursor_y < m_end.y;
m_is_inside_items = m_cursor_x > m_box_start.x && m_cursor_x < m_box_end.x && m_cursor_y > m_box_start.y && m_cursor_y < m_box_end.y;
if ( data->m_left_click && !data->m_ignore )
{
if ( m_is_inside )
{
m_is_open = !m_is_open;
data->m_ignore = true;
}
else if ( m_is_open && m_is_inside_items )
{
float offset = m_cursor_y - m_end.y;
*m_setting = (int)( offset / m_item_height );
data->m_ignore = true;
m_is_open = false;
}
else
{
m_is_open = false;
}
}
//clamp setting to avoid cwashing
*m_setting = std::clamp<int>( *m_setting, 0, std::max<int>( 0, items.size( ) - 1 ) );
draw( data );
}
void draw( c_window_data* data )
{
UIcolor_t text_color( 206, 206, 206, data->m_alpha );
UIcolor_t text_shadow( 0, 0, 0, data->m_alpha );
if ( m_text )
{
UI::string( text_shadow, m_start.x + 1.f, m_start.y + 1.f - 3.f, false, m_text ); //supwemacy dont have no shadow
UI::string( text_color, m_start.x, m_start.y - 3.f, false, m_text );
}
// outer edge
UI::filled_rect( UIcolor_t( 0, 0, 0, data->m_alpha ), m_box_start.x - 1.f, m_box_start.y - 1.f, m_end.x + 1.f, m_end.y + 1.f );
// inner background
UI::filled_rect( UIcolor_t( 36, 36, 36, data->m_alpha ), m_box_start.x, m_box_start.y, m_end.x, m_end.y );
UI::string( UIcolor_t( 153, 153, 153, data->m_alpha ), m_box_start.x + 10.f, m_box_start.y + 3.f, false, m_items.at( *m_setting ).c_str( ) );
// bester arrow
const UIcolor_t arrow_color( 153, 153, 153, data->m_alpha );
float x = m_end.x - 11.f;
float y = m_box_start.y + 9.f;
if ( m_is_open )
{
UI::line( arrow_color, x + 2.f, y, x + 3.f, y );
UI::line( arrow_color, x + 1.f, y + 1.f, x + 4.f, y + 1.f );
UI::line( arrow_color, x, y + 2.f, x + 5.f, y + 2.f );
}
else
{
UI::line( arrow_color, x + 2.f, y + 2.f, x + 3.f, y + 2.f );
UI::line( arrow_color, x + 1.f, y + 1.f, x + 4.f, y + 1.f );
UI::line( arrow_color, x, y, x + 5.f, y );
}
}
void dropdown( c_window_data* data )
{
// adjust end of dropdown
// sorry for ugly code
// as soon as m_is_open is false, m_box_end is set to bounding of button, so cant be used to just clamp it in 1 line, it would break close animation
// maybe this is reason supremacy also doesnt have close animation :>
if ( m_is_open )
{
m_dropdown_end += 2.f;
if ( m_dropdown_end + m_end.y > m_box_end.y )
m_dropdown_end = m_box_end.y - m_end.y;
}
else
{
m_dropdown_end -= 2.f;
if ( m_dropdown_end <= 0.f )
m_dropdown_end = 0.f;
}
// shop is closed!
if ( m_dropdown_end <= 0.f )
return;
UI::filled_rect( UIcolor_t( 0, 0, 0 ), m_box_start.x - 1.f, m_end.y + 2.f, m_box_end.x + 1.f, m_end.y + 2.f + m_dropdown_end );
UI::filled_rect( UIcolor_t( 36, 36, 36 ), m_box_start.x, m_end.y + 2.f + 1.f, m_box_end.x, m_end.y + 2.f + m_dropdown_end - 1.f );
for ( size_t i = 0; i < m_items.size( ); i++ )
{
float x = m_box_start.x + 10.f;
float y = m_end.y + 3.f + i * m_item_height;
if ( y + ( m_item_height * 0.5f ) > m_end.y + m_dropdown_end )
continue;
UI::string( *m_setting == i ? data->m_color : UIcolor_t( 153, 153, 153 ), x, y, false, m_items.at( i ).c_str( ) );
}
}
};
struct dropdown_item_t
{
bool* m_setting;
std::string m_text;
};
class c_multi_dropdown : public c_control
{
const char* m_text{ };
std::vector<dropdown_item_t> m_items{ };
bool m_is_open{ };
vec2 m_box_start;
vec2 m_box_end;
bool m_is_inside_items{ };
float m_dropdown_end{ };
const float m_item_height = 16.f;
public:
void handle( c_window_data* data, const char* text, const std::vector<dropdown_item_t>& items )
{
g_input.get_cursor_pos( m_cursor_x, m_cursor_y );
m_text = strlen( text ) > 1 ? text : nullptr;
m_items = items;
m_start = vec2( data->m_x + 20.f, data->m_y );
m_box_start = vec2( m_start.x, m_start.y );
data->m_y += 25.f;
if ( m_text )
{
m_box_start.y += 15.f;
data->m_y += 15.f;
}
m_bounds = vec2( 150, 20 );
m_end = m_box_start + m_bounds;
m_box_end = m_end;
if ( m_is_open )