-
Notifications
You must be signed in to change notification settings - Fork 0
/
AppLookAndFeel.cpp
100 lines (84 loc) · 3.56 KB
/
AppLookAndFeel.cpp
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
#include <JuceHeader.h>
#include "AppLookAndFeel.h"
/** Constructor for AppLookAndFeel */
AppLookAndFeel::AppLookAndFeel()
{
}
/** Destructor for AppLookAndFeel */
AppLookAndFeel::~AppLookAndFeel()
{
}
/** Sets up a given LookAndFeel */
void AppLookAndFeel::setupLookAndFeel(LookAndFeel& lookAndFeel){
// Main Window
lookAndFeel.setColour (juce::ResizableWindow::backgroundColourId, Colour(217,217,217));
// Buttons
lookAndFeel.setColour(juce::TextButton::textColourOffId, juce::Colours::black);
// Toggle Button
lookAndFeel.setColour(juce::ToggleButton::textColourId, juce::Colours::black);
lookAndFeel.setColour(juce::ToggleButton::tickColourId, juce::Colours::black);
lookAndFeel.setColour(juce::ToggleButton::tickDisabledColourId, juce::Colours::black);
// Default Slider
lookAndFeel.setColour(juce::Slider::textBoxOutlineColourId, juce::Colours::black);
lookAndFeel.setColour(juce::Slider::textBoxTextColourId, juce::Colours::black);
lookAndFeel.setColour(juce::Slider::thumbColourId, juce::Colours::white);
// Labels
lookAndFeel.setColour(juce::Label::textColourId, juce::Colours::black);
// Table
lookAndFeel.setColour(juce::TableHeaderComponent::backgroundColourId, juce::Colours::white);
lookAndFeel.setColour(juce::TableHeaderComponent::textColourId, juce::Colours::black);
lookAndFeel.setColour(juce::ListBox::backgroundColourId, juce::Colours::darkgrey);
lookAndFeel.setColour(juce::ListBox::textColourId, juce::Colours::black);
}
/** Draws a rotary slider. Overides default Juce rotary slider */
void AppLookAndFeel::drawRotarySlider(juce::Graphics& g,
int x,
int y,
int width,
int height,
float sliderPos,
const float rotaryStartAngle,
const float rotaryEndAngle,
juce::Slider& slider){
// https://docs.juce.com/master/tutorial_look_and_feel_customisation.html
auto radius = (float) juce::jmin (width / 2, height / 2) - 4.0f;
auto centreX = (float) x + (float) width * 0.5f;
auto centreY = (float) y + (float) height * 0.5f;
auto rx = centreX - radius;
auto ry = centreY - radius;
auto rw = radius * 2.0f;
auto angle = rotaryStartAngle + sliderPos * (rotaryEndAngle - rotaryStartAngle);
// fill
g.setColour(Colour(200,200,200));
g.fillEllipse (rx, ry, rw, rw);
// outline
g.setColour(Colour(150,150,150));
g.drawEllipse (rx, ry, rw, rw, 1.0f);
juce::Path p;
auto pointerLength = radius * 0.33f;
auto pointerThickness = 2.0f;
p.addRectangle(-pointerThickness * 0.5f, -radius, pointerThickness, pointerLength);
p.applyTransform(juce::AffineTransform::rotation (angle).translated (centreX, centreY));
// pointer
g.setColour(Colour(100,100,100));
g.fillPath(p);
}
/** Draws the background for standard buttons
* overrides default Juse button drawing */
void AppLookAndFeel::drawButtonBackground(juce::Graphics& g,
juce::Button& button,
const juce::Colour& backgroundColour,
bool isHighlighted,
bool isButtonDown){
auto buttonArea = button.getLocalBounds();
g.setColour(backgroundColour);
g.drawRect(buttonArea);
if(isHighlighted){
g.setColour(juce::Colours::dimgrey);
g.fillRect(buttonArea);
}
if(isButtonDown){
g.setColour(juce::Colours::darkgrey);
g.fillRect(buttonArea);
}
}