forked from open-ephys/plugin-GUI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomLookAndFeel.cpp
More file actions
1582 lines (1282 loc) · 65.5 KB
/
Copy pathCustomLookAndFeel.cpp
File metadata and controls
1582 lines (1282 loc) · 65.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
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
/*
------------------------------------------------------------------
This file is part of the Open Ephys GUI
Copyright (C) 2024 Open Ephys
------------------------------------------------------------------
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "CustomLookAndFeel.h"
#include "../../Utils/Utils.h"
CustomLookAndFeel::CustomLookAndFeel()
: silkscreen (Typeface::createSystemTypefaceFor (BinaryData::SilkscreenRegular_ttf,
BinaryData::SilkscreenRegular_ttfSize)),
nimbusSans (Typeface::createSystemTypefaceFor (BinaryData::NimbusSans_otf,
BinaryData::NimbusSans_otfSize)),
cpmonoExtraLight (Typeface::createSystemTypefaceFor (BinaryData::CPMonoExtraLight_otf,
BinaryData::CPMonoExtraLight_otfSize)),
cpmonoLight (Typeface::createSystemTypefaceFor (BinaryData::CPMonoLight_otf,
BinaryData::CPMonoLight_otfSize)),
cpmonoPlain (Typeface::createSystemTypefaceFor (BinaryData::CPMonoPlain_otf,
BinaryData::CPMonoPlain_otfSize)),
cpmonoBold (Typeface::createSystemTypefaceFor (BinaryData::CPMonoBold_otf,
BinaryData::CPMonoBold_otfSize)),
firaCodeLight (Typeface::createSystemTypefaceFor (BinaryData::FiraCodeLight_ttf,
BinaryData::FiraCodeLight_ttfSize)),
firaCodeMedium (Typeface::createSystemTypefaceFor (BinaryData::FiraCodeMedium_ttf,
BinaryData::FiraCodeMedium_ttfSize)),
firaCodeRetina (Typeface::createSystemTypefaceFor (BinaryData::FiraCodeRetina_ttf,
BinaryData::FiraCodeRetina_ttfSize)),
firaCodeRegular (Typeface::createSystemTypefaceFor (BinaryData::FiraCodeRegular_ttf,
BinaryData::FiraCodeRegular_ttfSize)),
firaCodeSemiBold (Typeface::createSystemTypefaceFor (BinaryData::FiraCodeSemiBold_ttf,
BinaryData::FiraCodeSemiBold_ttfSize)),
firaCodeBold (Typeface::createSystemTypefaceFor (BinaryData::FiraCodeBold_ttf,
BinaryData::FiraCodeBold_ttfSize)),
firaSansExtraLight (Typeface::createSystemTypefaceFor (BinaryData::FiraSansExtraLight_ttf,
BinaryData::FiraSansExtraLight_ttfSize)),
firaSansRegular (Typeface::createSystemTypefaceFor (BinaryData::FiraSansRegular_ttf,
BinaryData::FiraSansRegular_ttfSize)),
firaSansSemiBold (Typeface::createSystemTypefaceFor (BinaryData::FiraSansSemiBold_ttf,
BinaryData::FiraSansSemiBold_ttfSize)),
interBold (Typeface::createSystemTypefaceFor (BinaryData::InterBold_ttf,
BinaryData::InterBold_ttfSize)),
interLight (Typeface::createSystemTypefaceFor (BinaryData::InterLight_ttf,
BinaryData::InterLight_ttfSize)),
interMedium (Typeface::createSystemTypefaceFor (BinaryData::InterMedium_ttf,
BinaryData::InterMedium_ttfSize)),
interRegular (Typeface::createSystemTypefaceFor (BinaryData::InterRegular_ttf,
BinaryData::InterRegular_ttfSize)),
interSemiBold (Typeface::createSystemTypefaceFor (BinaryData::InterSemiBold_ttf,
BinaryData::InterSemiBold_ttfSize))
{
initializeColours();
setTheme (MEDIUM);
}
CustomLookAndFeel::~CustomLookAndFeel() {}
void CustomLookAndFeel::initializeColours()
{
// Processor colours are consistent across all themes, but
// can be customized by right-clicking on the processor list
setColour (ProcessorColour::IDs::FILTER_COLOUR, Colour (0, 160, 225));
setColour (ProcessorColour::IDs::SINK_COLOUR, Colour (0, 166, 81));
setColour (ProcessorColour::IDs::SOURCE_COLOUR, Colour (241, 90, 41));
setColour (ProcessorColour::IDs::UTILITY_COLOUR, Colour (90, 110, 110));
setColour (ProcessorColour::IDs::RECORD_COLOUR, Colour (255, 0, 0));
setColour (ProcessorColour::IDs::AUDIO_COLOUR, Colour (0, 0, 0));
setColour (ProcessorColour::IDs::SYNC_COLOUR, Colour (255, 165, 0));
themeColoursMap[MEDIUM] = {
{ ThemeColours::componentBackground, Colour (130, 130, 130) },
{ ThemeColours::componentParentBackground, Colour (58, 58, 58) },
{ ThemeColours::windowBackground, Colour (15, 15, 15) },
{ ThemeColours::widgetBackground, Colour (190, 190, 190) },
{ ThemeColours::controlPanelBackground, Colour (50, 50, 50) },
{ ThemeColours::controlPanelText, Colour (220, 220, 220) },
{ ThemeColours::menuBackground, Colour (140, 140, 140) },
{ ThemeColours::menuHighlightText, Colours::black },
{ ThemeColours::menuHighlightBackground, Colour (244, 148, 32) },
{ ThemeColours::outline, Colours::black },
{ ThemeColours::defaultText, Colours::black },
{ ThemeColours::defaultFill, Colour (95, 95, 95) },
{ ThemeColours::highlightedText, Colours::black },
{ ThemeColours::highlightedFill, Colour (244, 148, 32) },
{ ThemeColours::dropShadowColour, Colours::black.withAlpha (0.5f) }
};
themeColoursMap[DARK] = {
{ ThemeColours::componentBackground, Colour (45, 45, 45) },
{ ThemeColours::componentParentBackground, Colour (30, 30, 30).darker (0.3f) },
{ ThemeColours::windowBackground, Colour (15, 15, 15) },
{ ThemeColours::widgetBackground, Colour (40, 40, 40).darker() },
{ ThemeColours::controlPanelBackground, Colour (45, 45, 45) },
{ ThemeColours::controlPanelText, Colour (224, 224, 224) },
{ ThemeColours::menuBackground, Colour (30, 30, 30) },
{ ThemeColours::menuHighlightText, Colour (20, 20, 20) },
{ ThemeColours::menuHighlightBackground, Colour (153, 200, 214) },
{ ThemeColours::outline, Colours::black },
{ ThemeColours::defaultText, Colour (224, 224, 224) },
{ ThemeColours::defaultFill, Colour (80, 80, 80) },
{ ThemeColours::highlightedText, Colour (240, 240, 240) },
{ ThemeColours::highlightedFill, Colour (230, 152, 63) },
{ ThemeColours::dropShadowColour, Colours::black.withAlpha (0.75f) }
};
themeColoursMap[LIGHT] = {
{ ThemeColours::componentBackground, Colour (225, 225, 225) },
{ ThemeColours::componentParentBackground, Colour (225, 225, 225).darker() },
{ ThemeColours::windowBackground, Colour (176, 176, 176) },
{ ThemeColours::widgetBackground, Colour (225, 225, 225).brighter (0.6f) },
{ ThemeColours::controlPanelBackground, Colour (225, 225, 225) },
{ ThemeColours::controlPanelText, Colours::black },
{ ThemeColours::menuBackground, Colour (225, 225, 225) },
{ ThemeColours::menuHighlightText, Colours::black },
{ ThemeColours::menuHighlightBackground, Colour (138, 193, 232) },
{ ThemeColours::outline, Colours::black },
{ ThemeColours::defaultText, Colours::black },
{ ThemeColours::defaultFill, Colour (110, 110, 110) },
{ ThemeColours::highlightedText, Colours::black },
{ ThemeColours::highlightedFill, Colour (138, 193, 232) },
{ ThemeColours::dropShadowColour, Colours::black.withAlpha (0.4f) }
};
}
void CustomLookAndFeel::setTheme (ColourTheme theme)
{
auto currentThemeColours = themeColoursMap[theme];
for (const auto& [colourId, colour] : currentThemeColours)
{
setColour (colourId, colour);
}
const Colour transparent = Colour (0x00000000);
setColour (ProcessorColour::IDs::PROCESSOR_COLOUR, currentThemeColours[ThemeColours::controlPanelBackground]);
setColour (TextButton::buttonColourId, currentThemeColours[ThemeColours::widgetBackground]);
setColour (TextButton::buttonOnColourId, currentThemeColours[ThemeColours::highlightedFill]);
setColour (TextButton::textColourOnId, currentThemeColours[ThemeColours::defaultText]);
setColour (TextButton::textColourOffId, currentThemeColours[ThemeColours::defaultText]);
setColour (ToggleButton::textColourId, currentThemeColours[ThemeColours::defaultText]);
setColour (ToggleButton::tickColourId, currentThemeColours[ThemeColours::defaultText]);
setColour (ToggleButton::tickDisabledColourId, currentThemeColours[ThemeColours::widgetBackground]);
setColour (TextEditor::backgroundColourId, currentThemeColours[ThemeColours::widgetBackground]);
setColour (TextEditor::textColourId, currentThemeColours[ThemeColours::defaultText]);
setColour (TextEditor::highlightColourId, currentThemeColours[ThemeColours::widgetBackground].contrasting (0.5f).withAlpha (0.4f));
setColour (TextEditor::highlightedTextColourId, currentThemeColours[ThemeColours::highlightedText]);
setColour (TextEditor::outlineColourId, currentThemeColours[ThemeColours::outline]);
setColour (TextEditor::focusedOutlineColourId, currentThemeColours[ThemeColours::outline]);
setColour (TextEditor::shadowColourId, transparent);
float darkerAmount = theme == LIGHT ? 0.0f : 0.6f;
setColour (CodeEditorComponent::backgroundColourId, currentThemeColours[ThemeColours::controlPanelBackground].darker (darkerAmount));
setColour (CodeEditorComponent::defaultTextColourId, currentThemeColours[ThemeColours::controlPanelText]);
setColour (CodeEditorComponent::highlightColourId, currentThemeColours[ThemeColours::controlPanelBackground].contrasting (0.5f).withAlpha (0.4f));
setColour (CodeEditorComponent::lineNumberBackgroundId, currentThemeColours[ThemeColours::controlPanelBackground]);
setColour (CodeEditorComponent::lineNumberTextId, currentThemeColours[ThemeColours::controlPanelText]);
setColour (CaretComponent::caretColourId, currentThemeColours[ThemeColours::defaultText]);
setColour (Label::backgroundColourId, transparent);
setColour (Label::textColourId, currentThemeColours[ThemeColours::defaultText]);
setColour (Label::outlineColourId, transparent);
setColour (Label::textWhenEditingColourId, currentThemeColours[ThemeColours::defaultText]);
setColour (ScrollBar::backgroundColourId, transparent);
setColour (ScrollBar::thumbColourId, currentThemeColours[ThemeColours::defaultFill]);
setColour (ScrollBar::trackColourId, transparent);
setColour (PopupMenu::backgroundColourId, currentThemeColours[ThemeColours::menuBackground]);
setColour (PopupMenu::textColourId, currentThemeColours[ThemeColours::defaultText]);
setColour (PopupMenu::headerTextColourId, currentThemeColours[ThemeColours::defaultText]);
setColour (PopupMenu::highlightedTextColourId, currentThemeColours[ThemeColours::menuHighlightText]);
setColour (PopupMenu::highlightedBackgroundColourId, currentThemeColours[ThemeColours::menuHighlightBackground]);
setColour (ComboBox::buttonColourId, currentThemeColours[ThemeColours::defaultText]);
setColour (ComboBox::outlineColourId, currentThemeColours[ThemeColours::outline]);
setColour (ComboBox::textColourId, currentThemeColours[ThemeColours::defaultText]);
setColour (ComboBox::backgroundColourId, currentThemeColours[ThemeColours::widgetBackground]);
setColour (ComboBox::arrowColourId, currentThemeColours[ThemeColours::defaultText]);
setColour (ComboBox::focusedOutlineColourId, currentThemeColours[ThemeColours::highlightedFill]);
setColour (ListBox::backgroundColourId, currentThemeColours[ThemeColours::componentBackground]);
setColour (ListBox::outlineColourId, currentThemeColours[ThemeColours::outline]);
setColour (ListBox::textColourId, currentThemeColours[ThemeColours::defaultText]);
setColour (Slider::backgroundColourId, currentThemeColours[ThemeColours::widgetBackground]);
setColour (Slider::thumbColourId, currentThemeColours[ThemeColours::defaultFill]);
setColour (Slider::trackColourId, currentThemeColours[ThemeColours::highlightedFill]);
setColour (Slider::rotarySliderFillColourId, currentThemeColours[ThemeColours::highlightedFill]);
setColour (Slider::rotarySliderOutlineColourId, currentThemeColours[ThemeColours::widgetBackground]);
setColour (Slider::textBoxTextColourId, currentThemeColours[ThemeColours::defaultText]);
setColour (Slider::textBoxBackgroundColourId, transparent);
setColour (Slider::textBoxHighlightColourId, currentThemeColours[ThemeColours::menuHighlightBackground].withAlpha (0.4f));
setColour (Slider::textBoxOutlineColourId, currentThemeColours[ThemeColours::outline]);
setColour (ResizableWindow::backgroundColourId, currentThemeColours[ThemeColours::componentBackground]);
setColour (DocumentWindow::textColourId, currentThemeColours[ThemeColours::controlPanelText]);
setColour (AlertWindow::backgroundColourId, currentThemeColours[ThemeColours::componentBackground]);
setColour (AlertWindow::textColourId, currentThemeColours[ThemeColours::defaultText]);
setColour (AlertWindow::outlineColourId, currentThemeColours[ThemeColours::outline]);
setColour (ProgressBar::backgroundColourId, currentThemeColours[ThemeColours::widgetBackground]);
setColour (ProgressBar::foregroundColourId, currentThemeColours[ThemeColours::highlightedFill]);
setColour (TooltipWindow::backgroundColourId, currentThemeColours[ThemeColours::widgetBackground]);
setColour (TooltipWindow::textColourId, currentThemeColours[ThemeColours::defaultText]);
setColour (TooltipWindow::outlineColourId, currentThemeColours[ThemeColours::outline]);
setColour (TabbedComponent::backgroundColourId, transparent);
setColour (TabbedComponent::outlineColourId, transparent);
setColour (TabbedButtonBar::tabOutlineColourId, currentThemeColours[ThemeColours::outline].withAlpha (0.5f));
setColour (TabbedButtonBar::tabTextColourId, currentThemeColours[ThemeColours::defaultText].withAlpha (0.75f));
setColour (TabbedButtonBar::frontOutlineColourId, currentThemeColours[ThemeColours::outline]);
setColour (TabbedButtonBar::frontTextColourId, currentThemeColours[ThemeColours::defaultText]);
setColour (ResizableWindow::backgroundColourId, currentThemeColours[ThemeColours::windowBackground]);
setColour (TableHeaderComponent::backgroundColourId, currentThemeColours[ThemeColours::widgetBackground]);
setColour (TableHeaderComponent::textColourId, currentThemeColours[ThemeColours::defaultText]);
setColour (TableHeaderComponent::outlineColourId, currentThemeColours[ThemeColours::outline]);
setColour (TableHeaderComponent::highlightColourId, currentThemeColours[ThemeColours::highlightedFill]);
setColour (GroupComponent::textColourId, currentThemeColours[ThemeColours::defaultText]);
setColour (GroupComponent::outlineColourId, currentThemeColours[ThemeColours::defaultText].withAlpha (0.5f));
setColour (BubbleComponent::backgroundColourId, currentThemeColours[ThemeColours::widgetBackground]);
setColour (BubbleComponent::outlineColourId, currentThemeColours[ThemeColours::outline]);
setColour (HyperlinkButton::textColourId, theme == ColourTheme::DARK ? Colours::dodgerblue : Colour (0xff1a0dab));
}
//==============================================================================
// FONT/TYPEFACE METHODS :
//==============================================================================
Typeface::Ptr CustomLookAndFeel::getTypefaceForFont (const Font& font)
{
String typefaceName = font.getTypefaceName();
String typefaceStyle = font.getTypefaceStyle();
if (typefaceName.equalsIgnoreCase ("CP Mono"))
{
if (typefaceStyle.equalsIgnoreCase ("Plain"))
{
return cpmonoPlain;
}
else if (typefaceStyle.equalsIgnoreCase ("Extra Light"))
{
return cpmonoExtraLight;
}
else if (typefaceStyle.equalsIgnoreCase ("Light"))
{
return cpmonoLight;
}
else if (typefaceStyle.equalsIgnoreCase ("Bold"))
{
return cpmonoBold;
}
else
{
return cpmonoPlain; // default weight
}
}
else if (typefaceName.equalsIgnoreCase ("Fira Code"))
{
if (typefaceStyle.equalsIgnoreCase ("Light"))
{
return firaCodeLight;
}
else if (typefaceStyle.equalsIgnoreCase ("Medium"))
{
return firaCodeMedium;
}
else if (typefaceStyle.equalsIgnoreCase ("Regular"))
{
return firaCodeRegular;
}
else if (typefaceStyle.equalsIgnoreCase ("Retina"))
{
return firaCodeRetina;
}
else if (typefaceStyle.equalsIgnoreCase ("SemiBold"))
{
return firaCodeSemiBold;
}
else if (typefaceStyle.equalsIgnoreCase ("Bold"))
{
return firaCodeBold;
}
else
{
return firaCodeRegular; // default weight
}
}
else if (typefaceName.equalsIgnoreCase ("Fira Sans"))
{
if (typefaceStyle.equalsIgnoreCase ("Extra Light"))
{
return firaSansExtraLight;
}
else if (typefaceStyle.equalsIgnoreCase ("Regular"))
{
return firaSansRegular;
}
else if (typefaceStyle.equalsIgnoreCase ("SemiBold"))
{
return firaSansSemiBold;
}
else
{
return firaSansSemiBold; // default weight
}
}
else if (typefaceName.equalsIgnoreCase ("Silkscreen"))
{
return silkscreen;
}
else if (typefaceName.equalsIgnoreCase ("Nimbus Sans"))
{
return nimbusSans;
}
else if (typefaceName.equalsIgnoreCase ("Inter"))
{
if (typefaceStyle.equalsIgnoreCase ("Bold"))
{
return interBold;
}
else if (typefaceStyle.equalsIgnoreCase ("Light"))
{
return interLight;
}
else if (typefaceStyle.equalsIgnoreCase ("Medium"))
{
return interMedium;
}
else if (typefaceStyle.equalsIgnoreCase ("Regular"))
{
return interRegular;
}
else if (typefaceStyle.equalsIgnoreCase ("Semi Bold"))
{
return interSemiBold;
}
else
{
return interRegular; // default weight
}
}
else // default
{
#ifdef JUCE_MAC
return firaCodeRetina;
#else
return firaCodeRegular;
#endif
}
}
//==================================================================
// SCROLL BAR METHODS :
//==================================================================
void CustomLookAndFeel::drawScrollbarButton (Graphics& g,
ScrollBar& scrollbar,
int width,
int height,
int buttonDirection,
bool isScrollBarVertical,
bool isMouseOverButton,
bool isButtonDown)
{
Path p;
float w1 = 0.25f;
float w2 = 0.75f;
if (buttonDirection == 0)
p.addTriangle (width * 0.5f, height * 0.2f, width * w1, height * 0.7f, width * w2, height * 0.7f);
else if (buttonDirection == 1)
p.addTriangle (width * 0.8f, height * 0.5f, width * 0.3f, height * w1, width * 0.3f, height * w2);
else if (buttonDirection == 2)
p.addTriangle (width * 0.5f, height * 0.8f, width * w1, height * 0.3f, width * w2, height * 0.3f);
else if (buttonDirection == 3)
p.addTriangle (width * 0.2f, height * 0.5f, width * 0.7f, height * w1, width * 0.7f, height * w2);
if (isButtonDown)
g.setColour (findColour (ScrollBar::thumbColourId).contrasting (0.2f));
else
g.setColour (findColour (ScrollBar::thumbColourId));
g.fillPath (p);
if (isMouseOverButton)
g.strokePath (p, PathStrokeType (1.0f));
}
void CustomLookAndFeel::drawScrollbar (Graphics& g,
ScrollBar& scrollbar,
int x,
int y,
int width,
int height,
bool isScrollbarVertical,
int thumbStartPosition,
int thumbSize,
bool isMouseOver,
bool isMouseDown)
{
Path thumbPath;
const float slotIndent = jmin (width, height) > 15 ? 1.0f : 0.0f;
const float thumbIndent = slotIndent + 3.0f;
const float thumbIndentx2 = thumbIndent * 2.0f;
if (isScrollbarVertical)
{
if (thumbSize > 0)
thumbPath.addRoundedRectangle (x + thumbIndent,
thumbStartPosition + thumbIndent,
width - thumbIndentx2,
thumbSize - thumbIndentx2,
(width - thumbIndentx2) * 0.3f);
}
else
{
if (thumbSize > 0)
thumbPath.addRoundedRectangle (thumbStartPosition + thumbIndent,
y + thumbIndent,
thumbSize - thumbIndentx2,
height - thumbIndentx2,
(height - thumbIndentx2) * 0.3f);
}
g.setColour (findColour (ScrollBar::thumbColourId));
g.fillPath (thumbPath);
}
//==================================================================
// TOOLTIP METHODS :
//==================================================================
// TextLayout CustomLookAndFeel::layoutTooltipText (const String& text, Colour colour)
// {
// const float tooltipFontSize = 13.0f;
// const int maxToolTipWidth = 400;
// AttributedString s;
// s.setJustification (Justification::centredTop);
// s.append (text, Font (tooltipFontSize, Font::bold), colour);
// TextLayout tl;
// tl.createLayoutWithBalancedLineLengths (s, (float) maxToolTipWidth);
// return tl;
// }
// Rectangle<int> CustomLookAndFeel::getTooltipBounds(const String &tipText, Point<int> screenPos, Rectangle<int> parentArea)
// {
// const TextLayout tl (layoutTooltipText (tipText, Colours::black));
// auto w = (int) (tl.getWidth() + 14.0f);
// auto h = (int) (tl.getHeight() + 4.0f);
// return Rectangle<int> (screenPos.x > parentArea.getCentreX() ? screenPos.x - (w + 5) : screenPos.x + 10,
// screenPos.y > parentArea.getCentreY() ? screenPos.y - (h + 3) : screenPos.y + 3,
// w, h)
// .constrainedWithin (parentArea);
// }
// void CustomLookAndFeel::drawTooltip(Graphics &g, const String &text, int width, int height)
// {
// g.fillAll (findColour (TooltipWindow::backgroundColourId));
// #if ! JUCE_MAC // The mac windows already have a non-optional 1 pix outline, so don't double it here..
// g.setColour (findColour (TooltipWindow::outlineColourId));
// g.drawRect (0, 0, width, height, 1);
// #endif
// layoutTooltipText (text, findColour (TooltipWindow::textColourId))
// .draw (g, Rectangle<float> ((float) width, (float) height));
// }
//==================================================================
// SLIDER METHODS :
//==================================================================
void CustomLookAndFeel::drawLinearSlider (Graphics& g, int x, int y, int width, int height, float sliderPos, float minSliderPos, float maxSliderPos, const Slider::SliderStyle style, Slider& slider)
{
if (slider.isBar())
{
g.setColour (slider.findColour (Slider::backgroundColourId));
g.fillRect (x, y, width, height);
g.setColour (slider.findColour (Slider::trackColourId));
g.fillRect (slider.isHorizontal() ? Rectangle<float> (static_cast<float> (x), (float) y + 0.5f, sliderPos - (float) x, (float) height - 1.0f)
: Rectangle<float> ((float) x + 0.5f, sliderPos, (float) width - 1.0f, (float) y + ((float) height - sliderPos)));
drawLinearSliderOutline (g, x, y, width, height, style, slider);
}
else
{
auto isTwoVal = (style == Slider::SliderStyle::TwoValueVertical || style == Slider::SliderStyle::TwoValueHorizontal);
auto isThreeVal = (style == Slider::SliderStyle::ThreeValueVertical || style == Slider::SliderStyle::ThreeValueHorizontal);
auto trackWidth = jmin (6.0f, slider.isHorizontal() ? (float) height * 0.25f : (float) width * 0.25f);
Point<float> startPoint (slider.isHorizontal() ? (float) x : (float) x + (float) width * 0.5f,
slider.isHorizontal() ? (float) y + (float) height * 0.5f : (float) (height + y));
Point<float> endPoint (slider.isHorizontal() ? (float) (width + x) : startPoint.x,
slider.isHorizontal() ? startPoint.y : (float) y);
Path backgroundTrack;
backgroundTrack.startNewSubPath (startPoint);
backgroundTrack.lineTo (endPoint);
g.setColour (slider.findColour (Slider::backgroundColourId));
g.strokePath (backgroundTrack, { trackWidth, PathStrokeType::curved, PathStrokeType::rounded });
Path valueTrack;
Point<float> minPoint, maxPoint, thumbPoint;
if (isTwoVal || isThreeVal)
{
minPoint = { slider.isHorizontal() ? minSliderPos : (float) width * 0.5f,
slider.isHorizontal() ? (float) height * 0.5f : minSliderPos };
if (isThreeVal)
thumbPoint = { slider.isHorizontal() ? sliderPos : (float) width * 0.5f,
slider.isHorizontal() ? (float) height * 0.5f : sliderPos };
maxPoint = { slider.isHorizontal() ? maxSliderPos : (float) width * 0.5f,
slider.isHorizontal() ? (float) height * 0.5f : maxSliderPos };
}
else
{
auto kx = slider.isHorizontal() ? sliderPos : ((float) x + (float) width * 0.5f);
auto ky = slider.isHorizontal() ? ((float) y + (float) height * 0.5f) : sliderPos;
minPoint = startPoint;
maxPoint = { kx, ky };
}
auto thumbWidth = getSliderThumbRadius (slider);
valueTrack.startNewSubPath (minPoint);
valueTrack.lineTo (isThreeVal ? thumbPoint : maxPoint);
g.setColour (slider.findColour (Slider::trackColourId));
g.strokePath (valueTrack, { trackWidth, PathStrokeType::curved, PathStrokeType::rounded });
if (! isTwoVal)
{
g.setColour (slider.findColour (Slider::thumbColourId));
g.fillEllipse (Rectangle<float> (static_cast<float> (thumbWidth), static_cast<float> (thumbWidth)).withCentre (isThreeVal ? thumbPoint : maxPoint));
}
if (isTwoVal || isThreeVal)
{
auto sr = jmin (trackWidth, (slider.isHorizontal() ? (float) height : (float) width) * 0.4f);
auto pointerColour = slider.findColour (Slider::thumbColourId);
if (slider.isHorizontal())
{
drawPointer (g, minSliderPos - sr, jmax (0.0f, (float) y + (float) height * 0.5f - trackWidth * 2.0f), trackWidth * 2.0f, pointerColour, 2);
drawPointer (g, maxSliderPos - trackWidth, jmin ((float) (y + height) - trackWidth * 2.0f, (float) y + (float) height * 0.5f), trackWidth * 2.0f, pointerColour, 4);
}
else
{
drawPointer (g, jmax (0.0f, (float) x + (float) width * 0.5f - trackWidth * 2.0f), minSliderPos - trackWidth, trackWidth * 2.0f, pointerColour, 1);
drawPointer (g, jmin ((float) (x + width) - trackWidth * 2.0f, (float) x + (float) width * 0.5f), maxSliderPos - sr, trackWidth * 2.0f, pointerColour, 3);
}
}
}
}
int CustomLookAndFeel::getSliderThumbRadius (Slider& slider)
{
return jmin (12, slider.isHorizontal() ? static_cast<int> ((float) slider.getHeight() * 0.5f) : static_cast<int> ((float) slider.getWidth() * 0.5f));
}
void CustomLookAndFeel::drawPointer (Graphics& g, const float x, const float y, const float diameter, const Colour& colour, const int direction) noexcept
{
Path p;
p.startNewSubPath (x + diameter * 0.5f, y);
p.lineTo (x + diameter, y + diameter * 0.6f);
p.lineTo (x + diameter, y + diameter);
p.lineTo (x, y + diameter);
p.lineTo (x, y + diameter * 0.6f);
p.closeSubPath();
p.applyTransform (AffineTransform::rotation ((float) direction * MathConstants<float>::halfPi,
x + diameter * 0.5f,
y + diameter * 0.5f));
g.setColour (colour);
g.fillPath (p);
}
/// ------ combo box ---------------///
void CustomLookAndFeel::drawComboBox (Graphics& g, int width, int height, const bool isButtonDown, int buttonX, int buttonY, int buttonW, int buttonH, ComboBox& box)
{
auto cornerSize = box.findParentComponentOfClass<ChoicePropertyComponent>() != nullptr ? 0.0f : 3.0f;
bool flatonRight = box.findParentComponentOfClass<FilenameComponent>() != nullptr;
Rectangle<int> boxBounds (0, 0, width, height);
auto bounds = boxBounds.toFloat().reduced (0.5f, 0.5f);
auto baseColour = box.findColour (ComboBox::backgroundColourId).withMultipliedSaturation (box.hasKeyboardFocus (true) ? 1.3f : 0.9f).withMultipliedAlpha (box.isEnabled() ? 1.0f : 0.5f);
g.setColour (baseColour);
if (flatonRight)
{
Path path;
path.addRoundedRectangle (bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight(), cornerSize, cornerSize, true, false, true, false);
g.fillPath (path);
}
else
{
g.fillRoundedRectangle (bounds, cornerSize);
}
const float outlineThickness = box.isEnabled() ? (isButtonDown ? 1.2f : 0.5f) : 0.3f;
Rectangle<int> arrowZone (buttonX + outlineThickness, buttonY + outlineThickness, buttonW - outlineThickness, buttonH - outlineThickness);
Path path;
path.addTriangle (arrowZone.getCentreX() - 5.0f, arrowZone.getCentreY() - 2.0f, arrowZone.getCentreX(), arrowZone.getCentreY() + 5.0f, arrowZone.getCentreX() + 5.0f, arrowZone.getCentreY() - 2.0f);
g.setColour (box.findColour (ComboBox::arrowColourId).withAlpha ((box.isEnabled() ? 0.9f : 0.2f)));
g.fillPath (path);
g.setColour (box.findColour (ComboBox::outlineColourId).withMultipliedAlpha (box.isEnabled() ? 1.0f : 0.5f));
float lineThickness = 1.0f;
if (box.isPopupActive() || box.hasKeyboardFocus (false))
{
g.setColour (box.findColour (ComboBox::focusedOutlineColourId));
lineThickness = 1.5f;
}
if (flatonRight)
{
Path path;
path.addRoundedRectangle (bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight(), cornerSize, cornerSize, true, false, true, false);
g.strokePath (path, PathStrokeType (1.0f));
}
else
{
g.drawRoundedRectangle (bounds, cornerSize, 1.0f);
}
box.colourChanged();
}
Font CustomLookAndFeel::getComboBoxFont (ComboBox& box)
{
return FontOptions ("Inter", "Regular", box.getHeight() * 0.75);
}
void CustomLookAndFeel::positionComboBoxText (juce::ComboBox& box, juce::Label& label)
{
label.setFont (getComboBoxFont (box));
label.setBounds (0, 0, box.getWidth() - 20, box.getHeight());
box.setJustificationType (juce::Justification::left);
}
// ========= Popup Menu Background: ===========================
void CustomLookAndFeel::drawPopupMenuBackground (Graphics& g, int width, int height)
{
const Colour background (findColour (PopupMenu::backgroundColourId));
g.fillAll (background);
g.setColour (background.overlaidWith (Colour (0x2badd8e6)));
#if ! JUCE_MAC
g.setColour (findColour (PopupMenu::textColourId).withAlpha (0.6f));
g.drawRect (0, 0, width, height);
#endif
}
Font CustomLookAndFeel::getPopupMenuFont()
{
return getCommonMenuFont();
}
void CustomLookAndFeel::drawMenuBarBackground (Graphics& g, int width, int height, bool, MenuBarComponent& menuBar)
{
const Colour colour (findColour (ThemeColours::menuBackground));
Rectangle<int> r (0, 0, width, height);
g.setColour (colour.contrasting (0.15f));
g.fillRect (r.removeFromBottom (1));
g.setGradientFill (ColourGradient::vertical (colour, 0, colour.darker (0.2f), (float) height));
g.fillRect (r);
if (menuBar.getName().equalsIgnoreCase ("MainMenu"))
{
g.setColour (findColour (ThemeColours::defaultText).withAlpha (menuBar.isEnabled() ? 1.0f : 0.5f));
String ver = "v" + String (ProjectInfo::versionString);
g.setFont (getCommonMenuFont());
int verStrWidth = GlyphArrangement::getStringWidthInt (getCommonMenuFont(), ver);
g.drawText (ver, width - verStrWidth - 10, 0, verStrWidth, height, Justification::centred);
}
}
Font CustomLookAndFeel::getMenuBarFont (MenuBarComponent& menuBar, int /*itemIndex*/, const String& /*itemText*/)
{
return Font (FontOptions (getCommonMenuFont().getTypefaceName(), "Medium", menuBar.getHeight() * 0.65f));
}
//==================================================================
// BUTTON METHODS :
//==================================================================
void CustomLookAndFeel::drawButtonBackground (Graphics& g,
Button& button,
const Colour& backgroundColour,
bool isMouseOverButton,
bool isButtonDown)
{
auto cornerSize = 3.0f;
auto bounds = button.getLocalBounds().toFloat().reduced (0.5f, 0.5f);
auto baseColour = backgroundColour.withMultipliedSaturation (button.hasKeyboardFocus (true) ? 1.3f : 1.0f)
.withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f);
if (isButtonDown || isMouseOverButton)
baseColour = baseColour.contrasting (isButtonDown ? 0.2f : 0.05f);
g.setColour (baseColour);
auto flatOnLeft = button.isConnectedOnLeft();
auto flatOnRight = button.isConnectedOnRight();
auto flatOnTop = button.isConnectedOnTop();
auto flatOnBottom = button.isConnectedOnBottom();
if (flatOnLeft || flatOnRight || flatOnTop || flatOnBottom)
{
Path path;
path.addRoundedRectangle (bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight(), cornerSize, cornerSize, ! (flatOnLeft || flatOnTop), ! (flatOnRight || flatOnTop), ! (flatOnLeft || flatOnBottom), ! (flatOnRight || flatOnBottom));
g.fillPath (path);
g.setColour (button.findColour (ComboBox::outlineColourId).withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
g.strokePath (path, PathStrokeType (1.0f));
}
else
{
g.fillRoundedRectangle (bounds, cornerSize);
g.setColour (button.findColour (ComboBox::outlineColourId).withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
g.drawRoundedRectangle (bounds, cornerSize, 1.0f);
}
}
void CustomLookAndFeel::drawButtonText (Graphics& g,
TextButton& button,
bool isMouseOverButton,
bool isButtonDown)
{
Font font (getTextButtonFont (button, button.getHeight()));
g.setFont (font);
g.setColour (button.findColour (button.getToggleState() ? TextButton::textColourOnId
: TextButton::textColourOffId)
.withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
const int yIndent = jmin (4, button.proportionOfHeight (0.3f));
const int cornerSize = jmin (button.getHeight(), button.getWidth()) / 2;
const int fontHeight = roundToInt (font.getHeight() * 0.65f);
const int leftIndent = jmin (fontHeight, 2 + cornerSize / (button.isConnectedOnLeft() ? 4 : 2));
const int rightIndent = jmin (fontHeight, 2 + cornerSize / (button.isConnectedOnRight() ? 4 : 2));
const int textWidth = button.getWidth() - leftIndent - rightIndent;
if (textWidth > 0)
g.drawFittedText (button.getButtonText(),
leftIndent,
yIndent,
textWidth,
button.getHeight() - yIndent * 2,
Justification::centred,
1,
0.95f);
}
Font CustomLookAndFeel::getTextButtonFont (TextButton&, int buttonHeight)
{
return FontOptions (getCommonMenuFont().getTypefaceName(), "Medium", buttonHeight * 0.65f);
}
// ============ Common Font for Menus ================
Font CustomLookAndFeel::getCommonMenuFont()
{
return FontOptions ("Inter", "Regular", 18.f);
}
//==================================================================
// TOGGLE BUTTON METHODS :
//==================================================================
void CustomLookAndFeel::drawToggleButton (Graphics& g, ToggleButton& button, bool shouldDrawButtonAsHighlighted, bool shouldDrawButtonAsDown)
{
auto fontSize = jmin (18.0f, (float) button.getHeight() * 0.75f);
auto tickWidth = fontSize * 1.1f;
drawTickBox (g, button, 4.0f, (button.getHeight() - tickWidth) * 0.5f, tickWidth, tickWidth, button.getToggleState(), button.isEnabled(), shouldDrawButtonAsHighlighted, shouldDrawButtonAsDown);
g.setColour (button.findColour (ToggleButton::textColourId));
g.setFont (FontOptions ("Inter", "Regular", fontSize));
if (! button.isEnabled())
g.setOpacity (0.5f);
g.drawFittedText (button.getButtonText(),
button.getLocalBounds().withTrimmedLeft (roundToInt (tickWidth) + 10).withTrimmedRight (2),
Justification::centredLeft,
10);
}
void CustomLookAndFeel::drawTickBox (Graphics& g, Component& component, float x, float y, float w, float h, const bool ticked, const bool isEnabled, const bool shouldDrawButtonAsHighlighted, const bool shouldDrawButtonAsDown)
{
ignoreUnused (isEnabled, shouldDrawButtonAsHighlighted, shouldDrawButtonAsDown);
Rectangle<float> tickBounds (x, y, w, h);
g.setColour (component.findColour (ToggleButton::tickDisabledColourId));
g.fillRoundedRectangle (tickBounds.reduced (0.5f, 0.5f), 3.0f);
g.setColour (findColour (ThemeColours::outline));
g.drawRoundedRectangle (tickBounds.reduced (0.5f, 0.5f), 3.0f, 1.0f);
if (ticked)
{
g.setColour (component.findColour (ToggleButton::tickColourId));
auto tick = getTickShape (0.75f);
g.fillPath (tick, tick.getTransformToScaleToFit (tickBounds.reduced (4, 5).toFloat(), false));
}
}
Path CustomLookAndFeel::getTickShape (float height)
{
static const unsigned char pathData[] = { 110, 109, 32, 210, 202, 64, 126, 183, 148, 64, 108, 39, 244, 247, 64, 245, 76, 124, 64, 108, 178, 131, 27, 65, 246, 76, 252, 64, 108, 175, 242, 4, 65, 246, 76, 252, 64, 108, 236, 5, 68, 65, 0, 0, 160, 180, 108, 240, 150, 90, 65, 21, 136, 52, 63, 108, 48, 59, 16, 65, 0, 0, 32, 65, 108, 32, 210, 202, 64, 126, 183, 148, 64, 99, 101, 0, 0 };
Path path;
path.loadPathFromData (pathData, sizeof (pathData));
path.scaleToFit (0, 0, height * 2.0f, height, true);
return path;
}
void CustomLookAndFeel::drawProgressBar (Graphics& g, ProgressBar& progressBar, int width, int height, double progress, const String& textToShow)
{
switch (progressBar.getResolvedStyle())
{
case ProgressBar::Style::linear:
{
auto background = progressBar.findColour (ProgressBar::backgroundColourId);
auto foreground = progressBar.findColour (ProgressBar::foregroundColourId);
auto barBounds = progressBar.getLocalBounds().toFloat().reduced (1.0f);
g.setColour (background);
g.fillRoundedRectangle (barBounds, 5.0f);
if (progress >= 0.0f && progress <= 1.0f)
{
auto fillBounds = barBounds.withWidth (barBounds.getWidth() * (float) progress);
g.setColour (foreground);
g.fillRoundedRectangle (fillBounds, 5.0f);
}
else
{
// spinning bar..
g.setColour (background);
auto stripeWidth = height * 2;
auto position = static_cast<int> (Time::getMillisecondCounter() / 15) % stripeWidth;
Path p;
for (auto x = static_cast<float> (-position); x < (float) (width + stripeWidth); x += (float) stripeWidth)
p.addQuadrilateral (x, 0.0f, x + (float) stripeWidth * 0.5f, 0.0f, x, static_cast<float> (height), x - (float) stripeWidth * 0.5f, static_cast<float> (height));
Image im (Image::ARGB, width, height, true);
{
Graphics g2 (im);
g2.setColour (foreground);
g2.fillRoundedRectangle (barBounds, 5.0f);
}
g.setTiledImageFill (im, 0, 0, 0.85f);
g.fillPath (p);
}
if (textToShow.isNotEmpty())
{
g.setColour (Colour::contrasting (background, foreground));
g.setFont (FontOptions ("Inter", "Regular", (float) height * 0.6f));
g.drawText (textToShow, 0, 0, width, height, Justification::centred, false);
}
g.setColour (findColour (ThemeColours::outline));
g.drawRoundedRectangle (barBounds, 5.0f, 1.0f);
break;
}
case ProgressBar::Style::circular:
LookAndFeel_V4::drawProgressBar (g, progressBar, width, height, progress, textToShow);
break;
}
}
//==================================================================
// DOCUMENT WINDOW METHODS :
//==================================================================
class CustomDocumentWindowButton : public Button
{
public:
CustomDocumentWindowButton (const String& name, Colour c, const Path& normal, const Path& toggled)
: Button (name), colour (c), normalShape (normal), toggledShape (toggled)
{
}
void paintButton (Graphics& g, bool shouldDrawButtonAsHighlighted, bool shouldDrawButtonAsDown) override
{
auto pathColour = findColour (ThemeColours::controlPanelText).withAlpha (isEnabled() ? 1.0f : 0.5f);
// g.fillAll (background);
g.setColour ((! isEnabled() || shouldDrawButtonAsDown) ? colour.withAlpha (0.6f)
: colour);
if (shouldDrawButtonAsHighlighted)
{
g.fillAll();
}
auto& p = getToggleState() ? toggledShape : normalShape;
auto reducedRect = Justification (Justification::centred)
.appliedToRectangle (Rectangle<int> (getHeight(), getHeight()), getLocalBounds())
.toFloat()
.reduced ((float) getHeight() * 0.3f);
g.setColour (pathColour);
g.fillPath (p, p.getTransformToScaleToFit (reducedRect, true));
}
private:
Colour colour;
Path normalShape, toggledShape;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (CustomDocumentWindowButton)
};
Button* CustomLookAndFeel::createDocumentWindowButton (int buttonType)
{
Path shape;
auto crossThickness = 0.15f;
if (buttonType == DocumentWindow::closeButton)