WidgetSliderInput.h 3.9 KB

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