29static double getStepSize (
const Slider& slider)
31 const auto interval = slider.getInterval();
34 : slider.getRange().getLength() * 0.01;
61 void registerListeners()
68 bool isHorizontal()
const noexcept
76 bool isVertical()
const noexcept
84 bool isRotary()
const noexcept
92 bool isBar()
const noexcept
98 bool isTwoValue()
const noexcept
104 bool isThreeValue()
const noexcept
110 bool incDecDragDirectionIsHorizontal()
const noexcept
112 return incDecButtonMode == incDecButtonsDraggable_Horizontal
113 || (incDecButtonMode == incDecButtonsDraggable_AutoDirection && incDecButtonsSideBySide);
116 float getPositionOfValue (
double value)
const
118 if (isHorizontal() || isVertical())
119 return getLinearSliderPos (value);
128 numDecimalPlaces = fixedNumDecimalPlaces;
131 int getNumDecimalPlacesToDisplay()
const
133 return fixedNumDecimalPlaces == -1 ? numDecimalPlaces : fixedNumDecimalPlaces;
138 if (fixedNumDecimalPlaces == -1)
142 numDecimalPlaces = 7;
148 while ((v % 10) == 0 && numDecimalPlaces > 0)
183 double getValue()
const
198 newValue = constrainedValue (newValue);
205 static_cast<double> (valueMax.
getValue()),
211 if (valueBox !=
nullptr)
212 valueBox->hideEditor (
true);
214 lastCurrentValue = newValue;
220 currentValue = newValue;
235 newValue = constrainedValue (newValue);
242 newValue =
jmin (
static_cast<double> (valueMax.
getValue()), newValue);
249 newValue =
jmin (lastCurrentValue, newValue);
254 lastValueMin = newValue;
257 updatePopupDisplay();
269 newValue = constrainedValue (newValue);
276 newValue =
jmax (
static_cast<double> (valueMin.
getValue()), newValue);
283 newValue =
jmax (lastCurrentValue, newValue);
288 lastValueMax = newValue;
291 updatePopupDisplay();
321 double getMinValue()
const
330 double getMaxValue()
const
387 sliderBeingDragged = -1;
389 Component::BailOutChecker
checker (&owner);
390 listeners.callChecked (
checker, [&] (Slider::Listener&
l) {
l.sliderDragEnded (&owner); });
395 NullCheckedInvocation::invoke (owner.
onDragEnd);
398 void incrementOrDecrement (
double delta)
404 if (currentDrag !=
nullptr)
410 ScopedDragNotification drag (owner);
448 if (valueBox !=
nullptr)
452 if (newValue != valueBox->getText())
456 updatePopupDisplay();
459 double constrainedValue (
double value)
const
464 float getLinearSliderPos (
double value)
const
468 if (normRange.
end <= normRange.
start)
470 else if (value < normRange.
start)
472 else if (value > normRange.
end)
480 jassert (pos >= 0 && pos <= 1.0);
481 return (
float) (sliderRegionStart + pos * sliderRegionSize);
496 void setVelocityModeParameters (
double sensitivity,
int threshold,
501 velocityModeOffset = offset;
502 velocityModeThreshold = threshold;
509 if (incDecButtonMode != mode)
511 incDecButtonMode = mode;
522 || editableText != (! isReadOnly)
527 editableText = ! isReadOnly;
539 updateTextBoxEnablement();
546 if (valueBox !=
nullptr)
547 valueBox->showEditor();
552 if (valueBox !=
nullptr)
561 void setTextValueSuffix (
const String& suffix)
563 if (textSuffix != suffix)
570 void updateTextBoxEnablement()
572 if (valueBox !=
nullptr)
589 valueBox.reset (
lf.createSliderTextBox (owner));
592 valueBox->setWantsKeyboardFocus (
false);
595 updateTextBoxEnablement();
596 valueBox->onTextChange = [
this] { textChanged(); };
600 valueBox->addMouseListener (&owner,
false);
611 incButton.reset (
lf.createSliderButton (owner,
true));
612 decButton.reset (
lf.createSliderButton (owner,
false));
621 if (incDecButtonMode != incDecButtonsNotDraggable)
622 b.addMouseListener (&owner,
false);
624 b.setRepeatSpeed (300, 100, 20);
626 b.setTooltip (tooltip);
627 b.setAccessible (
false);
649 m.addItem (1,
TRANS (
"Velocity-sensitive mode"),
true, isVelocityBased);
663 m.showMenuAsync (PopupMenu::Options(),
667 static void sliderMenuCallback (
int result,
Slider* slider)
669 if (slider !=
nullptr)
673 case 1: slider->setVelocityBasedMode (! slider->getVelocityBasedMode());
break;
674 case 2: slider->setSliderStyle (
Rotary);
break;
683 int getThumbIndexAt (
const MouseEvent& e)
685 if (isTwoValue() || isThreeValue())
687 auto mousePos = isVertical() ? e.position.y : e.position.x;
707 void handleRotaryDrag (
const MouseEvent& e)
712 if (
dx *
dx + dy * dy > 25.0f)
719 if (rotaryParams.
stopAtEnd && e.mouseWasDraggedSinceMouseDown())
723 if (
angle >= lastAngle)
729 if (
angle >= lastAngle)
755 void handleAbsoluteDrag (
const MouseEvent& e)
764 && ! snapsToMousePos))
769 || (style ==
IncDecButtons && incDecDragDirectionIsHorizontal()))
770 ? e.position.x - mouseDragStartPos.
x
771 : mouseDragStartPos.
y - e.position.y;
774 +
mouseDiff * (1.0 / pixelsForFullDragExtent);
778 incButton->setState (
mouseDiff < 0 ? Button::buttonNormal : Button::buttonDown);
779 decButton->setState (
mouseDiff > 0 ? Button::buttonNormal : Button::buttonDown);
784 auto mouseDiff = (e.position.x - mouseDragStartPos.
x)
785 + (mouseDragStartPos.
y - e.position.y);
788 +
mouseDiff * (1.0 / pixelsForFullDragExtent);
803 void handleVelocityDrag (
const MouseEvent& e)
807 || (style ==
IncDecButtons && incDecDragDirectionIsHorizontal()));
810 ? (e.position.x - mousePosWhenLastDragged.
x) + (mousePosWhenLastDragged.
y - e.position.y)
812 : e.position.y - mousePosWhenLastDragged.y);
814 auto maxSpeed =
jmax (200.0, (
double) sliderRegionSize);
819 speed = 0.2 * velocityModeSensitivity
821 +
jmax (0.0, (
double) (
speed - velocityModeThreshold))
828 || (style ==
IncDecButtons && ! incDecDragDirectionIsHorizontal()))
836 e.source.enableUnboundedMouseMovement (
true,
false);
840 void mouseDown (
const MouseEvent& e)
842 incDecDragged =
false;
843 useDragEvents =
false;
844 mouseDragStartPos = mousePosWhenLastDragged = e.position;
846 popupDisplay.reset();
850 if (e.mods.isPopupMenu() && menuEnabled)
854 else if (canDoubleClickToValue()
855 && (singleClickModifiers != ModifierKeys() && e.mods.withoutMouseButtons() == singleClickModifiers))
859 else if (normRange.
end > normRange.
start)
861 useDragEvents =
true;
863 if (valueBox !=
nullptr)
864 valueBox->hideEditor (
true);
866 sliderBeingDragged = getThumbIndexAt (e);
868 minMaxDiff =
static_cast<double> (valueMax.
getValue()) -
static_cast<double> (valueMin.
getValue());
875 valueWhenLastDragged = (sliderBeingDragged == 2 ? valueMax
876 : (sliderBeingDragged == 1 ? valueMin
877 : currentValue)).getValue();
878 valueOnMouseDown = valueWhenLastDragged;
880 if (showPopupOnDrag || showPopupOnHover)
884 if (popupDisplay !=
nullptr)
885 popupDisplay->stopTimer();
888 currentDrag = std::make_unique<ScopedDragNotification> (owner);
894 void mouseDrag (
const MouseEvent& e)
896 if (useDragEvents && normRange.
end > normRange.
start
898 && e.mouseWasClicked() && valueBox !=
nullptr && valueBox->isEditable()))
904 handleRotaryDrag (e);
910 if (e.getDistanceFromDragStart() < 10 || ! e.mouseWasDraggedSinceMouseDown())
913 incDecDragged =
true;
914 mouseDragStartPos = e.position;
917 if (isAbsoluteDragMode (e.mods) || (normRange.
end - normRange.
start) / sliderRegionSize < normRange.
interval)
920 handleAbsoluteDrag (e);
925 handleVelocityDrag (e);
929 valueWhenLastDragged =
jlimit (normRange.
start, normRange.
end, valueWhenLastDragged);
931 if (sliderBeingDragged == 0)
936 else if (sliderBeingDragged == 1)
941 if (e.mods.isShiftDown())
944 minMaxDiff =
static_cast<double> (valueMax.
getValue()) -
static_cast<double> (valueMin.
getValue());
946 else if (sliderBeingDragged == 2)
951 if (e.mods.isShiftDown())
954 minMaxDiff =
static_cast<double> (valueMax.
getValue()) -
static_cast<double> (valueMin.
getValue());
957 mousePosWhenLastDragged = e.position;
965 && (normRange.
end > normRange.
start)
968 restoreMouseIfHidden();
974 popupDisplay.reset();
978 incButton->setState (Button::buttonNormal);
979 decButton->setState (Button::buttonNormal);
982 else if (popupDisplay !=
nullptr)
984 popupDisplay->startTimer (200);
1003 if (popupDisplay ==
nullptr)
1006 if (popupDisplay !=
nullptr && popupHoverTimeout != -1)
1007 popupDisplay->startTimer (popupHoverTimeout);
1014 popupDisplay.reset();
1017 bool keyPressed (
const KeyPress& key)
1019 if (key.getModifiers().isAnyModifierKeyDown())
1028 return getStepSize (owner);
1049 void showPopupDisplay()
1054 if (popupDisplay ==
nullptr)
1056 popupDisplay.reset (
new PopupDisplayComponent (owner, parentForPopupDisplay ==
nullptr));
1058 if (parentForPopupDisplay !=
nullptr)
1065 updatePopupDisplay();
1066 popupDisplay->setVisible (
true);
1070 void updatePopupDisplay()
1072 if (popupDisplay ==
nullptr)
1085 if (sliderBeingDragged == 2)
1086 return getMaxValue();
1088 if (sliderBeingDragged == 1)
1089 return getMinValue();
1097 bool canDoubleClickToValue()
const
1099 return doubleClickToValue
1101 && normRange.
start <= doubleClickReturnValue
1102 && normRange.
end >= doubleClickReturnValue;
1105 void mouseDoubleClick()
1107 if (canDoubleClickToValue())
1109 ScopedDragNotification drag (owner);
1114 double getMouseWheelDelta (
double value,
double wheelAmount)
1127 bool mouseWheelMove (
const MouseEvent& e,
const MouseWheelDetails&
wheel)
1129 if (scrollWheelEnabled
1135 if (e.eventTime != lastMouseWheelTime)
1137 lastMouseWheelTime = e.eventTime;
1139 if (normRange.
end > normRange.
start && ! e.mods.isAnyMouseButtonDown())
1141 if (valueBox !=
nullptr)
1142 valueBox->hideEditor (
false);
1144 auto value =
static_cast<double> (currentValue.
getValue());
1145 auto delta = getMouseWheelDelta (value, (std::abs (
wheel.deltaX) > std::abs (
wheel.deltaY)
1147 * (
wheel.isReversed ? -1.0f : 1.0f));
1150 auto newValue = value +
jmax (normRange.
interval, std::abs (delta)) * (delta < 0 ? -1.0 : 1.0);
1152 ScopedDragNotification drag (owner);
1164 void modifierKeysChanged (
const ModifierKeys&
modifiers)
1167 restoreMouseIfHidden();
1170 bool isAbsoluteDragMode (ModifierKeys mods)
const
1172 return isVelocityBased == (userKeyOverridesVelocity && mods.testFlags (modifierToSwapModes));
1175 void restoreMouseIfHidden()
1177 for (
auto&
ms : Desktop::getInstance().getMouseSources())
1179 if (
ms.isUnboundedMouseMovementEnabled())
1181 ms.enableUnboundedMouseMovement (
false);
1183 auto pos = sliderBeingDragged == 2 ? getMaxValue()
1184 : (sliderBeingDragged == 1 ? getMinValue()
1197 else mousePos += Point<float> (delta / -2.0f, delta / 2.0f);
1201 valueOnMouseDown = valueWhenLastDragged;
1211 const_cast <MouseInputSource&
> (
ms).setScreenPosition (
mousePos);
1217 void paint (Graphics& g, LookAndFeel&
lf)
1226 lf.drawRotarySlider (g,
1227 sliderRect.
getX(), sliderRect.
getY(),
1234 lf.drawLinearSlider (g,
1235 sliderRect.
getX(), sliderRect.
getY(),
1237 getLinearSliderPos (lastCurrentValue),
1238 getLinearSliderPos (lastValueMin),
1239 getLinearSliderPos (lastValueMax),
1248 auto layout =
lf.getSliderLayout (owner);
1249 sliderRect = layout.sliderBounds;
1251 if (valueBox !=
nullptr)
1252 valueBox->setBounds (layout.textBoxBounds);
1256 sliderRegionStart = layout.sliderBounds.getX();
1257 sliderRegionSize = layout.sliderBounds.getWidth();
1259 else if (isVertical())
1261 sliderRegionStart = layout.sliderBounds.getY();
1262 sliderRegionSize = layout.sliderBounds.getHeight();
1266 resizeIncDecButtons();
1271 void resizeIncDecButtons()
1282 if (incDecButtonsSideBySide)
1285 decButton->setConnectedEdges (Button::ConnectedOnRight);
1286 incButton->setConnectedEdges (Button::ConnectedOnLeft);
1291 decButton->setConnectedEdges (Button::ConnectedOnTop);
1292 incButton->setConnectedEdges (Button::ConnectedOnBottom);
1303 Value currentValue, valueMin, valueMax;
1304 double lastCurrentValue = 0, lastValueMin = 0, lastValueMax = 0;
1305 NormalisableRange<double> normRange { 0.0, 10.0 };
1306 double doubleClickReturnValue = 0;
1307 double valueWhenLastDragged = 0, valueOnMouseDown = 0, lastAngle = 0;
1308 double velocityModeSensitivity = 1.0, velocityModeOffset = 0, minMaxDiff = 0;
1309 int velocityModeThreshold = 1;
1310 RotaryParameters rotaryParams;
1311 Point<float> mouseDragStartPos, mousePosWhenLastDragged;
1312 int sliderRegionStart = 0, sliderRegionSize = 1;
1313 int sliderBeingDragged = -1;
1314 int pixelsForFullDragExtent = 250;
1315 Time lastMouseWheelTime;
1316 Rectangle<int> sliderRect;
1321 int numDecimalPlaces = 7;
1322 int fixedNumDecimalPlaces = -1;
1323 int textBoxWidth = 80, textBoxHeight = 20;
1327 bool editableText =
true;
1328 bool doubleClickToValue =
false;
1329 bool isVelocityBased =
false;
1330 bool userKeyOverridesVelocity =
true;
1331 bool incDecButtonsSideBySide =
false;
1332 bool sendChangeOnlyOnRelease =
false;
1333 bool showPopupOnDrag =
false;
1334 bool showPopupOnHover =
false;
1335 bool menuEnabled =
false;
1336 bool useDragEvents =
false;
1337 bool incDecDragged =
false;
1338 bool scrollWheelEnabled =
true;
1339 bool snapsToMousePos =
true;
1341 int popupHoverTimeout = 2000;
1342 double lastPopupDismissal = 0.0;
1344 ModifierKeys singleClickModifiers;
1367 if (owner.pimpl !=
nullptr)
1394 owner.pimpl->popupDisplay.reset();
1407 Component* parentForPopupDisplay =
nullptr;
1410 static double smallestAngleBetween (
double a1,
double a2)
noexcept
1419Slider::ScopedDragNotification::ScopedDragNotification (Slider& s)
1420 : sliderBeingDragged (s)
1422 sliderBeingDragged.pimpl->sendDragStart();
1425Slider::ScopedDragNotification::~ScopedDragNotification()
1427 if (sliderBeingDragged.pimpl !=
nullptr)
1428 sliderBeingDragged.pimpl->sendDragEnd();
1444 init (style, textBoxPos);
1447void Slider::init (SliderStyle style, TextEntryBoxPosition textBoxPos)
1452 pimpl.
reset (
new Pimpl (*
this, style, textBoxPos));
1457 pimpl->registerListeners();
1473 jassert (p.startAngleRadians >= 0 && p.endAngleRadians >= 0);
1477 pimpl->rotaryParams = p;
1482 setRotaryParameters ({ startAngleRadians, endAngleRadians, stopAtEnd });
1487 return pimpl->rotaryParams;
1505 pimpl->setVelocityModeParameters (
sensitivity, threshold, offset,
1514 pimpl->normRange.skew = factor;
1515 pimpl->normRange.symmetricSkew = symmetricSkew;
1560 pimpl->parentForPopupDisplay = parent;
1614 pimpl->singleClickModifiers = mods;
1622 pimpl->updateText();
1627 pimpl->setTextValueSuffix (suffix);
1632 return pimpl->textSuffix;
1637 auto getText = [
this] (
double val)
1661 while (t.startsWithChar (
'+'))
1662 t = t.substring (1).trimStart();
1664 return t.initialSectionContainingOnly (
"0123456789.,-")
1670 return pimpl->normRange.convertFrom0to1 (
proportion);
1675 return pimpl->normRange.convertTo0to1 (value);
1685 return pimpl->getNumDecimalPlacesToDisplay();
1741 pimpl->mouseDrag (e);
1747 pimpl->mouseDoubleClick();
1762 AccessibilityRole::slider,
1777 useMaxValue (slider.isTwoValue())
1781 bool isReadOnly()
const override {
return false; }
1783 double getCurrentValue()
const override
1785 return useMaxValue ? slider.getMaximum()
1786 : slider.getValue();
1789 void setValue (
double newValue)
override
1791 Slider::ScopedDragNotification drag (slider);
1799 String getCurrentValueAsString()
const override {
return slider.getTextFromValue (getCurrentValue()); }
1800 void setValueAsString (
const String& newValue)
override { setValue (slider.getValueFromText (newValue)); }
1802 AccessibleValueRange getRange()
const override
1804 return { { slider.getMinimum(), slider.getMaximum() },
1805 getStepSize (slider) };
1810 const bool useMaxValue;
1824 return std::make_unique<SliderAccessibilityHandler> (*
this);
A simple wrapper for building a collection of supported accessibility actions and corresponding callb...
Base class for accessible Components.
An abstract interface representing the value of an accessibility element.
Has a callback method that is triggered asynchronously.
void triggerAsyncUpdate()
Causes the callback to be triggered at a later time.
void cancelPendingUpdate() noexcept
This will stop any pending updates from happening.
A component for showing a message or other graphics inside a speech-bubble-shaped outline,...
void setPosition(Component *componentToPointTo, int distanceFromTarget=15, int arrowLength=10)
Moves and resizes the bubble to point at a given component.
void setAllowedPlacement(int newPlacement)
Tells the bubble which positions it's allowed to put itself in, relative to the point at which it's p...
@ windowIsTemporary
Indicates that the window is a temporary popup, like a menu, tooltip, etc.
@ windowIgnoresKeyPresses
Tells the window not to catch any keypresses.
@ windowIgnoresMouseClicks
Indicates that the window should let mouse clicks pass through it (may not be possible on some platfo...
A class to keep an eye on a component and check for it being deleted.
The base class for all JUCE user-interface objects.
void setLookAndFeel(LookAndFeel *newLookAndFeel)
Sets the look and feel to use for this component.
void setTransform(const AffineTransform &transform)
Sets a transform matrix to be applied to this component.
void setRepaintsOnMouseActivity(bool shouldRepaint) noexcept
Causes automatic repaints when the mouse enters or exits this component.
int getHeight() const noexcept
Returns the component's height in pixels.
Point< int > getLocalPoint(const Component *sourceComponent, Point< int > pointRelativeToSourceComponent) const
Converts a point to be relative to this component's coordinate space.
static float JUCE_CALLTYPE getApproximateScaleFactorForComponent(const Component *targetComponent)
Returns the approximate scale factor for a given component by traversing its parent hierarchy and app...
void addAndMakeVisible(Component *child, int zOrder=-1)
Adds a child component to this one, and also makes the child visible if it isn't already.
FocusChangeType
Enumeration used by the focusGained() and focusLost() methods.
void setAlwaysOnTop(bool shouldStayOnTop)
Sets whether the component should always be kept at the front of its siblings.
AccessibilityHandler * getAccessibilityHandler()
Returns the accessibility handler for this component, or nullptr if this component is not accessible.
void repaint()
Marks the whole component as needing to be redrawn.
Rectangle< int > getScreenBounds() const
Returns the bounds of this component, relative to the screen's top-left.
bool isOnDesktop() const noexcept
Returns true if this component is currently showing on the desktop.
void setWantsKeyboardFocus(bool wantsFocus) noexcept
Sets a flag to indicate whether this component wants keyboard focus or not.
bool isMouseOver(bool includeChildren=false) const
Returns true if the mouse is currently over this component.
int getWidth() const noexcept
Returns the component's width in pixels.
void mouseWheelMove(const MouseEvent &event, const MouseWheelDetails &wheel) override
Called when the mouse-wheel is moved.
bool isEnabled() const noexcept
Returns true if the component (and all its parents) are enabled.
Point< int > localPointToGlobal(Point< int > localPoint) const
Converts a point relative to this component's top-left into a screen coordinate.
LookAndFeel & getLookAndFeel() const noexcept
Finds the appropriate look-and-feel to use for this component.
void setComponentEffect(ImageEffectFilter *newEffect)
Adds an effect filter to alter the component's appearance.
void addChildComponent(Component *child, int zOrder=-1)
Adds a child component to this one.
void invalidateAccessibilityHandler()
Invalidates the AccessibilityHandler that is currently being used for this component.
Represents a particular font, including its size, style, etc.
float getHeight() const noexcept
Returns the total height of this font, in pixels.
int getStringWidth(const String &text) const
Returns the total width of a string as it would be drawn using this font.
A graphics context, used for drawing a component or image.
void drawFittedText(const String &text, int x, int y, int width, int height, Justification justificationFlags, int maximumNumberOfLines, float minimumHorizontalScale=0.0f) const
Tries to draw a text string inside a given space.
void setFont(const Font &newFont)
Changes the font to use for subsequent text-drawing functions.
void setColour(Colour newColour)
Changes the current drawing colour.
@ centred
Indicates that the item should be centred vertically and horizontally.
Represents a key press, including any modifier keys that are needed.
static const int upKey
key-code for the cursor-up key
static const int rightKey
key-code for the cursor-right key
static const int downKey
key-code for the cursor-down key
static const int leftKey
key-code for the cursor-left key
static ModalComponentManager::Callback * forComponent(void(*functionToCall)(int, ComponentType *), ComponentType *component)
This is a utility function to create a ModalComponentManager::Callback that will call a static functi...
Represents the state of the mouse buttons and modifier keys.
Flags
Flags that represent the different keys.
@ ctrlAltCommandModifiers
Represents a combination of all the alt, ctrl and command key modifiers.
@ ParentCursor
Indicates that the component's parent's cursor should be used.
Contains position and status information about a mouse event.
Represents a mapping between an arbitrary range of values and a normalised 0->1 range.
ValueType skew
An optional skew factor that alters the way values are distribute across the range.
ValueType end
The maximum value of the non-normalised range.
bool symmetricSkew
If true, the skew factor applies from the middle of the slider to each of its ends.
ValueType snapToLegalValue(ValueType v) const noexcept
Takes a non-normalised value and snaps it based on either the interval property of this NormalisableR...
ValueType start
The minimum value of the non-normalised range.
ValueType interval
The snapping interval that should be used (for a non-normalised value).
ValueType y
The point's Y coordinate.
ValueType x
The point's X coordinate.
A general-purpose range object, that simply represents any linear range with a start and end point.
Manages a rectangle and allows geometric operations to be performed on it.
Rectangle< float > toFloat() const noexcept
Casts this rectangle to a Rectangle<float>.
ValueType getX() const noexcept
Returns the x coordinate of the rectangle's left-hand-side.
ValueType getCentreX() const noexcept
Returns the x coordinate of the rectangle's centre.
ValueType getCentreY() const noexcept
Returns the y coordinate of the rectangle's centre.
ValueType getWidth() const noexcept
Returns the width of the rectangle.
void expand(ValueType deltaX, ValueType deltaY) noexcept
Expands the rectangle by a given amount.
Rectangle reduced(ValueType deltaX, ValueType deltaY) const noexcept
Returns a rectangle that is smaller than this one by a given amount.
Point< ValueType > getConstrainedPoint(Point< ValueType > point) const noexcept
Returns the nearest point to the specified point that lies within this rectangle.
ValueType getY() const noexcept
Returns the y coordinate of the rectangle's top edge.
ValueType getHeight() const noexcept
Returns the height of the rectangle.
String getHelp() const override
Some help text for the UI element (if required).
A class for receiving callbacks from a Slider.
void handleAsyncUpdate() override
Called back to do whatever your class needs to do.
void valueChanged(Value &value) override
Called when a Value object is changed.
An RAII class for sending slider listener drag messages.
A slider control for changing a value.
int getVelocityThreshold() const noexcept
Returns the velocity threshold setting.
void setSliderStyle(SliderStyle newStyle)
Changes the type of slider interface being used.
DragMode
Describes the type of mouse-dragging that is happening when a value is being changed.
@ notDragging
Dragging is not active.
@ velocityDrag
The dragging value change is relative to the velocity of the mouse movement.
@ absoluteDrag
The dragging corresponds directly to the value that is displayed.
void setPopupDisplayEnabled(bool shouldShowOnMouseDrag, bool shouldShowOnMouseHover, Component *parentComponentToUse, int hoverTimeout=2000)
If enabled, this gives the slider a pop-up bubble which appears while the slider is being dragged or ...
int getTextBoxWidth() const noexcept
Returns the width used for the text-box.
double getMinimum() const noexcept
Returns the current minimum value.
double getVelocityOffset() const noexcept
Returns the velocity offset setting.
void setMaxValue(double newValue, NotificationType notification=sendNotificationAsync, bool allowNudgingOfOtherValues=false)
For a slider with two or three thumbs, this sets the lower of its values.
void setMinAndMaxValues(double newMinValue, double newMaxValue, NotificationType notification=sendNotificationAsync)
For a slider with two or three thumbs, this sets the minimum and maximum thumb positions.
bool isRotary() const noexcept
True if the slider is in a rotary mode.
std::function< void()> onDragStart
You can assign a lambda to this callback object to have it called when the slider's drag begins.
double getMaxValue() const
For a slider with two or three thumbs, this returns the higher of its values.
virtual String getTextFromValue(double value)
Turns the slider's current value into a text string.
void addListener(Listener *listener)
Adds a listener to be called when this slider's value changes.
Value & getMaxValueObject() noexcept
For a slider with two or three thumbs, this returns the higher of its values.
void setDoubleClickReturnValue(bool shouldDoubleClickBeEnabled, double valueToSetOnDoubleClick, ModifierKeys singleClickModifiers=ModifierKeys::altModifier)
This lets you choose whether double-clicking or single-clicking with a specified key modifier moves t...
float getPositionOfValue(double value) const
Returns the X or Y coordinate of a value along the slider's length.
void focusOfChildComponentChanged(FocusChangeType) override
Called to indicate a change in whether or not this component is the parent of the currently-focused c...
std::function< void()> onValueChange
You can assign a lambda to this callback object to have it called when the slider value is changed.
IncDecButtonMode
Used by setIncDecButtonsMode().
bool getSliderSnapsToMousePosition() const noexcept
Returns true if setSliderSnapsToMousePosition() has been enabled.
void setRotaryParameters(RotaryParameters newParameters) noexcept
Changes the properties of a rotary slider.
void setVelocityModeParameters(double sensitivity=1.0, int threshold=1, double offset=0.0, bool userCanPressKeyToSwapMode=true, ModifierKeys::Flags modifiersToSwapModes=ModifierKeys::ctrlAltCommandModifiers)
Changes aspects of the scaling used when in velocity-sensitive mode.
virtual double valueToProportionOfLength(double value)
Allows a user-defined mapping of value to the position of the slider along its length.
std::function< String(double)> textFromValueFunction
You can assign a lambda that will be used to convert the slider's normalised position to a textual va...
bool getVelocityBasedMode() const noexcept
Returns true if velocity-based mode is active.
double getDoubleClickReturnValue() const noexcept
Returns the values last set by setDoubleClickReturnValue() method.
Range< double > getRange() const noexcept
Returns the slider's range.
void setSkewFactor(double factor, bool symmetricSkew=false)
Sets up a skew factor to alter the way values are distributed.
virtual double proportionOfLengthToValue(double proportion)
Allows a user-defined mapping of distance along the slider to its value.
float startAngleRadians
The angle (in radians, clockwise from the top) at which the slider's minimum value is represented.
int getMouseDragSensitivity() const noexcept
Returns the current sensitivity value set by setMouseDragSensitivity().
void colourChanged() override
This method is called when a colour is changed by the setColour() method, or when the look-and-feel i...
void setTextBoxIsEditable(bool shouldBeEditable)
Makes the text-box editable.
void mouseDrag(const MouseEvent &) override
Called when the mouse is moved while a button is held down.
void setScrollWheelEnabled(bool enabled)
This can be used to stop the mouse scroll-wheel from moving the slider.
void setChangeNotificationOnlyOnRelease(bool onlyNotifyOnRelease)
Tells the slider whether to keep sending change messages while the user is dragging the slider.
double getSkewFactor() const noexcept
Returns the current skew factor.
void hideTextBox(bool discardCurrentEditorContents)
If the text-box currently has focus and is being edited, this resets it and takes keyboard focus away...
void lookAndFeelChanged() override
Called to let the component react to a change in the look-and-feel setting.
String getTextValueSuffix() const
Returns the suffix that was set by setTextValueSuffix().
virtual double snapValue(double attemptedValue, DragMode dragMode)
This can be overridden to allow the slider to snap to user-definable values.
bool isDoubleClickReturnEnabled() const noexcept
Returns true if double-clicking to reset to a default value is enabled.
bool getVelocityModeIsSwappable() const noexcept
Returns the velocity user key setting.
void setIncDecButtonsMode(IncDecButtonMode mode)
When the style is IncDecButtons, this lets you turn on a mode where the mouse can be dragged on the b...
double getInterval() const noexcept
Returns the current step-size for values.
void mouseMove(const MouseEvent &) override
Called when the mouse moves inside a component.
void setVelocityBasedMode(bool isVelocityBased)
Changes the way the mouse is used when dragging the slider.
double getMaximum() const noexcept
Returns the current maximum value.
Component * getCurrentPopupDisplay() const noexcept
If a popup display is enabled and is currently visible, this returns the component that is being show...
void mouseExit(const MouseEvent &) override
Called when the mouse moves out of a component.
std::function< void()> onDragEnd
You can assign a lambda to this callback object to have it called when the slider's drag ends.
double getValue() const
Returns the slider's current value.
void showTextBox()
If the text-box is editable, this will give it the focus so that the user can type directly into it.
void resized() override
Called when this component's size has been changed.
~Slider() override
Destructor.
bool isHorizontal() const noexcept
True if the slider moves horizontally.
SliderStyle
The types of slider available.
@ LinearBarVertical
A vertical bar slider with the text label drawn on top of it.
@ IncDecButtons
A pair of buttons that increment or decrement the slider's value by the increment set in setRange().
@ ThreeValueHorizontal
A horizontal slider that has three thumbs instead of one, so it can show a minimum and maximum value,...
@ TwoValueHorizontal
A horizontal slider that has two thumbs instead of one, so it can show a minimum and maximum value.
@ Rotary
A rotary control that you move by dragging the mouse in a circular motion, like a knob.
@ LinearBar
A horizontal bar slider with the text label drawn on top of it.
@ LinearHorizontal
A traditional horizontal slider.
@ RotaryVerticalDrag
A rotary control that you move by dragging the mouse up-and-down.
@ LinearVertical
A traditional vertical slider.
@ RotaryHorizontalDrag
A rotary control that you move by dragging the mouse left-to-right.
@ ThreeValueVertical
A vertical slider that has three thumbs instead of one, so it can show a minimum and maximum value,...
@ RotaryHorizontalVerticalDrag
A rotary control that you move by dragging the mouse up-and-down or left-to-right.
@ TwoValueVertical
A vertical slider that has two thumbs instead of one, so it can show a minimum and maximum value.
double getMinValue() const
For a slider with two or three thumbs, this returns the lower of its values.
void mouseDoubleClick(const MouseEvent &) override
Called when a mouse button has been double-clicked on a component.
bool keyPressed(const KeyPress &) override
Called when a key is pressed.
bool isSymmetricSkew() const noexcept
Returns the whether the skew is symmetric from the midpoint to both sides.
void mouseDown(const MouseEvent &) override
Called when a mouse button is pressed.
Value & getMinValueObject() noexcept
For a slider with two or three thumbs, this returns the lower of its values.
float endAngleRadians
The angle (in radians, clockwise from the top) at which the slider's maximum value is represented.
void enablementChanged() override
Callback to indicate that this component has been enabled or disabled.
bool isThreeValue() const noexcept
True if the slider has three thumbs.
bool isVertical() const noexcept
True if the slider moves vertically.
int getTextBoxHeight() const noexcept
Returns the height used for the text-box.
bool isScrollWheelEnabled() const noexcept
Returns true if the scroll wheel can move the slider.
void removeListener(Listener *listener)
Removes a previously-registered listener.
void mouseUp(const MouseEvent &) override
Called when a mouse button is released.
void setNumDecimalPlacesToDisplay(int decimalPlacesToDisplay)
Modifies the best number of decimal places to use when displaying this slider's value.
bool stopAtEnd
Determines what happens when a circular drag action rotates beyond the minimum or maximum angle.
void modifierKeysChanged(const ModifierKeys &) override
Called when a modifier key is pressed or released.
std::function< double(const String &)> valueFromTextFunction
You can assign a lambda that will be used to convert textual values to the slider's normalised positi...
virtual void stoppedDragging()
Callback to indicate that the user has just stopped dragging the slider.
NormalisableRange< double > getNormalisableRange() const noexcept
Returns the slider's normalisable range.
bool isBar() const noexcept
True if the slider is in a linear bar mode.
void setPopupMenuEnabled(bool menuEnabled)
If this is set to true, then right-clicking on the slider will pop-up a menu to let the user change t...
virtual void valueChanged()
Callback to indicate that the user has just moved the slider.
bool isTextBoxEditable() const noexcept
Returns true if the text-box is read-only.
void setMinValue(double newValue, NotificationType notification=sendNotificationAsync, bool allowNudgingOfOtherValues=false)
For a slider with two or three thumbs, this sets the lower of its values.
TextEntryBoxPosition getTextBoxPosition() const noexcept
Returns the status of the text-box.
void setTextBoxStyle(TextEntryBoxPosition newPosition, bool isReadOnly, int textEntryBoxWidth, int textEntryBoxHeight)
Changes the location and properties of the text-entry box.
RotaryParameters getRotaryParameters() const noexcept
Changes the properties of a rotary slider.
virtual double getValueFromText(const String &text)
Subclasses can override this to convert a text string to a value.
void setValue(double newValue, NotificationType notification=sendNotificationAsync)
Changes the slider's current value.
int getThumbBeingDragged() const noexcept
Returns a number to indicate which thumb is currently being dragged by the mouse.
void setSkewFactorFromMidPoint(double sliderValueToShowAtMidPoint)
Sets up a skew factor to alter the way values are distributed.
Value & getValueObject() noexcept
Returns the Value object that represents the slider's current position.
std::unique_ptr< AccessibilityHandler > createAccessibilityHandler() override
Override this method to return a custom AccessibilityHandler for this component.
virtual void startedDragging()
Callback to indicate that the user is about to start dragging the slider.
void paint(Graphics &) override
Components can override this method to draw their content.
Slider()
Creates a slider.
void setTextValueSuffix(const String &suffix)
Sets a suffix to append to the end of the numeric value when it's displayed as a string.
void setSliderSnapsToMousePosition(bool shouldSnapToMouse)
This lets you change whether the slider thumb jumps to the mouse position when you click.
TextEntryBoxPosition
The position of the slider's text-entry box.
@ TextBoxRight
Puts the text box to the right of the slider, vertically centred.
@ NoTextBox
Doesn't display a text box.
@ TextBoxLeft
Puts the text box to the left of the slider, vertically centred.
void mouseWheelMove(const MouseEvent &, const MouseWheelDetails &) override
Called when the mouse-wheel is moved.
double getVelocitySensitivity() const noexcept
Returns the velocity sensitivity setting.
SliderStyle getSliderStyle() const noexcept
Returns the slider's current style.
int getNumDecimalPlacesToDisplay() const noexcept
Returns the best number of decimal places to use when displaying this slider's value.
void setRange(double newMinimum, double newMaximum, double newInterval=0)
Sets the limits that the slider's value can take.
void setMouseDragSensitivity(int distanceForFullScaleDrag)
Sets the distance the mouse has to move to drag the slider across the full extent of its range.
bool isTwoValue() const noexcept
True if the slider has two thumbs.
void updateText()
This can be called to force the text box to update its contents.
void setNormalisableRange(NormalisableRange< double > newNormalisableRange)
Sets a NormalisableRange to use for the Slider values.
void mouseEnter(const MouseEvent &) override
Called when the mouse first enters a component.
Structure defining rotary parameters for a slider.
String trimStart() const
Returns a copy of this string with any whitespace characters removed from the start.
String substring(int startIndex, int endIndex) const
Returns a subsection of the string.
static double getMillisecondCounterHiRes() noexcept
Returns the number of millisecs since a fixed event (usually system startup).
Makes repeated callbacks to a virtual method at a specified time interval.
void stopTimer() noexcept
Stops the timer.
Receives callbacks when a Value object changes.
Represents a shared variant value.
void addListener(Listener *listener)
Adds a listener to receive callbacks when the value changes.
void removeListener(Listener *listener)
Removes a listener that was previously added with addListener().
bool refersToSameSourceAs(const Value &other) const
Returns true if this object and the other one use the same underlying ValueSource object.
var getValue() const
Returns the current value.
#define TRANS(stringLiteral)
Uses the LocalisedStrings class to translate the given string literal.
constexpr bool approximatelyEqual(Type a, Type b, Tolerance< Type > tolerance=Tolerance< Type >{} .withAbsolute(std::numeric_limits< Type >::min()) .withRelative(std::numeric_limits< Type >::epsilon()))
Returns true if the two floating-point numbers are approximately equal.
constexpr Type jmin(Type a, Type b)
Returns the smaller of two values.
constexpr Type jmax(Type a, Type b)
Returns the larger of two values.
Type jlimit(Type lowerLimit, Type upperLimit, Type valueToConstrain) noexcept
Constrains a value to keep it within a given range.
@ valueChanged
Indicates that the UI element's value has changed.
NotificationType
These enums are used in various classes to indicate whether a notification event should be sent out.
@ sendNotificationAsync
Requests an asynchronous notification.
@ sendNotificationSync
Requests a synchronous notification.
@ dontSendNotification
No notification message should be sent.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
int roundToInt(const FloatType value) noexcept
Fast floating-point-to-integer conversion.
Contains status information about a mouse wheel event.
Utility struct which holds one or more accessibility interfaces.
Commonly used mathematical constants.
static constexpr FloatType twoPi
A predefined value for 2 * Pi.
static constexpr FloatType pi
A predefined value for Pi.