Fl_Valuator.H 5.0 KB

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