Valuator Class Reference

Inherits Widget.

Inherited by Adjuster, Dial, Slider, ThumbWheel, ValueInput, and ValueOutput.

List of all members.

Public Member Functions

double value () const
int value (double)
float minimum () const
void minimum (double a)
float maximum () const
void maximum (double a)
void range (double a, double b)
float step () const
void step (double a)
float linesize () const
void linesize (double a)
virtual int format (char *)
int handle (int)
 Valuator (int X, int Y, int W, int H, const char *L)
double previous_value () const
void handle_push ()
void handle_drag (double newvalue)
void handle_release ()
virtual void value_damage ()
void set_value (double v)


Detailed Description

Base class for sliders and all other one-value "knobs".The 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.

Callbacks are done each time the user changes the value. So if they drag a slider, the callback is done each time the slider handle moves to a new pixel.

For most subclasses you can call when() to get some other callback behaviors:

There are probably more of these classes in FLTK than any others:

valuators.gif

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). For consistency the symbol VERTICAL is defined as zero.


Constructor & Destructor Documentation

Valuator::Valuator int  X,
int  Y,
int  W,
int  H,
const char *  L
 

The constructor initializes:

  • value(0.0)
  • step(0)
  • range(0,1)
  • linesize(1)


Member Function Documentation

int Valuator::format char *  buffer  )  [virtual]
 

Print the current value into the passed buffer as a user-readable and editable string. Returns the number of bytes (not counting the terminating nul) written to the buffer. Calling code can assumme that the written string is never longer than 20 characters.

This is used by subclasses that let the user edit the value in a textfield. Since this is a virtual function, you can override this in a subclass of those and change how the numbers are displayed.

The default version prints enough digits for the current step() value. If step() is zero it does a g format. If step is an integer it does d format. Otherwise it does a .nf format where n is enough digits to show the step, maximum of 8.

int Valuator::handle int  event  )  [virtual]
 

The base class handle() accepts FOCUS and recognizes a number of keystrokes that adjust the value. A subclass can call this to get these keystrokes, it can also do it's own keystroke handling if it wants.

Reimplemented from Widget.

void Valuator::handle_drag double  v  ) 
 

Subclasses should call this as the user moves the value. The passed number is an arbitrary-precision value you want to set it to, this function clamps it to the range (if previous_value() is in range) and rounds it to the nearest multiple of step(), and then stores it into value(). It then does the callback() if necessary.

void Valuator::handle_push  )  [inline]
 

Subclasses should call this when the user starts to change the value.

void Valuator::handle_release  ) 
 

Subclasses should call this when the user stops moving the value. It may call the callback.

void Valuator::linesize double  a  )  [inline]
 

The linesize is the amount the valuator moves in response to an arrow key, or the user clicking an up/down button. The default value is 1. Negative values and values that are not a multiple of step() produce undocumented results.

void Valuator::maximum double  a  )  [inline]
 

Sets the maximum value for the valuator. For most subclasses the user cannot move the value outside the minimum()..maximum() range if it starts inside this range.

These values should be multiples of the step() to avoid ambiguity and possible implementation changes.

For most subclasses, the minimum may be greater than the maximum. This has the effect of "reversing" the object so the larger values are in the opposite direction. This also switches which end of the filled sliders is filled.

You probably need to redraw() the widget after changing the range.

void Valuator::minimum double  a  )  [inline]
 

Sets the minimum value for the valuator. See minimum().

double Valuator::previous_value  )  const [inline]
 

Value saved when handle_push() was last called.

void Valuator::range double  min,
double  max
[inline]
 

Sets both the minimum() and maximum().

void Valuator::set_value double  v  )  [inline]
 

Sets the current value but does not call value_damage().

void Valuator::step double  a  )  [inline]
 

Set the step value. As the user moves the mouse the value is rounded to a multiple of this. Values that are sufficently close to 1/N (where N is an integer) are detected and assummed to be exactly 1/N, so step(.00001) will work as wanted.

If this is zero (the default) then all rounding is disabled. This results in the smoothest controller movement but this is not recommended if you want to present the resulting numbers to the user as text, because they will have useless extra digits of precision.

For some widgets like Roller this is also the distance the value moves when the user drags the mouse 1 pixel. In these cases if step() is zero then it acts like it is .01.

Negative values for step() produce undocumented results.

int Valuator::value double  v  ) 
 

Sets the current value, redrawing the widget if necessary by calling value_damage(). The new value is stored unchanged, even if it is outside the range or not a multiple of step().

double Valuator::value  )  const [inline]
 

Returns the current value.

void Valuator::value_damage  )  [virtual]
 

Subclasses must implement this. It is called whenever the value() changes. They must call redraw() if necessary.


The documentation for this class was generated from the following files:
Sun Jan 7 00:55:18 2007. FLTK ©2006 Bill Spitzak and others.
Permission is granted to reproduce this manual or any portion for any purpose, provided this copyright and permission notice are preserved.