-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyLookAndFeel.h
179 lines (147 loc) · 7.63 KB
/
MyLookAndFeel.h
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
#pragma once
#include <JuceHeader.h>
#include "Components/SliderAdaptive.h"
#include "Parameters.h"
class MyLookAndFeel : public LookAndFeel_V4
{
public:
//https://0to255.com/7762f4
//const String accentColour = "";
//const String colourDark = "ff324399"; //sfondo
const String colourDark = "ff160970"; //sfondo
const String colourLessDark = "ff3213ee"; //icone slider
const String colourLessLight = "ff8a7bf4"; //riempimento slider
const String colourLight = "ffbcb1fa"; //sfondo slider
//slider sfondo non hover: a99bfa
MyLookAndFeel(/*int NumComponents*/) {
//numComponents = NumComponents;
setColour (Slider::backgroundColourId, Colour::fromString(colourLight)); //sfondo slider
//setColour (Slider::trackColourId, Colour::fromString(colourLight));
setColour (Slider::thumbColourId, Colour::fromString (colourLessDark));
setColour (Slider::rotarySliderFillColourId, Colour::fromString (colourLessLight)); //riempimento slider
setColour (Slider::rotarySliderOutlineColourId, Colour::fromString (colourLight)); //bordo slider
setColour (DrawableButton::backgroundColourId, Colours::transparentWhite);
// setColour (TextButton::buttonColourId, Colours::white);
// setColour (TextButton::textColourOffId, Colours::white);
// setColour (TextButton::buttonOnColourId, findColour (TextButton::textColourOffId));
// setColour (TextButton::textColourOnId, findColour (TextButton::buttonColourId));
}
MouseCursor getMouseCursorFor(Component& /*c*/) override{
#if DEBUG
return MouseCursor(MouseCursor::StandardCursorType::CrosshairCursor);
#else
return MouseCursor(MouseCursor::StandardCursorType::NoCursor);
#endif
}
void drawRotarySlider(Graphics& g,
int /*x*/, int /*y*/, int width, int height,
float sliderPosProportional, float rotaryStartAngle, float rotaryEndAngle,
Slider& slider) override
{
//TODO: sfumatura radiale (?)
const auto minDim = jmin(width,height);
auto bounds = Rectangle<int> (minDim, minDim).toFloat()/*.reduced (DECK_PADDING)*/;
bounds.setCentre(width/2,height/2);//GCC traduce da solo /2 in *0.5? boh, credo di si
{// Draw outline + background
Path p;
p.addPieSegment (bounds.reduced(SLIDER_PADDING),rotaryStartAngle,rotaryEndAngle,INNER_CIRCLE_TO_SLIDER_RATIO);
auto colour = slider.findColour (Slider::backgroundColourId)
.withMultipliedSaturation (slider.isMouseOver () ? 0.7f : 1.4f);
// DBG(colour.toString ());
g.setColour (colour);
g.fillPath (p.createPathWithRoundedCorners (COMPONENT_CORNER_ROUNDING));
//const auto lineThickness = jmin (15.0f, (float) minDim * 0.45f) * 0.3f;//TODO: aggiustare magic numbers
//const auto lineThickness = SLIDER_PADDING*2;
//g.strokePath (outline.createPathWithRoundedCorners (COMPONENT_CORNER_ROUNDING),PathStrokeType (lineThickness));//TODO: aggiustare magic numbers
}
{// Draw value pie
Path p;
const auto angle = jmap(sliderPosProportional,rotaryStartAngle,rotaryEndAngle);
SliderAdaptive *sliderA = dynamic_cast<SliderAdaptive*> (&slider);
p.addPieSegment (bounds.reduced(SLIDER_PADDING),
sliderA->getSnapToMiddleValue()? angle-0.03 : rotaryStartAngle,
sliderA->getSnapToMiddleValue()? angle+0.03 : angle,
INNER_CIRCLE_TO_SLIDER_RATIO);
auto colour = slider.findColour (Slider::rotarySliderFillColourId)
.withMultipliedSaturation (slider.isMouseOver () ? 0.8f : 1.4f);
g.setColour (colour);
g.fillPath (p.createPathWithRoundedCorners (COMPONENT_CORNER_ROUNDING));
}
}
void drawLinearSlider (Graphics& g, int x, int y, int width, int height,
float sliderPos, float minSliderPos, float maxSliderPos,
const Slider::SliderStyle style, Slider& slider) override
{
if (style == Slider::LinearHorizontal)
{
drawLinearSliderBackground (g, x, y, width, height, sliderPos, minSliderPos, maxSliderPos, style, slider);
drawLinearSliderThumb (g, x, y, width, height, sliderPos, minSliderPos, maxSliderPos, style, slider);
}
else
{
LookAndFeel_V4::drawLinearSlider (g, x, y, width, height, sliderPos, minSliderPos, maxSliderPos, style, slider);
}
}
/**
* @brief drawLinearSliderBackground draws the track of the lider
*/
void drawLinearSliderBackground (Graphics& g, int x, int y, int width, int height,
float sliderPos,
float minSliderPos,
float maxSliderPos,
const Slider::SliderStyle style, Slider& slider) override
{
if (style == Slider::LinearHorizontal)
{
auto colour = slider.findColour (Slider::backgroundColourId)
.withMultipliedSaturation (slider.isMouseOver () ? 1.0f : 1.3f);
g.setColour (colour);
Path backGround;
backGround.addRoundedRectangle (slider.getLocalBounds (), COMPONENT_CORNER_ROUNDING);
g.fillPath(backGround);
}
else{
LookAndFeel_V4::drawLinearSliderBackground (g, x, y, width, height, sliderPos, minSliderPos, maxSliderPos, style, slider);
}
}
void drawLinearSliderThumb (Graphics& g, int x, int y, int width, int height,
float sliderPos,
float minSliderPos,
float maxSliderPos,
const Slider::SliderStyle style, Slider& slider) override
{
if (style == Slider::LinearHorizontal)
{
auto thumb = Rectangle<float>(slider.getHeight()*0.2f,slider.getHeight());
thumb.setCentre (sliderPos, slider.getLocalBounds ().getCentreY());
Path roundedThumb;
roundedThumb.addRoundedRectangle (thumb, COMPONENT_CORNER_ROUNDING/2);
auto baseColour = slider.findColour (Slider::thumbColourId)
.withMultipliedSaturation (slider.isMouseOver () ? 1.0f : 1.3f);
g.setColour (baseColour);
g.fillPath (roundedThumb);
auto thumbLine = thumb;
thumbLine.removeFromRight (thumb.getWidth ()/3.0f);
thumbLine.removeFromLeft (thumb.getWidth ()/3.0f);
auto baseColourLine = slider.findColour (Slider::rotarySliderFillColourId)
.withMultipliedSaturation (slider.isMouseOver () ? 1.0f : 1.3f);
g.setColour (baseColourLine);
g.fillRect (thumbLine);
}
else
{
LookAndFeel_V4::drawLinearSliderThumb (g, x, y, width, height, sliderPos, minSliderPos, maxSliderPos, style, slider);
}
}
// int getSliderThumbRadius (Slider& slider) override
// {
// return slider.isHorizontal() ? static_cast<int> ((float) slider.getHeight() / 3)
// : static_cast<int> ((float) slider.getWidth() / 3);
// }
// int getNumComponents() const{
// return numComponents;
// }
private:
//int numComponents;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MyLookAndFeel)
};