FLTK 1.3.0
Fl_Valuator.H
00001 //
00002 // "$Id: Fl_Valuator.H 7981 2010-12-08 23:53:04Z greg.ercolano $"
00003 //
00004 // Valuator header file for the Fast Light Tool Kit (FLTK).
00005 //
00006 // Copyright 1998-2010 by Bill Spitzak and others.
00007 //
00008 // This library is free software; you can redistribute it and/or
00009 // modify it under the terms of the GNU Library General Public
00010 // License as published by the Free Software Foundation; either
00011 // version 2 of the License, or (at your option) any later version.
00012 //
00013 // This library is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016 // Library General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU Library General Public
00019 // License along with this library; if not, write to the Free Software
00020 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00021 // USA.
00022 //
00023 // Please report all bugs and problems on the following page:
00024 //
00025 //     http://www.fltk.org/str.php
00026 //
00027 
00028 /* \file
00029    Fl_Valuator widget . */
00030 
00031 #ifndef Fl_Valuator_H
00032 #define Fl_Valuator_H
00033 
00034 #ifndef Fl_Widget_H
00035 #include "Fl_Widget.H"
00036 #endif
00037 
00038 // shared type() values for classes that work in both directions:
00039 #define FL_VERTICAL             0 ///< The valuator can work vertically
00040 #define FL_HORIZONTAL           1 ///< The valuator can work horizontally
00041 
00055 class FL_EXPORT Fl_Valuator : public Fl_Widget {
00056 
00057   double value_;
00058   double previous_value_;
00059   double min, max; // truncates to this range *after* rounding
00060   double A; int B; // rounds to multiples of A/B, or no rounding if A is zero
00061 
00062 protected:
00064   int horizontal() const {return type()& FL_HORIZONTAL;}
00065   Fl_Valuator(int X, int Y, int W, int H, const char* L);
00066 
00068   double previous_value() const {return previous_value_;}
00070   void handle_push() {previous_value_ = value_;}
00071   double softclamp(double);
00072   void handle_drag(double newvalue);
00073   void handle_release(); // use drag() value
00074   virtual void value_damage(); // cause damage() due to value() changing
00076   void set_value(double v) {value_ = v;}
00077 
00078 public:
00079 
00081     void bounds(double a, double b) {min=a; max=b;}
00083     double minimum() const {return min;}
00085     void minimum(double a) {min = a;}
00087     double maximum() const {return max;}
00089     void maximum(double a) {max = a;}
00110   void range(double a, double b) {min = a; max = b;}
00112   void step(int a) {A = a; B = 1;}
00114   void step(double a, int b) {A = a; B = b;}
00115   void step(double s);
00127   double step() const {return A/B;}
00128   void precision(int);
00129 
00131   double value() const {return value_;}
00132   int value(double);
00133 
00134   virtual int format(char*);
00135   double round(double); // round to nearest multiple of step
00136   double clamp(double); // keep in range
00137   double increment(double, int); // add n*step to value
00138 };
00139 
00140 #endif
00141 
00142 //
00143 // End of "$Id: Fl_Valuator.H 7981 2010-12-08 23:53:04Z greg.ercolano $".
00144 //