Vital
Loading...
Searching...
No Matches
text_selector.cpp
Go to the documentation of this file.
1
3
4#include "text_selector.h"
5
7#include "lfo_section.h"
8#include "fonts.h"
9#include "skin.h"
10
12TextSelector::TextSelector(String name) : SynthSlider(name), long_lookup_(nullptr) { }
13
17void TextSelector::mouseDown(const juce::MouseEvent &e) {
18 if (e.mods.isPopupMenu()) {
20 return;
21 }
22
23 const std::string* lookup = long_lookup_ ? long_lookup_ : string_lookup_;
24
25 PopupItems options;
26 for (int i = 0; i <= getMaximum(); ++i)
27 options.addItem(i, lookup[i]);
28
29 parent_->showPopupSelector(this, Point<int>(0, getHeight()), options, [=](int value) { setValue(value); });
30}
31
34void TextSelector::mouseUp(const MouseEvent& e) {
35 if (e.mods.isPopupMenu()) {
37 return;
38 }
39}
40
44void PaintPatternSelector::paint(Graphics& g) {
45 static constexpr float kLineWidthHeightRatio = 0.05f;
46
47 std::vector<std::pair<float, float>> pattern = LfoSection::getPaintPattern(getValue());
48 int height = getHeight() - 2 * padding_ - 1;
49 int width = getWidth() - 2 * padding_ - 1;
50 float buffer = padding_ + 0.5f;
51 Path path;
52 path.startNewSubPath(buffer, buffer + height);
53 for (auto& pair : pattern)
54 path.lineTo(buffer + pair.first * width, buffer + (1.0f - pair.second) * height);
55
56 path.lineTo(buffer + width, buffer + height);
57
58 if (isActive()) {
59 g.setColour(findColour(Skin::kWidgetSecondary1, true));
60 g.fillPath(path);
61 g.setColour(findColour(Skin::kWidgetSecondary2, true));
62 g.fillPath(path);
63 }
64 else {
65 g.setColour(findColour(Skin::kLightenScreen, true));
66 g.fillPath(path);
67 }
68
69 g.setColour(isActive() ? findColour(Skin::kWidgetCenterLine, true) : findColour(Skin::kLightenScreen, true));
70
71 int line_width = getHeight() * kLineWidthHeightRatio;
72 line_width += (line_width + 1) % 2; // Ensures an even number
73 g.strokePath(path, PathStrokeType(line_width, PathStrokeType::curved, PathStrokeType::rounded));
74}
static std::vector< std::pair< float, float > > getPaintPattern(int pattern)
Retrieves a paint pattern as a vector of (x, y) pairs.
Definition lfo_section.h:54
SynthSection * parent_
The parent SynthSection.
Definition synth_slider.h:289
bool isActive() const
Definition synth_slider.h:172
void paint(Graphics &g) override
Definition text_selector.cpp:44
@ kWidgetSecondary1
Definition skin.h:168
@ kLightenScreen
Definition skin.h:141
@ kWidgetCenterLine
Definition skin.h:164
@ kWidgetSecondary2
Definition skin.h:169
void showPopupSelector(Component *source, Point< int > position, const PopupItems &options, std::function< void(int)> callback, std::function< void()> cancel={ })
Shows a popup selector with options.
Definition synth_section.cpp:119
A specialized slider with extended functionality for modulation, parameter control,...
Definition synth_slider.h:314
virtual void mouseDown(const MouseEvent &e) override
Mouse event overrides for custom behavior.
Definition synth_slider.cpp:234
virtual void mouseUp(const MouseEvent &e) override
Definition synth_slider.cpp:302
const std::string * string_lookup_
Definition synth_slider.h:763
void mouseDown(const MouseEvent &e) override
Definition text_selector.cpp:17
const std::string * long_lookup_
Optional alternate lookup table for longer strings.
Definition text_selector.h:37
TextSelector(String name)
Constructs a TextSelector with the given name.
Definition text_selector.cpp:12
void mouseUp(const MouseEvent &e) override
Definition text_selector.cpp:34
A hierarchical structure of popup menu items for a selector component.
Definition synth_section.h:29
void addItem(int sub_id, const std::string &sub_name, bool sub_selected=false)
Adds a new item as a submenu entry.
Definition synth_section.h:51
Declares the TextSelector class and PaintPatternSelector class for selecting text-based options and d...