Skip to content

Commit

Permalink
Plugin UI tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
FigBug committed Aug 25, 2023
1 parent 3e758af commit 96f0293
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 20 deletions.
15 changes: 9 additions & 6 deletions modules/gin_dsp/components/gin_wavetablecomponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,15 @@ void WavetableComponent::paint (juce::Graphics& g)
paths.add (createWavetablePath (float (i) / numTables));
}

g.setColour (findColour (waveColourId, true));
for (auto& p : paths)
g.strokePath (p, juce::PathStrokeType (0.75f));

g.setColour (findColour (activeWaveColourId, true));
g.strokePath (createWavetablePath (params.pw), juce::PathStrokeType (0.75f));
if (paths.size() > 0)
{
g.setColour (findColour (waveColourId, true));
for (auto& p : paths)
g.strokePath (p, juce::PathStrokeType (0.75f));

g.setColour (findColour (activeWaveColourId, true));
g.strokePath (createWavetablePath (params.pw), juce::PathStrokeType (0.75f));
}
}

juce::Path WavetableComponent::createWavetablePath (float wtPos)
Expand Down
46 changes: 41 additions & 5 deletions modules/gin_plugin/components/gin_parambox.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,21 @@ inline void gradientRect (juce::Graphics& g, juce::Rectangle<int> rc, juce::Colo
}

//==============================================================================
/** A header with optional power button
/** A header with title text
*/
class ParamHeader : public juce::Component
{
public:
ParamHeader (const juce::String& name_)
: name (name_)
{
setName (name);
}

void setTitle (const juce::String& name_)
{
name = name_;
repaint();
}

private:
Expand Down Expand Up @@ -48,28 +54,55 @@ class ParamBox : public MultiParamComponent
ParamBox (const juce::String& name)
: header (name)
{
setName (name);
addAndMakeVisible (frame);
addAndMakeVisible (header);
}

void addEnable (gin::Parameter::Ptr)
void setTitle (const juce::String& name)
{
header.setTitle (name);
}

void addEnable (gin::Parameter::Ptr p)
{
enableParam = p;

const auto icon = "M6 0H5V6H6V0ZM0 5.50001C0 3.36266 1.21916 1.51007 3 0.599716V1.75778C1.79401 2.56504 1 3.9398 1 5.50001C1 7.98529 3.01472 10 5.5 10C7.98528 10 10 7.98529 10 5.50001C10 3.9398 9.20599 2.56504 8 1.75778V0.599716C9.78084 1.51007 11 3.36266 11 5.50001C11 8.53757 8.53757 11 5.5 11C2.46243 11 0 8.53757 0 5.50001Z";

auto b = new SVGPluginButton (p, icon);
b->setBounds (6, 6, 12, 12);
controls.add (b);
addAndMakeVisible (b);

watchParam (p);
}

void addControl (Component* c, int x, int y, int cx = 1, int cy = 1)
{
c->setBounds (getGridArea (x, y, cx, cy));
controls.add (c);
addAndMakeVisible (c);
frame.addAndMakeVisible (c);
}

void addControl (Component* c, float x, float y, float cx = 1.0f, float cy = 1.0f)
{
c->setBounds (getGridArea (x, y, cx, cy));
controls.add (c);
addAndMakeVisible (c);
frame.addAndMakeVisible (c);
}

ParamHeader& getHeader() { return header; }

protected:
void paramChanged () override
{
MultiParamComponent::paramChanged();

if (enableParam)
frame.setEnabled (enableParam->getUserValue() > 0.0f);
}

private:
void paint (juce::Graphics& g) override
{
auto rc = getLocalBounds().withTrimmedTop (23);
Expand All @@ -79,6 +112,7 @@ class ParamBox : public MultiParamComponent
void resized() override
{
header.setBounds (getLocalBounds().removeFromTop (23));
frame.setBounds (getLocalBounds());
}

juce::Rectangle<int> getGridArea (int x, int y, int cx = 1, int cy = 1)
Expand All @@ -92,7 +126,9 @@ class ParamBox : public MultiParamComponent
}

ParamHeader header;
juce::Component frame;
juce::OwnedArray<Component> controls;
gin::Parameter::Ptr enableParam = nullptr;
};

//==============================================================================
Expand Down
48 changes: 48 additions & 0 deletions modules/gin_plugin/components/gin_plugincomponents.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class PluginButton : public juce::TextButton,
PluginButton (Parameter* parameter_)
: parameter (parameter_)
{
setName (parameter->getShortName());
setButtonText (parameter->getUserValueText());
setToggleState (parameter->getUserValue() > 0.0f, juce::dontSendNotification);

Expand Down Expand Up @@ -47,6 +48,53 @@ class PluginButton : public juce::TextButton,
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PluginButton)
};

//==============================================================================
/** Button for toggling a parameter
*/
class SVGPluginButton : public SVGButton,
private Parameter::ParameterListener
{
public:
SVGPluginButton (Parameter* parameter_, const juce::String& svg)
: SVGButton (parameter_->getShortName(), svg), parameter (parameter_)
{
setButtonText (parameter->getUserValueText());
setToggleState (parameter->getUserValue() > 0.0f, juce::dontSendNotification);

parameter->addListener (this);
}

~SVGPluginButton() override
{
parameter->removeListener (this);
}

void valueUpdated (Parameter*) override
{
setToggleState (parameter->getUserValue() > 0.0f, juce::dontSendNotification);
setButtonText (parameter->getUserValueText());
repaint ();
}

void clicked() override
{
parameter->beginUserAction();
parameter->setUserValueNotifingHost (parameter->getUserValue() > 0.0f ? 0.0f : 1.0f);
parameter->endUserAction();
setButtonText (parameter->getUserValueText());
}

void parentHierarchyChanged() override
{
auto a = wantsAccessibleKeyboard (*this);
setWantsKeyboardFocus (a);
}

Parameter* parameter;

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (SVGPluginButton)
};

/** Button for toggling a parameter, drawn as a power button
*/
class PowerButton : public PluginButton
Expand Down
9 changes: 0 additions & 9 deletions modules/gin_plugin/lookandfeel/gin_copperlookandfeel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,6 @@ void CopperLookAndFeel::drawButtonBackground (juce::Graphics&, juce::Button&, co

void CopperLookAndFeel::drawButtonText (juce::Graphics& g, juce::TextButton& b, bool, bool)
{
{
auto rc = b.getLocalBounds().toFloat();

g.setColour (findColour (PluginLookAndFeel::glass1ColourId));
g.fillRoundedRectangle (rc, rc.getHeight() / 2);
g.setColour (findColour (PluginLookAndFeel::glass2ColourId));
g.drawRoundedRectangle (rc, rc.getHeight() / 2, 1.0f);
}

auto c = b.findColour (b.getToggleState() ? juce::TextButton::textColourOnId : juce::TextButton::textColourOffId).withMultipliedAlpha (b.isEnabled() ? 1.0f : 0.5f);

if (b.isMouseOver() && b.isEnabled())
Expand Down

0 comments on commit 96f0293

Please sign in to comment.