generated from sudara/pamplejuce
-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move top row components to a new class
- Loading branch information
1 parent
5963661
commit 7094bff
Showing
5 changed files
with
154 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
// 2023 Tote Bag Labs | ||
|
||
#include "ValentineTopRowPanel.h" | ||
#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"; | ||
inline const juce::String kCompressSliderText = "COMPRESS"; | ||
inline const juce::String kSaturateSliderText = "SATURATE"; | ||
} // namespace detail | ||
|
||
TopRowPanel::TopRowPanel (ValentineAudioProcessor& processor) | ||
: crushEnableButton (parameterID (VParameter::crushEnable), processor.treeState) | ||
, crushSlider (detail::kCrushSliderText, | ||
parameterID (VParameter::bitCrush), | ||
processor.treeState) | ||
, compressSlider (detail::kCompressSliderText, | ||
parameterID (VParameter::inputGain), | ||
processor.treeState) | ||
, saturateEnableButton (parameterID (VParameter::saturateEnable), processor.treeState) | ||
, saturateSlider (detail::kSaturateSliderText, | ||
parameterID (VParameter::saturation), | ||
processor.treeState) | ||
, valentineTblLogo ( | ||
juce::Drawable::createFromImageData (BinaryData::val_totebag_logo_svg, | ||
BinaryData::val_totebag_logo_svgSize)) | ||
{ | ||
addAndMakeVisible (crushEnableButton); | ||
addAndMakeVisible (crushSlider); | ||
addAndMakeVisible (compressSlider); | ||
addAndMakeVisible (saturateEnableButton); | ||
addAndMakeVisible (saturateSlider); | ||
addAndMakeVisible (valentineTblLogo.get()); | ||
} | ||
|
||
TopRowPanel::~TopRowPanel() | ||
{ | ||
} | ||
|
||
void TopRowPanel::resized() | ||
{ | ||
auto bounds = getLocalBounds(); | ||
|
||
auto topRowSliders = | ||
bounds.removeFromLeft (juce::roundToInt (bounds.getWidth() * .65f)); | ||
const auto topRowButtonWidth = juce::roundToInt (topRowSliders.getWidth() * .033f); | ||
const auto adjustedTopRowComponentsWidth = | ||
topRowSliders.getWidth() - (topRowButtonWidth * 2.0f); | ||
const auto topRowSliderWidth = | ||
juce::roundToInt (adjustedTopRowComponentsWidth / 3.0f); | ||
|
||
const auto topRowButtonSpacer = | ||
juce::roundToInt ((topRowSliders.getHeight() - topRowButtonWidth) * .5f); | ||
|
||
// See below note about horizontal LabelSlider dimensions and button placement. | ||
const auto topRowButtonNudge = juce::roundToInt (topRowButtonWidth / 1.5f); | ||
|
||
const auto initialCrushButtonX = topRowSliders.getX(); | ||
const auto crushEnableButtonBounds = | ||
topRowSliders.removeFromLeft (topRowButtonWidth) | ||
.reduced (0, topRowButtonSpacer) | ||
.withX (initialCrushButtonX + topRowButtonNudge); | ||
|
||
crushEnableButton.setBounds (crushEnableButtonBounds); | ||
crushSlider.setBounds ( | ||
topRowSliders.removeFromLeft (topRowSliderWidth).reduced (topRowButtonNudge, 0)); | ||
compressSlider.setBounds (topRowSliders.removeFromLeft (topRowSliderWidth)); | ||
|
||
const auto initialSaturateButtonX = topRowSliders.getX(); | ||
const auto saturateEnableButtonBounds = | ||
topRowSliders.removeFromLeft (topRowButtonWidth) | ||
.reduced (0, topRowButtonSpacer) | ||
.withX (initialSaturateButtonX + topRowButtonNudge); | ||
|
||
saturateEnableButton.setBounds (saturateEnableButtonBounds); | ||
saturateSlider.setBounds ( | ||
topRowSliders.removeFromLeft (topRowSliderWidth).reduced (topRowButtonNudge, 0)); | ||
|
||
const auto logoHeight = bounds.getHeight() * .25f; | ||
const auto logoWidth = bounds.getWidth() * .75f; | ||
|
||
const auto logoVerticalSpacer = (bounds.getHeight() - logoHeight) / 2.0f; | ||
bounds.removeFromTop (juce::roundToInt (logoVerticalSpacer)); | ||
|
||
const auto logoHorizontalSpacer = (bounds.getWidth() - logoWidth) / 2.0f; | ||
|
||
// logoHorizontalSpacer is the amount we hypothetically should remove from left | ||
// in order to have the log centred. However, the spacing is fudged here to account | ||
// for the fact that our sliders don't take up all of the horizontal space given | ||
// to them. | ||
const auto horizontalKludgeQuotient = .8f; | ||
bounds.removeFromLeft ( | ||
juce::roundToInt (logoHorizontalSpacer * horizontalKludgeQuotient)); | ||
|
||
const auto valentineLogoBounds = bounds.removeFromLeft (juce::roundToInt (logoWidth)) | ||
.removeFromTop (juce::roundToInt (logoHeight)); | ||
|
||
valentineTblLogo->setTransformToFit ( | ||
valentineLogoBounds.toFloat(), | ||
juce::RectanglePlacement (juce::RectanglePlacement::centred | ||
| juce::RectanglePlacement::fillDestination)); | ||
} | ||
|
||
} // namespace valentine | ||
} // namespace tote_bag |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#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; | ||
|
||
namespace tote_bag | ||
{ | ||
namespace valentine | ||
{ | ||
class TopRowPanel : public juce::Component | ||
{ | ||
public: | ||
TopRowPanel (ValentineAudioProcessor& processor); | ||
~TopRowPanel() override; | ||
|
||
void resized() override; | ||
|
||
private: | ||
ToggleButton crushEnableButton; | ||
LabelSlider crushSlider; | ||
LabelSlider compressSlider; | ||
ToggleButton saturateEnableButton; | ||
LabelSlider saturateSlider; | ||
|
||
std::unique_ptr<juce::Drawable> valentineTblLogo; | ||
}; | ||
} // namespace valentine | ||
} // namespace tote_bag |