Skip to content

Commit

Permalink
Get a new toggle button kind of placed (split later)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoseDiazRohena committed Dec 12, 2023
1 parent 7570f73 commit 5b69ec0
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 1 deletion.
1 change: 1 addition & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ BreakBeforeBraces: Custom
BraceWrapping: # Allman except for lambdas
AfterClass: true
AfterCaseLabel: true
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterStruct: true
Expand Down
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,14 @@ set(SourceFiles
libs/tote_bag/juce_gui/components/widgets/LabelSlider.h
libs/tote_bag/juce_gui/components/widgets/ParameterSlider.h
libs/tote_bag/juce_gui/components/widgets/ParameterTextButton.h
libs/tote_bag/juce_gui/components/widgets/tbl_ToggleButton.h
libs/tote_bag/juce_gui/components/widgets/DrawableParameterButton.cpp
libs/tote_bag/juce_gui/components/widgets/FlatTextButton.cpp
libs/tote_bag/juce_gui/components/widgets/FlatTextChooser.cpp
libs/tote_bag/juce_gui/components/widgets/LabelSlider.cpp
libs/tote_bag/juce_gui/components/widgets/ParameterSlider.cpp
libs/tote_bag/juce_gui/components/widgets/ParameterTextButton.cpp
libs/tote_bag/juce_gui/components/widgets/tbl_ToggleButton.cpp

libs/tote_bag/juce_gui/lookandfeel/LookAndFeel.h
libs/tote_bag/juce_gui/lookandfeel/LookAndFeelConstants.h
Expand Down
14 changes: 14 additions & 0 deletions libs/tote_bag/juce_gui/components/widgets/tbl_ToggleButton.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// 2023 Tote Bag Labs

#include "tbl_ToggleButton.h"

namespace tote_bag
{
ToggleButton::ToggleButton (const juce::String& parameterId,
juce::AudioProcessorValueTreeState& stateToControl)
: juce::ToggleButton (parameterId)
, buttonValue (stateToControl, parameterId, *this)
{
setClickingTogglesState (true);
}
} // namespace tote_bag
28 changes: 28 additions & 0 deletions libs/tote_bag/juce_gui/components/widgets/tbl_ToggleButton.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

// 2023 Tote Bag Labs

#pragma once

#include <juce_audio_processors/juce_audio_processors.h>
#include <juce_gui_basics/juce_gui_basics.h>

namespace tote_bag
{
class ToggleButton : public juce::ToggleButton
{
public:
ToggleButton (const juce::String& parameterId,
juce::AudioProcessorValueTreeState& stateToControl);

enum ColourIds
{
backgroundColourId = 0x1006504,
highightColourId = 0x1006505,
};

private:
juce::AudioProcessorValueTreeState::ButtonAttachment buttonValue;

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ToggleButton)
};
} // namespace tote_bag
24 changes: 24 additions & 0 deletions libs/tote_bag/juce_gui/lookandfeel/LookAndFeel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "LookAndFeelConstants.h"

#include "tote_bag/juce_gui/components/widgets/FlatTextButton.h"
#include "tote_bag/juce_gui/components/widgets/tbl_ToggleButton.h"

namespace tote_bag
{
Expand All @@ -32,6 +33,10 @@ LookAndFeel::LookAndFeel()
setColour (juce::Slider::rotarySliderOutlineColourId, vPinkDark);
setColour (juce::Slider::rotarySliderFillColourId, juce::Colours::floralwhite);

// toggle button colours
setColour (ToggleButton::backgroundColourId, juce::Colours::grey);
setColour (ToggleButton::highightColourId, juce::Colours::green);

// so we don't get background painting on drawable buttons
setColour (juce::DrawableButton::backgroundOnColourId,
juce::Colours::transparentWhite);
Expand Down Expand Up @@ -399,6 +404,25 @@ void LookAndFeel::drawPopupMenuItem (juce::Graphics& g,
g.drawFittedText (text, r, juce::Justification::left, 1);
}

void LookAndFeel::drawToggleButton (juce::Graphics& g,
juce::ToggleButton& button,
bool,
bool)
{
const auto backgroundBounds = button.getLocalBounds();
g.setColour (findColour (ToggleButton::backgroundColourId));
g.fillEllipse (backgroundBounds.toFloat());

const auto buttonIsActive = button.getToggleState();
if (buttonIsActive)
{
const auto highlightBounds = backgroundBounds.reduced (
juce::roundToInt (backgroundBounds.getWidth() * .20f));
g.setColour (findColour (ToggleButton::highightColourId));
g.fillEllipse (highlightBounds.toFloat());
}
}

juce::Slider::SliderLayout LookAndFeel::getSliderLayout (juce::Slider& slider)
{
// 1. compute the actually visible textBox size from the slider textBox size and some additional constraints
Expand Down
5 changes: 5 additions & 0 deletions libs/tote_bag/juce_gui/lookandfeel/LookAndFeel.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ class LookAndFeel : public juce::LookAndFeel_V4,
const juce::Drawable*,
const juce::Colour*) override;

void drawToggleButton (juce::Graphics& g,
juce::ToggleButton& button,
bool shouldDrawButtonAsHighlighted,
bool shouldDrawButtonAsDown) override;

juce::Slider::SliderLayout getSliderLayout (juce::Slider& slider) override;

enum ColourIds { knobColourId = 0x1001800, pointerColourId = 0x1001801 };
Expand Down
28 changes: 27 additions & 1 deletion src/gui/panels/ValentineCenterPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,31 @@
#include "BinaryData.h"
#include "PluginProcessor.h"

#include "ValentineParameters.h"
#include "tote_bag/juce_gui/lookandfeel/LookAndFeelConstants.h"
#include "tote_bag/juce_gui/utilities/GraphicsUtilities.h"

namespace tote_bag
{
namespace valentine
{
namespace detail
{
inline const juce::String kCrushSliderText = "CRUSH";
} // namespace detail

CenterPanel::CenterPanel (ValentineAudioProcessor& processor)
: borderLineThickness (0.0f)
, borderCornerSize (0.0f)
, crushSlider (detail::kCrushSliderText,
parameterID (VParameter::bitCrush),
processor.treeState)
, crushEnableButton (parameterID (VParameter::crushEnable), processor.treeState)
, valentineLogo (
juce::Drawable::createFromImageData (BinaryData::logo_218x40_svg,
BinaryData::logo_218x40_svgSize))
{
addAndMakeVisible (crushEnableButton);
addAndMakeVisible (valentineLogo.get());
}

Expand Down Expand Up @@ -52,9 +63,24 @@ void CenterPanel::resized()
topRowBorder = topRowBounds.reduced (margin);

auto topRowComponents = topRowBorder.reduced (margin);
const auto topRowSliders = topRowComponents.removeFromLeft (
auto topRowSliders = topRowComponents.removeFromLeft (
juce::roundToInt (topRowComponents.getWidth() * .65f));

// Get basic width for top row sliders
auto topRowSliderWidth = juce::roundToInt (topRowSliders.getWidth() * .33f);
// Use slider width as reference for button width
const auto topRowButtonWidth = juce::roundToInt (topRowSliderWidth * .10f);
// Adjust button width to make room
topRowSliderWidth -= topRowButtonWidth;

auto crushButtonBounds = topRowSliders.removeFromLeft (topRowButtonWidth);
auto crushButtonSpacer = juce::roundToInt (
(crushButtonBounds.getHeight() - crushButtonBounds.getWidth()) * .5f);
crushButtonBounds.removeFromTop (crushButtonSpacer);
crushButtonBounds.removeFromBottom (crushButtonSpacer);

crushEnableButton.setBounds (crushButtonBounds);

const auto logoHeight = juce::roundToInt (topRowComponents.getHeight() * .25f);
topRowComponents.removeFromTop (logoHeight * 1.45f);
topRowComponents.removeFromRight (logoHeight * .5f);
Expand Down
6 changes: 6 additions & 0 deletions src/gui/panels/ValentineCenterPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

#pragma once

#include "tote_bag/juce_gui/components/widgets/LabelSlider.h"
#include "tote_bag/juce_gui/components/widgets/tbl_ToggleButton.h"

#include <juce_gui_basics/juce_gui_basics.h>

class ValentineAudioProcessor;
Expand All @@ -26,6 +29,9 @@ class CenterPanel : public juce::Component
float borderLineThickness;
float borderCornerSize;

LabelSlider crushSlider;
ToggleButton crushEnableButton;

std::unique_ptr<juce::Drawable> valentineLogo;

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (CenterPanel)
Expand Down

0 comments on commit 5b69ec0

Please sign in to comment.