Skip to content

Commit

Permalink
UI tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
FigBug committed Aug 25, 2023
1 parent 15facfa commit 3e758af
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 107 deletions.
2 changes: 1 addition & 1 deletion modules/gin_dsp/dsp/gin_wtoscillators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ void WTOscillator::processAdding (float noteL, float noteR, const Params& params

void WTOscillator::setWavetable (juce::OwnedArray<BandLimitedLookupTable>& table)
{
bllt.clear();
bllt.clearQuick();
bllt.addArray (table);
}

Expand Down
25 changes: 25 additions & 0 deletions modules/gin_gui/components/gin_svgbutton.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*==============================================================================
Copyright 2018 by Roland Rabien
For more information visit www.rabiensoftware.com
==============================================================================*/

#pragma once

//==============================================================================*/
/**
Button that draws an SVG
*/
class SVGButton : public juce::TextButton
{
public:
SVGButton (const juce::String& name, const juce::String& rawSVG_)
: juce::TextButton (name), rawSVG (rawSVG_)
{
}

// Handle the drawing in your look and feel

juce::String rawSVG;
};
1 change: 1 addition & 0 deletions modules/gin_gui/gin_gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,6 @@ namespace gin
#include "components/gin_mapviewer.h"
#include "components/gin_propertycomponents.h"
#include "components/gin_singlelinetexteditor.h"
#include "components/gin_svgbutton.h"

}
180 changes: 87 additions & 93 deletions modules/gin_plugin/components/gin_plugineditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ void NewsChecker::handleAsyncUpdate()
TitleBar::TitleBar (ProcessorEditor& e, Processor& p)
: editor (e), slProc (p)
{
setName ("titlebar");

programs.setName ("presets");

addAndMakeVisible (menuButton);
addAndMakeVisible (browseButton);
addAndMakeVisible (programs);
Expand All @@ -167,13 +171,6 @@ TitleBar::TitleBar (ProcessorEditor& e, Processor& p)
addAndMakeVisible (infoButton);

programs.addListener (this);
addButton.addListener (this);
deleteButton.addListener (this);
nextButton.addListener (this);
prevButton.addListener (this);
browseButton.addListener (this);
infoButton.addListener (this);
menuButton.addListener (this);

programs.setTitle ("Select Preset");
addButton.setTitle ("Add Preset");
Expand Down Expand Up @@ -206,6 +203,88 @@ TitleBar::TitleBar (ProcessorEditor& e, Processor& p)
newsChecker = std::make_unique<NewsChecker> (slProc);
newsChecker->onNewsUpdate = [](juce::String) {};
}

nextButton.onClick = [this]
{
int prog = slProc.getCurrentProgram() + 1;
if (prog >= slProc.getNumPrograms())
prog = 0;

slProc.setCurrentProgram (prog);
};
prevButton.onClick = [this]
{
int prog = slProc.getCurrentProgram() - 1;
if (prog < 0)
prog = slProc.getNumPrograms() - 1;

slProc.setCurrentProgram (prog);
};
browseButton.onClick = [this]
{
browseButton.setToggleState (! browseButton.getToggleState(), juce::dontSendNotification);
editor.showPatchBrowser (browseButton.getToggleState());
};
addButton.onClick = [this]
{
gin::PluginAlertWindow w ("Create preset:", "", juce::AlertWindow::NoIcon, getParentComponent());
w.setLookAndFeel (slProc.lf.get());
w.addTextEditor ("name", "", "Name:");

if (hasBrowser)
{
w.addTextEditor ("author", "", "Author:");
w.addTextEditor ("tags", "", "Tags:");
}

w.addButton ("OK", 1, juce::KeyPress (juce::KeyPress::returnKey));
w.addButton ("Cancel", 0, juce::KeyPress (juce::KeyPress::escapeKey));

if (w.runModalLoop (*getParentComponent()) == 1)
{
auto txt = juce::File::createLegalFileName (w.getTextEditor ("name")->getText());
auto aut = (hasBrowser) ? juce::File::createLegalFileName (w.getTextEditor ("author")->getText()) : juce::String();
auto tag = (hasBrowser) ? juce::File::createLegalFileName (w.getTextEditor ("tags")->getText()) : juce::String();

if (slProc.hasProgram (txt))
{
gin::PluginAlertWindow wc ("Overwrite preset '" + txt + "'?", "", juce::AlertWindow::NoIcon, this);
wc.addButton ("Yes", 1, juce::KeyPress (juce::KeyPress::returnKey));
wc.addButton ("No", 0, juce::KeyPress (juce::KeyPress::escapeKey));
wc.setLookAndFeel (slProc.lf.get());

if (wc.runModalLoop (*this) == 0)
return;
}

if (txt.isNotEmpty())
{
slProc.saveProgram (txt, aut, tag);
refreshPrograms();
}
}
};
deleteButton.onClick = [this]
{
gin::PluginAlertWindow w ("Delete preset '" + slProc.getProgramName (programs.getSelectedItemIndex()) + "'?", "", juce::AlertWindow::NoIcon, getParentComponent());
w.addButton ("Yes", 1, juce::KeyPress (juce::KeyPress::returnKey));
w.addButton ("No", 0, juce::KeyPress (juce::KeyPress::escapeKey));
w.setLookAndFeel (slProc.lf.get());

if (w.runModalLoop (*getParentComponent()))
{
slProc.deleteProgram (programs.getSelectedItemIndex());
refreshPrograms();
}
};
infoButton.onClick = [this]
{
editor.showAboutInfo();
};
menuButton.onClick = [this]
{
showMenu();
};
}

TitleBar::~TitleBar ()
Expand Down Expand Up @@ -310,91 +389,6 @@ void TitleBar::refreshPrograms()
editor.refreshPatchBrowser();
}

void TitleBar::buttonClicked (juce::Button* b)
{
if (b == &nextButton)
{
int prog = slProc.getCurrentProgram() + 1;
if (prog >= slProc.getNumPrograms())
prog = 0;

slProc.setCurrentProgram (prog);
}
else if (b == &prevButton)
{
int prog = slProc.getCurrentProgram() - 1;
if (prog < 0)
prog = slProc.getNumPrograms() - 1;

slProc.setCurrentProgram (prog);
}
else if (b == &browseButton)
{
b->setToggleState (! b->getToggleState(), juce::dontSendNotification);
editor.showPatchBrowser (b->getToggleState());
}
else if (b == &addButton)
{
gin::PluginAlertWindow w ("Create preset:", "", juce::AlertWindow::NoIcon, getParentComponent());
w.setLookAndFeel (slProc.lf.get());
w.addTextEditor ("name", "", "Name:");

if (hasBrowser)
{
w.addTextEditor ("author", "", "Author:");
w.addTextEditor ("tags", "", "Tags:");
}

w.addButton ("OK", 1, juce::KeyPress (juce::KeyPress::returnKey));
w.addButton ("Cancel", 0, juce::KeyPress (juce::KeyPress::escapeKey));

if (w.runModalLoop (*getParentComponent()) == 1)
{
auto txt = juce::File::createLegalFileName (w.getTextEditor ("name")->getText());
auto aut = (hasBrowser) ? juce::File::createLegalFileName (w.getTextEditor ("author")->getText()) : juce::String();
auto tag = (hasBrowser) ? juce::File::createLegalFileName (w.getTextEditor ("tags")->getText()) : juce::String();

if (slProc.hasProgram (txt))
{
gin::PluginAlertWindow wc ("Overwrite preset '" + txt + "'?", "", juce::AlertWindow::NoIcon, this);
wc.addButton ("Yes", 1, juce::KeyPress (juce::KeyPress::returnKey));
wc.addButton ("No", 0, juce::KeyPress (juce::KeyPress::escapeKey));
wc.setLookAndFeel (slProc.lf.get());

if (wc.runModalLoop (*this) == 0)
return;
}

if (txt.isNotEmpty())
{
slProc.saveProgram (txt, aut, tag);
refreshPrograms();
}
}
}
else if (b == &deleteButton)
{
gin::PluginAlertWindow w ("Delete preset '" + slProc.getProgramName (programs.getSelectedItemIndex()) + "'?", "", juce::AlertWindow::NoIcon, getParentComponent());
w.addButton ("Yes", 1, juce::KeyPress (juce::KeyPress::returnKey));
w.addButton ("No", 0, juce::KeyPress (juce::KeyPress::escapeKey));
w.setLookAndFeel (slProc.lf.get());

if (w.runModalLoop (*getParentComponent()))
{
slProc.deleteProgram (programs.getSelectedItemIndex());
refreshPrograms();
}
}
else if (b == &infoButton)
{
editor.showAboutInfo();
}
else if (b == &menuButton)
{
showMenu();
}
}

void TitleBar::showMenu()
{
juce::PopupMenu m;
Expand Down Expand Up @@ -613,7 +607,7 @@ void ProcessorEditor::resized()

void ProcessorEditor::showAboutInfo()
{
juce::String msg;
juce::String msg;

#ifdef JucePlugin_Name
#if JUCE_DEBUG
Expand Down
18 changes: 8 additions & 10 deletions modules/gin_plugin/components/gin_plugineditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ class ProcessorEditorBase : public juce::AudioProcessorEditor
*/
class ProcessorEditor;
class TitleBar : public juce::Component,
protected juce::Button::Listener,
protected juce::ComboBox::Listener,
protected juce::ChangeListener
{
Expand All @@ -182,7 +181,6 @@ class TitleBar : public juce::Component,

void showMenu();

void buttonClicked (juce::Button* b) override;
void comboBoxChanged (juce::ComboBox* c) override;
void changeListenerCallback (juce::ChangeBroadcaster*) override;
void parentHierarchyChanged() override;
Expand All @@ -194,14 +192,14 @@ class TitleBar : public juce::Component,
bool hasBrowser = false;

juce::ComboBox programs;
juce::TextButton addButton {"svg:M384 250v12c0 6.6-5.4 12-12 12h-98v98c0 6.6-5.4 12-12 12h-12c-6.6 0-12-5.4-12-12v-98h-98c-6.6 0-12-5.4-12-12v-12c0-6.6 5.4-12 12-12h98v-98c0-6.6 5.4-12 12-12h12c6.6 0 12 5.4 12 12v98h98c6.6 0 12 5.4 12 12zm120 6c0 137-111 248-248 248S8 393 8 256 119 8 256 8s248 111 248 248zm-32 0c0-119.9-97.3-216-216-216-119.9 0-216 97.3-216 216 0 119.9 97.3 216 216 216 119.9 0 216-97.3 216-216z"};
juce::TextButton deleteButton {"svg:M140 274c-6.6 0-12-5.4-12-12v-12c0-6.6 5.4-12 12-12h232c6.6 0 12 5.4 12 12v12c0 6.6-5.4 12-12 12H140zm364-18c0 137-111 248-248 248S8 393 8 256 119 8 256 8s248 111 248 248zm-32 0c0-119.9-97.3-216-216-216-119.9 0-216 97.3-216 216 0 119.9 97.3 216 216 216 119.9 0 216-97.3 216-216z"};
juce::TextButton browseButton {"svg:M194.74 96l54.63 54.63c6 6 14.14 9.37 22.63 9.37h192c8.84 0 16 7.16 16 16v224c0 8.84-7.16 16-16 16H48c-8.84 0-16-7.16-16-16V112c0-8.84 7.16-16 16-16h146.74M48 64C21.49 64 0 85.49 0 112v288c0 26.51 21.49 48 48 48h416c26.51 0 48-21.49 48-48V176c0-26.51-21.49-48-48-48H272l-54.63-54.63c-6-6-14.14-9.37-22.63-9.37H48z"};
juce::TextButton nextButton {"svg:M17.525 36.465l-7.071 7.07c-4.686 4.686-4.686 12.284 0 16.971L205.947 256 10.454 451.494c-4.686 4.686-4.686 12.284 0 16.971l7.071 7.07c4.686 4.686 12.284 4.686 16.97 0l211.051-211.05c4.686-4.686 4.686-12.284 0-16.971L34.495 36.465c-4.686-4.687-12.284-4.687-16.97 0z"};
juce::TextButton prevButton {"svg:M238.475 475.535l7.071-7.07c4.686-4.686 4.686-12.284 0-16.971L50.053 256 245.546 60.506c4.686-4.686 4.686-12.284 0-16.971l-7.071-7.07c-4.686-4.686-12.284-4.686-16.97 0L10.454 247.515c-4.686 4.686-4.686 12.284 0 16.971l211.051 211.05c4.686 4.686 12.284 4.686 16.97-.001z"};
SVGButton addButton {"add", "M384 250v12c0 6.6-5.4 12-12 12h-98v98c0 6.6-5.4 12-12 12h-12c-6.6 0-12-5.4-12-12v-98h-98c-6.6 0-12-5.4-12-12v-12c0-6.6 5.4-12 12-12h98v-98c0-6.6 5.4-12 12-12h12c6.6 0 12 5.4 12 12v98h98c6.6 0 12 5.4 12 12zm120 6c0 137-111 248-248 248S8 393 8 256 119 8 256 8s248 111 248 248zm-32 0c0-119.9-97.3-216-216-216-119.9 0-216 97.3-216 216 0 119.9 97.3 216 216 216 119.9 0 216-97.3 216-216z"};
SVGButton deleteButton {"delete", "M140 274c-6.6 0-12-5.4-12-12v-12c0-6.6 5.4-12 12-12h232c6.6 0 12 5.4 12 12v12c0 6.6-5.4 12-12 12H140zm364-18c0 137-111 248-248 248S8 393 8 256 119 8 256 8s248 111 248 248zm-32 0c0-119.9-97.3-216-216-216-119.9 0-216 97.3-216 216 0 119.9 97.3 216 216 216 119.9 0 216-97.3 216-216z"};
SVGButton browseButton {"browse", "M194.74 96l54.63 54.63c6 6 14.14 9.37 22.63 9.37h192c8.84 0 16 7.16 16 16v224c0 8.84-7.16 16-16 16H48c-8.84 0-16-7.16-16-16V112c0-8.84 7.16-16 16-16h146.74M48 64C21.49 64 0 85.49 0 112v288c0 26.51 21.49 48 48 48h416c26.51 0 48-21.49 48-48V176c0-26.51-21.49-48-48-48H272l-54.63-54.63c-6-6-14.14-9.37-22.63-9.37H48z"};
SVGButton nextButton {"next", "M17.525 36.465l-7.071 7.07c-4.686 4.686-4.686 12.284 0 16.971L205.947 256 10.454 451.494c-4.686 4.686-4.686 12.284 0 16.971l7.071 7.07c4.686 4.686 12.284 4.686 16.97 0l211.051-211.05c4.686-4.686 4.686-12.284 0-16.971L34.495 36.465c-4.686-4.687-12.284-4.687-16.97 0z"};
SVGButton prevButton {"prev", "M238.475 475.535l7.071-7.07c4.686-4.686 4.686-12.284 0-16.971L50.053 256 245.546 60.506c4.686-4.686 4.686-12.284 0-16.971l-7.071-7.07c-4.686-4.686-12.284-4.686-16.97 0L10.454 247.515c-4.686 4.686-4.686 12.284 0 16.971l211.051 211.05c4.686 4.686 12.284 4.686 16.97-.001z"};

juce::TextButton menuButton {"svg:M16 132h416c8.837 0 16-7.163 16-16V76c0-8.837-7.163-16-16-16H16C7.163 60 0 67.163 0 76v40c0 8.837 7.163 16 16 16zm0 160h416c8.837 0 16-7.163 16-16v-40c0-8.837-7.163-16-16-16H16c-8.837 0-16 7.163-16 16v40c0 8.837 7.163 16 16 16zm0 160h416c8.837 0 16-7.163 16-16v-40c0-8.837-7.163-16-16-16H16c-8.837 0-16 7.163-16 16v40c0 8.837 7.163 16 16 16z"};
juce::TextButton infoButton {"svg:M256 40c118.621 0 216 96.075 216 216 0 119.291-96.61 216-216 216-119.244 0-216-96.562-216-216 0-119.203 96.602-216 216-216m0-32C119.043 8 8 119.083 8 256c0 136.997 111.043 248 248 248s248-111.003 248-248C504 119.083 392.957 8 256 8zm-36 344h12V232h-12c-6.627 0-12-5.373-12-12v-8c0-6.627 5.373-12 12-12h48c6.627 0 12 5.373 12 12v140h12c6.627 0 12 5.373 12 12v8c0 6.627-5.373 12-12 12h-72c-6.627 0-12-5.373-12-12v-8c0-6.627 5.373-12 12-12zm36-240c-17.673 0-32 14.327-32 32s14.327 32 32 32 32-14.327 32-32-14.327-32-32-32z"};
SVGButton menuButton {"menu", "M16 132h416c8.837 0 16-7.163 16-16V76c0-8.837-7.163-16-16-16H16C7.163 60 0 67.163 0 76v40c0 8.837 7.163 16 16 16zm0 160h416c8.837 0 16-7.163 16-16v-40c0-8.837-7.163-16-16-16H16c-8.837 0-16 7.163-16 16v40c0 8.837 7.163 16 16 16zm0 160h416c8.837 0 16-7.163 16-16v-40c0-8.837-7.163-16-16-16H16c-8.837 0-16 7.163-16 16v40c0 8.837 7.163 16 16 16z"};
SVGButton infoButton {"info", "M256 40c118.621 0 216 96.075 216 216 0 119.291-96.61 216-216 216-119.244 0-216-96.562-216-216 0-119.203 96.602-216 216-216m0-32C119.043 8 8 119.083 8 256c0 136.997 111.043 248 248 248s248-111.003 248-248C504 119.083 392.957 8 256 8zm-36 344h12V232h-12c-6.627 0-12-5.373-12-12v-8c0-6.627 5.373-12 12-12h48c6.627 0 12 5.373 12 12v140h12c6.627 0 12 5.373 12 12v8c0 6.627-5.373 12-12 12h-72c-6.627 0-12-5.373-12-12v-8c0-6.627 5.373-12 12-12zm36-240c-17.673 0-32 14.327-32 32s14.327 32 32 32 32-14.327 32-32-14.327-32-32-32z"};

std::unique_ptr<NewsChecker> newsChecker;
std::unique_ptr<UpdateChecker> updateChecker;
Expand All @@ -217,7 +215,7 @@ class ProcessorEditor : public ProcessorEditorBase
ProcessorEditor (Processor&, int cx, int cy, EditorOptions eo = {}) noexcept;
~ProcessorEditor() override;

void showAboutInfo();
virtual void showAboutInfo();

void refreshPatchBrowser();
void showPatchBrowser (bool p);
Expand Down
5 changes: 2 additions & 3 deletions modules/gin_plugin/lookandfeel/gin_copperlookandfeel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,9 @@ void CopperLookAndFeel::drawButtonText (juce::Graphics& g, juce::TextButton& b,

g.setColour (c);

auto text = b.getButtonText();
if (text.startsWith ("svg:"))
if (auto svg = dynamic_cast<SVGButton*> (&b))
{
auto path = parseSVGPath (text.substring (4));
auto path = parseSVGPath (svg->rawSVG);
auto font = getTextButtonFont (b, b.getHeight());

int sz = std::min (b.getHeight(), b.getWidth());
Expand Down

0 comments on commit 3e758af

Please sign in to comment.