fltk::Slider Class Reference

Inherits fltk::Valuator.

Inherited by fltk::FillSlider, fltk::Scrollbar, and fltk::ValueSlider.

List of all members.

Public Member Functions

void draw ()
bool draw (const Rectangle &, Flags flags, bool slot)
void draw_ticks (const Rectangle &, int min_spacing)
int handle (int)
int handle (int event, const Rectangle &)
bool horizontal () const
double position_value (int x, int w)
int slider_position (double value, int w)
void slider_size (int n)
void tick_size (int n)

Detailed Description

This widget contains a sliding "knob" that controls a single floating-point value. Moving the box all the way to the left or bottom sets it to the minimum(), and to the top/right to the maximum() value. The minimum() may be greater than the maximum() in case you want the larger number at the opposite end.

See Valuator for how to set or get the value or handle callbacks when the value changes.

slider.gif

The appearance of the base class may be changed in several ways:

Setting the box() to any value other than the default of FLAT_BOX, as shown in the example on the bottom-left, will remove the "slot" and draw a box around the slider and the tick marks. The color() (which defaults to GRAY75) is used to fill in the area behind the slider and tick marks.

You can use set_vertical() to make the slider move up/down rather than horizontally.

The following bits may be or'd together and given to type():

  • fltk::Slider::TICK_ABOVE : Put tick marks above the horizontal slider.
  • fltk::Slider::TICK_LEFT : Put tick marks to the left of a vertical slider (same value as TICK_ABOVE)
  • fltk::Slider::TICK_BELOW : Put tick marks below the horizontal slider.
  • fltk::Slider::TICK_RIGHT : Put tick marks to the right of a vertical slider (same value as TICK_BELOW)
  • fltk::Slider::TICK_BOTH : Put tick marks on both sides of the slider.
  • fltk::Slider::LOG : Use a logarithimic or power scale for the slider.

The tick marks are placed the slider_size() or more apart (they are also no closer than the step() value). The color of the tick marks is controlled by textcolor(), and the font used to draw the numbers is textfont() and textsize() (which defaults to 8).

You can change the glyph() function to change how the moving part is drawn. The drawflags() determines what part of the slider is being drawn. The ScrollBar subclass turns on ALIGN_TOP/LEFT/RIGHT/BOTTOM to draw the buttons at the end (this is the same as Widget::default_glyph() takes and the default slider glyph just calls that). The moving part has bit 16 turned on, unless this is a fill slider in which case bit 16 is off. You can check the LAYOUT_VERTICAL flag to see which direction the slider is going in.

logslider.gif

"Log" sliders have a non-uniform scale. This diagram shows some examples. The scale is truly logarithmic if both the minimum() and the maximum() are non-zero and have the same sign. Otherwise the slider position is the square root of the value (or -sqrt(-value) for negative values).


Member Function Documentation

void Slider::draw ( void  ) [virtual]

Fltk calls this virtual function to draw the widget, after setting up the graphics (current window, xy translation, etc) so that any drawing functions will go into this widget.

User code should not call this! You probably want to call redraw().

The default version calls draw_box() and draw_label(), thus drawing the box() to fill the widget and putting the label() and image() inside it to fill it, unless the align() flags are set to put it outside.

Information on how to write your own version is here.

Reimplemented from fltk::Widget.

Reimplemented in fltk::Scrollbar, and fltk::ValueSlider.

bool Slider::draw ( const Rectangle sr,
Flags  flags,
bool  slot 
)

Subclasses can use this to redraw the moving part. Draw everything that is inside the box, such as the tick marks, the moving slider, and the "slot". The slot only drawn if slot is true. You should already have drawn the background of the slider.

void Slider::draw_ticks ( const Rectangle r,
int  min_spacing 
)

Draw tick marks. These lines cross the passed rectangle perpendicular to the slider direction. In the direction parallel to the slider direction the box should have the same size as the area the slider moves in.

int Slider::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 fltk::Valuator.

Reimplemented in fltk::Scrollbar, and fltk::ValueSlider.

int Slider::handle ( int  event,
const Rectangle r 
)

This call is provied so subclasses can draw the moving part inside an arbitrary rectangle.

bool fltk::Slider::horizontal ( ) const [inline]

Return true if this widget has a horizontal orientation and fltk::Pack will position it against the top or bottom edge. This is the default.

Reimplemented from fltk::Widget.

double Slider::position_value ( int  X,
int  w 
)

This is used by subclasses to handle events correctly: Return the value if the left/top edge of a box of slider_size() is placed at X pixels from the edge of an area of size w pixels. The range() and log() settings are taken into account, and it also rounds the value to multiples of step(), using powers of 10 larger and multiples of 2 or 5 to get the steps close to 1 pixel so the user is presented with nice numerical values.

int Slider::slider_position ( double  value,
int  w 
)

This is used by subclasses to draw the slider correctly. Return the location of the left/top edge of a box of slider_size() would be if the slider is set to value and can move in an area of w pixels. The range() and log() settings are taken into account.

void Slider::slider_size ( int  n) [inline]

Set the dimensions of the moving piece of slider. This is measured in pixels in a direction parallel to the slider's movement. The default value is 12.

Setting slider_size() to zero will make the slider into a "fill" slider that draws a solid bar from the left/bottom to the current value. This is useful for indicating progress or as a output indicator.

void Slider::tick_size ( int  n) [inline]

The slider is shrunk this many pixels from the widget's width so that the tick marks are visible next to it. The default value is 4.


The documentation for this class was generated from the following files: