Skip to content

Commit

Permalink
updated tabbedButtonBar
Browse files Browse the repository at this point in the history
  • Loading branch information
hsetlik committed Apr 16, 2021
1 parent a355193 commit d70d350
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 5 deletions.
25 changes: 22 additions & 3 deletions Source/CustomLnF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,26 @@ void LnF1::drawLinearSlider(juce::Graphics &g, int x, int y, int width, int heig
thumbWidth,
thumbHeight,
corner);



}


void LnF1::drawButtonBackground(juce::Graphics &g, juce::Button &b, const juce::Colour &backgroundColour, bool shouldDrawButtonAsHighlighted, bool shouldDrawButtonAsDown)
{
if(!b.getToggleState())
g.setColour(UXPalette::darkGray4);
else
g.setColour(UXPalette::lightGray);
auto fBounds = b.getLocalBounds().toFloat();
g.fillRoundedRectangle(fBounds, 5.0f);
}

void LnF1::drawButtonText(juce::Graphics &g, juce::TextButton &t, bool shouldDrawHighlighted, bool shouldDrawDown)
{
auto fBounds = t.getLocalBounds().toFloat();
auto delta = fBounds.getHeight() / 6.5f;
fBounds = fBounds.reduced(delta);
buttonFont = juce::Font(buttonFontName, 15.0f, 0);
g.setFont(buttonFont);
g.setColour(juce::Colours::white);
g.drawFittedText(t.getButtonText(), fBounds.toType<int>(), juce::Justification::centred, 1);
}
68 changes: 67 additions & 1 deletion Source/CustomLnF.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,18 @@
class LnF1 : public juce::LookAndFeel_V4
{
public:
LnF1()
LnF1() : buttonFontName("Bebas Neue")
{
setDefaultSansSerifTypefaceName("Bebas Neue");
}
void drawRotarySlider (juce::Graphics& g, int x, int y, int width, int height, float sliderPos,
const float rotaryStartAngle, const float rotaryEndAngle, juce::Slider& s) override;
void drawLinearSlider(juce::Graphics &g, int x, int y, int width, int height, float sliderPos, float minSliderPos, float maxSliderPos, const juce::Slider::SliderStyle, juce::Slider &) override;
void drawButtonBackground (juce::Graphics &, juce::Button &b, const juce::Colour &backgroundColour, bool shouldDrawButtonAsHighlighted, bool shouldDrawButtonAsDown) override;
void drawButtonText(juce::Graphics& g, juce::TextButton& t, bool shouldDrawHighlighted, bool shouldDrawDown) override;
private:
juce::String buttonFontName;
juce::Font buttonFont;
};

class LnF2 : public juce::LookAndFeel_V4
Expand All @@ -44,3 +50,63 @@ class OutputButtonLnF : public juce::LookAndFeel_V4
return juce::Font("Bebas Neue", 15.0f, 0);
}
};

class TabbedButtonLnF : public juce::LookAndFeel_V4
{
public:
TabbedButtonLnF()
{
setDefaultSansSerifTypefaceName("Bebas Neue");
}
juce::Font getTabButtonFont (juce::TabBarButton &, float height) override
{
return juce::Font("Bebas Neue", height, 0);
}
void createTabButtonShape(juce::TabBarButton& b, juce::Path& path, bool isMouseOver, bool isMouseDown) override
{
auto fBounds = b.getLocalBounds().toFloat();
auto bottomLeft = std::make_pair(fBounds.getX(), fBounds.getBottom());
auto bottomRight = std::make_pair(fBounds.getRight(), fBounds.getBottom());
auto dX = fBounds.getWidth() * 0.15f;
auto topLeft = std::make_pair(fBounds.getX() + dX, fBounds.getY());
auto topRight = std::make_pair(fBounds.getRight() - dX, fBounds.getY());
path.startNewSubPath(topLeft.first, topLeft.second);
path.lineTo(topRight.first, topRight.second);
path.lineTo(bottomRight.first, bottomRight.second);
path.lineTo(bottomLeft.first, bottomLeft.second);
path.closeSubPath();
}
void drawTabButton (juce::TabBarButton &b, juce::Graphics &g, bool isMouseOver, bool isMouseDown) override
{
juce::Path path;
auto fBounds = b.getLocalBounds().toFloat();
auto bottomLeft = std::make_pair(fBounds.getX(), fBounds.getBottom());
auto bottomRight = std::make_pair(fBounds.getRight(), fBounds.getBottom());
auto dX = fBounds.getWidth() * 0.15f;
auto topLeft = std::make_pair(fBounds.getX() + dX, fBounds.getY());
auto topRight = std::make_pair(fBounds.getRight() - dX, fBounds.getY());
path.startNewSubPath(topLeft.first, topLeft.second);
path.lineTo(topRight.first, topRight.second);
path.lineTo(bottomRight.first, bottomRight.second);
path.lineTo(bottomLeft.first, bottomLeft.second);
path.closeSubPath();
g.setColour(b.getTabBackgroundColour());
if(b.isFrontTab())
g.setColour(UXPalette::lightGray);
g.fillPath(path);
drawTabButtonText(b, g, isMouseOver, isMouseDown);
}
void drawTabButtonText(juce::TabBarButton &b, juce::Graphics &g, bool isMouseOver, bool isMouseDown) override
{
g.setFont(getTabButtonFont(b, (float)b.getTextArea().getHeight() * 0.75f));
auto fBounds = b.getLocalBounds().toFloat();
fBounds = fBounds.reduced(fBounds.getHeight() / 8.0f);
auto& bar = b.getTabbedButtonBar();
auto tabNames = bar.getTabNames();
auto idx = bar.indexOfTabButton(&b);
auto& str = tabNames[idx];
g.setColour(juce::Colours::white);
g.drawText(str, fBounds.toType<int>(), juce::Justification::centred);
}

};
1 change: 1 addition & 0 deletions Source/GlobalColor.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ static juce::Colour darkGray1 = Color::RGBColor(37, 50, 53);
static juce::Colour darkGray2 = Color::RGBColor(50, 80, 90);
static juce::Colour lightGray = Color::RGBColor(125, 126, 129);
static juce::Colour darkGray3 = lightGray.darker(0.7f);
static juce::Colour darkGray4 = lightGray.darker(0.9f);
static juce::Colour lightRed = Color::RGBColor(226, 76, 85);
static juce::Colour darkRed = lightRed.darker(0.45f);
static juce::Colour lightOrange = Color::RGBColor(249, 171, 62);
Expand Down
10 changes: 9 additions & 1 deletion Source/LfoGroupComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@
#include "LfoComponent.h"
#include "FilterPanel.h"
#include "WaveGraph.h"
#include "CustomLnF.h"

class LfoGroupComponent : public juce::TabbedComponent
{
public:
LfoGroupComponent() : juce::TabbedComponent(juce::TabbedButtonBar::TabsAtTop)
{
setLookAndFeel(&look);
getTabbedButtonBar().setLookAndFeel(&look);
auto tabColor = UXPalette::darkGray3;
setTabBarDepth(25);
for(int i = 0; i < 4; ++i)
Expand All @@ -29,7 +32,11 @@ class LfoGroupComponent : public juce::TabbedComponent
}
addTab("Filter", tabColor, &fPanel, false);
}
~LfoGroupComponent() {}
~LfoGroupComponent()
{
setLookAndFeel(nullptr);
getTabbedButtonBar().setLookAndFeel(nullptr);
}
void attachChildren(juce::AudioProcessorValueTreeState* pTree)
{
for(int i = 0; i < children.size(); ++i)
Expand All @@ -41,4 +48,5 @@ class LfoGroupComponent : public juce::TabbedComponent
private:
juce::OwnedArray<LfoComponent> children;
FilterPanel fPanel;
TabbedButtonLnF look;
};

0 comments on commit d70d350

Please sign in to comment.