1998-10-20 01:39:29 +04:00
|
|
|
//
|
|
|
|
// Valuator header file for the Fast Light Tool Kit (FLTK).
|
|
|
|
//
|
2022-10-09 20:34:34 +03:00
|
|
|
// Copyright 1998-2022 by Bill Spitzak and others.
|
1998-10-20 01:39:29 +04:00
|
|
|
//
|
2011-07-19 08:49:30 +04:00
|
|
|
// This library is free software. Distribution and use rights are outlined in
|
|
|
|
// the file "COPYING" which should have been included with this file. If this
|
|
|
|
// file is missing or damaged, see the license at:
|
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// https://www.fltk.org/COPYING.php
|
1998-10-20 01:39:29 +04:00
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// Please see the following page on how to report bugs and issues:
|
2005-04-16 04:13:17 +04:00
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// https://www.fltk.org/bugs.php
|
1998-10-20 01:39:29 +04:00
|
|
|
//
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2008-10-15 17:46:06 +04:00
|
|
|
/* \file
|
2008-09-16 11:26:22 +04:00
|
|
|
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:
|
2020-07-01 19:03:10 +03:00
|
|
|
#define FL_VERTICAL 0 ///< The valuator can work vertically
|
|
|
|
#define FL_HORIZONTAL 1 ///< The valuator can work horizontally
|
1998-10-06 22:21:25 +04:00
|
|
|
|
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.
|
2016-03-08 16:51:01 +03:00
|
|
|
|
|
|
|
There are probably more of these classes in FLTK than any others:
|
|
|
|
|
2022-10-09 20:34:34 +03:00
|
|
|
\image html valuators.png
|
2016-03-08 16:51:01 +03:00
|
|
|
\image latex valuators.png "Valuators derived from Fl_Valuators" width=10cm
|
|
|
|
|
|
|
|
In the above diagram each box surrounds an actual subclass. These
|
|
|
|
are further differentiated by setting the type() of the widget to
|
|
|
|
the symbolic value labeling the widget.
|
|
|
|
The ones labelled "0" are the default versions with a type(0).
|
2008-09-18 02:25:45 +04:00
|
|
|
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:
|
2008-09-18 23:09:34 +04:00
|
|
|
/** Tells if the valuator is an FL_HORIZONTAL one */
|
|
|
|
int horizontal() const {return type()& FL_HORIZONTAL;}
|
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
|
|
|
|
2008-09-18 23:09:34 +04:00
|
|
|
/** Gets the previous floating point value before an event changed it */
|
1998-10-06 22:21:25 +04:00
|
|
|
double previous_value() const {return previous_value_;}
|
2008-09-18 23:09:34 +04:00
|
|
|
/** Stores the current value in the previous value */
|
1998-10-06 22:21:25 +04:00
|
|
|
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
|
2008-09-18 23:09:34 +04:00
|
|
|
/** Sets the current floating point value. */
|
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).
|
2016-03-08 16:51:01 +03:00
|
|
|
|
|
|
|
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
|
2016-03-08 16:51:01 +03:00
|
|
|
the filled sliders is filled.
|
|
|
|
|
|
|
|
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
|
2016-03-08 16:51:01 +03:00
|
|
|
allowed.
|
|
|
|
|
|
|
|
The range may affect the display. You must redraw()
|
2008-09-15 12:41:54 +04:00
|
|
|
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
|
2016-03-08 16:51:01 +03:00
|
|
|
is done \e before clamping it to the range. For most widgets
|
2008-09-15 12:41:54 +04:00
|
|
|
the default step is zero.
|
2016-03-08 16:51:01 +03:00
|
|
|
|
|
|
|
For precision the step is stored as the ratio of a double \p A and
|
|
|
|
an integer \p B = A/B. You can set these values directly. Currently
|
2008-09-15 12:41:54 +04:00
|
|
|
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;}
|
2016-03-08 16:51:01 +03:00
|
|
|
void precision(int digits);
|
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
|