Vital
|
A component for rendering multiple quads using OpenGL, with customizable colors, rounding, and other effects. More...
#include <open_gl_multi_quad.h>
Public Member Functions | |
OpenGlMultiQuad (int max_quads, Shaders::FragmentShader shader=Shaders::kColorFragment) | |
Constructs an OpenGlMultiQuad with a given maximum number of quads. | |
virtual | ~OpenGlMultiQuad () |
Destructor. Frees any allocated OpenGL resources. | |
virtual void | init (OpenGlWrapper &open_gl) override |
Initializes OpenGL buffers and shader attributes. | |
virtual void | render (OpenGlWrapper &open_gl, bool animate) override |
Renders the quads using OpenGL. | |
virtual void | destroy (OpenGlWrapper &open_gl) override |
Releases OpenGL resources when the component is destroyed. | |
void | paintBackground (Graphics &g) override |
Suppresses background painting; rendering is handled by OpenGL. | |
void | resized () override |
Called when the component is resized. Marks data as dirty to recalculate positions if needed. | |
void | markDirty () |
Marks all vertex data as dirty, prompting a refresh on the next render. | |
void | setFragmentShader (Shaders::FragmentShader shader) |
Sets the fragment shader used to render the quads. | |
void | setNumQuads (int num_quads) |
Sets how many quads will actually be drawn (up to max_quads). | |
force_inline void | setColor (Colour color) |
Sets the base color for the quads. | |
force_inline Colour | getColor () |
Gets the current base color. | |
force_inline void | setAltColor (Colour color) |
Sets an alternate color, often used by custom shaders. | |
force_inline void | setModColor (Colour color) |
Sets a modulation color for custom effects in the shader. | |
force_inline void | setThumbColor (Colour color) |
Sets a "thumb" color, potentially for scroll bars or similar widgets. | |
force_inline void | setThumbAmount (float amount) |
Sets the amount of thumb exposure (used in certain shader effects). | |
force_inline void | setStartPos (float pos) |
Sets a starting position used by some shaders (e.g., arc start). | |
force_inline void | setMaxArc (float max_arc) |
Sets the maximum arc angle or similar parameter used by some shaders. | |
force_inline float | getMaxArc () |
Gets the current maximum arc value. | |
force_inline float | getQuadX (int i) const |
Gets the x-position of a specified quad. | |
force_inline float | getQuadY (int i) const |
Gets the y-position of a specified quad. | |
force_inline float | getQuadWidth (int i) const |
Gets the width of the specified quad. | |
force_inline float | getQuadHeight (int i) const |
Gets the height of the specified quad. | |
float * | getVerticesData (int i) |
Gets a pointer to the vertex data for a given quad. | |
void | setRotatedCoordinates (int i, float x, float y, float w, float h) |
Sets rotated coordinates for a quad, adjusting its texture mapping. | |
void | setCoordinates (int i, float x, float y, float w, float h) |
Sets coordinates for a quad in normalized device space. | |
void | setShaderValue (int i, float shader_value, int value_index=0) |
Sets a shader value for all four vertices of a quad. | |
void | setDimensions (int i, float quad_width, float quad_height, float full_width, float full_height) |
Sets dimensions for a quad, typically to scale based on component size. | |
void | setQuadHorizontal (int i, float x, float w) |
Sets horizontal position and width for a quad. | |
void | setQuadVertical (int i, float y, float h) |
Sets vertical position and height for a quad. | |
void | setQuad (int i, float x, float y, float w, float h) |
Sets the position and size of a quad in normalized device space. | |
void | setActive (bool active) |
Activates or deactivates rendering of this component. | |
void | setThickness (float thickness, bool reset=false) |
Sets the thickness used by some shaders and can reset to this thickness. | |
void | setRounding (float rounding) |
Sets the rounding radius of the quads. | |
void | setTargetComponent (Component *target_component) |
Sets a target component to help position the quads. | |
void | setScissorComponent (Component *scissor_component) |
Sets a component for scissoring (clipping) rendering area. | |
OpenGLShaderProgram * | shader () |
Gets the current OpenGL shader program. | |
void | setAdditive (bool additive) |
Enables or disables additive blending for rendering. | |
void | setAlpha (float alpha, bool reset=false) |
Sets the alpha blending multiplier, can reset to this alpha. | |
void | setDrawWhenNotVisible (bool draw) |
Sets whether to draw even if the component is not visible. | |
![]() | |
OpenGlComponent (String name="") | |
Constructs an OpenGlComponent. | |
virtual | ~OpenGlComponent () |
Destructor. | |
virtual void | parentHierarchyChanged () override |
Called when the component's parent hierarchy changes. | |
void | addRoundedCorners () |
Adds rounded corners to the component's edges. | |
void | addBottomRoundedCorners () |
Adds rounded corners only at the bottom of the component. | |
void | renderCorners (OpenGlWrapper &open_gl, bool animate, Colour color, float rounding) |
Renders the corner shapes using the given color and rounding amount. | |
void | renderCorners (OpenGlWrapper &open_gl, bool animate) |
Renders corners with default body color and rounding. | |
void | repaintBackground () |
Requests a repaint of the component's background on the OpenGL layer. | |
Colour | getBodyColor () const |
Retrieves the component's body color. | |
void | setParent (const SynthSection *parent) |
Sets a pointer to the parent SynthSection for skin value lookups. | |
float | findValue (Skin::ValueId value_id) |
Finds a float value from the skin associated with this component's parent. | |
void | setSkinValues (const Skin &skin) |
Applies the skin overrides to this component's colors. | |
void | setSkinOverride (Skin::SectionOverride skin_override) |
Sets a skin override to control the component's color scheme. | |
force_inline void | checkGlError () |
Checks for and asserts that there are no OpenGL errors. | |
void | setBackgroundColor (const Colour &color) |
Sets the background color of the component for painting operations. | |
Static Public Attributes | |
static constexpr int | kNumVertices = 4 |
Number of vertices per quad. | |
static constexpr int | kNumFloatsPerVertex = 10 |
Number of floats per vertex (x, y, w, h, plus custom shader values). | |
static constexpr int | kNumFloatsPerQuad = kNumVertices * kNumFloatsPerVertex |
Number of floats total per quad (4 vertices * 10 floats each). | |
static constexpr int | kNumIndicesPerQuad = 6 |
Number of indices per quad (2 triangles forming a rectangle). | |
static constexpr float | kThicknessDecay = 0.4f |
Decay factor for thickness adjustments over time. | |
static constexpr float | kAlphaInc = 0.2f |
Increment for alpha blending adjustments. | |
Protected Attributes | |
Component * | target_component_ |
The component this relates to for sizing/positioning. | |
Component * | scissor_component_ |
The component used for scissoring (clipping). | |
Shaders::FragmentShader | fragment_shader_ |
The fragment shader used for rendering. | |
int | max_quads_ |
Maximum number of quads. | |
int | num_quads_ |
Current number of quads to draw. | |
bool | draw_when_not_visible_ |
If true, draw even if the component is not visible. | |
bool | active_ |
If false, nothing is rendered. | |
bool | dirty_ |
If true, vertex data is dirty and needs re-upload. | |
Colour | color_ |
Base color tint. | |
Colour | alt_color_ |
Alternate color for shader use. | |
Colour | mod_color_ |
Modulation color for shader. | |
Colour | thumb_color_ |
Color for a "thumb" element (e.g., in a slider). | |
float | max_arc_ |
Maximum arc for certain shader effects. | |
float | thumb_amount_ |
Amount parameter for thumb effects. | |
float | start_pos_ |
Start position parameter for shader effects. | |
float | current_alpha_mult_ |
Current alpha multiplier for gradual changes. | |
float | alpha_mult_ |
Target alpha multiplier. | |
bool | additive_blending_ |
Use additive blending if true. | |
float | current_thickness_ |
Current thickness for gradual changes. | |
float | thickness_ |
Target thickness. | |
float | rounding_ |
Rounding radius for corners. | |
std::unique_ptr< float[]> | data_ |
Vertex data for all quads. | |
std::unique_ptr< int[]> | indices_ |
Index data for drawing quads. | |
OpenGLShaderProgram * | shader_ |
std::unique_ptr< OpenGLShaderProgram::Uniform > | color_uniform_ |
std::unique_ptr< OpenGLShaderProgram::Uniform > | alt_color_uniform_ |
std::unique_ptr< OpenGLShaderProgram::Uniform > | mod_color_uniform_ |
std::unique_ptr< OpenGLShaderProgram::Uniform > | background_color_uniform_ |
std::unique_ptr< OpenGLShaderProgram::Uniform > | thumb_color_uniform_ |
std::unique_ptr< OpenGLShaderProgram::Uniform > | thickness_uniform_ |
std::unique_ptr< OpenGLShaderProgram::Uniform > | rounding_uniform_ |
std::unique_ptr< OpenGLShaderProgram::Uniform > | max_arc_uniform_ |
std::unique_ptr< OpenGLShaderProgram::Uniform > | thumb_amount_uniform_ |
std::unique_ptr< OpenGLShaderProgram::Uniform > | start_pos_uniform_ |
std::unique_ptr< OpenGLShaderProgram::Uniform > | alpha_mult_uniform_ |
std::unique_ptr< OpenGLShaderProgram::Attribute > | position_ |
std::unique_ptr< OpenGLShaderProgram::Attribute > | dimensions_ |
std::unique_ptr< OpenGLShaderProgram::Attribute > | coordinates_ |
std::unique_ptr< OpenGLShaderProgram::Attribute > | shader_values_ |
GLuint | vertex_buffer_ |
OpenGL buffer for vertex data. | |
GLuint | indices_buffer_ |
OpenGL buffer for index data. | |
![]() | |
std::unique_ptr< OpenGlCorners > | corners_ |
Optional corners for rounded edges. | |
bool | only_bottom_corners_ |
Flag to round only the bottom corners. | |
Colour | background_color_ |
The background color of the component. | |
Colour | body_color_ |
The body color of the component. | |
const SynthSection * | parent_ |
Pointer to parent SynthSection for skin lookups. | |
Skin::SectionOverride | skin_override_ |
Skin override for custom appearance. | |
const vital::StatusOutput * | num_voices_readout_ |
StatusOutput for voice count lookups. | |
Additional Inherited Members | |
![]() | |
static bool | setViewPort (Component *component, Rectangle< int > bounds, OpenGlWrapper &open_gl) |
Sets the OpenGL viewport to match a specified rectangle within a component. | |
static bool | setViewPort (Component *component, OpenGlWrapper &open_gl) |
Convenience overload that sets the viewport for the entire component's local bounds. | |
static void | setScissor (Component *component, OpenGlWrapper &open_gl) |
Sets the OpenGL scissor region to the entire component's local bounds. | |
static void | setScissorBounds (Component *component, Rectangle< int > bounds, OpenGlWrapper &open_gl) |
Sets the OpenGL scissor region to a specified rectangle within a component. | |
static std::unique_ptr< OpenGLShaderProgram::Uniform > | getUniform (const OpenGlWrapper &open_gl, const OpenGLShaderProgram &program, const char *name) |
Retrieves a uniform from the shader program if it exists. | |
static std::unique_ptr< OpenGLShaderProgram::Attribute > | getAttribute (const OpenGlWrapper &open_gl, const OpenGLShaderProgram &program, const char *name) |
Retrieves an attribute from the shader program if it exists. | |
static String | translateFragmentShader (const String &code) |
Translates a fragment shader code snippet to be compatible with the current GL version. | |
static String | translateVertexShader (const String &code) |
Translates a vertex shader code snippet to be compatible with the current GL version. | |
![]() | |
bool | setViewPort (OpenGlWrapper &open_gl) |
Sets the viewport for this component using the current OpenGlWrapper. | |
A component for rendering multiple quads using OpenGL, with customizable colors, rounding, and other effects.
The OpenGlMultiQuad class manages and draws a set of rectangular quads on the screen via OpenGL. Each quad can be positioned, sized, and given unique shader values. Various parameters like thickness, rounding, and alpha blending can be adjusted. This makes it suitable for complex GUI elements such as scroll bars, progress bars, or other shapes.
OpenGlMultiQuad::OpenGlMultiQuad | ( | int | max_quads, |
Shaders::FragmentShader | shader = Shaders::kColorFragment ) |
Constructs an OpenGlMultiQuad with a given maximum number of quads.
max_quads | The maximum number of quads that can be drawn. |
shader | The fragment shader used to render the quads. |
|
virtual |
Destructor. Frees any allocated OpenGL resources.
|
overridevirtual |
Releases OpenGL resources when the component is destroyed.
open_gl | The OpenGlWrapper with the OpenGL context. |
Reimplemented from OpenGlComponent.
|
inline |
Gets the current base color.
|
inline |
Gets the current maximum arc value.
|
inline |
Gets the height of the specified quad.
|
inline |
Gets the width of the specified quad.
|
inline |
Gets the x-position of a specified quad.
i | The quad index. |
|
inline |
Gets the y-position of a specified quad.
|
inline |
Gets a pointer to the vertex data for a given quad.
i | The quad index. |
|
overridevirtual |
Initializes OpenGL buffers and shader attributes.
open_gl | The OpenGlWrapper providing the current OpenGL context. |
Reimplemented from OpenGlComponent.
Reimplemented in OpenGlSliderQuad.
|
inline |
Marks all vertex data as dirty, prompting a refresh on the next render.
|
inlineoverridevirtual |
Suppresses background painting; rendering is handled by OpenGL.
Reimplemented from OpenGlComponent.
Reimplemented in OpenGlSliderQuad.
|
overridevirtual |
Renders the quads using OpenGL.
open_gl | The OpenGlWrapper with the current OpenGL context. |
animate | If true, enables animated changes in properties like thickness or alpha. |
Implements OpenGlComponent.
Reimplemented in LoadingWheel, OpenGlScrollQuad, and PhaseEditor.
|
inlineoverridevirtual |
Called when the component is resized. Marks data as dirty to recalculate positions if needed.
Reimplemented from OpenGlComponent.
|
inline |
Activates or deactivates rendering of this component.
|
inline |
Enables or disables additive blending for rendering.
|
inline |
Sets the alpha blending multiplier, can reset to this alpha.
|
inline |
Sets an alternate color, often used by custom shaders.
color | The alternate color. |
|
inline |
Sets the base color for the quads.
color | The desired color. |
|
inline |
Sets coordinates for a quad in normalized device space.
|
inline |
Sets dimensions for a quad, typically to scale based on component size.
|
inline |
Sets whether to draw even if the component is not visible.
|
inline |
Sets the fragment shader used to render the quads.
shader | The fragment shader ID. |
|
inline |
Sets the maximum arc angle or similar parameter used by some shaders.
max_arc | The maximum arc value. |
|
inline |
Sets a modulation color for custom effects in the shader.
color | The modulation color. |
|
inline |
Sets how many quads will actually be drawn (up to max_quads).
num_quads | The number of quads to draw. |
|
inline |
Sets the position and size of a quad in normalized device space.
|
inline |
Sets horizontal position and width for a quad.
|
inline |
Sets vertical position and height for a quad.
|
inline |
Sets rotated coordinates for a quad, adjusting its texture mapping.
|
inline |
Sets the rounding radius of the quads.
|
inline |
Sets a component for scissoring (clipping) rendering area.
|
inline |
Sets a shader value for all four vertices of a quad.
i | The quad index. |
shader_value | The float value to set. |
value_index | The index of the shader value slot (0 to 3). |
|
inline |
Sets a starting position used by some shaders (e.g., arc start).
pos | The starting position. |
|
inline |
Sets a target component to help position the quads.
|
inline |
Sets the thickness used by some shaders and can reset to this thickness.
|
inline |
Sets the amount of thumb exposure (used in certain shader effects).
amount | A value representing the thumb amount. |
|
inline |
Sets a "thumb" color, potentially for scroll bars or similar widgets.
color | The thumb color. |
|
inline |
Gets the current OpenGL shader program.
|
protected |
If false, nothing is rendered.
|
protected |
Use additive blending if true.
|
protected |
Target alpha multiplier.
|
protected |
|
protected |
Alternate color for shader use.
|
protected |
|
protected |
|
protected |
Base color tint.
|
protected |
|
protected |
|
protected |
Current alpha multiplier for gradual changes.
|
protected |
Current thickness for gradual changes.
|
protected |
Vertex data for all quads.
|
protected |
|
protected |
If true, vertex data is dirty and needs re-upload.
|
protected |
If true, draw even if the component is not visible.
|
protected |
The fragment shader used for rendering.
|
protected |
Index data for drawing quads.
|
protected |
OpenGL buffer for index data.
|
staticconstexpr |
Increment for alpha blending adjustments.
|
staticconstexpr |
Number of floats total per quad (4 vertices * 10 floats each).
|
staticconstexpr |
Number of floats per vertex (x, y, w, h, plus custom shader values).
|
staticconstexpr |
Number of indices per quad (2 triangles forming a rectangle).
|
staticconstexpr |
Number of vertices per quad.
|
staticconstexpr |
Decay factor for thickness adjustments over time.
|
protected |
Maximum arc for certain shader effects.
|
protected |
|
protected |
Maximum number of quads.
|
protected |
Modulation color for shader.
|
protected |
|
protected |
Current number of quads to draw.
|
protected |
|
protected |
Rounding radius for corners.
|
protected |
|
protected |
The component used for scissoring (clipping).
|
protected |
|
protected |
|
protected |
Start position parameter for shader effects.
|
protected |
|
protected |
The component this relates to for sizing/positioning.
|
protected |
Target thickness.
|
protected |
|
protected |
Amount parameter for thumb effects.
|
protected |
|
protected |
Color for a "thumb" element (e.g., in a slider).
|
protected |
|
protected |
OpenGL buffer for vertex data.