2005-03-21 02:38:14 +03:00
|
|
|
//
|
|
|
|
// "$Id$"
|
|
|
|
//
|
|
|
|
// Spinner widget for the Fast Light Tool Kit (FLTK).
|
|
|
|
//
|
2017-03-10 01:08:29 +03:00
|
|
|
// Copyright 1998-2017 by Bill Spitzak and others.
|
2005-03-21 02:38:14 +03: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:
|
|
|
|
//
|
|
|
|
// http://www.fltk.org/COPYING.php
|
2005-03-21 02:38:14 +03:00
|
|
|
//
|
|
|
|
// Please report all bugs and problems on the following page:
|
|
|
|
//
|
|
|
|
// http://www.fltk.org/str.php
|
|
|
|
//
|
|
|
|
|
2008-10-15 17:46:06 +04:00
|
|
|
/* \file
|
2008-09-16 11:26:22 +04:00
|
|
|
Fl_Spinner widget . */
|
|
|
|
|
2005-03-21 02:38:14 +03:00
|
|
|
#ifndef Fl_Spinner_H
|
2017-03-10 01:08:29 +03:00
|
|
|
#define Fl_Spinner_H
|
2005-03-21 02:38:14 +03:00
|
|
|
|
2017-03-10 01:08:29 +03:00
|
|
|
#include <FL/Enumerations.H>
|
|
|
|
#include <FL/Fl_Group.H>
|
|
|
|
#include <FL/Fl_Input.H>
|
|
|
|
#include <FL/Fl_Repeat_Button.H>
|
2005-03-21 02:38:14 +03:00
|
|
|
|
2008-09-15 20:39:05 +04:00
|
|
|
/**
|
2017-03-10 01:08:29 +03:00
|
|
|
This widget is a combination of a numerical input widget and repeat buttons.
|
|
|
|
|
|
|
|
The user can either type into the input area or use the buttons to
|
|
|
|
change the value.
|
2012-05-11 16:12:00 +04:00
|
|
|
|
|
|
|
\image html Fl_Spinner.png "Fl_Spinner widget"
|
|
|
|
\image latex Fl_Spinner.png "Fl_Spinner widget" width=6cm
|
2008-09-15 20:39:05 +04:00
|
|
|
*/
|
2011-01-24 20:04:22 +03:00
|
|
|
class FL_EXPORT Fl_Spinner : public Fl_Group {
|
2017-03-10 01:08:29 +03:00
|
|
|
|
2005-03-25 05:39:25 +03:00
|
|
|
double value_; // Current value
|
|
|
|
double minimum_; // Minimum value
|
|
|
|
double maximum_; // Maximum value
|
|
|
|
double step_; // Amount to add/subtract for up/down
|
2017-03-10 01:08:29 +03:00
|
|
|
const char *format_; // Format string for input field
|
2017-03-10 21:49:44 +03:00
|
|
|
int wrap_; // wrap around at bounds (1/0)
|
2017-03-10 01:08:29 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
static void sb_cb(Fl_Widget *w, Fl_Spinner *sb); // internal callback
|
|
|
|
void update(); // update input field
|
2005-03-21 02:38:14 +03:00
|
|
|
|
2012-05-16 11:25:11 +04:00
|
|
|
protected:
|
2017-03-10 01:08:29 +03:00
|
|
|
|
2017-03-11 00:47:08 +03:00
|
|
|
// This class works like Fl_Input but ignores FL_Up and FL_Down key
|
|
|
|
// presses so they are handled by its parent, the Fl_Spinner widget.
|
|
|
|
// See STR #2989.
|
|
|
|
|
2017-07-13 00:51:42 +03:00
|
|
|
class FL_EXPORT Fl_Spinner_Input : public Fl_Input {
|
2017-03-11 00:47:08 +03:00
|
|
|
public:
|
|
|
|
Fl_Spinner_Input(int X, int Y, int W, int H)
|
|
|
|
: Fl_Input(X, Y, W, H) {}
|
|
|
|
int handle(int event); // implemented in src/Fl_Spinner.cxx
|
|
|
|
};
|
|
|
|
|
|
|
|
Fl_Spinner_Input input_; // Input field for the value
|
2005-03-21 02:38:14 +03:00
|
|
|
Fl_Repeat_Button
|
|
|
|
up_button_, // Up button
|
|
|
|
down_button_; // Down button
|
|
|
|
|
2017-03-10 01:08:29 +03:00
|
|
|
public:
|
|
|
|
|
|
|
|
// Constructor
|
2012-07-24 08:37:22 +04:00
|
|
|
Fl_Spinner(int X, int Y, int W, int H, const char *L = 0);
|
2017-03-10 01:08:29 +03:00
|
|
|
// Event handling
|
|
|
|
int handle(int event);
|
|
|
|
// Resize group and subwidgets
|
|
|
|
void resize(int X, int Y, int W, int H);
|
|
|
|
|
|
|
|
/** Returns the format string for the value. */
|
|
|
|
const char *format() const { return (format_); }
|
|
|
|
|
|
|
|
/** Sets the format string for the value. */
|
|
|
|
void format(const char *f) { format_ = f; update(); }
|
2005-03-21 02:38:14 +03:00
|
|
|
|
2008-09-18 02:25:45 +04:00
|
|
|
/** Gets the maximum value of the widget. */
|
2017-03-10 01:08:29 +03:00
|
|
|
double maximum() const { return (maximum_); }
|
|
|
|
|
2008-09-18 02:25:45 +04:00
|
|
|
/** Sets the maximum value of the widget. */
|
2017-03-10 01:08:29 +03:00
|
|
|
void maximum(double m) { maximum_ = m; }
|
|
|
|
|
2008-09-18 02:25:45 +04:00
|
|
|
/** Gets the minimum value of the widget. */
|
2017-03-10 01:08:29 +03:00
|
|
|
double minimum() const { return (minimum_); }
|
|
|
|
|
2008-09-18 02:25:45 +04:00
|
|
|
/** Sets the minimum value of the widget. */
|
2017-03-10 01:08:29 +03:00
|
|
|
void minimum(double m) { minimum_ = m; }
|
|
|
|
|
2008-09-15 20:39:05 +04:00
|
|
|
/** Sets the minimum and maximum values for the widget. */
|
2017-03-10 01:08:29 +03:00
|
|
|
void range(double a, double b) { minimum_ = a; maximum_ = b; }
|
|
|
|
|
|
|
|
// Sets the amount to change the value when the user clicks a button.
|
|
|
|
// Docs in src/Fl_Spinner.cxx
|
|
|
|
void step(double s);
|
|
|
|
|
2008-09-15 20:39:05 +04:00
|
|
|
/**
|
2017-03-10 01:08:29 +03:00
|
|
|
Gets the amount to change the value when the user clicks a button.
|
|
|
|
\see Fl_Spinner::step(double)
|
2008-09-15 20:39:05 +04:00
|
|
|
*/
|
2017-03-10 01:08:29 +03:00
|
|
|
double step() const { return (step_); }
|
|
|
|
|
2017-03-10 21:49:44 +03:00
|
|
|
/** Sets whether the spinner wraps around at upper and lower bounds.
|
|
|
|
|
2017-03-11 00:47:08 +03:00
|
|
|
If wrap mode is on the spinner value is set to the minimum() or
|
|
|
|
maximum() if the value exceeds the upper or lower bounds, resp., if
|
|
|
|
it was changed by one of the buttons or the FL_Up or FL_Down keys.
|
2017-03-10 21:49:44 +03:00
|
|
|
|
2017-03-11 00:47:08 +03:00
|
|
|
The spinner stops at the upper and lower bounds if wrap mode is off.
|
|
|
|
|
|
|
|
The default wrap mode is on for backwards compatibility with
|
|
|
|
FLTK 1.3.x and older versions.
|
2017-03-10 21:49:44 +03:00
|
|
|
|
2017-03-11 00:47:08 +03:00
|
|
|
\note Wrap mode does not apply to the input field if the input value
|
|
|
|
is edited directly as a number. The input value is always
|
|
|
|
clipped to the allowed range as if wrap mode was off when the
|
|
|
|
input field is left (i.e. loses focus).
|
|
|
|
|
|
|
|
\see minimum(), maximum()
|
2017-03-10 21:49:44 +03:00
|
|
|
|
|
|
|
\param[in] set non-zero sets wrap mode, zero resets wrap mode
|
|
|
|
|
|
|
|
\since 1.4.0
|
|
|
|
*/
|
|
|
|
void wrap(int set) { wrap_ = set ? 1 : 0; }
|
|
|
|
|
|
|
|
/** Gets the wrap mode of the Fl_Spinner widget.
|
|
|
|
\see void wrap(int)
|
|
|
|
\since 1.4.0
|
|
|
|
*/
|
|
|
|
int wrap() const { return wrap_; }
|
|
|
|
|
2008-09-18 02:25:45 +04:00
|
|
|
/** Gets the color of the text in the input field. */
|
2017-03-10 01:08:29 +03:00
|
|
|
Fl_Color textcolor() const { return (input_.textcolor()); }
|
|
|
|
|
2008-09-18 02:25:45 +04:00
|
|
|
/** Sets the color of the text in the input field. */
|
2017-03-10 01:08:29 +03:00
|
|
|
void textcolor(Fl_Color c) { input_.textcolor(c); }
|
|
|
|
|
2008-09-18 02:25:45 +04:00
|
|
|
/** Gets the font of the text in the input field. */
|
2017-03-10 01:08:29 +03:00
|
|
|
Fl_Font textfont() const { return (input_.textfont()); }
|
|
|
|
|
2008-09-18 02:25:45 +04:00
|
|
|
/** Sets the font of the text in the input field. */
|
2017-03-10 01:08:29 +03:00
|
|
|
void textfont(Fl_Font f) { input_.textfont(f); }
|
|
|
|
|
2008-09-18 02:25:45 +04:00
|
|
|
/** Gets the size of the text in the input field. */
|
2017-03-10 01:08:29 +03:00
|
|
|
Fl_Fontsize textsize() const { return (input_.textsize()); }
|
|
|
|
|
2008-09-18 02:25:45 +04:00
|
|
|
/** Sets the size of the text in the input field. */
|
2017-03-10 01:08:29 +03:00
|
|
|
void textsize(Fl_Fontsize s) { input_.textsize(s); }
|
|
|
|
|
|
|
|
// Sets the numeric representation in the input field.
|
|
|
|
// Docs see src/Fl_Spinner.cxx
|
|
|
|
void type(uchar v);
|
|
|
|
|
2011-01-30 11:45:34 +03:00
|
|
|
/** Gets the numeric representation in the input field.
|
2017-03-10 01:08:29 +03:00
|
|
|
\see Fl_Spinner::type(uchar)
|
2008-09-15 20:39:05 +04:00
|
|
|
*/
|
2017-03-10 01:08:29 +03:00
|
|
|
uchar type() const { return (input_.type()); }
|
|
|
|
|
2008-09-18 02:25:45 +04:00
|
|
|
/** Gets the current value of the widget. */
|
2017-03-10 01:08:29 +03:00
|
|
|
double value() const { return (value_); }
|
|
|
|
|
2008-09-15 20:39:05 +04:00
|
|
|
/**
|
2017-03-10 01:08:29 +03:00
|
|
|
Sets the current value of the input widget.
|
2014-09-12 13:08:41 +04:00
|
|
|
Before setting value to a non-integer value, the spinner
|
|
|
|
type() should be changed to floating point.
|
2008-09-15 20:39:05 +04:00
|
|
|
*/
|
2017-03-10 01:08:29 +03:00
|
|
|
void value(double v) { value_ = v; update(); }
|
|
|
|
|
2012-05-16 11:25:11 +04:00
|
|
|
/**
|
2017-03-10 01:08:29 +03:00
|
|
|
Sets the background color of the spinner widget's input field.
|
2012-05-16 11:25:11 +04:00
|
|
|
*/
|
2017-03-10 01:08:29 +03:00
|
|
|
void color(Fl_Color v) { input_.color(v); }
|
|
|
|
|
2012-05-16 11:25:11 +04:00
|
|
|
/**
|
2017-03-10 01:08:29 +03:00
|
|
|
Returns the background color of the spinner widget's input field.
|
2012-05-16 11:25:11 +04:00
|
|
|
*/
|
2017-03-10 01:08:29 +03:00
|
|
|
Fl_Color color() const { return(input_.color()); }
|
|
|
|
|
2013-05-16 09:02:18 +04:00
|
|
|
/**
|
2017-03-10 01:08:29 +03:00
|
|
|
Sets the selection color of the spinner widget's input field.
|
2013-05-16 09:02:18 +04:00
|
|
|
*/
|
2017-03-10 01:08:29 +03:00
|
|
|
void selection_color(Fl_Color val) { input_.selection_color(val); }
|
|
|
|
|
2013-05-16 09:02:18 +04:00
|
|
|
/**
|
2017-03-10 01:08:29 +03:00
|
|
|
Returns the selection color of the spinner widget's input field.
|
2013-05-16 09:02:18 +04:00
|
|
|
*/
|
2017-03-10 01:08:29 +03:00
|
|
|
Fl_Color selection_color() const { return input_.selection_color(); }
|
2019-02-01 20:58:43 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
Sets the maximum width of the input field.
|
|
|
|
*/
|
|
|
|
void maximum_size(int m) { if (m > 0) input_.maximum_size(m); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the maximum width of the input field.
|
|
|
|
*/
|
|
|
|
int maximum_size() const { return input_.maximum_size(); }
|
2005-03-21 02:38:14 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // !Fl_Spinner_H
|
|
|
|
|
2017-03-10 01:08:29 +03:00
|
|
|
|
2005-03-21 02:38:14 +03:00
|
|
|
//
|
|
|
|
// End of "$Id$".
|
|
|
|
//
|