WE Core
Loading...
Searching...
No Matches
RotarySliderV2.h
Go to the documentation of this file.
1/*
2 * File: RotarySliderV2.h
3 *
4 * Version: 1.0.0
5 *
6 * Created: 19/03/2019
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
38 template <typename BASE>
39 class RotarySliderV2 : public BASE {
40
41 public:
42 RotarySliderV2() = default;
43 virtual ~RotarySliderV2() = default;
44
46 inline virtual void drawRotarySlider(juce::Graphics& g,
47 int x,
48 int y,
49 int width,
50 int height,
51 float sliderPosProportional,
52 float rotaryStartAngle,
53 float rotaryEndAngle,
54 juce::Slider &slider) override;
56 };
57
58 template <typename BASE>
60 int /*x*/,
61 int /*y*/,
62 int width,
63 int height,
64 float /*sliderPosProportional*/,
65 float /*rotaryStartAngle*/,
66 float /*rotaryEndAngle*/,
67 juce::Slider &slider) {
68
69 // Calculate useful constants
70 constexpr double arcGap {CoreMath::DOUBLE_TAU / 4};
71 constexpr double rangeOfMotion {CoreMath::DOUBLE_TAU - arcGap};
72
73 const double sliderNormalisedValue {slider.valueToProportionOfLength(slider.getValue())};
74 const double arcEndPoint {sliderNormalisedValue * rangeOfMotion + arcGap / 2};
75
76 constexpr int margin {2};
77 juce::Rectangle<int> area = slider.getBounds();
78 area.reduce(margin, margin);
79 const int diameter {std::min(area.getWidth(), area.getHeight())};
80
81 if (slider.isEnabled()) {
82 g.setColour(slider.findColour(juce::Slider::rotarySliderFillColourId));
83 } else {
84 g.setColour(slider.findColour(juce::Slider::rotarySliderOutlineColourId));
85 }
86
87 juce::Path p;
88
89 // Draw inner ring
90 constexpr int arcSpacing {3};
91 p.addCentredArc(width / 2,
92 height / 2,
93 diameter / 2 - arcSpacing,
94 diameter / 2 - arcSpacing,
96 arcGap / 2,
97 CoreMath::DOUBLE_TAU - (arcGap / 2),
98 true);
99
100 g.strokePath(p, juce::PathStrokeType(0.7f));
101
102 // Draw outer ring
103 p.clear();
104 p.addCentredArc(width / 2,
105 height / 2,
106 diameter / 2,
107 diameter / 2,
109 arcGap / 2,
110 arcEndPoint,
111 true);
112 g.strokePath(p, juce::PathStrokeType(3.0f));
113 }
114}
virtual void drawRotarySlider(juce::Graphics &g, int x, int y, int width, int height, float sliderPosProportional, float rotaryStartAngle, float rotaryEndAngle, juce::Slider &slider) override
constexpr double DOUBLE_PI
Definition CoreMath.h:36
constexpr double DOUBLE_TAU
Definition CoreMath.h:39