class fltk::Slider
Class Hierarchy
fltk::Valuator
|
+----fltk::Slider
|
+----fltk::Scrollbar, fltk::ValueSlider
Include Files
#include <fltk/Slider.h>
Description
The fltk::Slider 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 set greater than
the maximum() to reverse the
slider direction. See fltk::Valuator for
how to set or get the value or handle callbacks when the value changes.
The appearance of the slider may be changed by setting the type() to the "or" of a several bits.
By default the slider moves vertically. Setting the
HORIZONTAL bit in the type makes it move horizontally.
"Log" sliders have a non-uniform scale. The above-right 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).
You can turn on tick marks by turning on bits in the type(). 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 text_color(), and the font used
to draw the numbers is text_font().
Setting the 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. Setting the color() fills in this box. Setting the
button_box() changes how the
moving part is drawn (only rectangular boxes work), and button_color() colors it.
Methods
Creates a new fltk::Slider widget using the given position,
size, and label string. The default type() is fltk::Slider::VERTICAL
(0).
The default boxtype is fltk::DOWN_BOX.
Destroys the valuator.
Any of these values may be "or'd" together to produce the type(),
the default value is VERTICAL.
- fltk::Slider::VERTICAL - Slider moves vertically.
- fltk::Slider::HORIZONTAL - Slider moves horizontally.
- 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.
Get or 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.
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.
Return the location in pixels of the left/top edge of a box of
slider_size() should be drawn at if it is positioned at the value
value in an area the slider can move in of width/height
w.
Return the value that would place the left/top edge of a box of
slider_size() at pixel x in an area the slider can move in of
width/height w.
Draw tick marks to fill the passed rectangle. 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.
Do minimal-update redraw of the moving part of the slider that fits in
the passed rectangle. Also draw the black slot if slot is
true. If this returnes true then it has done an fltk::push_clip() and you must fill
in the remaining area with the background that goes behind the
slider. The clipped area will either be the entire widget or the area
the slider used to be in, with the area of the new slider and the slot
removed from it. Typical usage in a subclass:
void MySlider::draw() {
// figure out inset box to hold moving part of slider:
int ix = 10;
int iy = 10;
int iw = w()-20;
int ih = h()-20;
// draw the moving part:
if (draw(ix, iy, iw, ih, 0, false)) {
// we must draw the background:
draw_spiffy_background(0,0,w(),h());
// draw the tick marks across whole widget:
draw_ticks(ix, 0, iw, h());
fltk::pop_clip();
}
}
Handle events for a slider where the moving part is in the passed box.