WE Core
Loading...
Searching...
No Matches
CoreLookAndFeel.h
Go to the documentation of this file.
1/*
2 * File: CoreLookAndFeel.h
3 *
4 * Version: 2.0.0
5 *
6 * Created: 17/09/2015
7 *
8 * This file is part of WECore.
9 *
10 * WECore is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * WECore is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with WECore. If not, see <http://www.gnu.org/licenses/>.
22 *
23 */
24
25#pragma once
26
27#include "../JuceLibraryCode/JuceHeader.h"
28#include "General/CoreMath.h"
29
30namespace WECore::JUCEPlugin {
31
44 class CoreLookAndFeel : public juce::LookAndFeel_V2 {
45 public:
47 setHighlightColour(juce::Colour(34, 252, 255));
48 setLightColour(juce::Colour(200, 200, 200));
49 setDarkColour(juce::Colour(107, 107, 107));
50 }
51
52 virtual ~CoreLookAndFeel() = default;
53
56
57 virtual inline void drawLinearSliderThumb(juce::Graphics& g,
58 int x,
59 int y,
60 int width,
61 int height,
62 float sliderPos,
63 float /*minSliderPos*/,
64 float /*maxSliderPos*/,
65 const juce::Slider::SliderStyle style,
66 juce::Slider& slider) override;
67
68 virtual inline void drawButtonBackground(juce::Graphics& g,
69 juce::Button& button,
70 const juce::Colour& /*backgroundColour*/,
71 bool /*isMouseOverButton*/,
72 bool /*isButtonDown*/) override;
73
74 virtual inline void drawButtonText(juce::Graphics& g,
75 juce::TextButton& textButton,
76 bool /*isMouseOverButton*/,
77 bool /*isButtonDown*/) override;
78
79 virtual inline void drawComboBox(juce::Graphics& g,
80 int /*width*/,
81 int /*height*/,
82 const bool /*isButtonDown*/,
83 int buttonX,
84 int buttonY,
85 int buttonW,
86 int buttonH,
87 juce::ComboBox& box) override;
88
89 virtual inline void drawLinearSlider(juce::Graphics& g,
90 int x,
91 int y,
92 int width,
93 int height,
94 float sliderPos,
95 float minSliderPos,
96 float maxSliderPos,
97 const juce::Slider::SliderStyle style,
98 juce::Slider& slider) override;
99
100 virtual inline void drawLinearSliderBackground(juce::Graphics& g,
101 int x,
102 int y,
103 int width,
104 int height,
105 float /*sliderPos*/,
106 float /*minSliderPos*/,
107 float /*maxSliderPos*/,
108 const juce::Slider::SliderStyle /*style*/,
109 juce::Slider& slider) override;
110
111 virtual inline void drawTooltip(juce::Graphics& g,
112 const juce::String& text,
113 int width,
114 int height) override;
115
116 virtual void setHighlightColour(juce::Colour newColour) {
117 setColour(juce::ComboBox::arrowColourId, newColour);
118 setColour(juce::GroupComponent::textColourId, newColour);
119 setColour(juce::Slider::rotarySliderFillColourId, newColour);
120 setColour(juce::Slider::thumbColourId, newColour);
121 setColour(juce::Slider::trackColourId, newColour);
122 setColour(juce::TextButton::buttonOnColourId, newColour);
123 setColour(juce::TextButton::textColourOnId, newColour);
124
125 highlightColour = newColour;
126 }
127
128 virtual void setLightColour(juce::Colour newColour) {
129 setColour(juce::PopupMenu::backgroundColourId, newColour);
130 setColour(juce::Slider::backgroundColourId, newColour);
131 setColour(juce::Slider::rotarySliderOutlineColourId, newColour);
132 setColour(juce::TextButton::buttonColourId, newColour);
133 setColour(juce::TextButton::textColourOffId, newColour);
134
135 lightColour = newColour;
136 }
137
138 virtual void setDarkColour(juce::Colour newColour) {
139 setColour(juce::PopupMenu::highlightedBackgroundColourId, newColour);
140
141 darkColour = newColour;
142 }
143
144 protected:
145 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CoreLookAndFeel)
146
147 juce::Colour lightColour,
150 };
151
152 void CoreLookAndFeel::drawLinearSliderThumb(juce::Graphics& g,
153 int x,
154 int y,
155 int width,
156 int height,
157 float sliderPos,
158 float /*minSliderPos*/,
159 float /*maxSliderPos*/,
160 const juce::Slider::SliderStyle style,
161 juce::Slider& slider) {
162
163 const float sliderRadius = static_cast<float>(getSliderThumbRadius(slider) - 2);
164
165 juce::Colour* ring;
166
167 if (slider.isEnabled()) {
168 ring = &highlightColour;
169 } else {
170 ring = &lightColour;
171 }
172
173 if (style == juce::Slider::LinearHorizontal || style == juce::Slider::LinearVertical)
174 {
175 float kx, ky;
176
177 if (style == juce::Slider::LinearVertical)
178 {
179 kx = x + width * 0.5f;
180 ky = sliderPos;
181 }
182 else
183 {
184 kx = sliderPos;
185 ky = y + height * 0.5f;
186 }
187
188 juce::Path p;
189 p.addEllipse(kx - sliderRadius, ky - sliderRadius, sliderRadius * 2, sliderRadius * 2);
190
191 g.setColour(darkColour);
192 g.fillPath(p);
193
194 g.setColour(*ring);
195 g.strokePath(p, juce::PathStrokeType(2.0f));
196 }
197
198 }
199
201 juce::Button& button,
202 const juce::Colour& /*backgroundColour*/,
203 bool /*isMouseOverButton*/,
204 bool /*isButtonDown*/) {
205 const int width {button.getWidth()};
206 const int height {button.getHeight()};
207
208 const float indent {2.0f};
209 const int cornerSize {juce::jmin(juce::roundToInt(width * 0.4f),
210 juce::roundToInt(height * 0.4f))};
211
212 juce::Path p;
213 juce::PathStrokeType pStroke(1);
214 juce::Colour* bc {nullptr};
215
216
217
218
219 if (button.isEnabled()) {
220 if (button.getToggleState()) {
221 bc = &highlightColour;
222 } else {
223 bc = &lightColour;
224 }
225 } else {
226 bc = &darkColour;
227 }
228
229 p.addRoundedRectangle(indent, indent, width - 2 * indent, height - 2 * indent, static_cast<float>(cornerSize));
230
231
232 g.setColour(*bc);
233 g.strokePath(p, pStroke);
234 }
235
236 void CoreLookAndFeel::drawButtonText(juce::Graphics& g,
237 juce::TextButton& textButton,
238 bool /*isMouseOverButton*/,
239 bool /*isButtonDown*/) {
240
241 juce::Colour* textColour {nullptr};
242
243 if (textButton.isEnabled()) {
244 if (textButton.getToggleState() || textButton.getWidth() < 24) {
245 textColour = &highlightColour;
246 } else {
247 textColour = &lightColour;
248 }
249 } else {
250 textColour = &darkColour;
251 }
252
253 g.setColour(*textColour);
254 int margin {0};
255
256 // differentiates between the small button on the tempo sync ratio and larger buttons
257 if (textButton.getWidth() > 24) {
258 margin = 5;
259 }
260
261 g.drawFittedText(textButton.getButtonText(), margin, 0, textButton.getWidth() - 2 * margin, textButton.getHeight(), juce::Justification::centred, 0);
262 }
263
264 void CoreLookAndFeel::drawComboBox(juce::Graphics& g,
265 int /*width*/,
266 int /*height*/,
267 const bool /*isButtonDown*/,
268 int buttonX,
269 int buttonY,
270 int buttonW,
271 int buttonH,
272 juce::ComboBox& box) {
273
274 g.fillAll(lightColour);
275 g.setColour(darkColour);
276 g.fillRect(buttonX, buttonY, buttonW, buttonH);
277
278 const float arrowX {0.2f};
279 const float arrowH {0.3f};
280
281 if (box.isEnabled()) {
282 juce::Path p;
283 p.addTriangle(buttonX + buttonW * 0.5f, buttonY + buttonH * (0.45f - arrowH),
284 buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.45f,
285 buttonX + buttonW * arrowX, buttonY + buttonH * 0.45f);
286
287 p.addTriangle(buttonX + buttonW * 0.5f, buttonY + buttonH * (0.55f + arrowH),
288 buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.55f,
289 buttonX + buttonW * arrowX, buttonY + buttonH * 0.55f);
290
291 g.setColour(box.isPopupActive() ? highlightColour : lightColour);
292
293 g.fillPath(p);
294 }
295 }
296
297 void CoreLookAndFeel::drawLinearSlider(juce::Graphics& g,
298 int x,
299 int y,
300 int width,
301 int height,
302 float sliderPos,
303 float minSliderPos,
304 float maxSliderPos,
305 const juce::Slider::SliderStyle style,
306 juce::Slider& slider) {
307 // Draw background first
308 drawLinearSliderBackground(g, x, y, width, height, sliderPos, minSliderPos, maxSliderPos, style, slider);
309 drawLinearSliderThumb(g, x, y, width, height, sliderPos, minSliderPos, maxSliderPos, style, slider);
310 }
311
313 int x,
314 int y,
315 int width,
316 int height,
317 float /*sliderPos*/,
318 float /*minSliderPos*/,
319 float /*maxSliderPos*/,
320 const juce::Slider::SliderStyle /*style*/,
321 juce::Slider& slider) {
322 g.setColour(lightColour);
323
324 if (slider.isHorizontal()) {
325 g.fillRect(x, y + height / 2, width, 2);
326 }
327 }
328
329 void CoreLookAndFeel::drawTooltip(juce::Graphics& g,
330 const juce::String& text,
331 int width,
332 int height) {
333 g.setColour(lightColour);
334 g.fillRect(0, 0, width, height);
335
336 g.setColour(darkColour);
337 g.drawFittedText(text, 0, 0, width, height, juce::Justification::centred, 3);
338 }
339}
virtual void drawButtonText(juce::Graphics &g, juce::TextButton &textButton, bool, bool) override
virtual void drawLinearSlider(juce::Graphics &g, int x, int y, int width, int height, float sliderPos, float minSliderPos, float maxSliderPos, const juce::Slider::SliderStyle style, juce::Slider &slider) override
virtual void setDarkColour(juce::Colour newColour)
CoreLookAndFeel operator=(CoreLookAndFeel &)=delete
virtual void drawButtonBackground(juce::Graphics &g, juce::Button &button, const juce::Colour &, bool, bool) override
virtual void setLightColour(juce::Colour newColour)
virtual void setHighlightColour(juce::Colour newColour)
CoreLookAndFeel(CoreLookAndFeel &)=delete
virtual void drawComboBox(juce::Graphics &g, int, int, const bool, int buttonX, int buttonY, int buttonW, int buttonH, juce::ComboBox &box) override
virtual void drawTooltip(juce::Graphics &g, const juce::String &text, int width, int height) override
virtual void drawLinearSliderBackground(juce::Graphics &g, int x, int y, int width, int height, float, float, float, const juce::Slider::SliderStyle, juce::Slider &slider) override
virtual void drawLinearSliderThumb(juce::Graphics &g, int x, int y, int width, int height, float sliderPos, float, float, const juce::Slider::SliderStyle style, juce::Slider &slider) override