JUCE-7.0.12-0-g4f43011b96 JUCE-7.0.12-0-g4f43011b96
JUCE — C++ application framework with suport for VST, VST3, LV2 audio plug-ins

« « « Anklang Documentation
Loading...
Searching...
No Matches
juce_Slider.h
Go to the documentation of this file.
1 /*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 By using JUCE, you agree to the terms of both the JUCE 7 End-User License
11 Agreement and JUCE Privacy Policy.
12
13 End User License Agreement: www.juce.com/juce-7-licence
14 Privacy Policy: www.juce.com/juce-privacy-policy
15
16 Or: You may also use this code under the terms of the GPL v3 (see
17 www.gnu.org/licenses).
18
19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21 DISCLAIMED.
22
23 ==============================================================================
24*/
25
26namespace juce
27{
28
29//==============================================================================
52class JUCE_API Slider : public Component,
54{
55public:
56 //==============================================================================
62 {
67 Rotary,
69 RotaryHorizontalDrag,
71 RotaryVerticalDrag,
73 RotaryHorizontalVerticalDrag,
77 TwoValueHorizontal,
79 TwoValueVertical,
82 ThreeValueHorizontal,
85 ThreeValueVertical
88 };
89
101
106 {
109 velocityDrag
110 };
111
112 //==============================================================================
116 Slider();
117
121 explicit Slider (const String& componentName);
122
124 Slider (SliderStyle style, TextEntryBoxPosition textBoxPosition);
125
127 ~Slider() override;
128
129 //==============================================================================
135 void setSliderStyle (SliderStyle newStyle);
136
140 SliderStyle getSliderStyle() const noexcept;
141
142 //==============================================================================
145 {
150
156
164 };
165
167 void setRotaryParameters (RotaryParameters newParameters) noexcept;
168
170 void setRotaryParameters (float startAngleRadians,
171 float endAngleRadians,
172 bool stopAtEnd) noexcept;
173
175 RotaryParameters getRotaryParameters() const noexcept;
176
183 void setMouseDragSensitivity (int distanceForFullScaleDrag);
184
186 int getMouseDragSensitivity() const noexcept;
187
188 //==============================================================================
197 void setVelocityBasedMode (bool isVelocityBased);
198
202 bool getVelocityBasedMode() const noexcept;
203
219 void setVelocityModeParameters (double sensitivity = 1.0,
220 int threshold = 1,
221 double offset = 0.0,
222 bool userCanPressKeyToSwapMode = true,
223 ModifierKeys::Flags modifiersToSwapModes = ModifierKeys::ctrlAltCommandModifiers);
224
228 double getVelocitySensitivity() const noexcept;
229
233 int getVelocityThreshold() const noexcept;
234
238 double getVelocityOffset() const noexcept;
239
243 bool getVelocityModeIsSwappable() const noexcept;
244
245 //==============================================================================
264 void setSkewFactor (double factor, bool symmetricSkew = false);
265
273 void setSkewFactorFromMidPoint (double sliderValueToShowAtMidPoint);
274
279 double getSkewFactor() const noexcept;
280
285 bool isSymmetricSkew() const noexcept;
286
287 //==============================================================================
291 {
292 incDecButtonsNotDraggable,
293 incDecButtonsDraggable_AutoDirection,
294 incDecButtonsDraggable_Horizontal,
295 incDecButtonsDraggable_Vertical
296 };
297
308 void setIncDecButtonsMode (IncDecButtonMode mode);
309
310 //==============================================================================
322 void setTextBoxStyle (TextEntryBoxPosition newPosition,
323 bool isReadOnly,
324 int textEntryBoxWidth,
325 int textEntryBoxHeight);
326
330 TextEntryBoxPosition getTextBoxPosition() const noexcept;
331
335 int getTextBoxWidth() const noexcept;
336
340 int getTextBoxHeight() const noexcept;
341
349 void setTextBoxIsEditable (bool shouldBeEditable);
350
354 bool isTextBoxEditable() const noexcept;
355
360 void showTextBox();
361
370 void hideTextBox (bool discardCurrentEditorContents);
371
372
373 //==============================================================================
388 void setValue (double newValue, NotificationType notification = sendNotificationAsync);
389
391 double getValue() const;
392
399 Value& getValueObject() noexcept;
400
401 //==============================================================================
409 void setRange (double newMinimum,
410 double newMaximum,
411 double newInterval = 0);
412
419 void setRange (Range<double> newRange, double newInterval);
420
425 void setNormalisableRange (NormalisableRange<double> newNormalisableRange);
426
428 NormalisableRange<double> getNormalisableRange() const noexcept;
429
431 Range<double> getRange() const noexcept;
432
436 double getMaximum() const noexcept;
437
441 double getMinimum() const noexcept;
442
446 double getInterval() const noexcept;
447
448 //==============================================================================
457 double getMinValue() const;
458
465 Value& getMinValueObject() noexcept;
466
486 void setMinValue (double newValue,
487 NotificationType notification = sendNotificationAsync,
488 bool allowNudgingOfOtherValues = false);
489
498 double getMaxValue() const;
499
506 Value& getMaxValueObject() noexcept;
507
527 void setMaxValue (double newValue,
528 NotificationType notification = sendNotificationAsync,
529 bool allowNudgingOfOtherValues = false);
530
547 void setMinAndMaxValues (double newMinValue, double newMaxValue,
548 NotificationType notification = sendNotificationAsync);
549
550 //==============================================================================
558 class JUCE_API Listener
559 {
560 public:
561 //==============================================================================
563 virtual ~Listener() = default;
564
565 //==============================================================================
575 virtual void sliderValueChanged (Slider* slider) = 0;
576
577 //==============================================================================
586 virtual void sliderDragStarted (Slider*) {}
587
591 virtual void sliderDragEnded (Slider*) {}
592 };
593
595 void addListener (Listener* listener);
596
598 void removeListener (Listener* listener);
599
600 //==============================================================================
603
606
609
612
615
616 //==============================================================================
627 void setDoubleClickReturnValue (bool shouldDoubleClickBeEnabled,
628 double valueToSetOnDoubleClick,
629 ModifierKeys singleClickModifiers = ModifierKeys::altModifier);
630
634 double getDoubleClickReturnValue() const noexcept;
635
639 bool isDoubleClickReturnEnabled() const noexcept;
640
641 //==============================================================================
650 void setChangeNotificationOnlyOnRelease (bool onlyNotifyOnRelease);
651
661 void setSliderSnapsToMousePosition (bool shouldSnapToMouse);
662
664 bool getSliderSnapsToMousePosition() const noexcept;
665
682 void setPopupDisplayEnabled (bool shouldShowOnMouseDrag,
683 bool shouldShowOnMouseHover,
684 Component* parentComponentToUse,
685 int hoverTimeout = 2000);
686
691 Component* getCurrentPopupDisplay() const noexcept;
692
700 void setPopupMenuEnabled (bool menuEnabled);
701
705 void setScrollWheelEnabled (bool enabled);
706
708 bool isScrollWheelEnabled() const noexcept;
709
715 int getThumbBeingDragged() const noexcept;
716
717 //==============================================================================
721 virtual void startedDragging();
722
726 virtual void stoppedDragging();
727
731 virtual void valueChanged();
732
733 //==============================================================================
742 virtual double getValueFromText (const String& text);
743
754 virtual String getTextFromValue (double value);
755
763 void setTextValueSuffix (const String& suffix);
764
766 String getTextValueSuffix() const;
767
775 int getNumDecimalPlacesToDisplay() const noexcept;
776
782 void setNumDecimalPlacesToDisplay (int decimalPlacesToDisplay);
783
784 //==============================================================================
796 virtual double proportionOfLengthToValue (double proportion);
797
811 virtual double valueToProportionOfLength (double value);
812
822 float getPositionOfValue (double value) const;
823
824 //==============================================================================
837 virtual double snapValue (double attemptedValue, DragMode dragMode);
838
839
840 //==============================================================================
844 void updateText();
845
847 bool isHorizontal() const noexcept;
849 bool isVertical() const noexcept;
851 bool isRotary() const noexcept;
853 bool isBar() const noexcept;
855 bool isTwoValue() const noexcept;
857 bool isThreeValue() const noexcept;
858
859 //==============================================================================
868 {
869 backgroundColourId = 0x1001200,
870 thumbColourId = 0x1001300,
872 trackColourId = 0x1001310,
873 rotarySliderFillColourId = 0x1001311,
874 rotarySliderOutlineColourId = 0x1001312,
876 textBoxTextColourId = 0x1001400,
877 textBoxBackgroundColourId = 0x1001500,
878 textBoxHighlightColourId = 0x1001600,
879 textBoxOutlineColourId = 0x1001700
880 };
881
882 //==============================================================================
887 {
888 Rectangle<int> sliderBounds;
889 Rectangle<int> textBoxBounds;
890 };
891
892 //==============================================================================
901 {
902 public:
903 explicit ScopedDragNotification (Slider&);
905
906 private:
907 Slider& sliderBeingDragged;
908
911 };
912
913 //==============================================================================
917 struct JUCE_API LookAndFeelMethods
918 {
919 virtual ~LookAndFeelMethods() = default;
920
921 //==============================================================================
922 virtual void drawLinearSlider (Graphics&,
923 int x, int y, int width, int height,
924 float sliderPos,
925 float minSliderPos,
926 float maxSliderPos,
928 Slider&) = 0;
929
930 virtual void drawLinearSliderBackground (Graphics&,
931 int x, int y, int width, int height,
932 float sliderPos,
933 float minSliderPos,
934 float maxSliderPos,
936 Slider&) = 0;
937
938 virtual void drawLinearSliderOutline (Graphics&,
939 int x, int y, int width, int height,
941 Slider&) = 0;
942
943 virtual void drawLinearSliderThumb (Graphics&,
944 int x, int y, int width, int height,
945 float sliderPos,
946 float minSliderPos,
947 float maxSliderPos,
949 Slider&) = 0;
950
951 virtual int getSliderThumbRadius (Slider&) = 0;
952
953 virtual void drawRotarySlider (Graphics&,
954 int x, int y, int width, int height,
955 float sliderPosProportional,
956 float rotaryStartAngle,
957 float rotaryEndAngle,
958 Slider&) = 0;
959
960 virtual Button* createSliderButton (Slider&, bool isIncrement) = 0;
961 virtual Label* createSliderTextBox (Slider&) = 0;
962
963 virtual ImageEffectFilter* getSliderEffect (Slider&) = 0;
964
965 virtual Font getSliderPopupFont (Slider&) = 0;
966 virtual int getSliderPopupPlacement (Slider&) = 0;
967
968 virtual SliderLayout getSliderLayout (Slider&) = 0;
969 };
970
971 //==============================================================================
973 void paint (Graphics&) override;
975 void resized() override;
977 void mouseDown (const MouseEvent&) override;
979 void mouseUp (const MouseEvent&) override;
981 void mouseDrag (const MouseEvent&) override;
983 void mouseDoubleClick (const MouseEvent&) override;
985 void mouseWheelMove (const MouseEvent&, const MouseWheelDetails&) override;
987 void modifierKeysChanged (const ModifierKeys&) override;
989 void lookAndFeelChanged() override;
991 void enablementChanged() override;
993 void focusOfChildComponentChanged (FocusChangeType) override;
995 void colourChanged() override;
997 void mouseMove (const MouseEvent&) override;
999 void mouseExit (const MouseEvent&) override;
1001 void mouseEnter (const MouseEvent&) override;
1003 bool keyPressed (const KeyPress&) override;
1005 std::unique_ptr<AccessibilityHandler> createAccessibilityHandler() override;
1006
1007 //==============================================================================
1008 #ifndef DOXYGEN
1009 // These methods' bool parameters have changed: see the new method signature.
1010 [[deprecated]] void setValue (double, bool);
1011 [[deprecated]] void setValue (double, bool, bool);
1012 [[deprecated]] void setMinValue (double, bool, bool, bool);
1013 [[deprecated]] void setMinValue (double, bool, bool);
1014 [[deprecated]] void setMinValue (double, bool);
1015 [[deprecated]] void setMaxValue (double, bool, bool, bool);
1016 [[deprecated]] void setMaxValue (double, bool, bool);
1017 [[deprecated]] void setMaxValue (double, bool);
1018 [[deprecated]] void setMinAndMaxValues (double, double, bool, bool);
1019 [[deprecated]] void setMinAndMaxValues (double, double, bool);
1020 #endif
1021
1022private:
1023 //==============================================================================
1024 JUCE_PUBLIC_IN_DLL_BUILD (class Pimpl)
1026
1027 void init (SliderStyle, TextEntryBoxPosition);
1028
1030};
1031
1032
1033} // namespace juce
A base class for buttons.
Definition juce_Button.h:43
The base class for all JUCE user-interface objects.
FocusChangeType
Enumeration used by the focusGained() and focusLost() methods.
Represents a particular font, including its size, style, etc.
Definition juce_Font.h:42
A graphics context, used for drawing a component or image.
A graphical effect filter that can be applied to components.
Represents a key press, including any modifier keys that are needed.
A component that displays a text string, and can optionally become a text editor when clicked.
Definition juce_Label.h:41
Represents the state of the mouse buttons and modifier keys.
Contains position and status information about a mouse event.
Represents a mapping between an arbitrary range of values and a normalised 0->1 range.
A general-purpose range object, that simply represents any linear range with a start and end point.
Definition juce_Range.h:40
Manages a rectangle and allows geometric operations to be performed on it.
An implementation of TooltipClient that stores the tooltip string and a method for changing it.
A class for receiving callbacks from a Slider.
virtual void sliderDragEnded(Slider *)
Called after a drag operation has finished.
virtual ~Listener()=default
Destructor.
virtual void sliderDragStarted(Slider *)
Called when the slider is about to be dragged.
virtual void sliderValueChanged(Slider *slider)=0
Called when the slider's value is changed.
An RAII class for sending slider listener drag messages.
A slider control for changing a value.
Definition juce_Slider.h:54
DragMode
Describes the type of mouse-dragging that is happening when a value is being changed.
@ notDragging
Dragging is not active.
@ absoluteDrag
The dragging corresponds directly to the value that is displayed.
std::function< void()> onDragStart
You can assign a lambda to this callback object to have it called when the slider's drag begins.
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().
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...
float startAngleRadians
The angle (in radians, clockwise from the top) at which the slider's minimum value is represented.
std::function< void()> onDragEnd
You can assign a lambda to this callback object to have it called when the slider's drag ends.
SliderStyle
The types of slider available.
Definition juce_Slider.h:62
@ LinearBarVertical
A vertical bar slider with the text label drawn on top of it.
Definition juce_Slider.h:66
@ IncDecButtons
A pair of buttons that increment or decrement the slider's value by the increment set in setRange().
Definition juce_Slider.h:75
@ LinearBar
A horizontal bar slider with the text label drawn on top of it.
Definition juce_Slider.h:65
@ LinearHorizontal
A traditional horizontal slider.
Definition juce_Slider.h:63
@ LinearVertical
A traditional vertical slider.
Definition juce_Slider.h:64
float endAngleRadians
The angle (in radians, clockwise from the top) at which the slider's maximum value is represented.
bool stopAtEnd
Determines what happens when a circular drag action rotates beyond the minimum or maximum angle.
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...
ColourIds
A set of colour IDs to use to change the colour of various aspects of the slider.
TextEntryBoxPosition
The position of the slider's text-entry box.
Definition juce_Slider.h:94
@ TextBoxRight
Puts the text box to the right of the slider, vertically centred.
Definition juce_Slider.h:97
@ NoTextBox
Doesn't display a text box.
Definition juce_Slider.h:95
@ TextBoxAbove
Puts the text box above the slider, horizontally centred.
Definition juce_Slider.h:98
@ TextBoxLeft
Puts the text box to the left of the slider, vertically centred.
Definition juce_Slider.h:96
Structure defining rotary parameters for a slider.
A struct defining the placement of the slider area and the text box area relative to the bounds of th...
The JUCE String class!
Definition juce_String.h:53
Represents a shared variant value.
Definition juce_Value.h:51
#define JUCE_DECLARE_NON_MOVEABLE(className)
This is a shorthand macro for deleting a class's move constructor and move assignment operator.
#define JUCE_DECLARE_NON_COPYABLE(className)
This is a shorthand macro for deleting a class's copy constructor and copy assignment operator.
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
This is a shorthand way of writing both a JUCE_DECLARE_NON_COPYABLE and JUCE_LEAK_DETECTOR macro for ...
typedef double
JUCE Namespace.
NotificationType
These enums are used in various classes to indicate whether a notification event should be sent out.
Contains status information about a mouse wheel event.
This abstract base class is implemented by LookAndFeel classes to provide slider drawing functionalit...