Vital
Loading...
Searching...
No Matches
BarEditor Class Reference

An interactive component that allows editing individual bars in a bar graph visually. More...

#include <bar_editor.h>

Inheritance diagram for BarEditor:
BarRenderer OpenGlComponent

Classes

class  Listener
 Interface for receiving notifications when bar values are changed. More...
 

Public Types

enum  BarEditorMenu {
  kCancel = 0 , kClear , kClearRight , kClearLeft ,
  kClearEven , kClearOdd , kRandomize
}
 Popup menu actions for bar editing. More...
 

Public Member Functions

 BarEditor (int num_points)
 Constructs a BarEditor for a given number of bars.
 
virtual ~BarEditor ()
 Destructor.
 
virtual void init (OpenGlWrapper &open_gl) override
 Initializes the OpenGL components used by this editor.
 
virtual void render (OpenGlWrapper &open_gl, bool animate) override
 Renders the editor including the highlight of the currently hovered bar.
 
virtual void destroy (OpenGlWrapper &open_gl) override
 Destroys all OpenGL components.
 
virtual void resized () override
 Called when the editor is resized.
 
void mouseMove (const MouseEvent &e) override
 Handles mouse move events to update hovered bar.
 
void mouseDown (const MouseEvent &e) override
 Handles mouse down events. Initiates editing or shows popup menu.
 
void mouseUp (const MouseEvent &e) override
 Handles mouse up events. Completes editing operation.
 
void mouseDrag (const MouseEvent &e) override
 Handles mouse drag events. Updates bar values while dragging.
 
void mouseExit (const MouseEvent &e) override
 Handles mouse exit events. Clears hover state.
 
void addListener (Listener *listener)
 Adds a listener to receive updates when bars change.
 
void setClearValue (float value)
 Sets the value used when clearing bars.
 
void randomize ()
 Randomizes all bars using a uniform distribution.
 
void clear ()
 Clears all bars to the clear value.
 
void clearRight ()
 Clears bars to the right of the currently hovered bar.
 
void clearLeft ()
 Clears bars to the left of the currently hovered bar.
 
void clearEven ()
 Clears every even-indexed bar.
 
void clearOdd ()
 Clears every odd-indexed bar.
 
- Public Member Functions inherited from BarRenderer
 BarRenderer (int num_points, bool vertical=true)
 Constructs a BarRenderer.
 
virtual ~BarRenderer ()
 Destructor.
 
void setColor (const Colour &color)
 Sets the color of the bars.
 
void setScale (float scale)
 Sets the scaling factor for the bars.
 
void setOffset (float offset)
 Sets an offset applied to the bar positions.
 
void setBarWidth (float bar_width)
 Sets the relative width of each bar.
 
void setNumPoints (int num_points)
 Updates the number of points (bars) to display.
 
float getBarWidth ()
 Gets the current bar width factor.
 
float xAt (int index)
 Gets the x-position of the top-left vertex of the given bar.
 
float rightAt (int index)
 Gets the x-position of the top-right vertex of the given bar.
 
float yAt (int index)
 Gets the y-position of the top-left vertex of the given bar.
 
float bottomAt (int index)
 Gets the y-position of the bottom-left vertex of the given bar.
 
force_inline void setX (int index, float val)
 Sets the x-position for all vertices of a specific bar.
 
force_inline void setY (int index, float val)
 Sets the top y-position of a specific bar.
 
force_inline void setBottom (int index, float val)
 Sets the bottom y-position of a specific bar.
 
void positionBar (int index, float x, float y, float width, float height)
 Positions a bar at a specific rectangle.
 
void setBarSizes ()
 Updates the bar sizes based on their positions and scaling.
 
void setPowerScale (bool scale)
 Enables or disables power scaling of bar heights.
 
void setSquareScale (bool scale)
 Enables or disables square scaling of bar heights.
 
force_inline float scaledYAt (int index)
 Gets the scaled y-value of a bar at a given index.
 
force_inline void setScaledY (int index, float val)
 Sets the scaled y-value at a specific index.
 
force_inline void setAdditiveBlending (bool additive_blending)
 Enables or disables additive blending for the bar rendering.
 
- Public Member Functions inherited from OpenGlComponent
 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.
 
virtual void paintBackground (Graphics &g)
 Paints a standard background for the component.
 
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.
 

Protected Member Functions

void changeValues (const MouseEvent &e)
 Changes values based on mouse drag position.
 
int getHoveredIndex (Point< int > position)
 Gets the index of the bar under the given position.
 
- Protected Member Functions inherited from BarRenderer
void drawBars (OpenGlWrapper &open_gl)
 Draws the bars to the currently active OpenGL context.
 
- Protected Member Functions inherited from OpenGlComponent
bool setViewPort (OpenGlWrapper &open_gl)
 Sets the viewport for this component using the current OpenGlWrapper.
 

Protected Attributes

OpenGlQuad editing_quad_
 Quad used to highlight the hovered bar.
 
vital::utils::RandomGenerator random_generator_
 Random generator for randomizing bars.
 
std::vector< Listener * > listeners_
 List of listeners for bar changes.
 
Point< int > current_mouse_position_
 Current mouse position.
 
Point< int > last_edit_position_
 Last position during editing for interpolation.
 
bool editing_
 Whether the user is currently editing bars.
 
float clear_value_
 Value to clear bars to.
 
- Protected Attributes inherited from BarRenderer
OpenGLShaderProgram * shader_
 The shader program used for rendering.
 
std::unique_ptr< OpenGLShaderProgram::Uniform > color_uniform_
 Uniform for bar color.
 
std::unique_ptr< OpenGLShaderProgram::Uniform > dimensions_uniform_
 Uniform for viewport dimensions.
 
std::unique_ptr< OpenGLShaderProgram::Uniform > offset_uniform_
 Uniform for position offset.
 
std::unique_ptr< OpenGLShaderProgram::Uniform > scale_uniform_
 Uniform for scaling factor.
 
std::unique_ptr< OpenGLShaderProgram::Uniform > width_percent_uniform_
 Uniform for bar width factor.
 
std::unique_ptr< OpenGLShaderProgram::Attribute > position_
 Attribute for vertex position.
 
std::unique_ptr< OpenGLShaderProgram::Attribute > corner_
 Attribute for corner coordinates.
 
Colour color_
 Current color of the bars.
 
bool vertical_
 True if bars are rendered vertically.
 
float scale_
 Scale factor for bar dimensions.
 
float offset_
 Offset applied to bar positions.
 
float bar_width_
 Relative width of each bar.
 
bool additive_blending_
 If true, uses additive blending for rendering.
 
float display_scale_
 Additional scaling factor applied to bar sizes.
 
bool power_scale_
 True if power scaling is applied to bar heights.
 
bool square_scale_
 True if square scaling is applied to bar heights.
 
bool dirty_
 True if bar data needs to be re-uploaded to the GPU.
 
int num_points_
 Number of bars to render.
 
int total_points_
 Total number of allocated points (bars).
 
std::unique_ptr< float[]> bar_data_
 Raw bar vertex position data.
 
std::unique_ptr< float[]> bar_corner_data_
 Bar corner coordinate data.
 
std::unique_ptr< int[]> bar_indices_
 Triangle index data for bars.
 
GLuint bar_buffer_
 OpenGL buffer object for bar positions.
 
GLuint bar_corner_buffer_
 OpenGL buffer object for bar corners.
 
GLuint bar_indices_buffer_
 OpenGL buffer object for bar indices.
 
- Protected Attributes inherited from OpenGlComponent
std::unique_ptr< OpenGlCornerscorners_
 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 SynthSectionparent_
 Pointer to parent SynthSection for skin lookups.
 
Skin::SectionOverride skin_override_
 Skin override for custom appearance.
 
const vital::StatusOutputnum_voices_readout_
 StatusOutput for voice count lookups.
 

Additional Inherited Members

- Static Public Member Functions inherited from OpenGlComponent
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.
 
- Static Public Attributes inherited from BarRenderer
static constexpr float kScaleConstant = 5.0f
 A scaling constant used when applying power scaling.
 
static constexpr int kFloatsPerVertex = 3
 Number of float values per vertex (x, y, [and potentially other attributes]).
 
static constexpr int kVerticesPerBar = 4
 Number of vertices per bar.
 
static constexpr int kFloatsPerBar = kVerticesPerBar * kFloatsPerVertex
 Number of floats per bar (4 vertices * 3 floats each).
 
static constexpr int kTriangleIndicesPerBar = 6
 Number of triangle indices per bar (each bar represented as two triangles).
 
static constexpr int kCornerFloatsPerVertex = 2
 Number of corner floats per vertex (used to determine corner coordinates).
 
static constexpr int kCornerFloatsPerBar = kVerticesPerBar * kCornerFloatsPerVertex
 Number of corner floats per bar.
 

Detailed Description

An interactive component that allows editing individual bars in a bar graph visually.

The BarEditor extends BarRenderer to handle mouse events for editing bar values. Users can click and drag to modify bar values, right-click to access a popup menu with various editing options, and perform actions such as clearing ranges or randomizing bar values.

Member Enumeration Documentation

◆ BarEditorMenu

Popup menu actions for bar editing.

Enumerator
kCancel 
kClear 
kClearRight 
kClearLeft 
kClearEven 
kClearOdd 
kRandomize 

Constructor & Destructor Documentation

◆ BarEditor()

BarEditor::BarEditor ( int num_points)
inline

Constructs a BarEditor for a given number of bars.

Parameters
num_pointsNumber of bars to be edited.

◆ ~BarEditor()

virtual BarEditor::~BarEditor ( )
inlinevirtual

Destructor.

Member Function Documentation

◆ addListener()

void BarEditor::addListener ( Listener * listener)
inline

Adds a listener to receive updates when bars change.

Parameters
listenerPointer to a listener.

◆ changeValues()

void BarEditor::changeValues ( const MouseEvent & e)
protected

Changes values based on mouse drag position.

Parameters
eThe mouse event.

◆ clear()

void BarEditor::clear ( )

Clears all bars to the clear value.

◆ clearEven()

void BarEditor::clearEven ( )

Clears every even-indexed bar.

◆ clearLeft()

void BarEditor::clearLeft ( )

Clears bars to the left of the currently hovered bar.

◆ clearOdd()

void BarEditor::clearOdd ( )

Clears every odd-indexed bar.

◆ clearRight()

void BarEditor::clearRight ( )

Clears bars to the right of the currently hovered bar.

◆ destroy()

virtual void BarEditor::destroy ( OpenGlWrapper & open_gl)
inlineoverridevirtual

Destroys all OpenGL components.

Parameters
open_glReference to the OpenGL wrapper.

Reimplemented from BarRenderer.

◆ getHoveredIndex()

int BarEditor::getHoveredIndex ( Point< int > position)
protected

Gets the index of the bar under the given position.

Parameters
positionThe mouse position.
Returns
The hovered bar index or a clamped value.

◆ init()

virtual void BarEditor::init ( OpenGlWrapper & open_gl)
inlineoverridevirtual

Initializes the OpenGL components used by this editor.

Parameters
open_glReference to the OpenGL wrapper.

Reimplemented from BarRenderer.

◆ mouseDown()

void BarEditor::mouseDown ( const MouseEvent & e)
override

Handles mouse down events. Initiates editing or shows popup menu.

Parameters
eThe mouse event.

◆ mouseDrag()

void BarEditor::mouseDrag ( const MouseEvent & e)
override

Handles mouse drag events. Updates bar values while dragging.

Parameters
eThe mouse event.

◆ mouseExit()

void BarEditor::mouseExit ( const MouseEvent & e)
override

Handles mouse exit events. Clears hover state.

Parameters
eThe mouse event.

◆ mouseMove()

void BarEditor::mouseMove ( const MouseEvent & e)
override

Handles mouse move events to update hovered bar.

Parameters
eThe mouse event.

◆ mouseUp()

void BarEditor::mouseUp ( const MouseEvent & e)
override

Handles mouse up events. Completes editing operation.

Parameters
eThe mouse event.

◆ randomize()

void BarEditor::randomize ( )

Randomizes all bars using a uniform distribution.

◆ render()

virtual void BarEditor::render ( OpenGlWrapper & open_gl,
bool animate )
inlineoverridevirtual

Renders the editor including the highlight of the currently hovered bar.

Parameters
open_glReference to the OpenGL wrapper.
animateWhether to animate (not used here).

Reimplemented from BarRenderer.

◆ resized()

virtual void BarEditor::resized ( )
inlineoverridevirtual

Called when the editor is resized.

Reimplemented from OpenGlComponent.

◆ setClearValue()

void BarEditor::setClearValue ( float value)
inline

Sets the value used when clearing bars.

Parameters
valueThe value to set cleared bars to.

Member Data Documentation

◆ clear_value_

float BarEditor::clear_value_
protected

Value to clear bars to.

◆ current_mouse_position_

Point<int> BarEditor::current_mouse_position_
protected

Current mouse position.

◆ editing_

bool BarEditor::editing_
protected

Whether the user is currently editing bars.

◆ editing_quad_

OpenGlQuad BarEditor::editing_quad_
protected

Quad used to highlight the hovered bar.

◆ last_edit_position_

Point<int> BarEditor::last_edit_position_
protected

Last position during editing for interpolation.

◆ listeners_

std::vector<Listener*> BarEditor::listeners_
protected

List of listeners for bar changes.

◆ random_generator_

vital::utils::RandomGenerator BarEditor::random_generator_
protected

Random generator for randomizing bars.


The documentation for this class was generated from the following files: