WidgetSliderInput.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. * This source file is part of RmlUi, the HTML/CSS Interface Middleware
  3. *
  4. * For the latest information, see http://github.com/mikke89/RmlUi
  5. *
  6. * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
  7. * Copyright (c) 2019 The RmlUi Team, and contributors
  8. *
  9. * Permission is hereby granted, free of charge, to any person obtaining a copy
  10. * of this software and associated documentation files (the "Software"), to deal
  11. * in the Software without restriction, including without limitation the rights
  12. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. * copies of the Software, and to permit persons to whom the Software is
  14. * furnished to do so, subject to the following conditions:
  15. *
  16. * The above copyright notice and this permission notice shall be included in
  17. * all copies or substantial portions of the Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  25. * THE SOFTWARE.
  26. *
  27. */
  28. #ifndef RMLUICONTROLSWIDGETSLIDERINPUT_H
  29. #define RMLUICONTROLSWIDGETSLIDERINPUT_H
  30. #include "WidgetSlider.h"
  31. namespace Rml {
  32. namespace Controls {
  33. /**
  34. A specialisation of the slider widget for input sliders.
  35. @author Peter Curry
  36. */
  37. class WidgetSliderInput : public WidgetSlider
  38. {
  39. public:
  40. WidgetSliderInput(ElementFormControl* parent);
  41. virtual ~WidgetSliderInput();
  42. /// Sets a new value on the slider.
  43. /// @param[in] value The new value for the slider. This will be clamped between the min and max values, and set to the nearest increment.
  44. void SetValue(float value);
  45. /// Returns the current value of the slider.
  46. /// @return The current value of the slider.
  47. float GetValue() const;
  48. /// Sets the minimum value of the slider.
  49. /// @param[in] min_value The new minimum value of the slider.
  50. void SetMinValue(float min_value);
  51. /// Sets the maximum value of the slider.
  52. /// @param[in] max_value The new minimum value of the slider.
  53. void SetMaxValue(float max_value);
  54. /// Sets the slider's value increment.
  55. /// @param[in] step The new increment for the slider's value.
  56. void SetStep(float step);
  57. /// Formats the slider's elements.
  58. void FormatElements();
  59. protected:
  60. /// Called when the slider's bar position is set or dragged.
  61. /// @param bar_position[in] The new position of the bar (0 representing the start of the track, 1 representing the end).
  62. /// @return The new position of the bar.
  63. float OnBarChange(float bar_position) override;
  64. /// Called when the slider is incremented by one 'line', either by the down / right key or a mouse-click on the
  65. /// increment arrow.
  66. /// @return The new position of the bar.
  67. float OnLineIncrement() override;
  68. /// Called when the slider is decremented by one 'line', either by the up / left key or a mouse-click on the
  69. /// decrement arrow.
  70. /// @return The new position of the bar.
  71. float OnLineDecrement() override;
  72. /// Called when the slider is incremented by one 'page', either by the page-up key or a mouse-click on the
  73. /// track below / right of the bar.
  74. /// @return The new position of the bar.
  75. float OnPageIncrement(float click_position) override;
  76. /// Called when the slider is incremented by one 'page', either by the page-down key or a mouse-click on the
  77. /// track above / left of the bar.
  78. /// @return The new position of the bar.
  79. float OnPageDecrement(float click_position) override;
  80. private:
  81. /// Clamps the new value, sets it on the slider and returns it as a number from 0 to 1, 0 being the minimum
  82. /// value and 1 the maximum.
  83. /// @param[in] new_value The new value to set on the slider.
  84. /// @return The new parametric value of the slider.
  85. float SetValueInternal(float new_value);
  86. float value;
  87. float min_value;
  88. float max_value;
  89. float step;
  90. };
  91. }
  92. }
  93. #endif