The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1448 lines
46KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. class Slider::PopupDisplayComponent : public BubbleComponent,
  19. public Timer
  20. {
  21. public:
  22. PopupDisplayComponent (Slider& owner_)
  23. : owner (owner_),
  24. font (15.0f, Font::bold)
  25. {
  26. setAlwaysOnTop (true);
  27. }
  28. void paintContent (Graphics& g, int w, int h)
  29. {
  30. g.setFont (font);
  31. g.setColour (findColour (TooltipWindow::textColourId, true));
  32. g.drawFittedText (text, 0, 0, w, h, Justification::centred, 1);
  33. }
  34. void getContentSize (int& w, int& h)
  35. {
  36. w = font.getStringWidth (text) + 18;
  37. h = (int) (font.getHeight() * 1.6f);
  38. }
  39. void updatePosition (const String& newText)
  40. {
  41. text = newText;
  42. BubbleComponent::setPosition (&owner);
  43. repaint();
  44. }
  45. void timerCallback()
  46. {
  47. owner.popupDisplay = nullptr;
  48. }
  49. private:
  50. Slider& owner;
  51. Font font;
  52. String text;
  53. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PopupDisplayComponent);
  54. };
  55. //==============================================================================
  56. Slider::Slider (const String& name)
  57. : Component (name),
  58. lastCurrentValue (0),
  59. lastValueMin (0),
  60. lastValueMax (0),
  61. minimum (0),
  62. maximum (10),
  63. interval (0),
  64. skewFactor (1.0),
  65. velocityModeSensitivity (1.0),
  66. velocityModeOffset (0.0),
  67. velocityModeThreshold (1),
  68. rotaryStart (float_Pi * 1.2f),
  69. rotaryEnd (float_Pi * 2.8f),
  70. numDecimalPlaces (7),
  71. sliderRegionStart (0),
  72. sliderRegionSize (1),
  73. sliderBeingDragged (-1),
  74. pixelsForFullDragExtent (250),
  75. style (LinearHorizontal),
  76. textBoxPos (TextBoxLeft),
  77. textBoxWidth (80),
  78. textBoxHeight (20),
  79. incDecButtonMode (incDecButtonsNotDraggable),
  80. editableText (true),
  81. doubleClickToValue (false),
  82. isVelocityBased (false),
  83. userKeyOverridesVelocity (true),
  84. rotaryStop (true),
  85. incDecButtonsSideBySide (false),
  86. sendChangeOnlyOnRelease (false),
  87. popupDisplayEnabled (false),
  88. menuEnabled (false),
  89. menuShown (false),
  90. scrollWheelEnabled (true),
  91. snapsToMousePos (true),
  92. parentForPopupDisplay (nullptr)
  93. {
  94. setWantsKeyboardFocus (false);
  95. setRepaintsOnMouseActivity (true);
  96. Slider::lookAndFeelChanged();
  97. updateText();
  98. currentValue.addListener (this);
  99. valueMin.addListener (this);
  100. valueMax.addListener (this);
  101. }
  102. Slider::~Slider()
  103. {
  104. currentValue.removeListener (this);
  105. valueMin.removeListener (this);
  106. valueMax.removeListener (this);
  107. popupDisplay = nullptr;
  108. }
  109. //==============================================================================
  110. void Slider::handleAsyncUpdate()
  111. {
  112. cancelPendingUpdate();
  113. Component::BailOutChecker checker (this);
  114. listeners.callChecked (checker, &SliderListener::sliderValueChanged, this); // (can't use Slider::Listener due to idiotic VC2005 bug)
  115. }
  116. void Slider::sendDragStart()
  117. {
  118. startedDragging();
  119. Component::BailOutChecker checker (this);
  120. listeners.callChecked (checker, &SliderListener::sliderDragStarted, this);
  121. }
  122. void Slider::sendDragEnd()
  123. {
  124. stoppedDragging();
  125. sliderBeingDragged = -1;
  126. Component::BailOutChecker checker (this);
  127. listeners.callChecked (checker, &SliderListener::sliderDragEnded, this);
  128. }
  129. void Slider::addListener (SliderListener* const listener)
  130. {
  131. listeners.add (listener);
  132. }
  133. void Slider::removeListener (SliderListener* const listener)
  134. {
  135. listeners.remove (listener);
  136. }
  137. //==============================================================================
  138. void Slider::setSliderStyle (const SliderStyle newStyle)
  139. {
  140. if (style != newStyle)
  141. {
  142. style = newStyle;
  143. repaint();
  144. lookAndFeelChanged();
  145. }
  146. }
  147. void Slider::setRotaryParameters (const float startAngleRadians,
  148. const float endAngleRadians,
  149. const bool stopAtEnd)
  150. {
  151. // make sure the values are sensible..
  152. jassert (rotaryStart >= 0 && rotaryEnd >= 0);
  153. jassert (rotaryStart < float_Pi * 4.0f && rotaryEnd < float_Pi * 4.0f);
  154. jassert (rotaryStart < rotaryEnd);
  155. rotaryStart = startAngleRadians;
  156. rotaryEnd = endAngleRadians;
  157. rotaryStop = stopAtEnd;
  158. }
  159. void Slider::setVelocityBasedMode (const bool velBased)
  160. {
  161. isVelocityBased = velBased;
  162. }
  163. void Slider::setVelocityModeParameters (const double sensitivity,
  164. const int threshold,
  165. const double offset,
  166. const bool userCanPressKeyToSwapMode)
  167. {
  168. jassert (threshold >= 0);
  169. jassert (sensitivity > 0);
  170. jassert (offset >= 0);
  171. velocityModeSensitivity = sensitivity;
  172. velocityModeOffset = offset;
  173. velocityModeThreshold = threshold;
  174. userKeyOverridesVelocity = userCanPressKeyToSwapMode;
  175. }
  176. void Slider::setSkewFactor (const double factor)
  177. {
  178. skewFactor = factor;
  179. }
  180. void Slider::setSkewFactorFromMidPoint (const double sliderValueToShowAtMidPoint)
  181. {
  182. if (maximum > minimum)
  183. skewFactor = log (0.5) / log ((sliderValueToShowAtMidPoint - minimum)
  184. / (maximum - minimum));
  185. }
  186. void Slider::setMouseDragSensitivity (const int distanceForFullScaleDrag)
  187. {
  188. jassert (distanceForFullScaleDrag > 0);
  189. pixelsForFullDragExtent = distanceForFullScaleDrag;
  190. }
  191. void Slider::setIncDecButtonsMode (const IncDecButtonMode mode)
  192. {
  193. if (incDecButtonMode != mode)
  194. {
  195. incDecButtonMode = mode;
  196. lookAndFeelChanged();
  197. }
  198. }
  199. void Slider::setTextBoxStyle (const TextEntryBoxPosition newPosition,
  200. const bool isReadOnly,
  201. const int textEntryBoxWidth,
  202. const int textEntryBoxHeight)
  203. {
  204. if (textBoxPos != newPosition
  205. || editableText != (! isReadOnly)
  206. || textBoxWidth != textEntryBoxWidth
  207. || textBoxHeight != textEntryBoxHeight)
  208. {
  209. textBoxPos = newPosition;
  210. editableText = ! isReadOnly;
  211. textBoxWidth = textEntryBoxWidth;
  212. textBoxHeight = textEntryBoxHeight;
  213. repaint();
  214. lookAndFeelChanged();
  215. }
  216. }
  217. void Slider::setTextBoxIsEditable (const bool shouldBeEditable)
  218. {
  219. editableText = shouldBeEditable;
  220. if (valueBox != nullptr)
  221. valueBox->setEditable (shouldBeEditable && isEnabled());
  222. }
  223. void Slider::showTextBox()
  224. {
  225. jassert (editableText); // this should probably be avoided in read-only sliders.
  226. if (valueBox != nullptr)
  227. valueBox->showEditor();
  228. }
  229. void Slider::hideTextBox (const bool discardCurrentEditorContents)
  230. {
  231. if (valueBox != nullptr)
  232. {
  233. valueBox->hideEditor (discardCurrentEditorContents);
  234. if (discardCurrentEditorContents)
  235. updateText();
  236. }
  237. }
  238. void Slider::setChangeNotificationOnlyOnRelease (const bool onlyNotifyOnRelease)
  239. {
  240. sendChangeOnlyOnRelease = onlyNotifyOnRelease;
  241. }
  242. void Slider::setSliderSnapsToMousePosition (const bool shouldSnapToMouse)
  243. {
  244. snapsToMousePos = shouldSnapToMouse;
  245. }
  246. void Slider::setPopupDisplayEnabled (const bool enabled, Component* const parentComponentToUse)
  247. {
  248. popupDisplayEnabled = enabled;
  249. parentForPopupDisplay = parentComponentToUse;
  250. }
  251. Component* Slider::getCurrentPopupDisplay() const noexcept
  252. {
  253. return popupDisplay.get();
  254. }
  255. //==============================================================================
  256. void Slider::colourChanged()
  257. {
  258. lookAndFeelChanged();
  259. }
  260. void Slider::lookAndFeelChanged()
  261. {
  262. LookAndFeel& lf = getLookAndFeel();
  263. if (textBoxPos != NoTextBox)
  264. {
  265. const String previousTextBoxContent (valueBox != nullptr ? valueBox->getText()
  266. : getTextFromValue (currentValue.getValue()));
  267. valueBox = nullptr;
  268. addAndMakeVisible (valueBox = getLookAndFeel().createSliderTextBox (*this));
  269. valueBox->setWantsKeyboardFocus (false);
  270. valueBox->setText (previousTextBoxContent, false);
  271. if (valueBox->isEditable() != editableText) // (avoid overriding the single/double click flags unless we have to)
  272. valueBox->setEditable (editableText && isEnabled());
  273. valueBox->addListener (this);
  274. if (style == LinearBar)
  275. valueBox->addMouseListener (this, false);
  276. else
  277. valueBox->setTooltip (getTooltip());
  278. }
  279. else
  280. {
  281. valueBox = nullptr;
  282. }
  283. if (style == IncDecButtons)
  284. {
  285. addAndMakeVisible (incButton = lf.createSliderButton (true));
  286. incButton->addListener (this);
  287. addAndMakeVisible (decButton = lf.createSliderButton (false));
  288. decButton->addListener (this);
  289. if (incDecButtonMode != incDecButtonsNotDraggable)
  290. {
  291. incButton->addMouseListener (this, false);
  292. decButton->addMouseListener (this, false);
  293. }
  294. else
  295. {
  296. incButton->setRepeatSpeed (300, 100, 20);
  297. incButton->addMouseListener (decButton, false);
  298. decButton->setRepeatSpeed (300, 100, 20);
  299. decButton->addMouseListener (incButton, false);
  300. }
  301. incButton->setTooltip (getTooltip());
  302. decButton->setTooltip (getTooltip());
  303. }
  304. else
  305. {
  306. incButton = nullptr;
  307. decButton = nullptr;
  308. }
  309. setComponentEffect (lf.getSliderEffect());
  310. resized();
  311. repaint();
  312. }
  313. //==============================================================================
  314. void Slider::setRange (const double newMin,
  315. const double newMax,
  316. const double newInt)
  317. {
  318. if (minimum != newMin
  319. || maximum != newMax
  320. || interval != newInt)
  321. {
  322. minimum = newMin;
  323. maximum = newMax;
  324. interval = newInt;
  325. // figure out the number of DPs needed to display all values at this
  326. // interval setting.
  327. numDecimalPlaces = 7;
  328. if (newInt != 0)
  329. {
  330. int v = abs ((int) (newInt * 10000000));
  331. while ((v % 10) == 0)
  332. {
  333. --numDecimalPlaces;
  334. v /= 10;
  335. }
  336. }
  337. // keep the current values inside the new range..
  338. if (style != TwoValueHorizontal && style != TwoValueVertical)
  339. {
  340. setValue (getValue(), false, false);
  341. }
  342. else
  343. {
  344. setMinValue (getMinValue(), false, false);
  345. setMaxValue (getMaxValue(), false, false);
  346. }
  347. updateText();
  348. }
  349. }
  350. void Slider::triggerChangeMessage (const bool synchronous)
  351. {
  352. if (synchronous)
  353. handleAsyncUpdate();
  354. else
  355. triggerAsyncUpdate();
  356. valueChanged();
  357. }
  358. void Slider::valueChanged (Value& value)
  359. {
  360. if (value.refersToSameSourceAs (currentValue))
  361. {
  362. if (style != TwoValueHorizontal && style != TwoValueVertical)
  363. setValue (currentValue.getValue(), false, false);
  364. }
  365. else if (value.refersToSameSourceAs (valueMin))
  366. setMinValue (valueMin.getValue(), false, false, true);
  367. else if (value.refersToSameSourceAs (valueMax))
  368. setMaxValue (valueMax.getValue(), false, false, true);
  369. }
  370. double Slider::getValue() const
  371. {
  372. // for a two-value style slider, you should use the getMinValue() and getMaxValue()
  373. // methods to get the two values.
  374. jassert (style != TwoValueHorizontal && style != TwoValueVertical);
  375. return currentValue.getValue();
  376. }
  377. void Slider::setValue (double newValue,
  378. const bool sendUpdateMessage,
  379. const bool sendMessageSynchronously)
  380. {
  381. // for a two-value style slider, you should use the setMinValue() and setMaxValue()
  382. // methods to set the two values.
  383. jassert (style != TwoValueHorizontal && style != TwoValueVertical);
  384. newValue = constrainedValue (newValue);
  385. if (style == ThreeValueHorizontal || style == ThreeValueVertical)
  386. {
  387. jassert ((double) valueMin.getValue() <= (double) valueMax.getValue());
  388. newValue = jlimit ((double) valueMin.getValue(),
  389. (double) valueMax.getValue(),
  390. newValue);
  391. }
  392. if (newValue != lastCurrentValue)
  393. {
  394. if (valueBox != nullptr)
  395. valueBox->hideEditor (true);
  396. lastCurrentValue = newValue;
  397. // (need to do this comparison because the Value will use equalsWithSameType to compare
  398. // the new and old values, so will generate unwanted change events if the type changes)
  399. if (currentValue != newValue)
  400. currentValue = newValue;
  401. updateText();
  402. repaint();
  403. if (popupDisplay != nullptr)
  404. popupDisplay->updatePosition (getTextFromValue (newValue));
  405. if (sendUpdateMessage)
  406. triggerChangeMessage (sendMessageSynchronously);
  407. }
  408. }
  409. double Slider::getMinValue() const
  410. {
  411. // The minimum value only applies to sliders that are in two- or three-value mode.
  412. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  413. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  414. return valueMin.getValue();
  415. }
  416. double Slider::getMaxValue() const
  417. {
  418. // The maximum value only applies to sliders that are in two- or three-value mode.
  419. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  420. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  421. return valueMax.getValue();
  422. }
  423. void Slider::setMinValue (double newValue, const bool sendUpdateMessage, const bool sendMessageSynchronously, const bool allowNudgingOfOtherValues)
  424. {
  425. // The minimum value only applies to sliders that are in two- or three-value mode.
  426. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  427. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  428. newValue = constrainedValue (newValue);
  429. if (style == TwoValueHorizontal || style == TwoValueVertical)
  430. {
  431. if (allowNudgingOfOtherValues && newValue > (double) valueMax.getValue())
  432. setMaxValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  433. newValue = jmin ((double) valueMax.getValue(), newValue);
  434. }
  435. else
  436. {
  437. if (allowNudgingOfOtherValues && newValue > lastCurrentValue)
  438. setValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  439. newValue = jmin (lastCurrentValue, newValue);
  440. }
  441. if (lastValueMin != newValue)
  442. {
  443. lastValueMin = newValue;
  444. valueMin = newValue;
  445. repaint();
  446. if (popupDisplay != nullptr)
  447. popupDisplay->updatePosition (getTextFromValue (newValue));
  448. if (sendUpdateMessage)
  449. triggerChangeMessage (sendMessageSynchronously);
  450. }
  451. }
  452. void Slider::setMaxValue (double newValue, const bool sendUpdateMessage, const bool sendMessageSynchronously, const bool allowNudgingOfOtherValues)
  453. {
  454. // The maximum value only applies to sliders that are in two- or three-value mode.
  455. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  456. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  457. newValue = constrainedValue (newValue);
  458. if (style == TwoValueHorizontal || style == TwoValueVertical)
  459. {
  460. if (allowNudgingOfOtherValues && newValue < (double) valueMin.getValue())
  461. setMinValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  462. newValue = jmax ((double) valueMin.getValue(), newValue);
  463. }
  464. else
  465. {
  466. if (allowNudgingOfOtherValues && newValue < lastCurrentValue)
  467. setValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  468. newValue = jmax (lastCurrentValue, newValue);
  469. }
  470. if (lastValueMax != newValue)
  471. {
  472. lastValueMax = newValue;
  473. valueMax = newValue;
  474. repaint();
  475. if (popupDisplay != nullptr)
  476. popupDisplay->updatePosition (getTextFromValue (valueMax.getValue()));
  477. if (sendUpdateMessage)
  478. triggerChangeMessage (sendMessageSynchronously);
  479. }
  480. }
  481. void Slider::setMinAndMaxValues (double newMinValue, double newMaxValue, bool sendUpdateMessage, bool sendMessageSynchronously)
  482. {
  483. // The maximum value only applies to sliders that are in two- or three-value mode.
  484. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  485. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  486. if (newMaxValue < newMinValue)
  487. std::swap (newMaxValue, newMinValue);
  488. newMinValue = constrainedValue (newMinValue);
  489. newMaxValue = constrainedValue (newMaxValue);
  490. if (lastValueMax != newMaxValue || lastValueMin != newMinValue)
  491. {
  492. lastValueMax = newMaxValue;
  493. lastValueMin = newMinValue;
  494. valueMin = newMinValue;
  495. valueMax = newMaxValue;
  496. repaint();
  497. if (sendUpdateMessage)
  498. triggerChangeMessage (sendMessageSynchronously);
  499. }
  500. }
  501. void Slider::setDoubleClickReturnValue (const bool isDoubleClickEnabled,
  502. const double valueToSetOnDoubleClick)
  503. {
  504. doubleClickToValue = isDoubleClickEnabled;
  505. doubleClickReturnValue = valueToSetOnDoubleClick;
  506. }
  507. double Slider::getDoubleClickReturnValue (bool& isEnabled_) const
  508. {
  509. isEnabled_ = doubleClickToValue;
  510. return doubleClickReturnValue;
  511. }
  512. void Slider::updateText()
  513. {
  514. if (valueBox != nullptr)
  515. valueBox->setText (getTextFromValue (currentValue.getValue()), false);
  516. }
  517. void Slider::setTextValueSuffix (const String& suffix)
  518. {
  519. if (textSuffix != suffix)
  520. {
  521. textSuffix = suffix;
  522. updateText();
  523. }
  524. }
  525. String Slider::getTextValueSuffix() const
  526. {
  527. return textSuffix;
  528. }
  529. String Slider::getTextFromValue (double v)
  530. {
  531. if (getNumDecimalPlacesToDisplay() > 0)
  532. return String (v, getNumDecimalPlacesToDisplay()) + getTextValueSuffix();
  533. else
  534. return String (roundToInt (v)) + getTextValueSuffix();
  535. }
  536. double Slider::getValueFromText (const String& text)
  537. {
  538. String t (text.trimStart());
  539. if (t.endsWith (textSuffix))
  540. t = t.substring (0, t.length() - textSuffix.length());
  541. while (t.startsWithChar ('+'))
  542. t = t.substring (1).trimStart();
  543. return t.initialSectionContainingOnly ("0123456789.,-")
  544. .getDoubleValue();
  545. }
  546. double Slider::proportionOfLengthToValue (double proportion)
  547. {
  548. if (skewFactor != 1.0 && proportion > 0.0)
  549. proportion = exp (log (proportion) / skewFactor);
  550. return minimum + (maximum - minimum) * proportion;
  551. }
  552. double Slider::valueToProportionOfLength (double value)
  553. {
  554. const double n = (value - minimum) / (maximum - minimum);
  555. return skewFactor == 1.0 ? n : pow (n, skewFactor);
  556. }
  557. double Slider::snapValue (double attemptedValue, const bool)
  558. {
  559. return attemptedValue;
  560. }
  561. //==============================================================================
  562. void Slider::startedDragging()
  563. {
  564. }
  565. void Slider::stoppedDragging()
  566. {
  567. }
  568. void Slider::valueChanged()
  569. {
  570. }
  571. //==============================================================================
  572. void Slider::enablementChanged()
  573. {
  574. repaint();
  575. }
  576. void Slider::setPopupMenuEnabled (const bool menuEnabled_)
  577. {
  578. menuEnabled = menuEnabled_;
  579. }
  580. void Slider::setScrollWheelEnabled (const bool enabled)
  581. {
  582. scrollWheelEnabled = enabled;
  583. }
  584. //==============================================================================
  585. void Slider::labelTextChanged (Label* label)
  586. {
  587. const double newValue = snapValue (getValueFromText (label->getText()), false);
  588. if (newValue != (double) currentValue.getValue())
  589. {
  590. sendDragStart();
  591. setValue (newValue, true, true);
  592. sendDragEnd();
  593. }
  594. updateText(); // force a clean-up of the text, needed in case setValue() hasn't done this.
  595. }
  596. void Slider::buttonClicked (Button* button)
  597. {
  598. if (style == IncDecButtons)
  599. {
  600. sendDragStart();
  601. if (button == incButton)
  602. setValue (snapValue (getValue() + interval, false), true, true);
  603. else if (button == decButton)
  604. setValue (snapValue (getValue() - interval, false), true, true);
  605. sendDragEnd();
  606. }
  607. }
  608. //==============================================================================
  609. double Slider::constrainedValue (double value) const
  610. {
  611. if (interval > 0)
  612. value = minimum + interval * std::floor ((value - minimum) / interval + 0.5);
  613. if (value <= minimum || maximum <= minimum)
  614. value = minimum;
  615. else if (value >= maximum)
  616. value = maximum;
  617. return value;
  618. }
  619. float Slider::getLinearSliderPos (const double value)
  620. {
  621. double sliderPosProportional;
  622. if (maximum > minimum)
  623. {
  624. if (value < minimum)
  625. {
  626. sliderPosProportional = 0.0;
  627. }
  628. else if (value > maximum)
  629. {
  630. sliderPosProportional = 1.0;
  631. }
  632. else
  633. {
  634. sliderPosProportional = valueToProportionOfLength (value);
  635. jassert (sliderPosProportional >= 0 && sliderPosProportional <= 1.0);
  636. }
  637. }
  638. else
  639. {
  640. sliderPosProportional = 0.5;
  641. }
  642. if (isVertical() || style == IncDecButtons)
  643. sliderPosProportional = 1.0 - sliderPosProportional;
  644. return (float) (sliderRegionStart + sliderPosProportional * sliderRegionSize);
  645. }
  646. bool Slider::isHorizontal() const
  647. {
  648. return style == LinearHorizontal
  649. || style == LinearBar
  650. || style == TwoValueHorizontal
  651. || style == ThreeValueHorizontal;
  652. }
  653. bool Slider::isVertical() const
  654. {
  655. return style == LinearVertical
  656. || style == TwoValueVertical
  657. || style == ThreeValueVertical;
  658. }
  659. bool Slider::incDecDragDirectionIsHorizontal() const
  660. {
  661. return incDecButtonMode == incDecButtonsDraggable_Horizontal
  662. || (incDecButtonMode == incDecButtonsDraggable_AutoDirection && incDecButtonsSideBySide);
  663. }
  664. float Slider::getPositionOfValue (const double value)
  665. {
  666. if (isHorizontal() || isVertical())
  667. {
  668. return getLinearSliderPos (value);
  669. }
  670. else
  671. {
  672. jassertfalse; // not a valid call on a slider that doesn't work linearly!
  673. return 0.0f;
  674. }
  675. }
  676. //==============================================================================
  677. void Slider::paint (Graphics& g)
  678. {
  679. if (style != IncDecButtons)
  680. {
  681. if (style == Rotary || style == RotaryHorizontalDrag || style == RotaryVerticalDrag)
  682. {
  683. const float sliderPos = (float) valueToProportionOfLength (lastCurrentValue);
  684. jassert (sliderPos >= 0 && sliderPos <= 1.0f);
  685. getLookAndFeel().drawRotarySlider (g,
  686. sliderRect.getX(),
  687. sliderRect.getY(),
  688. sliderRect.getWidth(),
  689. sliderRect.getHeight(),
  690. sliderPos,
  691. rotaryStart, rotaryEnd,
  692. *this);
  693. }
  694. else
  695. {
  696. getLookAndFeel().drawLinearSlider (g,
  697. sliderRect.getX(),
  698. sliderRect.getY(),
  699. sliderRect.getWidth(),
  700. sliderRect.getHeight(),
  701. getLinearSliderPos (lastCurrentValue),
  702. getLinearSliderPos (lastValueMin),
  703. getLinearSliderPos (lastValueMax),
  704. style,
  705. *this);
  706. }
  707. if (style == LinearBar && valueBox == nullptr)
  708. {
  709. g.setColour (findColour (Slider::textBoxOutlineColourId));
  710. g.drawRect (0, 0, getWidth(), getHeight(), 1);
  711. }
  712. }
  713. }
  714. void Slider::resized()
  715. {
  716. int minXSpace = 0;
  717. int minYSpace = 0;
  718. if (textBoxPos == TextBoxLeft || textBoxPos == TextBoxRight)
  719. minXSpace = 30;
  720. else
  721. minYSpace = 15;
  722. const int tbw = jmax (0, jmin (textBoxWidth, getWidth() - minXSpace));
  723. const int tbh = jmax (0, jmin (textBoxHeight, getHeight() - minYSpace));
  724. if (style == LinearBar)
  725. {
  726. if (valueBox != nullptr)
  727. valueBox->setBounds (getLocalBounds());
  728. }
  729. else
  730. {
  731. if (textBoxPos == NoTextBox)
  732. {
  733. sliderRect = getLocalBounds();
  734. }
  735. else if (textBoxPos == TextBoxLeft)
  736. {
  737. valueBox->setBounds (0, (getHeight() - tbh) / 2, tbw, tbh);
  738. sliderRect.setBounds (tbw, 0, getWidth() - tbw, getHeight());
  739. }
  740. else if (textBoxPos == TextBoxRight)
  741. {
  742. valueBox->setBounds (getWidth() - tbw, (getHeight() - tbh) / 2, tbw, tbh);
  743. sliderRect.setBounds (0, 0, getWidth() - tbw, getHeight());
  744. }
  745. else if (textBoxPos == TextBoxAbove)
  746. {
  747. valueBox->setBounds ((getWidth() - tbw) / 2, 0, tbw, tbh);
  748. sliderRect.setBounds (0, tbh, getWidth(), getHeight() - tbh);
  749. }
  750. else if (textBoxPos == TextBoxBelow)
  751. {
  752. valueBox->setBounds ((getWidth() - tbw) / 2, getHeight() - tbh, tbw, tbh);
  753. sliderRect.setBounds (0, 0, getWidth(), getHeight() - tbh);
  754. }
  755. }
  756. const int indent = getLookAndFeel().getSliderThumbRadius (*this);
  757. if (style == LinearBar)
  758. {
  759. const int barIndent = 1;
  760. sliderRegionStart = barIndent;
  761. sliderRegionSize = getWidth() - barIndent * 2;
  762. sliderRect.setBounds (sliderRegionStart, barIndent,
  763. sliderRegionSize, getHeight() - barIndent * 2);
  764. }
  765. else if (isHorizontal())
  766. {
  767. sliderRegionStart = sliderRect.getX() + indent;
  768. sliderRegionSize = jmax (1, sliderRect.getWidth() - indent * 2);
  769. sliderRect.setBounds (sliderRegionStart, sliderRect.getY(),
  770. sliderRegionSize, sliderRect.getHeight());
  771. }
  772. else if (isVertical())
  773. {
  774. sliderRegionStart = sliderRect.getY() + indent;
  775. sliderRegionSize = jmax (1, sliderRect.getHeight() - indent * 2);
  776. sliderRect.setBounds (sliderRect.getX(), sliderRegionStart,
  777. sliderRect.getWidth(), sliderRegionSize);
  778. }
  779. else
  780. {
  781. sliderRegionStart = 0;
  782. sliderRegionSize = 100;
  783. }
  784. if (style == IncDecButtons)
  785. {
  786. Rectangle<int> buttonRect (sliderRect);
  787. if (textBoxPos == TextBoxLeft || textBoxPos == TextBoxRight)
  788. buttonRect.expand (-2, 0);
  789. else
  790. buttonRect.expand (0, -2);
  791. incDecButtonsSideBySide = buttonRect.getWidth() > buttonRect.getHeight();
  792. if (incDecButtonsSideBySide)
  793. {
  794. decButton->setBounds (buttonRect.removeFromLeft (buttonRect.getWidth() / 2));
  795. decButton->setConnectedEdges (Button::ConnectedOnRight);
  796. incButton->setConnectedEdges (Button::ConnectedOnLeft);
  797. }
  798. else
  799. {
  800. decButton->setBounds (buttonRect.removeFromBottom (buttonRect.getHeight() / 2));
  801. decButton->setConnectedEdges (Button::ConnectedOnTop);
  802. incButton->setConnectedEdges (Button::ConnectedOnBottom);
  803. }
  804. incButton->setBounds (buttonRect);
  805. }
  806. }
  807. void Slider::focusOfChildComponentChanged (FocusChangeType)
  808. {
  809. repaint();
  810. }
  811. namespace SliderHelpers
  812. {
  813. double smallestAngleBetween (double a1, double a2) noexcept
  814. {
  815. return jmin (std::abs (a1 - a2),
  816. std::abs (a1 + double_Pi * 2.0 - a2),
  817. std::abs (a2 + double_Pi * 2.0 - a1));
  818. }
  819. void sliderMenuCallback (int result, Slider* slider)
  820. {
  821. if (slider != nullptr)
  822. {
  823. switch (result)
  824. {
  825. case 1: slider->setVelocityBasedMode (! slider->getVelocityBasedMode()); break;
  826. case 2: slider->setSliderStyle (Slider::Rotary); break;
  827. case 3: slider->setSliderStyle (Slider::RotaryHorizontalDrag); break;
  828. case 4: slider->setSliderStyle (Slider::RotaryVerticalDrag); break;
  829. default: break;
  830. }
  831. }
  832. }
  833. }
  834. void Slider::showPopupMenu()
  835. {
  836. menuShown = true;
  837. PopupMenu m;
  838. m.setLookAndFeel (&getLookAndFeel());
  839. m.addItem (1, TRANS ("velocity-sensitive mode"), true, isVelocityBased);
  840. m.addSeparator();
  841. if (style == Rotary || style == RotaryHorizontalDrag || style == RotaryVerticalDrag)
  842. {
  843. PopupMenu rotaryMenu;
  844. rotaryMenu.addItem (2, TRANS ("use circular dragging"), true, style == Rotary);
  845. rotaryMenu.addItem (3, TRANS ("use left-right dragging"), true, style == RotaryHorizontalDrag);
  846. rotaryMenu.addItem (4, TRANS ("use up-down dragging"), true, style == RotaryVerticalDrag);
  847. m.addSubMenu (TRANS ("rotary mode"), rotaryMenu);
  848. }
  849. m.showMenuAsync (PopupMenu::Options(),
  850. ModalCallbackFunction::forComponent (SliderHelpers::sliderMenuCallback, this));
  851. }
  852. int Slider::getThumbIndexAt (const MouseEvent& e)
  853. {
  854. const bool isTwoValue = (style == TwoValueHorizontal || style == TwoValueVertical);
  855. const bool isThreeValue = (style == ThreeValueHorizontal || style == ThreeValueVertical);
  856. if (isTwoValue || isThreeValue)
  857. {
  858. const float mousePos = (float) (isVertical() ? e.y : e.x);
  859. const float normalPosDistance = std::abs (getLinearSliderPos (currentValue.getValue()) - mousePos);
  860. const float minPosDistance = std::abs (getLinearSliderPos (valueMin.getValue()) - 0.1f - mousePos);
  861. const float maxPosDistance = std::abs (getLinearSliderPos (valueMax.getValue()) + 0.1f - mousePos);
  862. if (isTwoValue)
  863. return maxPosDistance <= minPosDistance ? 2 : 1;
  864. if (normalPosDistance >= minPosDistance && maxPosDistance >= minPosDistance)
  865. return 1;
  866. else if (normalPosDistance >= maxPosDistance)
  867. return 2;
  868. }
  869. return 0;
  870. }
  871. void Slider::mouseDown (const MouseEvent& e)
  872. {
  873. mouseWasHidden = false;
  874. incDecDragged = false;
  875. mouseDragStartPos = mousePosWhenLastDragged = e.getPosition();
  876. if (isEnabled())
  877. {
  878. if (e.mods.isPopupMenu() && menuEnabled)
  879. {
  880. showPopupMenu();
  881. }
  882. else if (maximum > minimum)
  883. {
  884. menuShown = false;
  885. if (valueBox != nullptr)
  886. valueBox->hideEditor (true);
  887. sliderBeingDragged = getThumbIndexAt (e);
  888. minMaxDiff = (double) valueMax.getValue() - (double) valueMin.getValue();
  889. lastAngle = rotaryStart + (rotaryEnd - rotaryStart)
  890. * valueToProportionOfLength (currentValue.getValue());
  891. valueWhenLastDragged = (sliderBeingDragged == 2 ? valueMax
  892. : (sliderBeingDragged == 1 ? valueMin
  893. : currentValue)).getValue();
  894. valueOnMouseDown = valueWhenLastDragged;
  895. if (popupDisplayEnabled)
  896. {
  897. PopupDisplayComponent* const popup = new PopupDisplayComponent (*this);
  898. popupDisplay = popup;
  899. if (parentForPopupDisplay != nullptr)
  900. parentForPopupDisplay->addChildComponent (popup);
  901. else
  902. popup->addToDesktop (0);
  903. popup->setVisible (true);
  904. }
  905. sendDragStart();
  906. mouseDrag (e);
  907. }
  908. }
  909. }
  910. void Slider::mouseUp (const MouseEvent&)
  911. {
  912. if (isEnabled()
  913. && (! menuShown)
  914. && (maximum > minimum)
  915. && (style != IncDecButtons || incDecDragged))
  916. {
  917. restoreMouseIfHidden();
  918. if (sendChangeOnlyOnRelease && valueOnMouseDown != (double) currentValue.getValue())
  919. triggerChangeMessage (false);
  920. sendDragEnd();
  921. popupDisplay = nullptr;
  922. if (style == IncDecButtons)
  923. {
  924. incButton->setState (Button::buttonNormal);
  925. decButton->setState (Button::buttonNormal);
  926. }
  927. }
  928. else if (popupDisplay != nullptr)
  929. {
  930. popupDisplay->startTimer (2000);
  931. }
  932. }
  933. void Slider::restoreMouseIfHidden()
  934. {
  935. if (mouseWasHidden)
  936. {
  937. mouseWasHidden = false;
  938. for (int i = Desktop::getInstance().getNumMouseSources(); --i >= 0;)
  939. Desktop::getInstance().getMouseSource(i)->enableUnboundedMouseMovement (false);
  940. const double pos = sliderBeingDragged == 2 ? getMaxValue()
  941. : (sliderBeingDragged == 1 ? getMinValue()
  942. : (double) currentValue.getValue());
  943. Point<int> mousePos;
  944. if (style == RotaryHorizontalDrag || style == RotaryVerticalDrag)
  945. {
  946. mousePos = Desktop::getLastMouseDownPosition();
  947. if (style == RotaryHorizontalDrag)
  948. {
  949. const double posDiff = valueToProportionOfLength (pos) - valueToProportionOfLength (valueOnMouseDown);
  950. mousePos += Point<int> (roundToInt (pixelsForFullDragExtent * posDiff), 0);
  951. }
  952. else
  953. {
  954. const double posDiff = valueToProportionOfLength (valueOnMouseDown) - valueToProportionOfLength (pos);
  955. mousePos += Point<int> (0, roundToInt (pixelsForFullDragExtent * posDiff));
  956. }
  957. }
  958. else
  959. {
  960. const int pixelPos = (int) getLinearSliderPos (pos);
  961. mousePos = localPointToGlobal (Point<int> (isHorizontal() ? pixelPos : (getWidth() / 2),
  962. isVertical() ? pixelPos : (getHeight() / 2)));
  963. }
  964. Desktop::setMousePosition (mousePos);
  965. }
  966. }
  967. void Slider::modifierKeysChanged (const ModifierKeys& modifiers)
  968. {
  969. if (isEnabled()
  970. && style != IncDecButtons
  971. && style != Rotary
  972. && isVelocityBased == modifiers.isAnyModifierKeyDown())
  973. {
  974. restoreMouseIfHidden();
  975. }
  976. }
  977. void Slider::handleRotaryDrag (const MouseEvent& e)
  978. {
  979. const int dx = e.x - sliderRect.getCentreX();
  980. const int dy = e.y - sliderRect.getCentreY();
  981. if (dx * dx + dy * dy > 25)
  982. {
  983. double angle = std::atan2 ((double) dx, (double) -dy);
  984. while (angle < 0.0)
  985. angle += double_Pi * 2.0;
  986. if (rotaryStop && ! e.mouseWasClicked())
  987. {
  988. if (std::abs (angle - lastAngle) > double_Pi)
  989. {
  990. if (angle >= lastAngle)
  991. angle -= double_Pi * 2.0;
  992. else
  993. angle += double_Pi * 2.0;
  994. }
  995. if (angle >= lastAngle)
  996. angle = jmin (angle, (double) jmax (rotaryStart, rotaryEnd));
  997. else
  998. angle = jmax (angle, (double) jmin (rotaryStart, rotaryEnd));
  999. }
  1000. else
  1001. {
  1002. while (angle < rotaryStart)
  1003. angle += double_Pi * 2.0;
  1004. if (angle > rotaryEnd)
  1005. {
  1006. if (SliderHelpers::smallestAngleBetween (angle, rotaryStart)
  1007. <= SliderHelpers::smallestAngleBetween (angle, rotaryEnd))
  1008. angle = rotaryStart;
  1009. else
  1010. angle = rotaryEnd;
  1011. }
  1012. }
  1013. const double proportion = (angle - rotaryStart) / (rotaryEnd - rotaryStart);
  1014. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, proportion));
  1015. lastAngle = angle;
  1016. }
  1017. }
  1018. void Slider::handleAbsoluteDrag (const MouseEvent& e)
  1019. {
  1020. const int mousePos = (isHorizontal() || style == RotaryHorizontalDrag) ? e.x : e.y;
  1021. double scaledMousePos = (mousePos - sliderRegionStart) / (double) sliderRegionSize;
  1022. if (style == RotaryHorizontalDrag
  1023. || style == RotaryVerticalDrag
  1024. || style == IncDecButtons
  1025. || ((style == LinearHorizontal || style == LinearVertical || style == LinearBar)
  1026. && ! snapsToMousePos))
  1027. {
  1028. const int mouseDiff = (style == RotaryHorizontalDrag
  1029. || style == LinearHorizontal
  1030. || style == LinearBar
  1031. || (style == IncDecButtons && incDecDragDirectionIsHorizontal()))
  1032. ? e.x - mouseDragStartPos.x
  1033. : mouseDragStartPos.y - e.y;
  1034. double newPos = valueToProportionOfLength (valueOnMouseDown)
  1035. + mouseDiff * (1.0 / pixelsForFullDragExtent);
  1036. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, newPos));
  1037. if (style == IncDecButtons)
  1038. {
  1039. incButton->setState (mouseDiff < 0 ? Button::buttonNormal : Button::buttonDown);
  1040. decButton->setState (mouseDiff > 0 ? Button::buttonNormal : Button::buttonDown);
  1041. }
  1042. }
  1043. else
  1044. {
  1045. if (isVertical())
  1046. scaledMousePos = 1.0 - scaledMousePos;
  1047. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, scaledMousePos));
  1048. }
  1049. }
  1050. void Slider::handleVelocityDrag (const MouseEvent& e)
  1051. {
  1052. const int mouseDiff = (isHorizontal() || style == RotaryHorizontalDrag
  1053. || (style == IncDecButtons && incDecDragDirectionIsHorizontal()))
  1054. ? e.x - mousePosWhenLastDragged.x
  1055. : e.y - mousePosWhenLastDragged.y;
  1056. const double maxSpeed = jmax (200, sliderRegionSize);
  1057. double speed = jlimit (0.0, maxSpeed, (double) abs (mouseDiff));
  1058. if (speed != 0)
  1059. {
  1060. speed = 0.2 * velocityModeSensitivity
  1061. * (1.0 + std::sin (double_Pi * (1.5 + jmin (0.5, velocityModeOffset
  1062. + jmax (0.0, (double) (speed - velocityModeThreshold))
  1063. / maxSpeed))));
  1064. if (mouseDiff < 0)
  1065. speed = -speed;
  1066. if (isVertical() || style == RotaryVerticalDrag
  1067. || (style == IncDecButtons && ! incDecDragDirectionIsHorizontal()))
  1068. speed = -speed;
  1069. const double currentPos = valueToProportionOfLength (valueWhenLastDragged);
  1070. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, currentPos + speed));
  1071. e.source.enableUnboundedMouseMovement (true, false);
  1072. mouseWasHidden = true;
  1073. }
  1074. }
  1075. void Slider::mouseDrag (const MouseEvent& e)
  1076. {
  1077. if (isEnabled()
  1078. && (! menuShown)
  1079. && (maximum > minimum)
  1080. && ! (style == LinearBar && e.mouseWasClicked() && valueBox != nullptr && valueBox->isEditable()))
  1081. {
  1082. if (style == Rotary)
  1083. {
  1084. handleRotaryDrag (e);
  1085. }
  1086. else
  1087. {
  1088. if (style == IncDecButtons && ! incDecDragged)
  1089. {
  1090. if (e.getDistanceFromDragStart() < 10 || e.mouseWasClicked())
  1091. return;
  1092. incDecDragged = true;
  1093. mouseDragStartPos = e.getPosition();
  1094. }
  1095. if (isVelocityBased == (userKeyOverridesVelocity && e.mods.testFlags (ModifierKeys::ctrlModifier
  1096. | ModifierKeys::commandModifier
  1097. | ModifierKeys::altModifier))
  1098. || (maximum - minimum) / sliderRegionSize < interval)
  1099. handleAbsoluteDrag (e);
  1100. else
  1101. handleVelocityDrag (e);
  1102. }
  1103. valueWhenLastDragged = jlimit (minimum, maximum, valueWhenLastDragged);
  1104. if (sliderBeingDragged == 0)
  1105. {
  1106. setValue (snapValue (valueWhenLastDragged, true),
  1107. ! sendChangeOnlyOnRelease, true);
  1108. }
  1109. else if (sliderBeingDragged == 1)
  1110. {
  1111. setMinValue (snapValue (valueWhenLastDragged, true),
  1112. ! sendChangeOnlyOnRelease, false, true);
  1113. if (e.mods.isShiftDown())
  1114. setMaxValue (getMinValue() + minMaxDiff, false, false, true);
  1115. else
  1116. minMaxDiff = (double) valueMax.getValue() - (double) valueMin.getValue();
  1117. }
  1118. else if (sliderBeingDragged == 2)
  1119. {
  1120. setMaxValue (snapValue (valueWhenLastDragged, true),
  1121. ! sendChangeOnlyOnRelease, false, true);
  1122. if (e.mods.isShiftDown())
  1123. setMinValue (getMaxValue() - minMaxDiff, false, false, true);
  1124. else
  1125. minMaxDiff = (double) valueMax.getValue() - (double) valueMin.getValue();
  1126. }
  1127. mousePosWhenLastDragged = e.getPosition();
  1128. }
  1129. }
  1130. void Slider::mouseDoubleClick (const MouseEvent&)
  1131. {
  1132. if (doubleClickToValue
  1133. && isEnabled()
  1134. && style != IncDecButtons
  1135. && minimum <= doubleClickReturnValue
  1136. && maximum >= doubleClickReturnValue)
  1137. {
  1138. sendDragStart();
  1139. setValue (doubleClickReturnValue, true, true);
  1140. sendDragEnd();
  1141. }
  1142. }
  1143. void Slider::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  1144. {
  1145. if (scrollWheelEnabled && isEnabled()
  1146. && style != TwoValueHorizontal
  1147. && style != TwoValueVertical)
  1148. {
  1149. if (maximum > minimum && ! e.mods.isAnyMouseButtonDown())
  1150. {
  1151. if (valueBox != nullptr)
  1152. valueBox->hideEditor (false);
  1153. const double value = (double) currentValue.getValue();
  1154. const double proportionDelta = (wheelIncrementX != 0 ? -wheelIncrementX : wheelIncrementY) * 0.15f;
  1155. const double currentPos = valueToProportionOfLength (value);
  1156. const double newValue = proportionOfLengthToValue (jlimit (0.0, 1.0, currentPos + proportionDelta));
  1157. double delta = (newValue != value)
  1158. ? jmax (std::abs (newValue - value), interval) : 0;
  1159. if (value > newValue)
  1160. delta = -delta;
  1161. sendDragStart();
  1162. setValue (snapValue (value + delta, false), true, true);
  1163. sendDragEnd();
  1164. }
  1165. }
  1166. else
  1167. {
  1168. Component::mouseWheelMove (e, wheelIncrementX, wheelIncrementY);
  1169. }
  1170. }
  1171. void SliderListener::sliderDragStarted (Slider*) // (can't write Slider::Listener due to idiotic VC2005 bug)
  1172. {
  1173. }
  1174. void SliderListener::sliderDragEnded (Slider*)
  1175. {
  1176. }
  1177. const Identifier Slider::Ids::tagType ("SLIDER");
  1178. const Identifier Slider::Ids::min ("min");
  1179. const Identifier Slider::Ids::max ("max");
  1180. const Identifier Slider::Ids::interval ("interval");
  1181. const Identifier Slider::Ids::type ("type");
  1182. const Identifier Slider::Ids::editable ("editable");
  1183. const Identifier Slider::Ids::textBoxPos ("textBoxPos");
  1184. const Identifier Slider::Ids::textBoxWidth ("textBoxWidth");
  1185. const Identifier Slider::Ids::textBoxHeight ("textBoxHeight");
  1186. const Identifier Slider::Ids::skew ("skew");
  1187. void Slider::refreshFromValueTree (const ValueTree& state, ComponentBuilder&)
  1188. {
  1189. ComponentBuilder::refreshBasicComponentProperties (*this, state);
  1190. setRange (static_cast <double> (state [Ids::min]),
  1191. static_cast <double> (state [Ids::max]),
  1192. static_cast <double> (state [Ids::interval]));
  1193. setSliderStyle ((SliderStyle) static_cast <int> (state [Ids::type]));
  1194. setTextBoxStyle ((TextEntryBoxPosition) static_cast <int> (state [Ids::textBoxPos]),
  1195. ! static_cast <bool> (state [Ids::editable]),
  1196. static_cast <int> (state [Ids::textBoxWidth]),
  1197. static_cast <int> (state [Ids::textBoxHeight]));
  1198. setSkewFactor (static_cast <double> (state [Ids::skew]));
  1199. }