Vital
Loading...
Searching...
No Matches
preset_selector.cpp
Go to the documentation of this file.
1#include "preset_selector.h"
2
3#include "skin.h"
5#include "fonts.h"
6
9 font_height_ratio_(kDefaultFontHeightRatio),
10 round_amount_(0.0f), hover_(false), text_component_(false) {
11 static const PathStrokeType arrow_stroke(0.05f, PathStrokeType::JointStyle::curved,
12 PathStrokeType::EndCapStyle::rounded);
13
14 text_ = std::make_unique<PlainTextComponent>("Text", "Init");
15 text_->setFontType(PlainTextComponent::kTitle);
16 text_->setInterceptsMouseClicks(false, false);
17 addOpenGlComponent(text_.get());
18 text_->setScissor(true);
19 Path prev_line, prev_shape, next_line, next_shape;
20
21 // Previous preset button
22 prev_preset_ = std::make_unique<OpenGlShapeButton>("Prev");
23 addAndMakeVisible(prev_preset_.get());
24 addOpenGlComponent(prev_preset_->getGlComponent());
25 prev_preset_->addListener(this);
26 prev_line.startNewSubPath(0.65f, 0.3f);
27 prev_line.lineTo(0.35f, 0.5f);
28 prev_line.lineTo(0.65f, 0.7f);
29
30 arrow_stroke.createStrokedPath(prev_shape, prev_line);
31 prev_shape.addLineSegment(Line<float>(0.0f, 0.0f, 0.0f, 0.0f), 0.2f);
32 prev_shape.addLineSegment(Line<float>(1.0f, 1.0f, 1.0f, 1.0f), 0.2f);
33 prev_preset_->setShape(prev_shape);
34
35 // Next preset button
36 next_preset_ = std::make_unique<OpenGlShapeButton>("Next");
37 addAndMakeVisible(next_preset_.get());
38 addOpenGlComponent(next_preset_->getGlComponent());
39 next_preset_->addListener(this);
40 next_line.startNewSubPath(0.35f, 0.3f);
41 next_line.lineTo(0.65f, 0.5f);
42 next_line.lineTo(0.35f, 0.7f);
43
44 arrow_stroke.createStrokedPath(next_shape, next_line);
45 next_shape.addLineSegment(Line<float>(0.0f, 0.0f, 0.0f, 0.0f), 0.2f);
46 next_shape.addLineSegment(Line<float>(1.0f, 1.0f, 1.0f, 1.0f), 0.2f);
47 next_preset_->setShape(next_shape);
48}
49
52
56 float round_amount = findValue(Skin::kWidgetRoundedCorner);
57 g.setColour(findColour(Skin::kPopupSelectorBackground, true));
58 g.fillRoundedRectangle(0, 0, getWidth(), getHeight(), round_amount);
59}
60
64
65 if (text_component_) {
66 SynthSection* parent = findParentComponentOfClass<SynthSection>();
67 int button_height = parent->findValue(Skin::kTextComponentFontSize);
68 int offset = parent->findValue(Skin::kTextComponentOffset);
69 int button_y = (getHeight() - button_height) / 2 + offset;
70 prev_preset_->setBounds(0, button_y, button_height, button_height);
71 next_preset_->setBounds(getWidth() - button_height, button_y, button_height, button_height);
72 text_->setBounds(getLocalBounds().translated(0, offset));
73 text_->setTextSize(button_height);
74 }
75 else {
76 int height = getHeight();
77 text_->setBounds(Rectangle<int>(height, 0, getWidth() - 2 * height, height));
78 text_->setTextSize(height * font_height_ratio_);
79 prev_preset_->setBounds(0, 0, height, height);
80 next_preset_->setBounds(getWidth() - height, 0, height, height);
81 text_->setColor(findColour(Skin::kPresetText, true));
82 }
83}
84
88void PresetSelector::mouseDown(const MouseEvent& e) {
89 textMouseDown(e);
90}
91
95void PresetSelector::mouseUp(const MouseEvent& e) {
96 textMouseUp(e);
97}
98
101void PresetSelector::buttonClicked(Button* clicked_button) {
102 if (clicked_button == prev_preset_.get())
103 clickPrev();
104 else if (clicked_button == next_preset_.get())
105 clickNext();
106}
107
110void PresetSelector::setText(String text) {
111 text_->setText(text);
112}
113
118void PresetSelector::setText(String left, String center, String right) {
119 text_->setText(left + " " + center + " " + right);
120}
121
124 for (Listener* listener : listeners_)
125 listener->prevClicked();
126}
127
130 for (Listener* listener : listeners_)
131 listener->nextClicked();
132}
133
136void PresetSelector::textMouseDown(const MouseEvent& e) {
137 for (Listener* listener : listeners_)
138 listener->textMouseDown(e);
139}
140
143void PresetSelector::textMouseUp(const MouseEvent& e) {
144 for (Listener* listener : listeners_)
145 listener->textMouseUp(e);
146}
@ kTitle
Definition open_gl_image_component.h:308
Interface for objects that want to be notified of PresetSelector events.
Definition preset_selector.h:24
PresetSelector()
Constructor.
Definition preset_selector.cpp:8
void resized() override
Resizes and lays out the child components.
Definition preset_selector.cpp:62
void buttonClicked(Button *clicked_button) override
Definition preset_selector.cpp:101
void clickNext()
Programmatically simulate a click on the "next" preset button.
Definition preset_selector.cpp:129
void clickPrev()
Programmatically simulate a click on the "previous" preset button.
Definition preset_selector.cpp:123
void mouseDown(const MouseEvent &e) override
Definition preset_selector.cpp:88
~PresetSelector()
Destructor.
Definition preset_selector.cpp:51
void setText(String text)
Definition preset_selector.cpp:110
void paintBackground(Graphics &g) override
Definition preset_selector.cpp:55
void mouseUp(const MouseEvent &e) override
Definition preset_selector.cpp:95
@ kTextComponentFontSize
Definition skin.h:86
@ kTextComponentOffset
Definition skin.h:85
@ kWidgetRoundedCorner
Definition skin.h:104
@ kPopupSelectorBackground
Definition skin.h:143
@ kPresetText
Definition skin.h:132
Base class for all synthesizer sections, providing UI layout, painting, and interaction logic.
Definition synth_section.h:193
virtual void resized() override
Called when the component is resized. Arranges layout of child components.
Definition synth_section.cpp:35
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
void addOpenGlComponent(OpenGlComponent *open_gl_component, bool to_beginning=false)
Definition synth_section.cpp:489
Declares the PresetSelector class which provides a UI component for selecting presets.