WE Core
Loading...
Searching...
No Matches
LinearSliderV2.h
Go to the documentation of this file.
1/*
2 * File: LinearSliderV2.h
3 *
4 * Version: 1.0.0
5 *
6 * Created: 04/07/2021
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
30
39 template <typename BASE>
40 class LinearSliderV2 : public BASE {
41 public:
42 LinearSliderV2() = default;
43 virtual ~LinearSliderV2() = default;
44
46 inline virtual void drawLinearSlider(juce::Graphics& g,
47 int x,
48 int y,
49 int width,
50 int height,
51 float sliderPos,
52 float minSliderPos,
53 float maxSliderPos,
54 const juce::Slider::SliderStyle style,
55 juce::Slider& slider) override;
56
57 inline virtual 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 inline virtual void drawLinearSliderBackground(juce::Graphics& g,
69 int x,
70 int y,
71 int width,
72 int height,
73 float sliderPos,
74 float minSliderPos,
75 float maxSliderPos,
76 const juce::Slider::SliderStyle style,
77 juce::Slider& slider) override;
79 };
80
81 template <typename BASE>
83 int x,
84 int y,
85 int width,
86 int height,
87 float sliderPos,
88 float minSliderPos,
89 float maxSliderPos,
90 const juce::Slider::SliderStyle style,
91 juce::Slider& slider) {
92 // Draw background first
93 drawLinearSliderBackground(g, x, y, width, height, sliderPos, minSliderPos, maxSliderPos, style, slider);
94 drawLinearSliderThumb(g, x, y, width, height, sliderPos, minSliderPos, maxSliderPos, style, slider);
95 }
96
97 template <typename BASE>
99 int x,
100 int y,
101 int width,
102 int height,
103 float sliderPos,
104 float minSliderPos,
105 float /*maxSliderPos*/,
106 const juce::Slider::SliderStyle style,
107 juce::Slider& slider) {
108
109 constexpr float MARGIN {2};
110
111 if (slider.isEnabled()) {
112 g.setColour(slider.findColour(juce::Slider::thumbColourId));
113 } else {
114 g.setColour(slider.findColour(juce::Slider::backgroundColourId));
115 }
116
117 if (style == juce::Slider::LinearHorizontal) {
118 // Horizontal rectangle
119 g.fillRect(juce::Rectangle<float>(minSliderPos,
120 y + MARGIN,
121 sliderPos - minSliderPos,
122 height - 3 * MARGIN));
123 } else {
124 // Vertical rectangle
125 g.fillRect(juce::Rectangle<float>(x + MARGIN,
126 y + height,
127 width - 3 * MARGIN,
128 -(y + height - sliderPos)));
129 }
130 }
131
132 template <typename BASE>
134 int x,
135 int y,
136 int width,
137 int height,
138 float /*sliderPos*/,
139 float /*minSliderPos*/,
140 float /*maxSliderPos*/,
141 const juce::Slider::SliderStyle style,
142 juce::Slider& slider) {
143
144 constexpr int MARGIN {2};
145 constexpr int LINE_WIDTH {1};
146
147 if (slider.isEnabled()) {
148 g.setColour(slider.findColour(juce::Slider::trackColourId));
149 } else {
150 g.setColour(slider.findColour(juce::Slider::backgroundColourId));
151 }
152
153 if (style == juce::Slider::LinearHorizontal) {
154 // Horizontal line
155 g.fillRect(juce::Rectangle<float>(x,
156 y + height - MARGIN - (LINE_WIDTH / 2),
157 width,
158 LINE_WIDTH));
159 } else {
160 // Vertical line
161 g.fillRect(juce::Rectangle<float>(x + width - MARGIN - (LINE_WIDTH / 2),
162 y,
163 LINE_WIDTH,
164 height));
165
166 }
167 }
168}
virtual void drawLinearSliderThumb(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 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 drawLinearSliderBackground(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