diff --git a/examples/Demo/Source/Demos/WidgetsDemo.cpp b/examples/Demo/Source/Demos/WidgetsDemo.cpp index 7db1a79b35..7e9b64088f 100644 --- a/examples/Demo/Source/Demos/WidgetsDemo.cpp +++ b/examples/Demo/Source/Demos/WidgetsDemo.cpp @@ -129,7 +129,7 @@ struct SlidersPage : public Component s->setSliderStyle (Slider::LinearHorizontal); s->setTextBoxStyle (Slider::NoTextBox, false, 0, 0); s->setBounds (180, 65, 150, 20); - s->setPopupDisplayEnabled (true, this); + s->setPopupDisplayEnabled (true, false, this); s->setTextValueSuffix (" nuns required to change a lightbulb"); s = createSlider (false); @@ -170,13 +170,13 @@ struct SlidersPage : public Component s->setSliderStyle (Slider::LinearBarVertical); s->setTextBoxStyle (Slider::NoTextBox, false, 0, 0); s->setBounds (540, 35, 20, 230); - s->setPopupDisplayEnabled (true, this); + s->setPopupDisplayEnabled (true, true, this); s->setTextValueSuffix (" mickles in a muckle"); for (int i = 7; i <= 10; ++i) { sliders.getUnchecked(i)->setTextBoxStyle (Slider::NoTextBox, false, 0, 0); - sliders.getUnchecked(i)->setPopupDisplayEnabled (true, this); + sliders.getUnchecked(i)->setPopupDisplayEnabled (true, false, this); } /* Here, we'll create a Value object, and tell a bunch of our sliders to use it as their diff --git a/modules/juce_gui_basics/widgets/juce_Slider.cpp b/modules/juce_gui_basics/widgets/juce_Slider.cpp index b3d6dac21d..2fa8a560ce 100644 --- a/modules/juce_gui_basics/widgets/juce_Slider.cpp +++ b/modules/juce_gui_basics/widgets/juce_Slider.cpp @@ -24,10 +24,10 @@ ============================================================================== */ -class Slider::Pimpl : public AsyncUpdater, - public Button::Listener, - public Label::Listener, - public Value::Listener +class Slider::Pimpl : private AsyncUpdater, + private Button::Listener, + private Label::Listener, + private Value::Listener { public: Pimpl (Slider& s, SliderStyle sliderStyle, TextEntryBoxPosition textBoxPosition) @@ -118,11 +118,13 @@ public: int v = std::abs (roundToInt (newInt * 10000000)); if (v > 0) + { while ((v % 10) == 0) { --numDecimalPlaces; v /= 10; } + } } // keep the current values inside the new range.. @@ -180,9 +182,7 @@ public: updateText(); owner.repaint(); - - if (popupDisplay != nullptr) - popupDisplay->updatePosition (owner.getTextFromValue (newValue)); + updatePopupDisplay (newValue); triggerChangeMessage (notification); } @@ -217,9 +217,7 @@ public: lastValueMin = newValue; valueMin = newValue; owner.repaint(); - - if (popupDisplay != nullptr) - popupDisplay->updatePosition (owner.getTextFromValue (newValue)); + updatePopupDisplay (newValue); triggerChangeMessage (notification); } @@ -254,9 +252,7 @@ public: lastValueMax = newValue; valueMax = newValue; owner.repaint(); - - if (popupDisplay != nullptr) - popupDisplay->updatePosition (owner.getTextFromValue (valueMax.getValue())); + updatePopupDisplay (valueMax.getValue()); triggerChangeMessage (notification); } @@ -680,6 +676,7 @@ public: if (dx * dx + dy * dy > 25.0f) { double angle = std::atan2 ((double) dx, (double) -dy); + while (angle < 0.0) angle += double_Pi * 2.0; @@ -730,12 +727,12 @@ public: || ((style == LinearHorizontal || style == LinearVertical || style == LinearBar || style == LinearBarVertical) && ! snapsToMousePos)) { - const float mouseDiff = (style == RotaryHorizontalDrag - || style == LinearHorizontal - || style == LinearBar - || (style == IncDecButtons && incDecDragDirectionIsHorizontal())) - ? e.position.x - mouseDragStartPos.x - : mouseDragStartPos.y - e.position.y; + auto mouseDiff = (style == RotaryHorizontalDrag + || style == LinearHorizontal + || style == LinearBar + || (style == IncDecButtons && incDecDragDirectionIsHorizontal())) + ? e.position.x - mouseDragStartPos.x + : mouseDragStartPos.y - e.position.y; newPos = owner.valueToProportionOfLength (valueOnMouseDown) + mouseDiff * (1.0 / pixelsForFullDragExtent); @@ -748,8 +745,8 @@ public: } else if (style == RotaryHorizontalVerticalDrag) { - const float mouseDiff = (e.position.x - mouseDragStartPos.x) - + (mouseDragStartPos.y - e.position.y); + auto mouseDiff = (e.position.x - mouseDragStartPos.x) + + (mouseDragStartPos.y - e.position.y); newPos = owner.valueToProportionOfLength (valueOnMouseDown) + mouseDiff * (1.0 / pixelsForFullDragExtent); @@ -809,6 +806,7 @@ public: useDragEvents = false; mouseDragStartPos = mousePosWhenLastDragged = e.position; currentDrag = nullptr; + popupDisplay = nullptr; if (owner.isEnabled()) { @@ -841,17 +839,10 @@ public: : currentValue)).getValue(); valueOnMouseDown = valueWhenLastDragged; - if (popupDisplayEnabled) + if (showPopupOnDrag || showPopupOnHover) { - PopupDisplayComponent* const popup = new PopupDisplayComponent (owner); - popupDisplay = popup; - - if (parentForPopupDisplay != nullptr) - parentForPopupDisplay->addChildComponent (popup); - else - popup->addToDesktop (ComponentPeer::windowIsTemporary); - - popup->setVisible (true); + showPopupDisplay(); + popupDisplay->stopTimer(); } currentDrag = new DragInProgress (*this); @@ -950,12 +941,57 @@ public: } else if (popupDisplay != nullptr) { - popupDisplay->startTimer (2000); + popupDisplay->startTimer (200); } currentDrag = nullptr; } + void mouseMove() + { + if (showPopupOnHover + && style != TwoValueHorizontal + && style != TwoValueVertical) + { + if (owner.isMouseOver (true) && owner.getTopLevelComponent()->hasKeyboardFocus (true)) + { + if (popupDisplay == nullptr) + showPopupDisplay(); + + updatePopupDisplay (getValue()); + + if (popupDisplay != nullptr) + popupDisplay->startTimer (2000); + } + } + } + + void mouseExit() + { + popupDisplay = nullptr; + } + + void showPopupDisplay() + { + if (popupDisplay == nullptr) + { + popupDisplay = new PopupDisplayComponent (owner); + + if (parentForPopupDisplay != nullptr) + parentForPopupDisplay->addChildComponent (popupDisplay); + else + popupDisplay->addToDesktop (ComponentPeer::windowIsTemporary); + + popupDisplay->setVisible (true); + } + } + + void updatePopupDisplay (double valueToShow) + { + if (popupDisplay != nullptr) + popupDisplay->updatePosition (owner.getTextFromValue (valueToShow)); + } + bool canDoubleClickToValue() const { return doubleClickToValue @@ -1196,7 +1232,8 @@ public: bool userKeyOverridesVelocity = true; bool incDecButtonsSideBySide = false; bool sendChangeOnlyOnRelease = false; - bool popupDisplayEnabled = false; + bool showPopupOnDrag = false; + bool showPopupOnHover = false; bool menuEnabled = false; bool useDragEvents = false; bool incDecDragged = false; @@ -1207,10 +1244,9 @@ public: ScopedPointer