FLTK 1.3.0
Fl_Valuator.H
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 
28 /* \file
29  Fl_Valuator widget . */
30 
31 #ifndef Fl_Valuator_H
32 #define Fl_Valuator_H
33 
34 #ifndef Fl_Widget_H
35 #include "Fl_Widget.H"
36 #endif
37 
38 // shared type() values for classes that work in both directions:
39 #define FL_VERTICAL 0
40 #define FL_HORIZONTAL 1
41 
42 
55 class FL_EXPORT Fl_Valuator : public Fl_Widget {
56 
57  double value_;
58  double previous_value_;
59  double min, max; // truncates to this range *after* rounding
60  double A; int B; // rounds to multiples of A/B, or no rounding if A is zero
61 
62 protected:
64  int horizontal() const {return type()& FL_HORIZONTAL;}
65  Fl_Valuator(int X, int Y, int W, int H, const char* L);
66 
68  double previous_value() const {return previous_value_;}
70  void handle_push() {previous_value_ = value_;}
71  double softclamp(double);
72  void handle_drag(double newvalue);
73  void handle_release(); // use drag() value
74  virtual void value_damage(); // cause damage() due to value() changing
76  void set_value(double v) {value_ = v;}
77 
78 public:
79 
81  void bounds(double a, double b) {min=a; max=b;}
83  double minimum() const {return min;}
85  void minimum(double a) {min = a;}
87  double maximum() const {return max;}
89  void maximum(double a) {max = a;}
110  void range(double a, double b) {min = a; max = b;}
112  void step(int a) {A = a; B = 1;}
114  void step(double a, int b) {A = a; B = b;}
115  void step(double s);
127  double step() const {return A/B;}
128  void precision(int);
129 
131  double value() const {return value_;}
132  int value(double);
133 
134  virtual int format(char*);
135  double round(double); // round to nearest multiple of step
136  double clamp(double); // keep in range
137  double increment(double, int); // add n*step to value
138 };
139 
140 #endif
141 
142 //
143 // End of "$Id: Fl_Valuator.H 7981 2010-12-08 23:53:04Z greg.ercolano $".
144 //
Fl_Widget is the base class for all widgets in FLTK.
Definition: Fl_Widget.H:109
The Fl_Valuator class controls a single floating-point value and provides a consistent interface to s...
Definition: Fl_Valuator.H:55
void maximum(double a)
Sets the maximum value for the valuator.
Definition: Fl_Valuator.H:89
double previous_value() const
Gets the previous floating point value before an event changed it.
Definition: Fl_Valuator.H:68
double minimum() const
Gets the minimum value for the valuator.
Definition: Fl_Valuator.H:83
int horizontal() const
Tells if the valuator is an FL_HORIZONTAL one.
Definition: Fl_Valuator.H:64
void set_value(double v)
Sets the current floating point value.
Definition: Fl_Valuator.H:76
void step(double a, int b)
See double Fl_Valuator::step() const.
Definition: Fl_Valuator.H:114
Fl_Widget, Fl_Label classes .
double maximum() const
Gets the maximum value for the valuator.
Definition: Fl_Valuator.H:87
void handle_push()
Stores the current value in the previous value.
Definition: Fl_Valuator.H:70
void minimum(double a)
Sets the minimum value for the valuator.
Definition: Fl_Valuator.H:85
void bounds(double a, double b)
Sets the minimum (a) and maximum (b) values for the valuator widget.
Definition: Fl_Valuator.H:81
double value() const
Gets the floating point(double) value.
Definition: Fl_Valuator.H:131
void range(double a, double b)
Sets the minimum and maximum values for the valuator.
Definition: Fl_Valuator.H:110
void step(int a)
See double Fl_Valuator::step() const.
Definition: Fl_Valuator.H:112
double step() const
Gets or sets the step value.
Definition: Fl_Valuator.H:127
uchar type() const
Gets the widget type.
Definition: Fl_Widget.H:270