Browse Source

Added an option to Slider::setVelocityModeParameters() to set the modifier keys

tags/2021-05-28
jules 7 years ago
parent
commit
edea094d7d
2 changed files with 28 additions and 17 deletions
  1. +24
    -16
      modules/juce_gui_basics/widgets/juce_Slider.cpp
  2. +4
    -1
      modules/juce_gui_basics/widgets/juce_Slider.h

+ 24
- 16
modules/juce_gui_basics/widgets/juce_Slider.cpp View File

@@ -448,12 +448,14 @@ public:
} }
void setVelocityModeParameters (double sensitivity, int threshold, void setVelocityModeParameters (double sensitivity, int threshold,
double offset, bool userCanPressKeyToSwapMode)
double offset, bool userCanPressKeyToSwapMode,
ModifierKeys::Flags newModifierToSwapModes)
{ {
velocityModeSensitivity = sensitivity; velocityModeSensitivity = sensitivity;
velocityModeOffset = offset; velocityModeOffset = offset;
velocityModeThreshold = threshold; velocityModeThreshold = threshold;
userKeyOverridesVelocity = userCanPressKeyToSwapMode; userKeyOverridesVelocity = userCanPressKeyToSwapMode;
modifierToSwapModes = newModifierToSwapModes;
} }
void setSkewFactorFromMidPoint (double sliderValueToShowAtMidPoint) void setSkewFactorFromMidPoint (double sliderValueToShowAtMidPoint)
@@ -545,7 +547,8 @@ public:
: owner.getTextFromValue (currentValue.getValue())); : owner.getTextFromValue (currentValue.getValue()));
valueBox.reset(); valueBox.reset();
owner.addAndMakeVisible (valueBox = lf.createSliderTextBox (owner));
valueBox.reset (lf.createSliderTextBox (owner));
owner.addAndMakeVisible (valueBox.get());
valueBox->setWantsKeyboardFocus (false); valueBox->setWantsKeyboardFocus (false);
valueBox->setText (previousTextBoxContent, dontSendNotification); valueBox->setText (previousTextBoxContent, dontSendNotification);
@@ -566,10 +569,13 @@ public:
if (style == IncDecButtons) if (style == IncDecButtons)
{ {
owner.addAndMakeVisible (incButton = lf.createSliderButton (owner, true));
incButton->onClick = [this] { incrementOrDecrement (interval); };
incButton.reset (lf.createSliderButton (owner, true));
decButton.reset (lf.createSliderButton (owner, false));
owner.addAndMakeVisible (incButton.get());
owner.addAndMakeVisible (decButton.get());
owner.addAndMakeVisible (decButton = lf.createSliderButton (owner, false));
incButton->onClick = [this] { incrementOrDecrement (interval); };
decButton->onClick = [this] { incrementOrDecrement (-interval); }; decButton->onClick = [this] { incrementOrDecrement (-interval); };
if (incDecButtonMode != incDecButtonsNotDraggable) if (incDecButtonMode != incDecButtonsNotDraggable)
@@ -840,7 +846,7 @@ public:
popupDisplay->stopTimer(); popupDisplay->stopTimer();
} }
currentDrag = new DragInProgress (*this);
currentDrag.reset (new DragInProgress (*this));
mouseDrag (e); mouseDrag (e);
} }
} }
@@ -979,10 +985,10 @@ public:
if (popupDisplay == nullptr) if (popupDisplay == nullptr)
{ {
popupDisplay = new PopupDisplayComponent (owner);
popupDisplay.reset (new PopupDisplayComponent (owner));
if (parentForPopupDisplay != nullptr) if (parentForPopupDisplay != nullptr)
parentForPopupDisplay->addChildComponent (popupDisplay);
parentForPopupDisplay->addChildComponent (popupDisplay.get());
else else
popupDisplay->addToDesktop (ComponentPeer::windowIsTemporary); popupDisplay->addToDesktop (ComponentPeer::windowIsTemporary);
@@ -1079,8 +1085,7 @@ public:
bool isAbsoluteDragMode (ModifierKeys mods) const bool isAbsoluteDragMode (ModifierKeys mods) const
{ {
return isVelocityBased == (userKeyOverridesVelocity
&& mods.testFlags (ModifierKeys::ctrlAltCommandModifiers));
return isVelocityBased == (userKeyOverridesVelocity && mods.testFlags (modifierToSwapModes));
} }
void restoreMouseIfHidden() void restoreMouseIfHidden()
@@ -1239,6 +1244,7 @@ public:
int numDecimalPlaces = 7; int numDecimalPlaces = 7;
int textBoxWidth = 80, textBoxHeight = 20; int textBoxWidth = 80, textBoxHeight = 20;
IncDecButtonMode incDecButtonMode = incDecButtonsNotDraggable; IncDecButtonMode incDecButtonMode = incDecButtonsNotDraggable;
ModifierKeys::Flags modifierToSwapModes = ModifierKeys::ctrlAltCommandModifiers;
bool editableText = true; bool editableText = true;
bool doubleClickToValue = false; bool doubleClickToValue = false;
@@ -1312,7 +1318,7 @@ public:
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PopupDisplayComponent) JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PopupDisplayComponent)
}; };
ScopedPointer<PopupDisplayComponent> popupDisplay;
std::unique_ptr<PopupDisplayComponent> popupDisplay;
Component* parentForPopupDisplay = nullptr; Component* parentForPopupDisplay = nullptr;
//============================================================================== //==============================================================================
@@ -1376,8 +1382,7 @@ void Slider::setRotaryParameters (RotaryParameters p) noexcept
void Slider::setRotaryParameters (float startAngleRadians, float endAngleRadians, bool stopAtEnd) noexcept void Slider::setRotaryParameters (float startAngleRadians, float endAngleRadians, bool stopAtEnd) noexcept
{ {
RotaryParameters p = { startAngleRadians, endAngleRadians, stopAtEnd };
setRotaryParameters (p);
setRotaryParameters ({ startAngleRadians, endAngleRadians, stopAtEnd });
} }
Slider::RotaryParameters Slider::getRotaryParameters() const noexcept Slider::RotaryParameters Slider::getRotaryParameters() const noexcept
@@ -1392,13 +1397,16 @@ int Slider::getVelocityThreshold() const noexcept { return pimpl->velo
double Slider::getVelocitySensitivity() const noexcept { return pimpl->velocityModeSensitivity; } double Slider::getVelocitySensitivity() const noexcept { return pimpl->velocityModeSensitivity; }
double Slider::getVelocityOffset() const noexcept { return pimpl->velocityModeOffset; } double Slider::getVelocityOffset() const noexcept { return pimpl->velocityModeOffset; }
void Slider::setVelocityModeParameters (double sensitivity, int threshold, double offset, bool userCanPressKeyToSwapMode)
void Slider::setVelocityModeParameters (double sensitivity, int threshold,
double offset, bool userCanPressKeyToSwapMode,
ModifierKeys::Flags modifierToSwapModes)
{ {
jassert (threshold >= 0); jassert (threshold >= 0);
jassert (sensitivity > 0); jassert (sensitivity > 0);
jassert (offset >= 0); jassert (offset >= 0);
pimpl->setVelocityModeParameters (sensitivity, threshold, offset, userCanPressKeyToSwapMode);
pimpl->setVelocityModeParameters (sensitivity, threshold, offset,
userCanPressKeyToSwapMode, modifierToSwapModes);
} }
double Slider::getSkewFactor() const noexcept { return pimpl->skewFactor; } double Slider::getSkewFactor() const noexcept { return pimpl->skewFactor; }
@@ -1535,7 +1543,7 @@ String Slider::getTextFromValue (double v)
double Slider::getValueFromText (const String& text) double Slider::getValueFromText (const String& text)
{ {
String t (text.trimStart());
auto t = text.trimStart();
if (t.endsWith (getTextValueSuffix())) if (t.endsWith (getTextValueSuffix()))
t = t.substring (0, t.length() - getTextValueSuffix().length()); t = t.substring (0, t.length() - getTextValueSuffix().length());


+ 4
- 1
modules/juce_gui_basics/widgets/juce_Slider.h View File

@@ -211,11 +211,14 @@ public:
the threshold is reached the threshold is reached
@param userCanPressKeyToSwapMode if true, then the user can hold down the ctrl or command @param userCanPressKeyToSwapMode if true, then the user can hold down the ctrl or command
key to toggle velocity-sensitive mode key to toggle velocity-sensitive mode
@param modifiersToSwapModes this is a set of modifier flags which will be tested when determining
whether to enable/disable velocity-sensitive mode
*/ */
void setVelocityModeParameters (double sensitivity = 1.0, void setVelocityModeParameters (double sensitivity = 1.0,
int threshold = 1, int threshold = 1,
double offset = 0.0, double offset = 0.0,
bool userCanPressKeyToSwapMode = true);
bool userCanPressKeyToSwapMode = true,
ModifierKeys::Flags modifiersToSwapModes = ModifierKeys::ctrlAltCommandModifiers);
/** Returns the velocity sensitivity setting. /** Returns the velocity sensitivity setting.
@see setVelocityModeParameters @see setVelocityModeParameters


Loading…
Cancel
Save