Vital
Loading...
Searching...
No Matches
wavetable_component_overlay.cpp
Go to the documentation of this file.
2
4#include "fonts.h"
5#include "skin.h"
6
8 static constexpr float kTextHeightRatio = 0.6f;
10
11 if (findParentComponentOfClass<SynthGuiInterface>() == nullptr)
12 return;
13
14 // Set base colors and styles
15 background_.setColor(findColour(Skin::kBody, true));
16 border_.setColor(findColour(Skin::kWidgetPrimary1, true));
17 Colour lighten = findColour(Skin::kLightenScreen, true);
18 Colour text = findColour(Skin::kBodyText, true);
19 lines_.setColor(lighten);
20 title_backgrounds_.setColor(lighten);
21 float width = getWidth();
22 float line_width = 2.0f / width;
23
24 // Set line positions
25 for (int i = 0; i < line_positions_.size() && i < kMaxLines; ++i)
26 lines_.setQuad(i, line_positions_[i] * 2.0f / width - 1.0f, -1.0f, line_width, 2.0f);
27
28 lines_.setNumQuads(std::min<int>(static_cast<int>(line_positions_.size()), kMaxLines));
29
30 // Set titles and background quads
31 int num_titles = static_cast<int>(titles_.size());
32 int num_positions = static_cast<int>(line_positions_.size());
33 int title_height = getHeight() * WavetableComponentOverlay::kTitleHeightRatio;
34 float gl_title_height = title_height * 2.0f / getHeight();
35
36 for (int i = 0; i < num_titles && i - 1 < num_positions; ++i) {
37 std::string title = titles_[i];
38 title_texts_[i]->setColor(text);
39 title_texts_[i]->setTextSize(title_height * kTextHeightRatio);
40 title_texts_[i]->setText(title);
41 title_texts_[i]->setActive(true);
42
43 int start_position = 0;
44 int end_position = getWidth();
45 if (i > 0)
46 start_position = line_positions_[i - 1];
47 if (i < line_positions_.size())
48 end_position = line_positions_[i];
49
50 title_texts_[i]->setBounds(start_position, 0, end_position - start_position, title_height);
51 if (title.empty())
52 title_backgrounds_.setQuad(i, -2.0f, -2.0f, 0.0f, 0.0f);
53 else {
54 title_backgrounds_.setQuad(i, start_position * 2.0f / getWidth() - 1.0f, 1.0f - gl_title_height,
55 (end_position - start_position) * 2.0f / getWidth(), gl_title_height);
56 }
57
58 title_texts_[i]->redrawImage(true);
59 }
60
61 title_backgrounds_.setNumQuads(num_titles);
62 for (int i = num_titles; i <= kMaxLines; ++i) {
63 title_texts_[i]->setActive(false);
64 }
65}
66
67void WavetableComponentOverlay::setEditBounds(Rectangle<int> bounds) {
68 edit_bounds_ = bounds;
69 int x = edit_bounds_.getX() + (edit_bounds_.getWidth() - controls_width_) / 2;
70 controls_background_.setBounds(x, edit_bounds_.getY(), controls_width_, edit_bounds_.getHeight());
71 controls_background_.repaint();
72
73 repaint();
74}
75
80
85
87 if (mouse_up) {
89 listener->frameDoneEditing();
90 }
91 else {
93 listener->frameChanged();
94 }
95}
96
100
104
108
void setQuad(int i, float x, float y, float w, float h)
Sets the position and size of a quad in normalized device space.
Definition open_gl_multi_quad.h:313
void setNumQuads(int num_quads)
Sets how many quads will actually be drawn (up to max_quads).
Definition open_gl_multi_quad.h:92
force_inline void setColor(Colour color)
Sets the base color for the quads.
Definition open_gl_multi_quad.h:102
@ kWidgetPrimary1
Definition skin.h:165
@ kBodyText
Definition skin.h:133
@ kLightenScreen
Definition skin.h:141
@ kBody
Definition skin.h:129
A base class representing a component in a wavetable synthesis chain.
Definition wavetable_component.h:32
void setPositions()
Updates all OpenGL components and text positions after changes to lines or titles.
Definition wavetable_component_overlay.cpp:7
static constexpr int kMaxLines
Maximum possible lines for control divisions.
Definition wavetable_component_overlay.h:45
A listener interface for receiving changes to the wavetable overlay.
Definition wavetable_component_overlay.h:118
int getWidgetPadding()
Gets the widget padding.
Definition wavetable_component_overlay.cpp:109
void setComponent(WavetableComponent *component)
Sets the WavetableComponent that this overlay is editing.
Definition wavetable_component_overlay.cpp:81
static constexpr float kWidgetHeightForWidth
Definition wavetable_component_overlay.h:29
ControlsBackground controls_background_
Definition wavetable_component_overlay.h:300
virtual void setEditBounds(Rectangle< int > bounds)
Sets the editing bounds within which controls and titles are placed.
Definition wavetable_component_overlay.cpp:67
void resetOverlay()
Resets the overlay, clearing any associated component.
Definition wavetable_component_overlay.cpp:76
std::vector< Listener * > listeners_
Definition wavetable_component_overlay.h:301
static constexpr float kTitleHeightRatio
Definition wavetable_component_overlay.h:32
static constexpr float kTitleHeightForWidth
Ratio constants for layout and sizing.
Definition wavetable_component_overlay.h:28
int getDividerX()
Gets the x position of a divider line.
Definition wavetable_component_overlay.cpp:101
Rectangle< int > edit_bounds_
Definition wavetable_component_overlay.h:302
static constexpr float kDividerPoint
Definition wavetable_component_overlay.h:31
float getTitleHeight()
Gets the title height based on ratio and current edit bounds.
Definition wavetable_component_overlay.cpp:97
int getWidgetHeight()
Gets the widget height for controls.
Definition wavetable_component_overlay.cpp:105
WavetableComponent * current_component_
Definition wavetable_component_overlay.h:299
int controls_width_
Definition wavetable_component_overlay.h:303
void notifyChanged(bool mouse_up)
Notifies listeners that a change has occurred to the frame.
Definition wavetable_component_overlay.cpp:86
static void setOverlayOwner(WavetableComponentOverlay *overlay, WavetableComponent *owner)
Set the owner WavetableComponent of an already created overlay.
Definition wavetable_overlay_factory.cpp:42