Skip to content

Commit

Permalink
Add a metronome glyph; add Glyph mode to toggle button
Browse files Browse the repository at this point in the history
ToggleButton basically gets a naked glyph mode
Metronome glyph suitable for temposync for now
API points to allow same
  • Loading branch information
baconpaul committed Oct 1, 2023
1 parent 407227b commit b2c4583
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
1 change: 1 addition & 0 deletions include/sst/jucegui/components/GlyphPainter.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ struct GlyphPainter : public juce::Component,
TUNING,
CROSS,
ARROW_L_TO_R,
METRONOME,

JOG_UP,
JOG_DOWN,
Expand Down
12 changes: 11 additions & 1 deletion include/sst/jucegui/components/ToggleButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <sst/jucegui/data/Discrete.h>
#include <sst/jucegui/components/BaseStyles.h>
#include <sst/jucegui/components/DiscreteParamEditor.h>
#include <sst/jucegui/components/GlyphPainter.h>

#include <string>

Expand Down Expand Up @@ -54,7 +55,8 @@ struct ToggleButton : DiscreteParamEditor,
enum struct DrawMode
{
LABELED,
FILLED
FILLED,
GLYPH
} drawMode{DrawMode::LABELED};

void setDrawMode(DrawMode m)
Expand All @@ -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;

Expand Down
21 changes: 21 additions & 0 deletions src/sst/jucegui/components/GlyphPainter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,22 @@ static void paintCrossGlyph(juce::Graphics &g, const juce::Rectangle<int> &into)
g.drawLine(0, h, h, 0);
}

static void paintMetronomeGlyph(juce::Graphics &g, const juce::Rectangle<int> &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<int> &into)
{
auto sq = into.toFloat().reduced(1, 1);
Expand Down Expand Up @@ -233,6 +249,11 @@ void GlyphPainter::paintGlyph(juce::Graphics &g, const juce::Rectangle<int> &int
paintHamburgerGlyph(g, into);
return;

case METRONOME:
paintMetronomeGlyph(g, into);
return;

break;
default:
{
auto w = std::min(into.getHeight(), into.getWidth());
Expand Down
10 changes: 10 additions & 0 deletions src/sst/jucegui/components/ToggleButton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit b2c4583

Please sign in to comment.