Vital
Loading...
Searching...
No Matches
bar_editor.h
Go to the documentation of this file.
1#pragma once
2
3#include "JuceHeader.h"
4#include "bar_renderer.h"
5#include "common.h"
7#include "skin.h"
8#include "utils.h"
9
18class BarEditor : public BarRenderer {
19public:
24 class Listener {
25 public:
26 virtual ~Listener() { }
27
35 virtual void barsChanged(int start, int end, bool mouse_up) = 0;
36 };
37
51
56 BarEditor(int num_points) : BarRenderer(num_points), editing_quad_(Shaders::kColorFragment),
57 random_generator_(-1.0f, 1.0f), editing_(false), clear_value_(-1.0f) {
58 current_mouse_position_ = Point<int>(-10, -10);
59 }
60
64 virtual ~BarEditor() { }
65
70 virtual void init(OpenGlWrapper& open_gl) override {
71 BarRenderer::init(open_gl);
72 editing_quad_.init(open_gl);
73 }
74
80 virtual void render(OpenGlWrapper& open_gl, bool animate) override {
81 BarRenderer::render(open_gl, animate);
82 int hovered_index = getHoveredIndex(current_mouse_position_);
84 hovered_index = -1;
85 float bar_width = 2.0f * scale_ / num_points_;
86 editing_quad_.setQuad(0, bar_width * hovered_index - 1.0f, -1.0f, bar_width, 2.0f);
87 editing_quad_.render(open_gl, animate);
88 }
89
94 virtual void destroy(OpenGlWrapper& open_gl) override {
95 BarRenderer::destroy(open_gl);
96 editing_quad_.destroy(open_gl);
97 }
98
102 virtual void resized() override {
105 }
106
111 void mouseMove(const MouseEvent& e) override;
112
117 void mouseDown(const MouseEvent& e) override;
118
123 void mouseUp(const MouseEvent& e) override;
124
129 void mouseDrag(const MouseEvent& e) override;
130
135 void mouseExit(const MouseEvent& e) override;
136
141 void addListener(Listener* listener) { listeners_.push_back(listener); }
142
147 void setClearValue(float value) { clear_value_ = value; }
148
152 void randomize();
153
157 void clear();
158
162 void clearRight();
163
167 void clearLeft();
168
172 void clearEven();
173
177 void clearOdd();
178
179protected:
184 void changeValues(const MouseEvent& e);
185
191 int getHoveredIndex(Point<int> position);
192
195 std::vector<Listener*> listeners_;
198 bool editing_;
200 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(BarEditor)
201};
Interface for receiving notifications when bar values are changed.
Definition bar_editor.h:24
virtual void barsChanged(int start, int end, bool mouse_up)=0
Called when bar values have changed.
virtual ~Listener()
Definition bar_editor.h:26
An interactive component that allows editing individual bars in a bar graph visually.
Definition bar_editor.h:18
void mouseExit(const MouseEvent &e) override
Handles mouse exit events. Clears hover state.
Definition bar_editor.cpp:78
void addListener(Listener *listener)
Adds a listener to receive updates when bars change.
Definition bar_editor.h:141
void clearOdd()
Clears every odd-indexed bar.
Definition bar_editor.cpp:125
void mouseDown(const MouseEvent &e) override
Handles mouse down events. Initiates editing or shows popup menu.
Definition bar_editor.cpp:35
Point< int > current_mouse_position_
Current mouse position.
Definition bar_editor.h:196
virtual void render(OpenGlWrapper &open_gl, bool animate) override
Renders the editor including the highlight of the currently hovered bar.
Definition bar_editor.h:80
void mouseDrag(const MouseEvent &e) override
Handles mouse drag events. Updates bar values while dragging.
Definition bar_editor.cpp:70
void mouseMove(const MouseEvent &e) override
Handles mouse move events to update hovered bar.
Definition bar_editor.cpp:31
void mouseUp(const MouseEvent &e) override
Handles mouse up events. Completes editing operation.
Definition bar_editor.cpp:58
virtual void resized() override
Called when the editor is resized.
Definition bar_editor.h:102
vital::utils::RandomGenerator random_generator_
Random generator for randomizing bars.
Definition bar_editor.h:194
float clear_value_
Value to clear bars to.
Definition bar_editor.h:199
virtual void destroy(OpenGlWrapper &open_gl) override
Destroys all OpenGL components.
Definition bar_editor.h:94
void changeValues(const MouseEvent &e)
Changes values based on mouse drag position.
Definition bar_editor.cpp:133
void clearLeft()
Clears bars to the left of the currently hovered bar.
Definition bar_editor.cpp:108
void clearRight()
Clears bars to the right of the currently hovered bar.
Definition bar_editor.cpp:99
BarEditorMenu
Popup menu actions for bar editing.
Definition bar_editor.h:42
@ kClearEven
Definition bar_editor.h:47
@ kClearLeft
Definition bar_editor.h:46
@ kRandomize
Definition bar_editor.h:49
@ kClearOdd
Definition bar_editor.h:48
@ kClear
Definition bar_editor.h:44
@ kCancel
Definition bar_editor.h:43
@ kClearRight
Definition bar_editor.h:45
void clearEven()
Clears every even-indexed bar.
Definition bar_editor.cpp:117
void setClearValue(float value)
Sets the value used when clearing bars.
Definition bar_editor.h:147
bool editing_
Whether the user is currently editing bars.
Definition bar_editor.h:198
int getHoveredIndex(Point< int > position)
Gets the index of the bar under the given position.
Definition bar_editor.cpp:172
virtual void init(OpenGlWrapper &open_gl) override
Initializes the OpenGL components used by this editor.
Definition bar_editor.h:70
OpenGlQuad editing_quad_
Quad used to highlight the hovered bar.
Definition bar_editor.h:193
void randomize()
Randomizes all bars using a uniform distribution.
Definition bar_editor.cpp:82
BarEditor(int num_points)
Constructs a BarEditor for a given number of bars.
Definition bar_editor.h:56
virtual ~BarEditor()
Destructor.
Definition bar_editor.h:64
void clear()
Clears all bars to the clear value.
Definition bar_editor.cpp:91
std::vector< Listener * > listeners_
List of listeners for bar changes.
Definition bar_editor.h:195
Point< int > last_edit_position_
Last position during editing for interpolation.
Definition bar_editor.h:197
A renderer for drawing a series of bars using OpenGL.
Definition bar_renderer.h:18
virtual void destroy(OpenGlWrapper &open_gl) override
Destroys any allocated OpenGL resources.
Definition bar_renderer.cpp:153
virtual void init(OpenGlWrapper &open_gl) override
Initializes the renderer with an OpenGL context.
Definition bar_renderer.cpp:57
int num_points_
Number of bars to render.
Definition bar_renderer.h:280
virtual void render(OpenGlWrapper &open_gl, bool animate) override
Renders the bars using the current OpenGL context.
Definition bar_renderer.cpp:149
float scale_
Scale factor for bar dimensions.
Definition bar_renderer.h:271
virtual void resized() override
Called when the component is resized.
Definition open_gl_component.cpp:121
virtual void init(OpenGlWrapper &open_gl) override
Initializes OpenGL buffers and shader attributes.
Definition open_gl_multi_quad.cpp:37
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
virtual void render(OpenGlWrapper &open_gl, bool animate) override
Renders the quads using OpenGL.
Definition open_gl_multi_quad.cpp:92
virtual void destroy(OpenGlWrapper &open_gl) override
Releases OpenGL resources when the component is destroyed.
Definition open_gl_multi_quad.cpp:69
force_inline void setColor(Colour color)
Sets the base color for the quads.
Definition open_gl_multi_quad.h:102
A convenience class for a single quad rendered via OpenGL.
Definition open_gl_multi_quad.h:447
Manages and provides access to vertex and fragment shaders used by the OpenGL rendering pipeline.
Definition shaders.h:19
@ kLightenScreen
Definition skin.h:141
A basic random number generator for producing uniform distributions of floats.
Definition utils.h:61
A helper struct containing references to OpenGL context, shaders, and display scale.
Definition shaders.h:174
Provides various utility functions, classes, and constants for audio, math, and general-purpose opera...