1998-10-20 01:39:29 +04:00
|
|
|
//
|
2005-02-25 00:55:12 +03:00
|
|
|
// "$Id$"
|
1998-10-20 01:39:29 +04:00
|
|
|
//
|
|
|
|
// Valuator header file for the Fast Light Tool Kit (FLTK).
|
|
|
|
//
|
2008-09-16 11:26:22 +04:00
|
|
|
// Copyright 1998-2008 by Bill Spitzak and others.
|
1998-10-20 01:39:29 +04:00
|
|
|
//
|
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Library General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Library General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Library General Public
|
|
|
|
// License along with this library; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
// USA.
|
|
|
|
//
|
2005-04-16 04:13:17 +04:00
|
|
|
// Please report all bugs and problems on the following page:
|
|
|
|
//
|
|
|
|
// http://www.fltk.org/str.php
|
1998-10-20 01:39:29 +04:00
|
|
|
//
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2008-09-16 11:26:22 +04:00
|
|
|
/** \file
|
|
|
|
Fl_Valuator widget . */
|
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
#ifndef Fl_Valuator_H
|
|
|
|
#define Fl_Valuator_H
|
|
|
|
|
|
|
|
#ifndef Fl_Widget_H
|
|
|
|
#include "Fl_Widget.H"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// shared type() values for classes that work in both directions:
|
|
|
|
#define FL_VERTICAL 0
|
|
|
|
#define FL_HORIZONTAL 1
|
|
|
|
|
2008-09-15 12:41:54 +04:00
|
|
|
/**
|
|
|
|
The Fl_Valuator class controls a single floating-point value
|
|
|
|
and provides a consistent interface to set the value, range, and step,
|
|
|
|
and insures that callbacks are done the same for every object.
|
2008-09-18 02:25:45 +04:00
|
|
|
<P>There are probably more of these classes in FLTK than any others:
|
2008-09-15 22:01:19 +04:00
|
|
|
<P ALIGN=CENTER>\image html valuators.gif</P>
|
2008-09-15 12:41:54 +04:00
|
|
|
<P>In the above diagram each box surrounds an actual subclass. These
|
2008-09-18 02:25:45 +04:00
|
|
|
are further differentiated by setting the type() of the widget t
|
|
|
|
o the symbolic value labeling the widget.
|
|
|
|
The ones labelled "0" are the default versions with a type(0).
|
|
|
|
For consistency the symbol FL_VERTICAL is defined as zero.
|
2008-09-15 12:41:54 +04:00
|
|
|
*/
|
2002-08-14 20:19:48 +04:00
|
|
|
class FL_EXPORT Fl_Valuator : public Fl_Widget {
|
1998-10-06 22:21:25 +04:00
|
|
|
|
|
|
|
double value_;
|
|
|
|
double previous_value_;
|
|
|
|
double min, max; // truncates to this range *after* rounding
|
|
|
|
double A; int B; // rounds to multiples of A/B, or no rounding if A is zero
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
int horizontal() const {return type()&1;}
|
2002-08-14 20:19:48 +04:00
|
|
|
Fl_Valuator(int X, int Y, int W, int H, const char* L);
|
1998-10-06 22:21:25 +04:00
|
|
|
|
|
|
|
double previous_value() const {return previous_value_;}
|
|
|
|
void handle_push() {previous_value_ = value_;}
|
2002-08-14 20:19:48 +04:00
|
|
|
double softclamp(double);
|
|
|
|
void handle_drag(double newvalue);
|
|
|
|
void handle_release(); // use drag() value
|
|
|
|
virtual void value_damage(); // cause damage() due to value() changing
|
2000-04-04 21:05:59 +04:00
|
|
|
void set_value(double v) {value_ = v;}
|
1998-10-06 22:21:25 +04:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2008-09-15 16:46:49 +04:00
|
|
|
/** Sets the minimum (a) and maximum (b) values for the valuator widget. */
|
2008-09-15 12:41:54 +04:00
|
|
|
void bounds(double a, double b) {min=a; max=b;}
|
2008-09-15 16:46:49 +04:00
|
|
|
/** Gets the minimum value for the valuator. */
|
2008-09-15 12:41:54 +04:00
|
|
|
double minimum() const {return min;}
|
2008-09-15 16:46:49 +04:00
|
|
|
/** Sets the minimum value for the valuator. */
|
2008-09-15 12:41:54 +04:00
|
|
|
void minimum(double a) {min = a;}
|
2008-09-15 16:46:49 +04:00
|
|
|
/** Gets the maximum value for the valuator. */
|
|
|
|
double maximum() const {return max;}
|
|
|
|
/** Sets the maximum value for the valuator. */
|
|
|
|
void maximum(double a) {max = a;}
|
2008-09-15 12:41:54 +04:00
|
|
|
/**
|
|
|
|
Sets the minimum and maximum values for the valuator. When
|
|
|
|
the user manipulates the widget, the value is limited to this
|
|
|
|
range. This clamping is done <I>after</I> rounding to the step
|
|
|
|
value (this makes a difference if the range is not a multiple of
|
|
|
|
the step).
|
|
|
|
|
|
|
|
<P>The minimum may be greater than the maximum. This has the
|
2008-09-17 19:44:43 +04:00
|
|
|
effect of "reversing" the object so the larger values
|
2008-09-15 12:41:54 +04:00
|
|
|
are in the opposite direction. This also switches which end of
|
|
|
|
the filled sliders is filled.</P>
|
|
|
|
|
2008-09-17 19:44:43 +04:00
|
|
|
<P>Some widgets consider this a "soft" range. This
|
2008-09-15 12:41:54 +04:00
|
|
|
means they will stop at the range, but if the user releases and
|
|
|
|
grabs the control again and tries to move it further, it is
|
|
|
|
allowed.</P>
|
|
|
|
|
|
|
|
<P>The range may affect the display. You must redraw()
|
|
|
|
the widget after changing the range.
|
|
|
|
*/
|
1998-10-06 22:21:25 +04:00
|
|
|
void range(double a, double b) {min = a; max = b;}
|
2008-09-15 12:41:54 +04:00
|
|
|
/** See double Fl_Valuator::step() const */
|
1998-10-06 22:21:25 +04:00
|
|
|
void step(int a) {A = a; B = 1;}
|
2008-09-15 12:41:54 +04:00
|
|
|
/** See double Fl_Valuator::step() const */
|
1998-10-06 22:21:25 +04:00
|
|
|
void step(double a, int b) {A = a; B = b;}
|
2002-08-14 20:19:48 +04:00
|
|
|
void step(double s);
|
2008-09-15 12:41:54 +04:00
|
|
|
/**
|
|
|
|
Gets or sets the step value. As the user moves the mouse the
|
|
|
|
value is rounded to the nearest multiple of the step value. This
|
|
|
|
is done <I>before</I> clamping it to the range. For most widgets
|
|
|
|
the default step is zero.
|
|
|
|
|
|
|
|
<P>For precision the step is stored as the ratio of two
|
|
|
|
integers, A/B. You can set these integers directly. Currently
|
|
|
|
setting a floating point value sets the nearest A/1 or 1/B value
|
|
|
|
possible.
|
|
|
|
*/
|
1998-10-06 22:21:25 +04:00
|
|
|
double step() const {return A/B;}
|
2002-08-14 20:19:48 +04:00
|
|
|
void precision(int);
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2008-09-18 02:25:45 +04:00
|
|
|
/** Gets the floating point(double) value. See int value(double) */
|
1998-10-06 22:21:25 +04:00
|
|
|
double value() const {return value_;}
|
2002-08-14 20:19:48 +04:00
|
|
|
int value(double);
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2002-08-14 20:19:48 +04:00
|
|
|
virtual int format(char*);
|
|
|
|
double round(double); // round to nearest multiple of step
|
|
|
|
double clamp(double); // keep in range
|
|
|
|
double increment(double, int); // add n*step to value
|
1998-10-06 22:21:25 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
1998-10-20 01:39:29 +04:00
|
|
|
//
|
2005-02-25 00:55:12 +03:00
|
|
|
// End of "$Id$".
|
1998-10-20 01:39:29 +04:00
|
|
|
//
|