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.

145 lines
5.4KB

  1. //
  2. // "$Id: Fl_Valuator.H 7981 2010-12-08 23:53:04Z greg.ercolano $"
  3. //
  4. // Valuator header file for the Fast Light Tool Kit (FLTK).
  5. //
  6. // Copyright 1998-2010 by Bill Spitzak and others.
  7. //
  8. // This library is free software; you can redistribute it and/or
  9. // modify it under the terms of the GNU Library General Public
  10. // License as published by the Free Software Foundation; either
  11. // version 2 of the License, or (at your option) any later version.
  12. //
  13. // This library is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. // Library General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Library General Public
  19. // License along with this library; if not, write to the Free Software
  20. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  21. // USA.
  22. //
  23. // Please report all bugs and problems on the following page:
  24. //
  25. // http://www.fltk.org/str.php
  26. //
  27. /* \file
  28. Fl_Valuator widget . */
  29. #ifndef Fl_Valuator_H
  30. #define Fl_Valuator_H
  31. #ifndef Fl_Widget_H
  32. #include "Fl_Widget.H"
  33. #endif
  34. // shared type() values for classes that work in both directions:
  35. #define FL_VERTICAL 0 ///< The valuator can work vertically
  36. #define FL_HORIZONTAL 1 ///< The valuator can work horizontally
  37. /**
  38. The Fl_Valuator class controls a single floating-point value
  39. and provides a consistent interface to set the value, range, and step,
  40. and insures that callbacks are done the same for every object.
  41. <P>There are probably more of these classes in FLTK than any others:
  42. <P ALIGN=CENTER>\image html valuators.png</P>
  43. \image latex valuators.png "Valuators derived from Fl_Valuators" width=10cm
  44. <P>In the above diagram each box surrounds an actual subclass. These
  45. are further differentiated by setting the type() of the widget t
  46. o the symbolic value labeling the widget.
  47. The ones labelled "0" are the default versions with a type(0).
  48. For consistency the symbol FL_VERTICAL is defined as zero.
  49. */
  50. class FL_EXPORT Fl_Valuator : public Fl_Widget {
  51. double value_;
  52. double previous_value_;
  53. double min, max; // truncates to this range *after* rounding
  54. double A; int B; // rounds to multiples of A/B, or no rounding if A is zero
  55. protected:
  56. /** Tells if the valuator is an FL_HORIZONTAL one */
  57. int horizontal() const {return type()& FL_HORIZONTAL;}
  58. Fl_Valuator(int X, int Y, int W, int H, const char* L);
  59. /** Gets the previous floating point value before an event changed it */
  60. double previous_value() const {return previous_value_;}
  61. /** Stores the current value in the previous value */
  62. void handle_push() {previous_value_ = value_;}
  63. double softclamp(double);
  64. void handle_drag(double newvalue);
  65. void handle_release(); // use drag() value
  66. virtual void value_damage(); // cause damage() due to value() changing
  67. /** Sets the current floating point value. */
  68. void set_value(double v) {value_ = v;}
  69. public:
  70. /** Sets the minimum (a) and maximum (b) values for the valuator widget. */
  71. void bounds(double a, double b) {min=a; max=b;}
  72. /** Gets the minimum value for the valuator. */
  73. double minimum() const {return min;}
  74. /** Sets the minimum value for the valuator. */
  75. void minimum(double a) {min = a;}
  76. /** Gets the maximum value for the valuator. */
  77. double maximum() const {return max;}
  78. /** Sets the maximum value for the valuator. */
  79. void maximum(double a) {max = a;}
  80. /**
  81. Sets the minimum and maximum values for the valuator. When
  82. the user manipulates the widget, the value is limited to this
  83. range. This clamping is done <I>after</I> rounding to the step
  84. value (this makes a difference if the range is not a multiple of
  85. the step).
  86. <P>The minimum may be greater than the maximum. This has the
  87. effect of "reversing" the object so the larger values
  88. are in the opposite direction. This also switches which end of
  89. the filled sliders is filled.</P>
  90. <P>Some widgets consider this a "soft" range. This
  91. means they will stop at the range, but if the user releases and
  92. grabs the control again and tries to move it further, it is
  93. allowed.</P>
  94. <P>The range may affect the display. You must redraw()
  95. the widget after changing the range.
  96. */
  97. void range(double a, double b) {min = a; max = b;}
  98. /** See double Fl_Valuator::step() const */
  99. void step(int a) {A = a; B = 1;}
  100. /** See double Fl_Valuator::step() const */
  101. void step(double a, int b) {A = a; B = b;}
  102. void step(double s);
  103. /**
  104. Gets or sets the step value. As the user moves the mouse the
  105. value is rounded to the nearest multiple of the step value. This
  106. is done <I>before</I> clamping it to the range. For most widgets
  107. the default step is zero.
  108. <P>For precision the step is stored as the ratio of two
  109. integers, A/B. You can set these integers directly. Currently
  110. setting a floating point value sets the nearest A/1 or 1/B value
  111. possible.
  112. */
  113. double step() const {return A/B;}
  114. void precision(int);
  115. /** Gets the floating point(double) value. See int value(double) */
  116. double value() const {return value_;}
  117. int value(double);
  118. virtual int format(char*);
  119. double round(double); // round to nearest multiple of step
  120. double clamp(double); // keep in range
  121. double increment(double, int); // add n*step to value
  122. };
  123. #endif
  124. //
  125. // End of "$Id: Fl_Valuator.H 7981 2010-12-08 23:53:04Z greg.ercolano $".
  126. //