-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBasicStyle.cpp
More file actions
204 lines (144 loc) · 5.94 KB
/
BasicStyle.cpp
File metadata and controls
204 lines (144 loc) · 5.94 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
/*
==============================================================================
BasicStyle.cpp
Created: 6 Jul 2022 3:46:46pm
Author: trissy the sissy
==============================================================================
*/
#include <JuceHeader.h>
#include "BasicStyle.h"
//==============================================================================
//BasicStyle::
/** Draws the contents of a standard ToggleButton. */
void BasicStyle::drawToggleButton (Graphics& g, ToggleButton& t,
bool shouldDrawButtonAsHighlighted, bool shouldDrawButtonAsDown)
{
//button pressed drawing
if(shouldDrawButtonAsDown)
{
g.setColour(Colours::black);
g.fillRect(t.getLocalBounds() );
}
else {
//draw unpressed button based on toggle state
if(t.getToggleState())
{
g.setColour(Colours::lightblue.withAlpha(0.5f));
}
else
{
g.setColour(Colours::lightgrey.withAlpha(0.3f));
}
g.fillRect(t.getLocalBounds());
g.setColour(Colours::lightgrey);
g.drawRect(t.getLocalBounds());
//draw button name
g.setColour(t.findColour(0x1006502));
g.drawText(t.getButtonText(), t.getLocalBounds(), Justification::centred);
}
}
void BasicStyle::drawLinearSlider (Graphics& g,
int x, int y, int width, int height,
float sliderPos,
float minSliderPos,
float maxSliderPos,
const Slider::SliderStyle,
Slider& s)
{
//drawing linear vertical slider
if(s.getSliderStyle() == Slider::LinearVertical)
{
//ratio of the height to draw
float ratio = s.getValue()/s.getMaximum();
//how many rectangles
int numDrawn = int(20 *ratio);
for(int i=0; i<20;i++)
{
float ratio = i/20.0f;
g.setColour(Colours::lightblue);
g.fillRect(width/2-15.0f, height-ratio*height, 30.0f, 10.0f);
if(i>= numDrawn) break;
}
//DRAWING NUMBERS
juce::String suffix = s.getTextValueSuffix();
if(s.getTextBoxPosition() == Slider::TextBoxLeft)
{
g.setColour(Colours::black.withAlpha(0.4f));
float gain = s.getValue();
gain = gain;
gain = juce::Decibels::gainToDecibels(gain);
gain = std::ceil(gain*100)/100;
g.drawText((String)gain+ suffix, 0, 0, width, height, Justification::centred);
}
if(s.getTextBoxPosition() == Slider::TextBoxRight)
{
g.setColour(Colours::black.withAlpha(0.4f));
float percent = 100*s.getValue();
g.drawText((String)percent+ suffix, 0, 0, width, height, Justification::centred);
}
}
//Linear horizontal style
else if(s.getSliderStyle() == Slider::LinearHorizontal)
{
//draw outline
g.setColour(Colours::black);
g.drawRect(x, y, width, height);
//drawing number
g.setColour(Colours::lightgrey);
g.drawText(s.getTextFromValue(s.getValue()), s.getLocalBounds(), Justification::centred);
//draw rectangle
g.fillRect(x, y,int(sliderPos-12) , height);
g.setColour(Colours::red);
g.drawRect(x, y,int(sliderPos-12) , height);
if(s.getValue()> (s.getMaximum()/2))
{
g.setColour(Colours::white);
g.drawText((s.getTextFromValue(s.getValue())), s.getLocalBounds(), Justification::centred);
}
}
}
void BasicStyle::drawRotarySlider (Graphics& g, int x, int y, int width, int height,
float sliderPosProportional, float rotaryStartAngle,
float rotaryEndAngle, Slider& s)
{
//draw a circle of blue balls
//convert the value of the slider to an integer 1- 20
//ratio/number of balls to draw
float ratio = s.getValue()/s.getMaximum();
int numDrawn = int(20 *ratio);
float pitwo = 2 * 3.1415;
float r = width/2-12;
//draw each ball at the right place until we get to the ratio
for(int i=0; i< 20;i++)
{
//distances from centre to each ball
float adjacent = cos((i/20.0f)*pitwo)*r;
float opposite = sin((i/20.0f)*pitwo)*r;
//x is middle minus distance to x
//y is midd +distance to y
//draw balls
g.setColour(Colours::aliceblue);
g.fillEllipse(width/2-adjacent, height/2-opposite, 9.0f, 9.0f);
//another ball
g.setColour(Colours::lightblue);
g.drawEllipse(width/2-adjacent, height/2-opposite, 9.0f, 9.0f, 2.0f);
//stop drawing
if(i>(numDrawn-2)) break;
}
//get suffix from slider
juce::String suffix = s.getTextValueSuffix();
//write values on sliders
if(s.getTextBoxPosition() == Slider::TextBoxLeft)
{
float gain = s.getValue();
gain = 4* gain;
gain = std::pow(10, gain);
gain = juce::Decibels::gainToDecibels(gain);
g.drawText((String)gain+ suffix, 0, 0, width, height, Justification::centred);
}
if(s.getTextBoxPosition() == Slider::TextBoxRight)
{
float perc = s.getValue()*100;
g.drawText((String)perc + suffix, 0, 0, width, height, Justification::centred);
}
}