@@ -1478,12 +1478,20 @@ class PowerButton final : public Component
14781478 chevron.setButtonText (Icons::ThinDown);
14791479 chevron.onClick = [this ] { showCallout (); };
14801480
1481+ toggle.addMouseListener (this , false );
1482+ chevron.addMouseListener (this , false );
1483+
14811484 addAndMakeVisible (toggle);
14821485 addAndMakeVisible (chevron);
1483-
14841486 setRepaintsOnMouseActivity (true );
14851487 }
14861488
1489+ ~PowerButton () override
1490+ {
1491+ toggle.removeMouseListener (this );
1492+ chevron.removeMouseListener (this );
1493+ }
1494+
14871495 void resized () override
14881496 {
14891497 auto b = getLocalBounds ();
@@ -1505,17 +1513,60 @@ class PowerButton final : public Component
15051513 toggle.setColour (TextButton::textColourOnId, colour);
15061514 }
15071515
1516+ void mouseEnter (MouseEvent const & e) override { updateHover (e); }
1517+ void mouseExit (MouseEvent const & e) override { updateHover (e); }
1518+ void mouseMove (MouseEvent const & e) override { updateHover (e); }
1519+
15081520 void paint (Graphics& g) override
15091521 {
1510- g.setColour (PlugDataColours::levelMeterBackgroundColour);
1511- g.fillRoundedRectangle (getLocalBounds ().toFloat ().reduced (0 , 4 .5f ), Corners::defaultCornerRadius);
1522+ auto const bounds = getLocalBounds ().toFloat ().reduced (0 , 4 .5f );
1523+ constexpr float cornerRadius = Corners::defaultCornerRadius;
1524+ auto const chevronWidth = 14 .0f ;
1525+
1526+ auto const togglePart = bounds.withWidth (bounds.getWidth () - chevronWidth);
1527+ auto const chevronPart = bounds.withLeft (bounds.getRight () - chevronWidth);
15121528
1513- g.setColour (PlugDataColours::levelMeterBackgroundColour.contrasting (0 .1f ));
1514- auto const x = getWidth () - 15 ;
1529+ auto const baseColour = PlugDataColours::levelMeterBackgroundColour;
1530+ auto const hoverColour = baseColour.contrasting (0 .06f );
1531+
1532+ {
1533+ Path p;
1534+ p.addRoundedRectangle (togglePart.getX (), togglePart.getY (),
1535+ togglePart.getWidth (), togglePart.getHeight (),
1536+ cornerRadius, cornerRadius,
1537+ true , false , true , false );
1538+ g.setColour (toggleHovered ? hoverColour : baseColour);
1539+ g.fillPath (p);
1540+ }
1541+ {
1542+ Path p;
1543+ p.addRoundedRectangle (chevronPart.getX (), chevronPart.getY (),
1544+ chevronPart.getWidth (), chevronPart.getHeight (),
1545+ cornerRadius, cornerRadius,
1546+ false , true , false , true );
1547+ g.setColour (chevronHovered ? hoverColour : baseColour);
1548+ g.fillPath (p);
1549+ }
1550+
1551+ g.setColour (baseColour.contrasting (0 .1f ));
1552+ auto const x = getWidth () - 15 .0f ;
15151553 g.drawLine (x, 4 .5f , x, getHeight () - 4 .5f );
15161554 }
15171555
15181556private:
1557+ void updateHover (MouseEvent const &)
1558+ {
1559+ auto const mousePos = getMouseXYRelative ();
1560+ bool const inToggle = toggle.getBounds ().contains (mousePos);
1561+ bool const inChevron = chevron.getBounds ().contains (mousePos);
1562+
1563+ if (inToggle != toggleHovered || inChevron != chevronHovered) {
1564+ toggleHovered = inToggle;
1565+ chevronHovered = inChevron;
1566+ repaint ();
1567+ }
1568+ }
1569+
15191570 void showCallout ()
15201571 {
15211572 auto * editor = findParentComponentOfClass<PluginEditor>();
@@ -1526,6 +1577,8 @@ class PowerButton final : public Component
15261577 PluginProcessor* pd;
15271578 SmallIconButton toggle;
15281579 SmallIconButton chevron;
1580+ bool toggleHovered = false ;
1581+ bool chevronHovered = false ;
15291582
15301583 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PowerButton)
15311584};
0 commit comments