Vital
Loading...
Searching...
No Matches
text_look_and_feel.cpp
Go to the documentation of this file.
2
3#include "skin.h"
4#include "fonts.h"
5#include "synth_button.h"
6#include "synth_section.h"
7#include "synth_slider.h"
8
9TextLookAndFeel::TextLookAndFeel() { }
10
11void TextLookAndFeel::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 // Draws text in place of a rotary arc, showing value as text
15 static constexpr float kTextPercentage = 0.5f;
16
17 SynthSlider* s_slider = dynamic_cast<SynthSlider*>(&slider);
18 float text_percentage = kTextPercentage;
19 bool active = true;
20 String text = slider.getTextFromValue(slider.getValue());
21 float offset = 0.0f;
22 float font_size = slider.getHeight() * text_percentage;
23 if (s_slider) {
24 text_percentage = s_slider->getTextHeightPercentage();
25 font_size = slider.getHeight() * text_percentage;
26 active = s_slider->isActive();
27 text = s_slider->getSliderTextFromValue(slider.getValue());
28
29 offset = s_slider->findValue(Skin::kTextComponentOffset);
30 if (text_percentage == 0.0f)
31 font_size = s_slider->findValue(Skin::kTextComponentFontSize);
32 }
33
34 Colour text_color = slider.findColour(Skin::kTextComponentText, true);
35 if (!active)
36 text_color = text_color.withMultipliedAlpha(0.5f);
37
38 g.setColour(text_color);
39 g.setFont(Fonts::instance()->proportional_light().withPointHeight(font_size));
40 g.drawText(text, x, y + std::round(offset), width, height, Justification::centred, false);
41}
42
43void TextLookAndFeel::drawToggleButton(Graphics& g, ToggleButton& button, bool hover, bool is_down) {
44 // Draws a text-based toggle button
45 static constexpr float kTextPercentage = 0.7f;
46 static constexpr float kTextShrinkage = 0.98f;
47
48 bool toggled = button.getToggleState();
49 SynthButton* s_button = dynamic_cast<SynthButton*>(&button);
50 const std::string* string_lookup = nullptr;
51 if (s_button) {
52 string_lookup = s_button->getStringLookup();
53 }
54
55 // Color based on state
56 if (toggled && string_lookup == nullptr) {
57 if (is_down)
58 g.setColour(button.findColour(Skin::kIconButtonOnPressed, true));
59 else if (hover)
60 g.setColour(button.findColour(Skin::kIconButtonOnHover, true));
61 else
62 g.setColour(button.findColour(Skin::kIconButtonOn, true));
63 }
64 else {
65 if (is_down)
66 g.setColour(button.findColour(Skin::kIconButtonOffPressed, true));
67 else if (hover)
68 g.setColour(button.findColour(Skin::kIconButtonOffHover, true));
69 else
70 g.setColour(button.findColour(Skin::kIconButtonOff, true));
71 }
72
73 String text = button.getButtonText();
74 if (string_lookup) {
75 int index = toggled ? 1 : 0;
76 text = string_lookup[index];
77 }
78
79 int rounding = 0;
80 float text_percentage = kTextPercentage;
81 if (is_down)
82 text_percentage *= kTextShrinkage;
83
84 float font_size = button.getHeight() * text_percentage;
85 SynthSection* section = button.findParentComponentOfClass<SynthSection>();
86 if (section) {
87 font_size = section->findValue(Skin::kButtonFontSize);
88 rounding = section->findValue(Skin::kWidgetRoundedCorner);
89 }
90
91 if (text.isEmpty())
92 g.fillRoundedRectangle(button.getLocalBounds().toFloat(), rounding);
93 else {
94 g.setFont(Fonts::instance()->monospace().withPointHeight(font_size));
95 g.drawText(text, 0, 0, button.getWidth(), button.getHeight(), Justification::centred);
96 }
97}
98
99void TextLookAndFeel::drawTickBox(Graphics& g, Component& component,
100 float x, float y, float w, float h, bool ticked,
101 bool enabled, bool mouse_over, bool button_down) {
102 // Minimal checkbox drawing: if ticked, draw a small red fill inside
103 float border_width = 1.5f;
104 if (ticked) {
105 g.setColour(Colours::red);
106 g.fillRect(x + 3 * border_width, y + 3 * border_width,
107 w - 6 * border_width, h - 6 * border_width);
108 }
109}
110
111void TextLookAndFeel::drawLabel(Graphics& g, Label& label) {
112 // Set label text color to body text
113 Colour text = label.findColour(Skin::kBodyText, true);
114 label.setColour(Label::textColourId, text);
115
116 DefaultLookAndFeel::drawLabel(g, label);
117}
118
119void TextLookAndFeel::drawComboBox(Graphics& g, int width, int height, bool is_down,
120 int button_x, int button_y, int button_w, int button_h, ComboBox& box) {
121 // ComboBox with text styling
122 Colour background = box.findColour(Skin::kTextComponentBackground, true);
123 Colour text = box.findColour(Skin::kBodyText, true);
124 Colour caret = box.findColour(Skin::kTextEditorCaret, true);
125
126 box.setColour(ComboBox::backgroundColourId, background);
127 box.setColour(ComboBox::arrowColourId, caret);
128 box.setColour(ComboBox::outlineColourId, Colours::transparentBlack);
129 box.setColour(ComboBox::textColourId, text);
130
131 DefaultLookAndFeel::drawComboBox(g, width, height, is_down, button_x, button_y, button_w, button_h, box);
132}
void drawComboBox(Graphics &g, int width, int height, const bool button_down, int button_x, int button_y, int button_w, int button_h, ComboBox &box) override
Draws the background and arrow of a ComboBox.
Definition default_look_and_feel.cpp:66
static Fonts * instance()
Gets the singleton instance of the Fonts class.
Definition fonts.h:52
bool isActive() const
Definition synth_slider.h:172
@ kButtonFontSize
Definition skin.h:88
@ kTextComponentFontSize
Definition skin.h:86
@ kTextComponentOffset
Definition skin.h:85
@ kWidgetRoundedCorner
Definition skin.h:104
@ kIconButtonOff
Definition skin.h:185
@ kIconButtonOn
Definition skin.h:188
@ kIconButtonOffHover
Definition skin.h:186
@ kBodyText
Definition skin.h:133
@ kIconButtonOffPressed
Definition skin.h:187
@ kIconButtonOnPressed
Definition skin.h:190
@ kTextComponentBackground
Definition skin.h:147
@ kTextComponentText
Definition skin.h:148
@ kIconButtonOnHover
Definition skin.h:189
@ kTextEditorCaret
Definition skin.h:202
A specialized OpenGlToggleButton with additional functionality for the Vital synth.
Definition synth_button.h:450
const std::string * getStringLookup() const
Definition synth_button.h:483
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
float getTextHeightPercentage()
Definition synth_slider.h:588
float findValue(Skin::ValueId value_id) const override
Definition synth_slider.h:681
String getSliderTextFromValue(double value)
Definition synth_slider.cpp:387
void drawLabel(Graphics &g, Label &label) override
Draws a label with text-focused style.
Definition text_look_and_feel.cpp:111
void drawToggleButton(Graphics &g, ToggleButton &button, bool hover, bool is_down) override
Draws a toggle button with a text-centered style.
Definition text_look_and_feel.cpp:43
void drawComboBox(Graphics &g, int width, int height, bool is_down, int button_x, int button_y, int button_w, int button_h, ComboBox &box) override
Draws a combo box with text styling.
Definition text_look_and_feel.cpp:119
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 using a text-focused design.
Definition text_look_and_feel.cpp:11
void drawTickBox(Graphics &g, Component &component, float x, float y, float w, float h, bool ticked, bool enabled, bool mouse_over, bool button_down) override
Draws a tick box (for checkboxes) with minimal text-focused styling.
Definition text_look_and_feel.cpp:99
Declares classes for OpenGL-based buttons used in the Vital synth UI.
Declares the SynthSlider and related classes, providing various slider styles and functionality in th...