Avoid having to change alpha for disabled components

pull/170/head
James Ball 2023-12-03 22:52:34 +00:00
rodzic 50cc383e25
commit a520ec1621
4 zmienionych plików z 14 dodań i 110 usunięć

Wyświetl plik

@ -45,13 +45,11 @@ OscirenderLookAndFeel::OscirenderLookAndFeel() {
void OscirenderLookAndFeel::drawComboBox(juce::Graphics& g, int width, int height, bool, int, int, int, int, juce::ComboBox& box) {
juce::Rectangle<int> boxBounds{0, 0, width, height};
float alpha = box.isEnabled() ? 1.0f : 0.5f;
g.setColour(box.findColour(juce::ComboBox::backgroundColourId).withAlpha(alpha));
g.setColour(box.findColour(juce::ComboBox::backgroundColourId));
g.fillRect(boxBounds.toFloat());
g.setColour(box.findColour(juce::ComboBox::outlineColourId).withAlpha(alpha));
g.setColour(box.findColour(juce::ComboBox::outlineColourId));
g.drawRect(boxBounds.toFloat().reduced(0.5f, 0.5f), 1.0f);
juce::Rectangle<int> arrowZone{width - 15, 0, 10, height};
@ -61,7 +59,7 @@ void OscirenderLookAndFeel::drawComboBox(juce::Graphics& g, int width, int heigh
path.lineTo((float)arrowZone.getRight(), (float)arrowZone.getCentreY() - 3.0f);
path.closeSubPath();
g.setColour(box.findColour(juce::ComboBox::arrowColourId).withAlpha(alpha));
g.setColour(box.findColour(juce::ComboBox::arrowColourId));
g.fillPath(path);
}
@ -140,101 +138,7 @@ void OscirenderLookAndFeel::drawGroupComponentOutline(juce::Graphics& g, int wid
}
void OscirenderLookAndFeel::drawLinearSlider(juce::Graphics& g, int x, int y, int width, int height, float sliderPos, float minSliderPos, float maxSliderPos, const juce::Slider::SliderStyle style, juce::Slider& slider) {
float alpha = slider.isEnabled() ? 1.0f : 0.5f;
if (slider.isBar())
{
g.setColour (slider.findColour (juce::Slider::trackColourId).withAlpha(alpha));
g.fillRect (slider.isHorizontal() ? juce::Rectangle<float> (static_cast<float> (x), (float) y + 0.5f, sliderPos - (float) x, (float) height - 1.0f)
: juce::Rectangle<float> ((float) x + 0.5f, sliderPos, (float) width - 1.0f, (float) y + ((float) height - sliderPos)));
drawLinearSliderOutline (g, x, y, width, height, style, slider);
}
else
{
auto isTwoVal = (style == juce::Slider::SliderStyle::TwoValueVertical || style == juce::Slider::SliderStyle::TwoValueHorizontal);
auto isThreeVal = (style == juce::Slider::SliderStyle::ThreeValueVertical || style == juce::Slider::SliderStyle::ThreeValueHorizontal);
auto trackWidth = juce::jmin (6.0f, slider.isHorizontal() ? (float) height * 0.25f : (float) width * 0.25f);
juce::Point<float> startPoint (slider.isHorizontal() ? (float) x : (float) x + (float) width * 0.5f,
slider.isHorizontal() ? (float) y + (float) height * 0.5f : (float) (height + y));
juce::Point<float> endPoint (slider.isHorizontal() ? (float) (width + x) : startPoint.x,
slider.isHorizontal() ? startPoint.y : (float) y);
juce::Path backgroundTrack;
backgroundTrack.startNewSubPath (startPoint);
backgroundTrack.lineTo (endPoint);
g.setColour (slider.findColour (juce::Slider::backgroundColourId));
g.strokePath (backgroundTrack, { trackWidth, juce::PathStrokeType::curved, juce::PathStrokeType::rounded });
juce::Path valueTrack;
juce::Point<float> minPoint, maxPoint, thumbPoint;
if (isTwoVal || isThreeVal)
{
minPoint = { slider.isHorizontal() ? minSliderPos : (float) width * 0.5f,
slider.isHorizontal() ? (float) height * 0.5f : minSliderPos };
if (isThreeVal)
thumbPoint = { slider.isHorizontal() ? sliderPos : (float) width * 0.5f,
slider.isHorizontal() ? (float) height * 0.5f : sliderPos };
maxPoint = { slider.isHorizontal() ? maxSliderPos : (float) width * 0.5f,
slider.isHorizontal() ? (float) height * 0.5f : maxSliderPos };
}
else
{
auto kx = slider.isHorizontal() ? sliderPos : ((float) x + (float) width * 0.5f);
auto ky = slider.isHorizontal() ? ((float) y + (float) height * 0.5f) : sliderPos;
minPoint = startPoint;
maxPoint = { kx, ky };
}
auto thumbWidth = getSliderThumbRadius (slider);
valueTrack.startNewSubPath (minPoint);
valueTrack.lineTo (isThreeVal ? thumbPoint : maxPoint);
g.setColour (slider.findColour (juce::Slider::trackColourId).withAlpha(alpha));
g.strokePath (valueTrack, { trackWidth, juce::PathStrokeType::curved, juce::PathStrokeType::rounded });
if (! isTwoVal)
{
g.setColour (slider.findColour (juce::Slider::thumbColourId));
g.fillEllipse (juce::Rectangle<float> (static_cast<float> (thumbWidth), static_cast<float> (thumbWidth)).withCentre (isThreeVal ? thumbPoint : maxPoint));
}
if (isTwoVal || isThreeVal)
{
auto sr = juce::jmin (trackWidth, (slider.isHorizontal() ? (float) height : (float) width) * 0.4f);
auto pointerColour = slider.findColour (juce::Slider::thumbColourId);
if (slider.isHorizontal())
{
drawPointer (g, minSliderPos - sr,
juce::jmax (0.0f, (float) y + (float) height * 0.5f - trackWidth * 2.0f),
trackWidth * 2.0f, pointerColour, 2);
drawPointer (g, maxSliderPos - trackWidth,
juce::jmin ((float) (y + height) - trackWidth * 2.0f, (float) y + (float) height * 0.5f),
trackWidth * 2.0f, pointerColour, 4);
}
else
{
drawPointer (g, juce::jmax (0.0f, (float) x + (float) width * 0.5f - trackWidth * 2.0f),
minSliderPos - trackWidth,
trackWidth * 2.0f, pointerColour, 1);
drawPointer (g, juce::jmin ((float) (x + width) - trackWidth * 2.0f, (float) x + (float) width * 0.5f), maxSliderPos - sr,
trackWidth * 2.0f, pointerColour, 3);
}
}
if (slider.isBar())
drawLinearSliderOutline (g, x, y, width, height, style, slider);
}
juce::LookAndFeel_V4::drawLinearSlider(g, x, y, width, height, sliderPos, minSliderPos, maxSliderPos, style, slider);
auto kx = slider.isHorizontal() ? sliderPos : ((float)x + (float)width * 0.5f);
auto ky = slider.isHorizontal() ? ((float)y + (float)height * 0.5f) : sliderPos;
@ -243,7 +147,7 @@ void OscirenderLookAndFeel::drawLinearSlider(juce::Graphics& g, int x, int y, in
auto thumbWidth = getSliderThumbRadius(slider);
g.setColour(slider.findColour(sliderThumbOutlineColourId).withAlpha(alpha));
g.setColour(slider.findColour(sliderThumbOutlineColourId));
g.drawEllipse(juce::Rectangle<float>(static_cast<float>(thumbWidth), static_cast<float>(thumbWidth)).withCentre(point), 1.0f);
}

Wyświetl plik

@ -11,10 +11,10 @@ enum ColourIds {
};
namespace Colours {
const juce::Colour dark{0xff424242};
const juce::Colour darker{0xff212121};
const juce::Colour veryDark{0xff111111};
const juce::Colour grey{0xff555555};
const juce::Colour dark{0xff555555};
const juce::Colour darker{0xff333333};
const juce::Colour veryDark{0xff000000};
const juce::Colour grey{0xff666666};
const juce::Colour accentColor{0xff00cc00};
}
@ -59,4 +59,4 @@ public:
void drawMenuBarBackground(juce::Graphics& g, int width, int height, bool, juce::MenuBarComponent& menuBar) override;
juce::CodeEditorComponent::ColourScheme getDefaultColourScheme();
};
};

Wyświetl plik

@ -148,6 +148,9 @@ void EffectComponent::paint(juce::Graphics& g) {
g.fillAll(findColour(effectComponentBackgroundColourId));
g.setColour(juce::Colours::white);
g.drawText(effect.parameters[index]->name, textBounds, juce::Justification::left);
}
void EffectComponent::paintOverChildren(juce::Graphics &g) {
if (!selected.getToggleState()) {
g.setColour(juce::Colours::black.withAlpha(0.5f));
g.fillAll();
@ -195,9 +198,5 @@ void EffectComponent::setSubParameter(bool subParameter) {
}
void EffectComponent::updateEnabled() {
bool enabled = selected.getToggleState();
slider.setEnabled(enabled);
lfoSlider.setEnabled(enabled);
lfo.setEnabled(enabled);
repaint();
}

Wyświetl plik

@ -14,6 +14,7 @@ public:
void resized() override;
void paint(juce::Graphics& g) override;
void paintOverChildren(juce::Graphics& g) override;
void mouseDown(const juce::MouseEvent& event) override;
void parameterValueChanged(int parameterIndex, float newValue) override;
void parameterGestureChanged(int parameterIndex, bool gestureIsStarting) override;