Vital
Loading...
Searching...
No Matches
curve_look_and_feel.cpp
Go to the documentation of this file.
2
3#include "skin.h"
4#include "fonts.h"
5#include "poly_utils.h"
6#include "futils.h"
7#include "synth_slider.h"
8
9CurveLookAndFeel::CurveLookAndFeel() { }
10
11void CurveLookAndFeel::drawRotarySlider(Graphics& g, int x, int y, int width, int height,
12 float slider_t, float start_angle, float end_angle,
13 Slider& slider) {
14 bool active = true;
15 bool bipolar = false;
16
17 // Check if we are dealing with a SynthSlider and get its active/bipolar state
18 SynthSlider* s_slider = dynamic_cast<SynthSlider*>(&slider);
19 if (s_slider) {
20 active = s_slider->isActive();
21 bipolar = s_slider->isBipolar();
22 }
23 // Determine maximum size and rounding for the curve based on the parent SynthSection
24 float rounding = 0.0f;
25 float short_side = std::min(width, height);
26 float max_width = short_side;
27 SynthSection* section = slider.findParentComponentOfClass<SynthSection>();
28 if (section) {
29 rounding = section->findValue(Skin::kWidgetRoundedCorner);
30 max_width = std::min(max_width, section->findValue(Skin::kKnobArcSize));
31 }
32
33 int inset = rounding / sqrtf(2.0f) + (short_side - max_width) / 2.0f;
34 drawCurve(g, slider, x + inset, y + inset, width - 2.0f * inset, height - 2.0f * inset, active, bipolar);
35}
36
37void CurveLookAndFeel::drawCurve(Graphics& g, Slider& slider, int x, int y, int width, int height,
38 bool active, bool bipolar) {
39 static constexpr int kResolution = 16;
40 static constexpr float kLineWidth = 2.0f;
41 PathStrokeType stroke(kLineWidth, PathStrokeType::beveled, PathStrokeType::rounded);
42
43 float curve_width = std::min(width, height);
44 float x_offset = (width - curve_width) / 2.0f;
45 float power = -slider.getValue();
46 Path path;
47 float start_x = x + x_offset + kLineWidth / 2.0f;
48 float start_y = y + height - kLineWidth / 2.0f;
49 path.startNewSubPath(start_x, start_y);
50 float active_width = curve_width - kLineWidth;
51 float active_height = curve_width - kLineWidth;
52
53 // Construct the path for the curve, adjusting for bipolar if needed
54 if (bipolar) {
55 float half_width = active_width / 2.0f;
56 float half_height = active_height / 2.0f;
57 // Left half of curve (negative portion)
58 for (int i = 0; i < kResolution / 2; ++i) {
59 float t = 2 * (i + 1.0f) / kResolution;
60 float power_t = vital::futils::powerScale(t, -power);
61 path.lineTo(start_x + t * half_width, start_y - power_t * half_height);
62 }
63 // Right half of curve (positive portion)
64 for (int i = 0; i < kResolution / 2; ++i) {
65 float t = 2 * (i + 1.0f) / kResolution;
66 float power_t = vital::futils::powerScale(t, power);
67 path.lineTo(start_x + t * half_width + half_width, start_y - power_t * half_height - half_height);
68 }
69 }
70 else {
71 // Unipolar curve
72 for (int i = 0; i < kResolution; ++i) {
73 float t = (i + 1.0f) / kResolution;
74 float power_t = vital::futils::powerScale(t, power);
75 path.lineTo(start_x + t * active_width, start_y - power_t * active_height);
76 }
77 }
78
79 Colour line = slider.findColour(Skin::kRotaryArc, true);
80 if (!active)
81 line = slider.findColour(Skin::kWidgetPrimaryDisabled, true);
82
83 g.setColour(line);
84 g.strokePath(path, stroke);
85}
86
void drawRotarySlider(Graphics &g, int x, int y, int width, int height, float slider_t, float start_angle, float end_angle, Slider &slider) override
Draws a rotary slider with a curve-shaped indicator.
Definition curve_look_and_feel.cpp:11
void drawCurve(Graphics &g, Slider &slider, int x, int y, int width, int height, bool active, bool bipolar)
Draws the power-scale curve for the slider.
Definition curve_look_and_feel.cpp:37
bool isBipolar() const
Definition synth_slider.h:168
bool isActive() const
Definition synth_slider.h:172
@ kKnobArcSize
Definition skin.h:89
@ kWidgetRoundedCorner
Definition skin.h:104
@ kWidgetPrimaryDisabled
Definition skin.h:167
@ kRotaryArc
Definition skin.h:150
Base class for all synthesizer sections, providing UI layout, painting, and interaction logic.
Definition synth_section.h:193
float findValue(Skin::ValueId value_id) const
Finds a value in the skin overrides or from the parent if not found locally.
Definition synth_section.cpp:18
A specialized slider with extended functionality for modulation, parameter control,...
Definition synth_slider.h:314
Contains faster but less accurate versions of utility math functions, such as exponential,...
force_inline mono_float powerScale(mono_float value, mono_float power)
A power-scaling function to map a linear range to a curved response.
Definition futils.h:455
Declares the SynthSlider and related classes, providing various slider styles and functionality in th...