Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a metronome glyph; add Glyph mode to toggle button #46

Merged
merged 1 commit into from
Oct 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading