From b2c4583eb712bbb3de63fa93f9283ed1a5ec333d Mon Sep 17 00:00:00 2001 From: Paul Walker Date: Sun, 1 Oct 2023 11:37:15 -0400 Subject: [PATCH] Add a metronome glyph; add Glyph mode to toggle button ToggleButton basically gets a naked glyph mode Metronome glyph suitable for temposync for now API points to allow same --- include/sst/jucegui/components/GlyphPainter.h | 1 + include/sst/jucegui/components/ToggleButton.h | 12 ++++++++++- src/sst/jucegui/components/GlyphPainter.cpp | 21 +++++++++++++++++++ src/sst/jucegui/components/ToggleButton.cpp | 10 +++++++++ 4 files changed, 43 insertions(+), 1 deletion(-) diff --git a/include/sst/jucegui/components/GlyphPainter.h b/include/sst/jucegui/components/GlyphPainter.h index 648a933..cc66f45 100644 --- a/include/sst/jucegui/components/GlyphPainter.h +++ b/include/sst/jucegui/components/GlyphPainter.h @@ -37,6 +37,7 @@ struct GlyphPainter : public juce::Component, TUNING, CROSS, ARROW_L_TO_R, + METRONOME, JOG_UP, JOG_DOWN, diff --git a/include/sst/jucegui/components/ToggleButton.h b/include/sst/jucegui/components/ToggleButton.h index 8656bad..5f0d356 100644 --- a/include/sst/jucegui/components/ToggleButton.h +++ b/include/sst/jucegui/components/ToggleButton.h @@ -25,6 +25,7 @@ #include #include #include +#include #include @@ -54,7 +55,8 @@ struct ToggleButton : DiscreteParamEditor, enum struct DrawMode { LABELED, - FILLED + FILLED, + GLYPH } drawMode{DrawMode::LABELED}; void setDrawMode(DrawMode m) @@ -64,6 +66,14 @@ struct ToggleButton : DiscreteParamEditor, } void setLabel(const std::string &l) { label = l; } + GlyphPainter::GlyphType type{GlyphPainter::CROSS}; + void setGlyph(GlyphPainter::GlyphType gt) + { + drawMode = DrawMode::GLYPH; + type = gt; + repaint(); + } + void mouseDown(const juce::MouseEvent &e) override; void mouseUp(const juce::MouseEvent &e) override; diff --git a/src/sst/jucegui/components/GlyphPainter.cpp b/src/sst/jucegui/components/GlyphPainter.cpp index 69ffb56..87da241 100644 --- a/src/sst/jucegui/components/GlyphPainter.cpp +++ b/src/sst/jucegui/components/GlyphPainter.cpp @@ -78,6 +78,22 @@ static void paintCrossGlyph(juce::Graphics &g, const juce::Rectangle &into) g.drawLine(0, h, h, 0); } +static void paintMetronomeGlyph(juce::Graphics &g, const juce::Rectangle &into) +{ + auto sq = centeredSquareIn(into).reduced(1, 1); + auto h = sq.getHeight(); + auto off = (int)(h * 0.1); + auto boff = (int)(h * 0.2); + + auto grd = juce::Graphics::ScopedSaveState(g); + g.addTransform(juce::AffineTransform().translated(sq.getX(), sq.getY())); + + g.drawLine(off, h, h / 2, 0); + g.drawLine(h - off, h, h / 2, 0); + g.drawLine(off, h, h - off, h); + g.drawLine(h / 2, h - 2 * boff, h - boff, 0); +} + static void paintArrowLtoR(juce::Graphics &g, const juce::Rectangle &into) { auto sq = into.toFloat().reduced(1, 1); @@ -233,6 +249,11 @@ void GlyphPainter::paintGlyph(juce::Graphics &g, const juce::Rectangle &int paintHamburgerGlyph(g, into); return; + case METRONOME: + paintMetronomeGlyph(g, into); + return; + + break; default: { auto w = std::min(into.getHeight(), into.getWidth()); diff --git a/src/sst/jucegui/components/ToggleButton.cpp b/src/sst/jucegui/components/ToggleButton.cpp index a7bb01d..c3dbadc 100644 --- a/src/sst/jucegui/components/ToggleButton.cpp +++ b/src/sst/jucegui/components/ToggleButton.cpp @@ -58,6 +58,16 @@ void ToggleButton::paint(juce::Graphics &g) fg = getColour(Styles::texthoveroffcol); } + if (drawMode == DrawMode::GLYPH) + { + if (v) + g.setColour(getColour(Styles::onbgcol)); + else + g.setColour(getColour(Styles::onbgcol).withSaturation(0.2).withAlpha(0.5f)); + GlyphPainter::paintGlyph(g, getLocalBounds(), type); + return; + } + g.setColour(bg); g.fillRoundedRectangle(b, rectCorner);