-
-
Notifications
You must be signed in to change notification settings - Fork 99
Expand file tree
/
Copy pathLookAndFeel.cpp
More file actions
1465 lines (1257 loc) · 58.1 KB
/
LookAndFeel.cpp
File metadata and controls
1465 lines (1257 loc) · 58.1 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
/*
// Copyright (c) 2021-2025 Timothy Schoen
// For information on usage and redistribution, and for a DISCLAIMER OF ALL
// WARRANTIES, see the file, "LICENSE.txt," in this distribution.
*/
#include <juce_gui_basics/juce_gui_basics.h>
#include <juce_gui_extra/juce_gui_extra.h>
#include "LookAndFeel.h"
#include "Utility/StackShadow.h"
class PlugData_DocumentWindowButton final : public Button {
public:
explicit PlugData_DocumentWindowButton(int const buttonType)
: Button("")
{
constexpr auto crossThickness = 0.2f;
String name;
switch (buttonType) {
case DocumentWindow::closeButton: {
name = "close";
shape.addLineSegment({ 0.0f, 0.0f, 1.0f, 1.0f }, crossThickness);
shape.addLineSegment({ 1.0f, 0.0f, 0.0f, 1.0f }, crossThickness);
toggledShape = shape;
break;
}
case DocumentWindow::minimiseButton: {
name = "minimise";
shape.addLineSegment({ 0.0f, 0.5f, 1.0f, 0.5f }, crossThickness);
toggledShape = shape;
break;
}
case DocumentWindow::maximiseButton: {
name = "maximise";
shape.addLineSegment({ 0.5f, 0.0f, 0.5f, 1.0f }, crossThickness);
shape.addLineSegment({ 0.0f, 0.5f, 1.0f, 0.5f }, crossThickness);
toggledShape.startNewSubPath(45.0f, 100.0f);
toggledShape.lineTo(0.0f, 100.0f);
toggledShape.lineTo(0.0f, 0.0f);
toggledShape.lineTo(100.0f, 0.0f);
toggledShape.lineTo(100.0f, 45.0f);
toggledShape.addRectangle(45.0f, 45.0f, 100.0f, 100.0f);
PathStrokeType(30.0f).createStrokedPath(toggledShape, toggledShape);
break;
}
default:
break;
}
setName(name);
setButtonText(name);
}
void paintButton(Graphics& g, bool const shouldDrawButtonAsHighlighted, bool const shouldDrawButtonAsDown) override
{
auto circleColour = PlugDataColours::toolbarHoverColour;
if (shouldDrawButtonAsHighlighted)
circleColour = circleColour.contrasting(0.04f);
if (!isEnabled()) {
circleColour = circleColour.interpolatedWith(Colours::black, 0.5f);
}
g.setColour(circleColour);
g.fillEllipse(getLocalBounds().withSizeKeepingCentre(getWidth() - 8, getWidth() - 8).toFloat());
auto const colour = findColour(TextButton::textColourOffId);
g.setColour(!isEnabled() || shouldDrawButtonAsDown ? colour.withAlpha(0.6f) : colour);
auto const& p = getToggleState() ? toggledShape : shape;
auto const reducedRect = Justification(Justification::centred).appliedToRectangle(Rectangle<int>(getHeight(), getHeight()), getLocalBounds()).toFloat().reduced(getHeight() * 0.35f);
g.fillPath(p, p.getTransformToScaleToFit(reducedRect, true));
}
private:
Path shape, toggledShape;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(PlugData_DocumentWindowButton)
};
PlugDataLook::PlugDataLook()
{
}
void PlugDataLook::settingsChanged(String const& name, var const& value)
{
if (name == "touch_mode") {
useTouchMode = static_cast<bool>(value);
}
}
void PlugDataLook::fillResizableWindowBackground(Graphics& g, int w, int h, BorderSize<int> const& border, ResizableWindow& window)
{
if (dynamic_cast<FileChooserDialogBox*>(&window)) {
g.fillAll(PlugDataColours::canvasBackgroundColour);
}
}
void PlugDataLook::drawCallOutBoxBackground(CallOutBox& box, Graphics& g, Path const& path, Image& cachedImage)
{
if (!ProjectInfo::canUseSemiTransparentWindows()) {
auto const bounds = path.getBounds();
g.setColour(PlugDataColours::popupMenuBackgroundColour);
g.fillRect(bounds);
g.setColour(PlugDataColours::outlineColour);
g.drawRect(bounds);
return;
}
if (cachedImage.isNull()) {
cachedImage = { Image::ARGB, box.getWidth(), box.getHeight(), true };
Graphics g2(cachedImage);
StackShadow::drawShadowForPath(g2, 0, path, 8, Colours::black.withAlpha(0.18f), 2);
}
g.setColour(Colours::black);
g.drawImageAt(cachedImage, 0, 0);
g.setColour(PlugDataColours::popupMenuBackgroundColour);
g.fillPath(path);
g.setColour(PlugDataColours::outlineColour);
g.strokePath(path, PathStrokeType(1.0f));
}
int PlugDataLook::getCallOutBoxBorderSize(CallOutBox const& c)
{
return 20;
}
void PlugDataLook::drawButtonText(Graphics& g, TextButton& button, bool isMouseOverButton, bool isButtonDown)
{
Font font(getTextButtonFont(button, button.getHeight()));
if (static_cast<bool>(button.getProperties().getVarPointer("bold_text"))) {
font = Font(Fonts::getSemiBoldFont()).withHeight(button.getHeight() * 0.65f);
}
g.setFont(font);
auto colour = button.findColour(button.getToggleState() ? TextButton::textColourOnId
: TextButton::textColourOffId)
.withMultipliedAlpha(button.isEnabled() ? 1.0f : 0.5f);
if (!button.getClickingTogglesState() && button.isMouseOver()) {
colour = button.findColour(TextButton::textColourOnId);
}
int const yIndent = jmin(4, button.proportionOfHeight(0.3f));
int const cornerSize = jmin(button.getHeight(), button.getWidth()) / 2;
int const fontHeight = roundToInt(font.getHeight() * 0.6f);
int const leftIndent = jmin(fontHeight, 2 + cornerSize / (button.isConnectedOnLeft() ? 4 : 2));
int const rightIndent = jmin(fontHeight, 2 + cornerSize / (button.isConnectedOnRight() ? 4 : 2));
int const textWidth = button.getWidth() - leftIndent - rightIndent;
g.setColour(colour);
if (textWidth > 0) {
g.drawFittedText(button.getButtonText(), leftIndent, yIndent, textWidth, button.getHeight() - yIndent * 2, Justification::centred, 1);
}
}
Font PlugDataLook::getTextButtonFont(TextButton& but, int const buttonHeight)
{
return { FontOptions(buttonHeight / 1.7f) };
}
Button* PlugDataLook::createDocumentWindowButton(int const buttonType)
{
if (buttonType == -1)
return new PlugData_DocumentWindowButton(DocumentWindow::closeButton);
#if JUCE_MAC
return nullptr;
#endif
return new PlugData_DocumentWindowButton(buttonType);
}
void PlugDataLook::positionDocumentWindowButtons(DocumentWindow& window,
int titleBarX, int titleBarY, int const titleBarW, int titleBarH,
Button* minimiseButton,
Button* maximiseButton,
Button* closeButton,
bool positionTitleBarButtonsOnLeft)
{
if (SettingsFile::getInstance()->getProperty<bool>("native_window"))
return;
#if JUCE_MAC
auto areButtonsLeft = true;
#else
auto areButtonsLeft = false;
#endif
// heuristic to offset the buttons when positioned left, as we are drawing larger to provide a shadow
// we check if the system is drawing with a dropshadow- hence semi transparent will be true
#if JUCE_LINUX || JUCE_BSD
auto leftOffset = titleBarX;
if (maximiseButton != nullptr && areButtonsLeft && ProjectInfo::canUseSemiTransparentWindows()) {
if (maximiseButton->getToggleState())
leftOffset += 8;
else
leftOffset += 25;
}
#else
auto leftOffset = areButtonsLeft ? titleBarX + 10 : titleBarX;
#endif
if (areButtonsLeft) {
titleBarY += 3;
titleBarH -= 4;
}
auto const buttonW = static_cast<int>(titleBarH * 1.2);
auto x = areButtonsLeft ? leftOffset : leftOffset + titleBarW - buttonW;
if (closeButton != nullptr) {
closeButton->setBounds(x, titleBarY, buttonW, titleBarH);
x += areButtonsLeft ? titleBarH * 1.1 : -buttonW;
}
if (areButtonsLeft)
std::swap(minimiseButton, maximiseButton);
if (maximiseButton != nullptr) {
maximiseButton->setBounds(x, titleBarY, buttonW, titleBarH);
x += areButtonsLeft ? titleBarH * 1.1 : -buttonW;
}
if (minimiseButton != nullptr) {
minimiseButton->setBounds(x, titleBarY, buttonW, titleBarH);
}
}
Font PlugDataLook::getTabButtonFont(TabBarButton&, float height)
{
return Fonts::getCurrentFont().withHeight(13.5f);
}
void PlugDataLook::drawScrollbar(Graphics& g, ScrollBar& scrollbar, int x, int y, int width, int height,
bool const isScrollbarVertical, int thumbStartPosition, int thumbSize, bool const isMouseOver, [[maybe_unused]] bool isMouseDown)
{
Rectangle<int> thumbBounds;
if (isScrollbarVertical)
thumbBounds = { x, thumbStartPosition, width, thumbSize };
else
thumbBounds = { thumbStartPosition, y, thumbSize, height };
auto const c = scrollbar.findColour(ScrollBar::ColourIds::thumbColourId);
g.setColour(isMouseOver ? c.brighter(0.25f) : c);
auto const thumbRadius = isScrollbarVertical ? (thumbBounds.getWidth() - 2.0f) / 2.0f : (thumbBounds.getHeight() - 2.0f) / 2.0f;
g.fillRoundedRectangle(thumbBounds.reduced(1).toFloat(), thumbRadius);
}
void PlugDataLook::getIdealPopupMenuItemSize(String const& text, bool const isSeparator, int const standardMenuItemHeight, int& idealWidth, int& idealHeight)
{
if (isSeparator) {
idealWidth = 50;
idealHeight = standardMenuItemHeight > 0 ? standardMenuItemHeight / 10 : 10;
} else {
auto font = getPopupMenuFont();
if (standardMenuItemHeight > 0 && font.getHeight() > static_cast<float>(standardMenuItemHeight) / 1.3f)
font.setHeight(static_cast<float>(standardMenuItemHeight) / 1.3f);
idealHeight = standardMenuItemHeight > 0 ? standardMenuItemHeight : roundToInt(font.getHeight() * 1.3f);
idealWidth = Fonts::getStringWidth(text, font) + idealHeight;
#if !JUCE_MAC
// Dumb check to see if there is a keyboard shortcut after the text.
// On Linux and Windows, it seems to reserve way to much space for those.
if (text.contains(" ")) {
idealWidth -= 46;
}
#endif
}
}
void PlugDataLook::drawPopupMenuBackgroundWithOptions(Graphics& g, int const width, int const height, PopupMenu::Options const& options)
{
auto const background = PlugDataColours::popupMenuBackgroundColour;
if (Desktop::canUseSemiTransparentWindows()) {
StackShadow::drawShadowForRect(g, Rectangle<int>(width, height).reduced(10), 12, Corners::defaultCornerRadius, 0.6f, 1);
g.setColour(background);
auto const bounds = Rectangle<float>(5, 6, width - 10, height - 12);
g.fillRoundedRectangle(bounds, Corners::largeCornerRadius);
g.setColour(PlugDataColours::outlineColour);
g.drawRoundedRectangle(bounds, Corners::largeCornerRadius, 1.0f);
} else {
auto const bounds = Rectangle<float>(0, 0, width, height);
g.setColour(background);
g.fillRect(bounds);
g.setColour(PlugDataColours::outlineColour);
g.drawRect(bounds, 1.0f);
}
}
Path PlugDataLook::getTickShape(float const height)
{
Path path;
path.startNewSubPath(0.4f * height, 0.6f * height);
path.lineTo(0.475f * height, 0.7f * height);
path.lineTo(0.65f * height, 0.475f * height);
Path strokedPath;
PathStrokeType(height / 15.0f, PathStrokeType::curved, PathStrokeType::rounded).createStrokedPath(strokedPath, path, AffineTransform(), 5.0f);
return strokedPath;
}
void PlugDataLook::drawPopupMenuItem(Graphics& g, Rectangle<int> const& area,
bool const isSeparator, bool const isActive,
bool const isHighlighted, bool const isTicked,
bool const hasSubMenu, String const& text,
String const& shortcutKeyText,
Drawable const* icon, Colour const* const textColourToUse)
{
int margin = Desktop::canUseSemiTransparentWindows() ? 7 : 2;
if (isSeparator) {
auto r = area.reduced(margin + 8, 0);
r.removeFromTop(roundToInt(static_cast<float>(r.getHeight()) * 0.5f - 0.5f));
g.setColour(PlugDataColours::outlineColour.withAlpha(0.7f));
g.fillRect(r.removeFromTop(1));
} else {
auto r = area.reduced(margin, 0);
auto colour = findColour(PopupMenu::textColourId).withMultipliedAlpha(isActive ? 1.0f : 0.5f);
if (isHighlighted && isActive) {
g.setColour(PlugDataColours::popupMenuActiveBackgroundColour);
g.fillRoundedRectangle(r.toFloat().reduced(4, 0), Corners::defaultCornerRadius);
}
g.setColour(colour);
r.reduce(jmin(5, area.getWidth() / 20), 0);
auto font = getPopupMenuFont();
auto maxFontHeight = static_cast<float>(r.getHeight()) / 1.3f;
if (font.getHeight() > maxFontHeight)
font.setHeight(maxFontHeight);
g.setFont(font);
if (icon != nullptr) {
auto iconArea = r.removeFromLeft(roundToInt(maxFontHeight)).toFloat();
icon->drawWithin(g, iconArea, RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize, 1.0f);
r.removeFromLeft(roundToInt(maxFontHeight * 0.5f));
} else if (isTicked) {
auto iconArea = r.removeFromLeft(roundToInt(maxFontHeight)).toFloat();
auto tick = getTickShape(1.0f);
g.fillPath(tick, tick.getTransformToScaleToFit(iconArea.reduced(iconArea.getWidth() / 5, 0).toFloat(), true));
} else {
r.removeFromLeft(8);
}
if (hasSubMenu) {
auto arrowH = 0.6f * getPopupMenuFont().getAscent();
auto x = static_cast<float>(r.removeFromRight(static_cast<int>(arrowH) + 3).getX());
auto halfH = static_cast<float>(r.getCentreY());
Path path;
path.startNewSubPath(x, halfH - arrowH * 0.5f);
path.lineTo(x + arrowH * 0.5f, halfH);
path.lineTo(x, halfH + arrowH * 0.5f);
g.strokePath(path, PathStrokeType(1.5f));
}
r.removeFromRight(3);
Fonts::drawFittedText(g, text, r, colour);
auto shortcutBounds = r.translated(-4, 0);
#if JUCE_MAC
for (int i = shortcutKeyText.length() - 1; i >= 0; i--) {
auto font = Fonts::getSemiBoldFont().withHeight(10.5f);
auto text = shortcutKeyText.substring(i, i + 1);
auto width = std::max(Fonts::getStringWidthInt(text, font) + 4, 16);
auto b = shortcutBounds.removeFromRight(width).toFloat().reduced(1.0f, 5.0f).translated(1.5f, 0.5f);
g.setColour(PlugDataColours::popupMenuTextColour.withAlpha(isActive ? 0.9f : 0.35f));
g.fillRoundedRectangle(b.toFloat(), 3.0f);
g.setColour(PlugDataColours::popupMenuBackgroundColour);
g.setFont(Fonts::getSemiBoldFont().withHeight(11));
g.drawText(text, b, Justification::centred);
}
#else
auto keys = StringArray::fromTokens(shortcutKeyText, "+", "");
for (int i = keys.size() - 1; i >= 0; i--) {
auto font = Fonts::getSemiBoldFont().withHeight(10.5f);
auto width = std::max(Fonts::getStringWidthInt(keys[i].trim(), font) + 8, 15);
auto b = shortcutBounds.removeFromRight(width).reduced(1, 5);
g.setColour(PlugDataColours::popupMenuTextColour.withAlpha(isActive ? 0.9f : 0.35f));
g.fillRoundedRectangle(b.toFloat(), 3.0f);
g.setColour(PlugDataColours::popupMenuBackgroundColour);
g.setFont(font);
g.drawText(keys[i], b, Justification::centred);
}
#endif
}
}
int PlugDataLook::getMenuWindowFlags()
{
return ComponentPeer::windowIsTemporary;
}
int PlugDataLook::getPopupMenuBorderSize()
{
if (Desktop::canUseSemiTransparentWindows()) {
return 12;
}
return 6;
}
void PlugDataLook::drawTreeviewPlusMinusBox(Graphics& g, Rectangle<float> const& area, Colour, bool const isOpen, bool const isMouseOver)
{
Path p;
p.startNewSubPath(0.0f, 0.0f);
p.lineTo(0.5f, 0.5f);
p.lineTo(isOpen ? 1.0f : 0.0f, isOpen ? 0.0f : 1.0f);
auto const size = std::min(area.getWidth(), area.getHeight()) * 0.5f;
g.setColour(PlugDataColours::panelTextColour.withAlpha(isMouseOver ? 0.7f : 1.0f));
g.strokePath(p, PathStrokeType(2.0f, PathStrokeType::curved, PathStrokeType::rounded), p.getTransformToScaleToFit(area.withSizeKeepingCentre(size, size), true));
}
void PlugDataLook::drawComboBox(Graphics& g, int const width, int const height, bool, int, int, int, int, ComboBox& object)
{
bool const inspectorElement = object.getProperties()["Style"] == "Inspector";
Rectangle<int> const boxBounds(0, 0, width, height);
if (!inspectorElement) {
g.setColour(object.findColour(ComboBox::backgroundColourId));
g.fillRoundedRectangle(boxBounds.toFloat(), Corners::defaultCornerRadius);
g.setColour(object.findColour(ComboBox::outlineColourId));
g.drawRoundedRectangle(boxBounds.toFloat().reduced(0.5f, 0.5f), Corners::defaultCornerRadius, 1.0f);
}
Rectangle<int> const arrowZone(width - 22, 9, 14, height - 18);
Path path;
path.startNewSubPath(static_cast<float>(arrowZone.getX()) + 3.0f, static_cast<float>(arrowZone.getCentreY()) - 2.0f);
path.lineTo(static_cast<float>(arrowZone.getCentreX()), static_cast<float>(arrowZone.getCentreY()) + 2.0f);
path.lineTo(static_cast<float>(arrowZone.getRight()) - 3.0f, static_cast<float>(arrowZone.getCentreY()) - 2.0f);
g.setColour(PlugDataColours::panelTextColour.withAlpha(object.isEnabled() ? 0.9f : 0.2f));
g.strokePath(path, PathStrokeType(2.0f));
}
PopupMenu::Options PlugDataLook::getOptionsForComboBoxPopupMenu(ComboBox& box, Label& label)
{
auto options = PopupMenu::Options().withTargetComponent(&box).withItemThatMustBeVisible(box.getSelectedId()).withInitiallySelectedItem(box.getSelectedId()).withMinimumWidth(box.getWidth()).withMaximumNumColumns(1).withStandardItemHeight(22);
#if JUCE_IOS
if (mainComponent)
options = options.withParentComponent(mainComponent);
#endif
return options;
}
void PlugDataLook::fillTextEditorBackground(Graphics& g, int const width, int const height, TextEditor& textEditor)
{
if (textEditor.getProperties()["NoBackground"].isVoid()) {
g.setColour(textEditor.findColour(TextEditor::backgroundColourId));
g.fillRoundedRectangle(2, 3, width - 4, height - 6, Corners::defaultCornerRadius);
}
}
void PlugDataLook::drawTextEditorOutline(Graphics& g, int const width, int const height, TextEditor& textEditor)
{
if (textEditor.getProperties()["NoOutline"].isVoid()) {
if (textEditor.isEnabled()) {
if (textEditor.hasKeyboardFocus(true) && !textEditor.isReadOnly()) {
g.setColour(textEditor.findColour(TextEditor::focusedOutlineColourId));
g.drawRoundedRectangle(2, 3, width - 4, height - 6, Corners::defaultCornerRadius, 2.0f);
} else {
g.setColour(textEditor.findColour(TextEditor::outlineColourId));
g.drawRoundedRectangle(2, 3, width - 4, height - 6, Corners::defaultCornerRadius, 2.0f);
}
}
}
}
void PlugDataLook::drawSpinningWaitAnimation(Graphics& g, Colour const& colour, int const x, int const y, int const w, int const h)
{
float const radius = static_cast<float>(jmin(w, h)) * 0.4f;
float const thickness = radius * 0.3f;
float const cx = static_cast<float>(x) + static_cast<float>(w) * 0.5f;
float const cy = static_cast<float>(y) + static_cast<float>(h) * 0.5f;
// Compute animation progress
double const animationTime = Time::getMillisecondCounterHiRes() / 1000.0;
double const progress = fmod(animationTime, 2.0); // Loops every 2 seconds
// Adwaita-style arc calculation
constexpr float minArcLength = MathConstants<float>::pi * 0.2f; // Shortest segment
constexpr float maxArcLength = MathConstants<float>::pi * 0.8f; // Longest segment
float const startAngle = MathConstants<float>::twoPi * progress; // Rotating angle
float const t = (sinf(progress * MathConstants<float>::pi) + 1.0f) / 2.0f; // Smooth curve
float const arcLength = minArcLength + t * (maxArcLength - minArcLength);
float const endAngle = startAngle + arcLength;
// Draw background circle
g.setColour(colour.withAlpha(0.1f));
g.drawEllipse(cx - radius, cy - radius, radius * 2.0f, radius * 2.0f, thickness);
Path p;
p.addCentredArc(cx, cy, radius, radius, 0.0f, startAngle, endAngle, true);
// Draw moving arc
g.setColour(colour);
g.strokePath(p, PathStrokeType(thickness, PathStrokeType::curved, PathStrokeType::rounded));
}
void PlugDataLook::drawCornerResizer(Graphics& g, int const w, int const h, bool const isMouseOver, bool isMouseDragging)
{
Path triangle;
triangle.addTriangle(Point<float>(0, h), Point<float>(w, h), Point<float>(w, 0));
g.saveState();
g.setColour(PlugDataColours::objectSelectedOutlineColour.withAlpha(isMouseOver ? 1.0f : 0.6f));
g.fillPath(triangle);
g.restoreState();
}
void PlugDataLook::drawTooltip(Graphics& g, String const& text, int const width, int const height)
{
auto const expandTooltip = ProjectInfo::canUseSemiTransparentWindows();
auto const bounds = Rectangle<int>(0, 0, width, height).reduced(expandTooltip ? 6 : 0);
auto const shadowBounds = bounds.reduced(2);
auto const cornerSize = ProjectInfo::canUseSemiTransparentWindows() ? Corners::defaultCornerRadius : 0;
StackShadow::drawShadowForRect(g, shadowBounds, 9, cornerSize, 0.44f);
g.setColour(PlugDataColours::popupMenuBackgroundColour);
g.fillRoundedRectangle(bounds.toFloat(), cornerSize);
g.setColour(PlugDataColours::outlineColour);
g.drawRoundedRectangle(bounds.toFloat().reduced(0.5f, 0.5f), cornerSize, 1.0f);
AttributedString s;
s.setJustification(Justification::centredLeft);
auto lines = StringArray::fromLines(convertURLtoUTF8(text));
for (auto const& line : lines) {
constexpr float tooltipFontSize = 14.0f;
if (line.contains("(") && line.contains(")")) {
auto const type = line.fromFirstOccurrenceOf("(", false, false).upToFirstOccurrenceOf(")", false, false);
auto const description = line.fromFirstOccurrenceOf(")", false, false);
s.append(type + ":", Fonts::getSemiBoldFont().withHeight(tooltipFontSize), PlugDataColours::popupMenuTextColour);
s.append(description + "\n", Font(FontOptions(tooltipFontSize)), PlugDataColours::popupMenuTextColour);
} else {
s.append(line, Font(FontOptions(tooltipFontSize)), PlugDataColours::popupMenuTextColour);
}
}
constexpr int maxToolTipWidth = 1000;
auto const textOffset = expandTooltip ? 10 : 0;
TextLayout tl;
tl.createLayoutWithBalancedLineLengths(s, static_cast<float>(maxToolTipWidth));
tl.draw(g, bounds.toFloat().withSizeKeepingCentre(width - (20 + textOffset), height - (2 + textOffset)));
}
Font PlugDataLook::getComboBoxFont(ComboBox& box)
{
return Fonts::getDefaultFont().withHeight(std::clamp(box.getHeight() * 0.85f, 13.5f, 15.0f));
}
void PlugDataLook::drawLasso(Graphics& g, Component& lassoComp)
{
float outlineThickness = 0.75f;
// Apply inverted scaling of the canvas to the outline of the lasso, so the lasso outline doesn't grow larger as you zoom in
if (auto const* parent = lassoComp.getParentComponent()) {
auto const transform = parent->getTransform();
auto const transformScale = std::sqrt(std::abs(transform.getDeterminant()));
outlineThickness = 0.75f / std::max(transformScale, std::numeric_limits<float>::epsilon());
}
Path p;
p.addRectangle(lassoComp.getLocalBounds().reduced(1));
g.setColour(lassoComp.findColour(0x1000440 /*lassoFillColourId*/));
g.fillPath(p);
g.setColour(lassoComp.findColour(0x1000441 /*lassoOutlineColourId*/));
g.strokePath(p, PathStrokeType(outlineThickness));
}
void PlugDataLook::drawLabel(Graphics& g, Label& label)
{
g.fillAll(label.findColour(Label::backgroundColourId));
if (!label.isBeingEdited()) {
auto const alpha = label.isEnabled() ? 1.0f : 0.5f;
Font const font = label.getFont();
auto const textArea = getLabelBorderSize(label).subtractedFrom(label.getLocalBounds());
g.setFont(font);
g.setColour(label.findColour(Label::textColourId));
g.drawFittedText(label.getText(), textArea, label.getJustificationType(), 1, label.getMinimumHorizontalScale());
g.setColour(label.findColour(Label::outlineColourId).withMultipliedAlpha(alpha));
} else if (label.isEnabled()) {
g.setColour(label.findColour(Label::outlineColourId));
}
g.drawRect(label.getLocalBounds());
}
void PlugDataLook::drawPropertyComponentLabel(Graphics& g, int width, int const height, PropertyComponent& component)
{
auto const indent = jmin(10, component.getWidth() / 10);
auto const colour = component.findColour(PropertyComponent::labelTextColourId)
.withMultipliedAlpha(component.isEnabled() ? 0.77f : 0.3f);
auto const textW = jmin(300, component.getWidth() / 2) - 5;
Fonts::drawFittedText(g, component.getName(), indent + 1, 0, textW, component.getHeight() - 1, colour, 1, 1.0f, static_cast<float>(jmin(height, 24)) * 0.65f, Justification::centredLeft);
}
void PlugDataLook::drawPropertyPanelSectionHeader(Graphics& g, String const& name, bool const isOpen, int const width, int const height)
{
auto buttonSize = static_cast<float>(height) * 0.75f;
auto buttonIndent = (static_cast<float>(height) - buttonSize) * 0.5f;
drawTreeviewPlusMinusBox(g, { buttonIndent, buttonIndent, buttonSize, buttonSize }, findColour(ResizableWindow::backgroundColourId), isOpen, false);
auto const textX = static_cast<int>(buttonIndent * 2.0f + buttonSize + 2.0f);
Fonts::drawStyledText(g, name, textX, 0, std::max(width - textX - 4, 0), height, findColour(PropertyComponent::labelTextColourId), Bold, height * 0.6f);
}
Rectangle<int> PlugDataLook::getTooltipBounds(String const& tipText, Point<int> const screenPos, Rectangle<int> parentArea)
{
auto const expandTooltip = ProjectInfo::canUseSemiTransparentWindows();
constexpr float tooltipFontSize = 14.0f;
constexpr int maxToolTipWidth = 1000;
AttributedString s;
s.setJustification(Justification::centredLeft);
auto lines = StringArray::fromLines(tipText);
for (auto const& line : lines) {
if (line.contains("(") && line.contains(")")) {
auto const type = line.fromFirstOccurrenceOf("(", false, false).upToFirstOccurrenceOf(")", false, false);
auto const description = line.fromFirstOccurrenceOf(")", false, false);
s.append(type + ":", Fonts::getSemiBoldFont().withHeight(tooltipFontSize), PlugDataColours::popupMenuTextColour);
s.append(description + "\n", Font(FontOptions(tooltipFontSize)), PlugDataColours::popupMenuTextColour);
} else {
s.append(line, Font(FontOptions(tooltipFontSize)), PlugDataColours::popupMenuTextColour);
}
}
TextLayout tl;
tl.createLayoutWithBalancedLineLengths(s, static_cast<float>(maxToolTipWidth));
constexpr int marginX = 17.0f;
constexpr int marginY = 10.0f;
auto const w = static_cast<int>(tl.getWidth() + marginX);
auto const h = static_cast<int>(tl.getHeight() + marginY);
#if JUCE_WINDOWS || JUCE_LINUX || JUCE_BSD
if (!ProjectInfo::isStandalone) {
auto const mouseSource = Desktop::getInstance().getMainMouseSource();
auto* newComp = mouseSource.isTouch() ? nullptr : mouseSource.getComponentUnderMouse();
if (newComp) {
auto globalScale = SettingsFile::getInstance()->getProperty<float>("global_scale");
auto transformScale = Component::getApproximateScaleFactorForComponent(newComp);
parentArea /= (transformScale / globalScale);
}
}
#endif
return Rectangle<int>(screenPos.x > parentArea.getCentreX() ? screenPos.x - (w + 12) : screenPos.x + 24,
screenPos.y > parentArea.getCentreY() ? screenPos.y - (h + 6) : screenPos.y + 6,
w, h)
.expanded(expandTooltip ? 6 : 0)
.constrainedWithin(parentArea);
}
int PlugDataLook::getTreeViewIndentSize(TreeView&)
{
return 36;
}
void PlugDataLook::setColours(UnorderedMap<PlugDataColour, Colour>& colours)
{
for (auto colourId = 0; colourId < PlugDataColour::numberOfColours; colourId++) {
setColour(colourId, colours.at(static_cast<PlugDataColour>(colourId)));
}
setColour(PopupMenu::highlightedBackgroundColourId,
colours.at(PlugDataColour::panelActiveBackgroundColourId));
setColour(TextButton::textColourOnId,
colours.at(PlugDataColour::toolbarTextColourId));
setColour(Slider::thumbColourId,
colours.at(PlugDataColour::levelMeterThumbColourId));
setColour(ScrollBar::thumbColourId,
colours.at(PlugDataColour::scrollbarThumbColourId));
setColour(DirectoryContentsDisplayComponent::highlightColourId,
colours.at(PlugDataColour::panelActiveBackgroundColourId));
setColour(CaretComponent::caretColourId,
colours.at(PlugDataColour::caretColourId));
setColour(TextEditor::focusedOutlineColourId,
colours.at(PlugDataColour::caretColourId));
setColour(TextButton::buttonColourId,
colours.at(PlugDataColour::toolbarBackgroundColourId));
setColour(TextButton::buttonOnColourId,
colours.at(PlugDataColour::toolbarBackgroundColourId));
setColour(ComboBox::backgroundColourId,
colours.at(PlugDataColour::toolbarBackgroundColourId));
setColour(ListBox::backgroundColourId,
colours.at(PlugDataColour::toolbarBackgroundColourId));
getCurrentColourScheme().setUIColour(ColourScheme::UIColour::widgetBackground, colours.at(PlugDataColour::panelBackgroundColourId));
setColour(TooltipWindow::backgroundColourId,
colours.at(PlugDataColour::panelBackgroundColourId));
// Add dummy alpha to prevent JUCE from making it opaque
setColour(PopupMenu::backgroundColourId,
colours.at(PlugDataColour::panelBackgroundColourId).withAlpha(0.99f));
setColour(ResizableWindow::backgroundColourId,
colours.at(PlugDataColour::canvasBackgroundColourId));
setColour(ScrollBar::backgroundColourId,
colours.at(PlugDataColour::canvasBackgroundColourId));
setColour(Slider::backgroundColourId,
colours.at(PlugDataColour::canvasBackgroundColourId));
setColour(Slider::trackColourId,
colours.at(PlugDataColour::levelMeterBackgroundColourId));
setColour(TextEditor::backgroundColourId,
colours.at(PlugDataColour::canvasBackgroundColourId));
setColour(FileBrowserComponent::currentPathBoxBackgroundColourId,
colours.at(PlugDataColour::panelBackgroundColourId));
setColour(FileBrowserComponent::filenameBoxBackgroundColourId,
colours.at(PlugDataColour::panelBackgroundColourId));
setColour(TooltipWindow::textColourId,
colours.at(PlugDataColour::panelTextColourId));
setColour(TextButton::textColourOffId,
colours.at(PlugDataColour::panelTextColourId));
setColour(ComboBox::textColourId,
colours.at(PlugDataColour::panelTextColourId));
setColour(TableListBox::textColourId,
colours.at(PlugDataColour::panelTextColourId));
setColour(Label::textColourId,
colours.at(PlugDataColour::panelTextColourId));
setColour(Label::textWhenEditingColourId,
colours.at(PlugDataColour::panelTextColourId));
setColour(ListBox::textColourId,
colours.at(PlugDataColour::panelTextColourId));
setColour(TextEditor::textColourId,
colours.at(PlugDataColour::panelTextColourId));
setColour(PropertyComponent::labelTextColourId,
colours.at(PlugDataColour::panelTextColourId));
setColour(PopupMenu::textColourId,
colours.at(PlugDataColour::panelTextColourId));
setColour(KeyMappingEditorComponent::textColourId,
colours.at(PlugDataColour::panelTextColourId));
setColour(DirectoryContentsDisplayComponent::textColourId,
colours.at(PlugDataColour::panelTextColourId));
setColour(Slider::textBoxTextColourId,
colours.at(PlugDataColour::panelTextColourId));
setColour(FileBrowserComponent::currentPathBoxTextColourId,
colours.at(PlugDataColour::panelTextColourId));
setColour(FileBrowserComponent::currentPathBoxArrowColourId,
colours.at(PlugDataColour::panelTextColourId));
setColour(FileBrowserComponent::filenameBoxTextColourId,
colours.at(PlugDataColour::panelTextColourId));
setColour(FileChooserDialogBox::titleTextColourId,
colours.at(PlugDataColour::panelTextColourId));
setColour(DirectoryContentsDisplayComponent::highlightedTextColourId,
colours.at(PlugDataColour::panelTextColourId));
setColour(TooltipWindow::outlineColourId,
colours.at(PlugDataColour::outlineColourId));
setColour(ComboBox::outlineColourId,
colours.at(PlugDataColour::outlineColourId));
setColour(TextEditor::outlineColourId,
colours.at(PlugDataColour::outlineColourId));
setColour(ListBox::outlineColourId,
colours.at(PlugDataColour::outlineColourId));
setColour(AlertWindow::textColourId, colours.at(PlugDataColour::panelTextColourId));
setColour(Slider::textBoxOutlineColourId,
Colours::transparentBlack);
setColour(TreeView::backgroundColourId,
Colours::transparentBlack);
}
void PlugDataLook::drawTableHeaderColumn(Graphics& g, TableHeaderComponent&,
String const& columnName, int columnId,
int const width, int const height,
bool isMouseOver, bool isMouseDown, int columnFlags)
{
Rectangle<int> area(width, height);
area.reduce(4, 0);
g.setColour(PlugDataColours::panelTextColour);
g.setFont(Fonts::getSemiBoldFont());
g.drawFittedText(columnName, area, Justification::centred, 1);
}
void PlugDataLook::drawTableHeaderBackground(Graphics& g, TableHeaderComponent& header)
{
g.setColour(PlugDataColours::outlineColour);
for (int i = header.getNumColumns(true); --i >= 0;)
g.fillRect(header.getColumnPosition(i).removeFromRight(1).reduced(0, 2));
}
void PlugDataLook::drawAlertBox(Graphics& g, AlertWindow& alert,
Rectangle<int> const& textArea, TextLayout& textLayout)
{
constexpr auto cornerSize = Corners::largeCornerRadius;
auto const bounds = alert.getLocalBounds().reduced(1);
g.setColour(PlugDataColours::outlineColour);
g.drawRoundedRectangle(bounds.toFloat(), cornerSize, 1.0f);
g.reduceClipRegion(bounds);
g.setColour(PlugDataColours::dialogBackgroundColour);
g.fillRoundedRectangle(bounds.toFloat(), cornerSize);
auto iconSpaceUsed = 0;
constexpr auto iconWidth = 80;
auto iconSize = jmin(iconWidth + 50, bounds.getHeight() + 20);
if (alert.containsAnyExtraComponents() || alert.getNumButtons() > 2)
iconSize = jmin(iconSize, textArea.getHeight() + 50);
Rectangle<int> const iconRect(iconSize / -10, iconSize / -10,
iconSize, iconSize);
if (alert.getAlertType() != MessageBoxIconType::NoIcon) {
Path icon;
char character;
uint32 colour;
if (alert.getAlertType() == MessageBoxIconType::WarningIcon) {
character = '!';
icon.addTriangle(static_cast<float>(iconRect.getX()) + static_cast<float>(iconRect.getWidth()) * 0.5f, static_cast<float>(iconRect.getY()),
static_cast<float>(iconRect.getRight()), static_cast<float>(iconRect.getBottom()),
static_cast<float>(iconRect.getX()), static_cast<float>(iconRect.getBottom()));
icon = icon.createPathWithRoundedCorners(5.0f);
colour = 0x66ff2a00;
} else {
colour = Colour(0xff00b0b9).withAlpha(0.4f).getARGB();
character = alert.getAlertType() == MessageBoxIconType::InfoIcon ? 'i' : '?';
icon.addEllipse(iconRect.toFloat());
}
GlyphArrangement ga;
ga.addFittedText({ FontOptions(static_cast<float>(iconRect.getHeight()) * 0.9f, Font::bold) },
String::charToString(static_cast<uint8>(character)),
static_cast<float>(iconRect.getX()), static_cast<float>(iconRect.getY()),
static_cast<float>(iconRect.getWidth()), static_cast<float>(iconRect.getHeight()),
Justification::centred, false);
ga.createPath(icon);
icon.setUsingNonZeroWinding(false);
g.setColour(Colour(colour));
g.fillPath(icon);
iconSpaceUsed = iconWidth;
}
g.setColour(alert.findColour(AlertWindow::textColourId));
Rectangle<int> const alertBounds(bounds.getX() + iconSpaceUsed, 30,
bounds.getWidth(), bounds.getHeight() - getAlertWindowButtonHeight() - 20);
textLayout.draw(g, alertBounds.toFloat());
}
void PlugDataLook::setDefaultFont(String const& fontName)
{
auto& lnf = dynamic_cast<PlugDataLook&>(getDefaultLookAndFeel());
if (fontName.isEmpty() || fontName == "Inter") {
auto const defaultFont = Fonts::getDefaultFont();
lnf.setDefaultSansSerifTypeface(defaultFont.getTypefacePtr());
Fonts::setCurrentFont(defaultFont);
} else {
auto const newDefaultFont = Font(FontOptions(fontName, 15, Font::plain));
Fonts::setCurrentFont(newDefaultFont);
lnf.setDefaultSansSerifTypeface(newDefaultFont.getTypefacePtr());
}
}
// clang-format off
const String PlugDataLook::defaultThemesJSON = R"(
[
{
"name": "max",
"toolbar_background": "ff333333",
"toolbar_text": "ffe4e4e4",
"toolbar_active": "ff72aedf",
"toolbar_hover": "ff424242",
"tabbar_background": "ff333333",
"tab_text": "ffe4e4e4",
"selected_tab_background": "ff494949",
"selected_tab_text": "ff72aedf",
"canvas_background": "ffe5e5e5",
"canvas_text": "ffeeeeee",
"canvas_dots": "ff7f7f7f",
"presentation_background": "ff72aedf",
"default_object_background": "ff333333",
"object_outline_colour": "ff696969",
"selected_object_outline_colour": "ff72aedf",
"gui_internal_outline_colour": "ff696969",
"toolbar_outline_colour": "ff393939",
"outline_colour": "ff393939",
"data_colour": "ff72aedf",
"connection_colour": "ffb3b3b3",
"signal_colour": "ffe1ef00",
"gem_colour": "ff01be00",
"dialog_background": "ff3b3b3b",
"sidebar_colour": "ff3e3e3e",
"sidebar_text": "ffe4e4e4",
"sidebar_background_active": "ff4f4f4f",
"levelmeter_active": "ff72aedf",
"levelmeter_background": "ff494949",
"levelmeter_thumb": "ffe4e4e4",
"panel_background": "ff4f4f4f",
"panel_foreground": "ff3f3f3f",
"panel_text": "ffe4e4e4",
"panel_background_active": "ff525252",
"popup_background": "ff333333",
"popup_background_active": "ff72aedf",
"popup_text": "ffe4e4e4",
"scrollbar_thumb": "ffa9a9a9",
"graph_area": "ffff0000",
"grid_colour": "ff72aedf",
"caret_colour": "ff72aedf",
"iolet_area_colour": "ff808080",
"iolet_outline_colour": "ff696969",
"text_object_background": "ff333333",
"comment_text_colour": "ff111111",
"connection_style": 1,
"straight_connections": false,
"connection_look": false,
"square_iolets": false,
"square_object_corners": true,
"iolet_spacing_edge": false,
"object_flag_outlined": false,
"highlight_syntax": true
},
{
"name": "classic",
"toolbar_background": "ffffffff",
"toolbar_text": "ff000000",
"toolbar_active": "ff787878",
"toolbar_hover": "ffededed",
"tabbar_background": "ffffffff",
"tab_text": "ff000000",
"selected_tab_background": "ffededed",
"selected_tab_text": "ff000000",