Skip to content

Commit

Permalink
Get rid of this multiple outlines and drop shadow business
Browse files Browse the repository at this point in the history
  • Loading branch information
JoseDiazRohena committed Jan 5, 2024
1 parent 9a814c3 commit 18e4fe2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 56 deletions.
58 changes: 4 additions & 54 deletions libs/tote_bag/juce_gui/lookandfeel/LookAndFeel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@ void LookAndFeel::drawKnob (juce::Graphics& g,
const float radius,
const float toAngle,
const juce::Rectangle<float> bounds,
juce::Slider&,
const bool withDropShadow)
juce::Slider&)
{
const auto centreX = bounds.getCentreX();
const auto centreY = bounds.getCentreY();
Expand All @@ -137,63 +136,14 @@ void LookAndFeel::drawKnob (juce::Graphics& g,
g.setColour (fillColour);
g.fillEllipse (rx, ry, rw, rw);

// Get thicknesses for outline rings...
const auto innerOutlineThickness = juce::roundToInt (juce::jmax ((rw * .05f), 1.0f));
const auto outerOutlineThickness = innerOutlineThickness * .15f;

// Offset inner outline by its thickness
auto innerOutlineRadius = radius - (innerOutlineThickness * .5f);
auto innerOutlineRx = centreX - innerOutlineRadius;
auto innerOutlineRy = centreY - innerOutlineRadius;
auto innerOutlineRw = innerOutlineRadius * 2.0f;

// Draw inner outline
g.setColour (fillColour.darker (.15f));
g.drawEllipse (innerOutlineRx,
innerOutlineRy,
innerOutlineRw,
innerOutlineRw,
innerOutlineThickness);

// Offset outer outline by its thickness
auto outerOutlineRadius = radius - (outerOutlineThickness * .5f);
auto outerOutlineRx = centreX - outerOutlineRadius;
auto outerOutlineRy = centreY - outerOutlineRadius;
auto outerOutlineRw = outerOutlineRadius * 2.0f;

// Draw outer outline
if (withDropShadow)
{
auto xOffset = juce::jmin (juce::roundToInt (innerOutlineThickness * .25), 1);
auto yOffset = juce::jmin (juce::roundToInt (innerOutlineThickness * .5), 1);

auto shadow = juce::DropShadow (fillColour.darker(),
innerOutlineThickness,
{xOffset, yOffset});
juce::Path shadowPath;
shadowPath.addEllipse (outerOutlineRx,
outerOutlineRy,
outerOutlineRw,
outerOutlineRw);
shadow.drawForPath (g, shadowPath);
}
else
{
g.setColour (fillColour.darker (.85f));
g.drawEllipse (outerOutlineRx,
outerOutlineRy,
outerOutlineRw,
outerOutlineRw,
outerOutlineThickness);
}

// Pointer
juce::Path p;
auto pointerLength = radius * 0.33f;
auto pointerThickness = pointerLength * .2f;
const auto pointerY = juce::roundToInt (juce::jmax ((rw * .05f), 1.0f)) - radius;
auto cornerSize = pointerThickness * .35f;
p.addRoundedRectangle (-pointerThickness * 0.5f,
-radius + innerOutlineThickness,
pointerY,
pointerThickness,
pointerLength,
cornerSize,
Expand Down Expand Up @@ -239,7 +189,7 @@ void LookAndFeel::drawRotarySlider (juce::Graphics& g,

const auto knobRadius = arcRadius * .80f;

drawKnob (g, knobRadius, toAngle, bounds, slider, true);
drawKnob (g, knobRadius, toAngle, bounds, slider);
}

juce::Font LookAndFeel::getTextButtonFont (juce::TextButton&, int buttonHeight)
Expand Down
3 changes: 1 addition & 2 deletions libs/tote_bag/juce_gui/lookandfeel/LookAndFeel.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ class LookAndFeel : public juce::LookAndFeel_V4,
const float radius,
const float toAngle,
const juce::Rectangle<float> bounds,
juce::Slider&,
const bool withDropShadow);
juce::Slider&);

void drawRotarySlider (juce::Graphics& g,
int x,
Expand Down

0 comments on commit 18e4fe2

Please sign in to comment.