Krotos Modules 3
Loading...
Searching...
No Matches
Krotos_LookAndFeel.cpp
Go to the documentation of this file.
2
3namespace krotos
4{
7
8 const Identifier Krotos_LookAndFeel::Properties::ComboBox::DisableHover{"DisableHover"};
9 const Identifier Krotos_LookAndFeel::Properties::ComboBox::RoundedCornerID{"RoundedCornerID"};
10 const Identifier Krotos_LookAndFeel::Properties::ComboBox::IconPositionID{"ComboBoxIconPosition"};
11 const Identifier Krotos_LookAndFeel::Properties::ComboBox::FontSize{"ComboBoxFontSize"};
12 const Identifier Krotos_LookAndFeel::Properties::ComboBox::UseCustomIcon{"ComboBoxUseCustomIcon"};
13
15
16#ifdef CONCEPT_STYLE
17
18 // The rotary slider style used in Concept
19 void Krotos_LookAndFeel::drawRotarySlider(Graphics& g, int x, int y, int width, int height, float sliderPos,
20 float rotaryStartAngle, float rotaryEndAngle, juce::Slider& slider)
21 {
22 float border = 5.0; // Must leave enough space around the slider for the shadow
23
24 float radius((float)juce::jmin(width / 2, height / 2));
25 radius -= border;
26 const float centreX(x + width * 0.5f);
27 const float centreY(y + height * 0.5f);
28 const float rx(centreX - radius);
29 const float ry(centreY - radius);
30 const float rw(radius * 2.0f);
31 const float angle(rotaryStartAngle + sliderPos * (rotaryEndAngle - rotaryStartAngle));
32 const bool isMouseOver(slider.isMouseOverOrDragging() && slider.isEnabled());
33 juce::DropShadow shadow(juce::DropShadow(juce::Colours::black.withAlpha(0.22f), /*Radius*/ 2,
34 /*offset*/ juce::Point<int>(3, 3)));
35 auto fillColour = findColour(Slider::ColourIds::rotarySliderFillColourId);
36 auto backgroundColour = findColour(Slider::ColourIds::backgroundColourId);
37 auto disabledFillColour = fillColour.darker();
38 auto disabledBackgroundColour = backgroundColour.darker();
39
40 if (radius > 12.0f)
41 {
42 const float thickness = 0.75f;
43
44 {
45 juce::Path p;
46 g.fillPath(p, juce::AffineTransform::rotation(angle).translated(centreX, centreY));
47 }
48
49 slider.isEnabled() ? g.setColour(backgroundColour) : g.setColour(disabledBackgroundColour);
50
51 // Slider background
52 juce::Path outlineArc;
53 outlineArc.addPieSegment(rx, ry, rw, rw, rotaryStartAngle, rotaryEndAngle, thickness);
54 outlineArc.closeSubPath();
55 g.fillPath(outlineArc);
56
57 // Slider track
58 slider.isEnabled() ? g.setColour(fillColour) : g.setColour(disabledFillColour);
59 juce::Path filledArc;
60 filledArc.addPieSegment(rx, ry, rw, rw, rotaryStartAngle, angle, thickness);
61 g.fillPath(filledArc);
62 shadow.drawForPath(g, outlineArc);
63 }
64 else
65 {
66 if (slider.isEnabled())
67 {
68 g.setColour(fillColour.withAlpha(isMouseOver ? 1.0f : 0.7f));
69 }
70 else
71 {
72 g.setColour(disabledBackgroundColour);
73 }
74
75 juce::Path p;
76 p.addEllipse(-0.4f * rw, -0.4f * rw, rw * 0.8f, rw * 0.8f);
77 juce::PathStrokeType(rw * 0.1f).createStrokedPath(p, p);
78
79 p.addLineSegment(juce::Line<float>(0.0f, 0.0f, 0.0f, -radius), rw * 0.2f);
80
81 g.fillPath(p, juce::AffineTransform::rotation(angle).translated(centreX, centreY));
82 }
83 }
84
85#else
86
87 // The rotary slider style used in Krotos Studio
88 void Krotos_LookAndFeel::drawRotarySlider(Graphics& g, int /*x*/, int /*y*/, int width, int /*height*/,
89 float sliderPos, float /*rotaryStartAngle*/, float /*rotaryEndAngle*/,
90 juce::Slider& slider)
91 {
92 slider.setPopupDisplayEnabled(false, false, nullptr);
93
94 float globalAlpha = slider.isEnabled() ? layout.enabledAlphaEnabled : layout.enabledAlphaDisabled;
95 float mouseOverAlpha =
96 slider.isMouseOverOrDragging() ? layout.mouseOverAlphaOver : layout.mouseOverAlphaDefault;
97
98 Colour trackColourInner = layout.trackColourInner.withAlpha(globalAlpha);
99 Colour thumbColour = layout.thumbColour.withAlpha(globalAlpha);
100 Colour trackColourOuter = layout.trackColourOuter.withAlpha(globalAlpha).withAlpha(mouseOverAlpha);
101 Colour textColour = layout.textColour.withAlpha(globalAlpha);
102
103 float positionRadians = jmap<float>(sliderPos, layout.sliderValueMin, layout.sliderValueMax,
105
106 // Horribleness to make it resizable maintaining the proportions (almost) of the
107 // original 86x96 design
108 float scalar = (float)width / layout.enclosingRectangle.getWidth();
109 auto scaledSquare = layout.enclosingSquare * scalar;
110 auto scaledSquareTrack = layout.enclosingSquareTrack * scalar;
111 auto scaledThumbEnd = layout.thumbEnd * scalar;
112 auto scaledThumbStart = layout.thumbStart * scalar;
113 auto scaledArcCenter = scaledSquare.getCentre();
114 auto scaledTextRectangle = layout.textRectangle * scalar;
115 scaledTextRectangle.setHeight(layout.textRectangle.getHeight());
116 scaledTextRectangle.setX(layout.textRectangle.getX());
117
118 // Slider outline arc
119 juce::Path outlineArc;
120 outlineArc.addPieSegment(scaledSquare, layout.startRadians, layout.endRadians,
122 outlineArc.closeSubPath();
123 g.setColour(trackColourOuter);
124 g.fillPath(outlineArc);
125
126 // Slider track
127 juce::Path trackArc;
128 trackArc.addPieSegment(scaledSquareTrack, layout.startRadians, positionRadians, layout.trackArcInnerProportion);
129 trackArc.closeSubPath();
130 g.setColour(trackColourInner);
131 g.fillPath(trackArc);
132
133 if (slider.isMouseOverOrDragging())
134 {
135 // Slider thumb
136 juce::Path thumb;
137 auto thumbEnd = scaledThumbEnd.rotatedAboutOrigin(positionRadians) + scaledArcCenter;
138 auto thumbStart = scaledThumbStart.rotatedAboutOrigin(positionRadians) + scaledArcCenter;
139 thumb.addLineSegment(juce::Line<float>(thumbStart, thumbEnd), layout.thumbWidth);
140 g.setColour(thumbColour);
141 g.fillPath(thumb);
142
143 // Slider value text
144 String value{slider.getValue(), layout.numDecimalPlaces};
145 Font font(scaledTextRectangle.getHeight(), Font::FontStyleFlags::plain);
146 font.setExtraKerningFactor(layout.KerningFactor);
147 g.setFont(font);
148 g.setColour(textColour);
149 g.drawFittedText(value, scaledTextRectangle.toNearestInt(), Justification::centred, layout.maxTextLines);
150 }
151 }
152
153#endif
154
156 {
157 // Set the text color to #81AFFF for both off and on states
158 setColour(TextButton::ColourIds::textColourOffId, Colour(0xff81AFFF));
159 setColour(TextButton::ColourIds::textColourOnId, Colour(0xff81AFFF));
160 }
161
162 void Krotos_LookAndFeel::LinkButtonLAF::drawButtonText(Graphics& g, TextButton& button,
163 bool shouldDrawButtonAsHighlighted,
164 bool shouldDrawButtonAsDown)
165 {
166 Font::FontStyleFlags flag = Font::FontStyleFlags::plain;
167
168 if (shouldDrawButtonAsDown)
169 flag = Font::FontStyleFlags::bold;
170
171 Font font(getTextButtonFont(button, button.getHeight()));
172 font.setStyleFlags(flag);
173 g.setFont(font);
174
175 // Set the text color explicitly to #81AFFF
176 g.setColour(Colour(0xff81AFFF));
177
178 const int yIndent = jmin(4, button.proportionOfHeight(0.3f));
179 const int cornerSize = jmin(button.getHeight(), button.getWidth()) / 2;
180
181 const int fontHeight = roundToInt(font.getHeight() * 0.6f);
182 const int leftIndent = jmin(fontHeight, 2 + cornerSize / (button.isConnectedOnLeft() ? 4 : 2));
183 const int rightIndent = jmin(fontHeight, 2 + cornerSize / (button.isConnectedOnRight() ? 4 : 2));
184 const int textWidth = button.getWidth() - leftIndent - rightIndent;
185
186 if (textWidth > 0)
187 g.drawFittedText(button.getButtonText(), leftIndent, yIndent, textWidth, button.getHeight() - yIndent * 2,
188 Justification::centred, 2);
189 }
190} // namespace krotos
The default colours and visuals to be used in Krotos plugins.
struct krotos::Krotos_LookAndFeel::Layout layout
ColourScheme getKrotosDefaultColourScheme()
Definition Krotos_LookAndFeel.h:153
void drawRotarySlider(Graphics &g, int x, int y, int width, int height, float sliderPos, float rotaryStartAngle, float rotaryEndAngle, juce::Slider &slider) override
Definition Krotos_LookAndFeel.cpp:88
Krotos_LookAndFeel()
Definition Krotos_LookAndFeel.cpp:14
Definition AirAbsorptionFilter.cpp:2
const juce::Rectangle< float > enclosingSquareTrack
Definition Krotos_LookAndFeel.h:127
const float endRadians
Definition Krotos_LookAndFeel.h:113
const float thumbWidth
Definition Krotos_LookAndFeel.h:120
const juce::Point< float > thumbStart
Definition Krotos_LookAndFeel.h:134
const juce::Rectangle< float > enclosingSquare
Definition Krotos_LookAndFeel.h:126
const float enabledAlphaEnabled
Definition Krotos_LookAndFeel.h:145
const int maxTextLines
Definition Krotos_LookAndFeel.h:121
const Colour textColour
Definition Krotos_LookAndFeel.h:140
const float sliderValueMax
Definition Krotos_LookAndFeel.h:119
const juce::Rectangle< float > textRectangle
Definition Krotos_LookAndFeel.h:129
const Colour trackColourOuter
Definition Krotos_LookAndFeel.h:138
const float enabledAlphaDisabled
Definition Krotos_LookAndFeel.h:146
const juce::Rectangle< float > enclosingRectangle
Definition Krotos_LookAndFeel.h:128
const Colour trackColourInner
Definition Krotos_LookAndFeel.h:137
const float KerningFactor
Definition Krotos_LookAndFeel.h:123
const Colour thumbColour
Definition Krotos_LookAndFeel.h:139
const float trackArcInnerProportion
Definition Krotos_LookAndFeel.h:117
const float mouseOverAlphaDefault
Definition Krotos_LookAndFeel.h:148
const float sliderValueMin
Definition Krotos_LookAndFeel.h:118
const juce::Point< float > thumbEnd
Definition Krotos_LookAndFeel.h:133
const float outlineArcInnerProportion
Definition Krotos_LookAndFeel.h:116
const float startRadians
Definition Krotos_LookAndFeel.h:112
const int numDecimalPlaces
Definition Krotos_LookAndFeel.h:122
const float mouseOverAlphaOver
Definition Krotos_LookAndFeel.h:149
static const Identifier AlertHeightID
Definition Krotos_LookAndFeel.h:24
static const Identifier AlertWidthID
Definition Krotos_LookAndFeel.h:23
static const Identifier RoundedCornerID
Specify which corners to round on a component.
Definition Krotos_LookAndFeel.h:38
static const Identifier IconPositionID
Where to place the icon. This determines how the text is offset.
Definition Krotos_LookAndFeel.h:58
static const Identifier UseCustomIcon
Hide the default dropdown arrow icon, leaving an empty spot to draw a custom icon.
Definition Krotos_LookAndFeel.h:54
static const Identifier DisableHover
Disable Mouse Hover affecting drawing over buttons, etc.
Definition Krotos_LookAndFeel.h:33
static const Identifier FontSize
The size of the font in the ComboBox label.
Definition Krotos_LookAndFeel.h:68