From dc03409d25a9ec37319f1a862ec2c29e64d259d0 Mon Sep 17 00:00:00 2001 From: Joscha Schmiedt Date: Mon, 23 Jun 2025 17:59:34 +0200 Subject: [PATCH] Allow overriding of InteractivePlot elements Making InteractivePlot::plot virtual as well as XYLine::draw allows re-using them in custom plugins. --- .../Visualization/InteractivePlot.h | 41 ++++++++++--------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/Source/Processors/Visualization/InteractivePlot.h b/Source/Processors/Visualization/InteractivePlot.h index 8f1caf2e3..4e4235883 100644 --- a/Source/Processors/Visualization/InteractivePlot.h +++ b/Source/Processors/Visualization/InteractivePlot.h @@ -74,6 +74,7 @@ class XYLine public: /** Creates a line from vectors of x and y values */ XYLine (std::vector x, std::vector y); + virtual ~XYLine() = default; /** Sets the colour of the line*/ void setColour (Colour c); @@ -92,7 +93,7 @@ class XYLine /** Renders the line. Stretches Y such that ymin->0 and ymax->plotHeight and only display points between [xmin and xmax] */ - void draw (Graphics& g, XYRange& range, int width, int height); + virtual void draw (Graphics& g, XYRange& range, int width, int height); /** The x values */ std::vector x; @@ -100,7 +101,7 @@ class XYLine /** The x values */ std::vector y; -private: +protected: /** The parameters of this line */ Colour colour; float width; @@ -121,7 +122,7 @@ class Axis : public Component Axis(); /** Destructor */ - ~Axis() {} + ~Axis() override {} /** Sets the min / max range, and number of ticks between them */ void setRange (float minvalue, float maxvalue, int numTicks = 10); @@ -179,7 +180,7 @@ class XAxis : public Axis XAxis() {} /** Renders the axis */ - void paint (Graphics& g); + void paint (Graphics& g) override; }; /** @@ -194,7 +195,7 @@ class YAxis : public Axis YAxis() {} /** Renders the axis */ - void paint (Graphics& g); + void paint (Graphics& g) override; }; /** @@ -210,7 +211,7 @@ class PLUGIN_API DrawComponent : public Component DrawComponent (Axis* x, Axis* y); /** Destructor */ - ~DrawComponent() {} + ~DrawComponent() override {} /** Adds a line to be drawn */ void add (XYLine* line); @@ -250,9 +251,9 @@ class PLUGIN_API DrawComponent : public Component OwnedArray lines; /** Mouse listeners */ - void mouseDown (const juce::MouseEvent& event); - void mouseDrag (const juce::MouseEvent& event); - void mouseWheelMove (const MouseEvent& event, const MouseWheelDetails& wheel); + void mouseDown (const juce::MouseEvent& event) override; + void mouseDrag (const juce::MouseEvent& event) override; + void mouseWheelMove (const MouseEvent& event, const MouseWheelDetails& wheel) override; //std::vector computeSamplePositions(int subsample); std::list rangeMemory; @@ -263,7 +264,7 @@ class PLUGIN_API DrawComponent : public Component void drawGrid (Graphics& g); - void paint (Graphics& g); + void paint (Graphics& g) override; XYRange range, limit, originalRange; @@ -292,15 +293,15 @@ class PLUGIN_API InteractivePlot : public Component, InteractivePlot(); /** Destructor */ - ~InteractivePlot() {} + ~InteractivePlot() override {} /** Adds a line based on X and Y values */ - void plot (std::vector x, - std::vector y, - Colour c = Colours::white, - float width = 1.0f, - float opacity = 1.0f, - PlotType type = PlotType::LINE); + virtual void plot (std::vector x, + std::vector y, + Colour c = Colours::white, + float width = 1.0f, + float opacity = 1.0f, + PlotType type = PlotType::LINE); /** Clears all lines from the plot */ void clear(); @@ -345,11 +346,11 @@ class PLUGIN_API InteractivePlot : public Component, void getRange (XYRange& range); /** Called when size of plot is changed */ - void resized(); + void resized() override; -private: +protected: /** Respond to button clicks */ - void buttonClicked (Button* btn); + void buttonClicked (Button* btn) override; FontOptions font; juce::Colour backgroundColour;