1998-10-19 20:46:58 +00:00
|
|
|
//
|
|
|
|
|
// Slider widget for the Fast Light Tool Kit (FLTK).
|
|
|
|
|
//
|
2015-01-29 16:56:12 +00:00
|
|
|
// Copyright 1998-2015 by Bill Spitzak and others.
|
1998-10-19 20:46:58 +00:00
|
|
|
//
|
2011-07-19 04:49:30 +00: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 16:03:10 +00:00
|
|
|
// https://www.fltk.org/COPYING.php
|
1998-10-19 20:46:58 +00:00
|
|
|
//
|
2020-07-01 16:03:10 +00:00
|
|
|
// Please see the following page on how to report bugs and issues:
|
2005-04-16 00:13:17 +00:00
|
|
|
//
|
2020-07-01 16:03:10 +00:00
|
|
|
// https://www.fltk.org/bugs.php
|
1998-10-19 20:46:58 +00:00
|
|
|
//
|
1998-10-06 18:21:25 +00:00
|
|
|
|
|
|
|
|
#include <FL/Fl.H>
|
|
|
|
|
#include <FL/Fl_Slider.H>
|
2012-07-24 04:37:22 +00:00
|
|
|
#include <FL/Fl_Fill_Slider.H>
|
|
|
|
|
#include <FL/Fl_Hor_Slider.H>
|
|
|
|
|
#include <FL/Fl_Hor_Fill_Slider.H>
|
|
|
|
|
#include <FL/Fl_Hor_Nice_Slider.H>
|
|
|
|
|
#include <FL/Fl_Nice_Slider.H>
|
1998-10-06 18:21:25 +00:00
|
|
|
#include <FL/fl_draw.H>
|
|
|
|
|
#include <math.h>
|
2006-09-17 14:58:25 +00:00
|
|
|
#include "flstring.h"
|
1998-10-06 18:21:25 +00:00
|
|
|
|
2011-05-23 18:32:47 +00:00
|
|
|
|
1998-10-06 18:21:25 +00:00
|
|
|
void Fl_Slider::_Fl_Slider() {
|
|
|
|
|
slider_size_ = 0;
|
|
|
|
|
slider_ = 0; // FL_UP_BOX;
|
|
|
|
|
}
|
|
|
|
|
|
2008-09-15 12:46:49 +00:00
|
|
|
/**
|
|
|
|
|
Creates a new Fl_Slider widget using the given position,
|
|
|
|
|
size, and label string. The default boxtype is FL_DOWN_BOX.
|
|
|
|
|
*/
|
2009-03-14 11:46:43 +00:00
|
|
|
Fl_Slider::Fl_Slider(int X, int Y, int W, int H, const char* L)
|
|
|
|
|
: Fl_Valuator(X, Y, W, H, L) {
|
1998-10-06 18:21:25 +00:00
|
|
|
box(FL_DOWN_BOX);
|
|
|
|
|
_Fl_Slider();
|
|
|
|
|
}
|
|
|
|
|
|
2008-09-15 12:46:49 +00:00
|
|
|
/**
|
2012-05-20 17:06:10 +00:00
|
|
|
Creates a new Fl_Slider widget using the given type, position,
|
2009-03-14 11:46:43 +00:00
|
|
|
size, and label string.
|
2008-09-15 12:46:49 +00:00
|
|
|
*/
|
2009-03-14 11:46:43 +00:00
|
|
|
Fl_Slider::Fl_Slider(uchar t, int X, int Y, int W, int H, const char* L)
|
|
|
|
|
: Fl_Valuator(X, Y, W, H, L) {
|
1998-10-06 18:21:25 +00:00
|
|
|
type(t);
|
|
|
|
|
box(t==FL_HOR_NICE_SLIDER || t==FL_VERT_NICE_SLIDER ?
|
|
|
|
|
FL_FLAT_BOX : FL_DOWN_BOX);
|
|
|
|
|
_Fl_Slider();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Fl_Slider::slider_size(double v) {
|
|
|
|
|
if (v < 0) v = 0;
|
|
|
|
|
if (v > 1) v = 1;
|
1998-10-19 17:53:09 +00:00
|
|
|
if (slider_size_ != float(v)) {
|
2020-07-01 16:03:10 +00:00
|
|
|
slider_size_ = float(v);
|
1998-10-19 17:53:09 +00:00
|
|
|
damage(FL_DAMAGE_EXPOSE);
|
|
|
|
|
}
|
1998-10-06 18:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2020-07-01 16:03:10 +00:00
|
|
|
/**
|
|
|
|
|
Sets the minimum (a) and maximum (b) values for the valuator widget.
|
2008-09-15 12:46:49 +00:00
|
|
|
if at least one of the values is changed, a partial redraw is asked.
|
|
|
|
|
*/
|
1998-10-06 18:21:25 +00:00
|
|
|
void Fl_Slider::bounds(double a, double b) {
|
1998-10-19 17:53:09 +00:00
|
|
|
if (minimum() != a || maximum() != b) {
|
2020-07-01 16:03:10 +00:00
|
|
|
Fl_Valuator::bounds(a, b);
|
1998-10-19 17:53:09 +00:00
|
|
|
damage(FL_DAMAGE_EXPOSE);
|
|
|
|
|
}
|
1998-10-06 18:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2009-03-11 22:15:14 +00:00
|
|
|
/**
|
|
|
|
|
Sets the size and position of the sliding knob in the box.
|
2009-03-14 11:46:43 +00:00
|
|
|
\param[in] pos position of first line displayed
|
|
|
|
|
\param[in] size size of window in lines
|
|
|
|
|
\param[in] first number of first line
|
|
|
|
|
\param[in] total total number of lines
|
2009-03-11 22:15:14 +00:00
|
|
|
Returns Fl_Valuator::value(p)
|
|
|
|
|
*/
|
2009-03-14 11:46:43 +00:00
|
|
|
int Fl_Slider::scrollvalue(int pos, int size, int first, int total) {
|
1998-10-06 18:21:25 +00:00
|
|
|
step(1, 1);
|
2009-03-14 11:46:43 +00:00
|
|
|
if (pos+size > first+total) total = pos+size-first;
|
|
|
|
|
slider_size(size >= total ? 1.0 : double(size)/double(total));
|
|
|
|
|
bounds(first, total-size+first);
|
|
|
|
|
return value(pos);
|
1998-10-06 18:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// All slider interaction is done as though the slider ranges from
|
|
|
|
|
// zero to one, and the left (bottom) edge of the slider is at the
|
|
|
|
|
// given position. Since when the slider is all the way to the
|
|
|
|
|
// right (top) the left (bottom) edge is not all the way over, a
|
|
|
|
|
// position on the widget itself covers a wider range than 0-1,
|
|
|
|
|
// actually it ranges from 0 to 1/(1-size).
|
2025-11-26 13:07:34 +00:00
|
|
|
// S is the size of the slider knob
|
|
|
|
|
void Fl_Slider::draw_bg(int X, int Y, int W, int H, int S) {
|
2004-03-11 05:17:12 +00:00
|
|
|
fl_push_clip(X, Y, W, H);
|
|
|
|
|
draw_box();
|
|
|
|
|
fl_pop_clip();
|
2002-08-13 15:42:44 +00:00
|
|
|
|
2002-04-11 10:46:19 +00:00
|
|
|
Fl_Color black = active_r() ? FL_FOREGROUND_COLOR : FL_INACTIVE_COLOR;
|
1998-10-06 18:21:25 +00:00
|
|
|
if (type() == FL_VERT_NICE_SLIDER) {
|
2025-11-26 13:07:34 +00:00
|
|
|
if (ticks()) draw_ticks(Fl_Rect { X, Y+S/2, W, H-S}, S);
|
2002-08-09 03:17:30 +00:00
|
|
|
draw_box(FL_THIN_DOWN_BOX, X+W/2-2, Y, 4, H, black);
|
1998-10-06 18:21:25 +00:00
|
|
|
} else if (type() == FL_HOR_NICE_SLIDER) {
|
2025-11-26 13:07:34 +00:00
|
|
|
if (ticks()) draw_ticks(Fl_Rect { X+S/2, Y, W-S, H}, S);
|
2002-08-09 03:17:30 +00:00
|
|
|
draw_box(FL_THIN_DOWN_BOX, X, Y+H/2-2, W, 4, black);
|
1998-10-06 18:21:25 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2002-08-09 03:17:30 +00:00
|
|
|
void Fl_Slider::draw(int X, int Y, int W, int H) {
|
1998-10-06 18:21:25 +00:00
|
|
|
|
2000-06-15 05:37:40 +00:00
|
|
|
double val;
|
1998-10-06 18:21:25 +00:00
|
|
|
if (minimum() == maximum())
|
|
|
|
|
val = 0.5;
|
2025-11-26 13:07:34 +00:00
|
|
|
else
|
|
|
|
|
val = value_to_position(value());
|
|
|
|
|
|
2002-08-09 03:17:30 +00:00
|
|
|
int ww = (horizontal() ? W : H);
|
|
|
|
|
int xx, S;
|
1998-10-06 18:21:25 +00:00
|
|
|
if (type()==FL_HOR_FILL_SLIDER || type() == FL_VERT_FILL_SLIDER) {
|
2002-08-09 03:17:30 +00:00
|
|
|
S = int(val*ww+.5);
|
|
|
|
|
if (minimum()>maximum()) {S = ww-S; xx = ww-S;}
|
|
|
|
|
else xx = 0;
|
1998-10-06 18:21:25 +00:00
|
|
|
} else {
|
2002-08-09 03:17:30 +00:00
|
|
|
S = int(slider_size_*ww+.5);
|
|
|
|
|
int T = (horizontal() ? H : W)/2+1;
|
1998-10-06 18:21:25 +00:00
|
|
|
if (type()==FL_VERT_NICE_SLIDER || type()==FL_HOR_NICE_SLIDER) T += 4;
|
|
|
|
|
if (S < T) S = T;
|
2002-08-09 03:17:30 +00:00
|
|
|
xx = int(val*(ww-S)+.5);
|
1998-10-06 18:21:25 +00:00
|
|
|
}
|
|
|
|
|
int xsl, ysl, wsl, hsl;
|
|
|
|
|
if (horizontal()) {
|
2002-08-09 03:17:30 +00:00
|
|
|
xsl = X+xx;
|
1998-10-06 18:21:25 +00:00
|
|
|
wsl = S;
|
2002-08-09 03:17:30 +00:00
|
|
|
ysl = Y;
|
|
|
|
|
hsl = H;
|
1998-10-06 18:21:25 +00:00
|
|
|
} else {
|
2002-08-09 03:17:30 +00:00
|
|
|
ysl = Y+xx;
|
1998-10-06 18:21:25 +00:00
|
|
|
hsl = S;
|
2002-08-09 03:17:30 +00:00
|
|
|
xsl = X;
|
|
|
|
|
wsl = W;
|
1998-10-06 18:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2025-11-26 13:07:34 +00:00
|
|
|
draw_bg(X, Y, W, H, S);
|
1998-10-06 18:21:25 +00:00
|
|
|
|
|
|
|
|
Fl_Boxtype box1 = slider();
|
|
|
|
|
if (!box1) {box1 = (Fl_Boxtype)(box()&-2); if (!box1) box1 = FL_UP_BOX;}
|
|
|
|
|
if (type() == FL_VERT_NICE_SLIDER) {
|
|
|
|
|
draw_box(box1, xsl, ysl, wsl, hsl, FL_GRAY);
|
|
|
|
|
int d = (hsl-4)/2;
|
|
|
|
|
draw_box(FL_THIN_DOWN_BOX, xsl+2, ysl+d, wsl-4, hsl-2*d,selection_color());
|
|
|
|
|
} else if (type() == FL_HOR_NICE_SLIDER) {
|
|
|
|
|
draw_box(box1, xsl, ysl, wsl, hsl, FL_GRAY);
|
|
|
|
|
int d = (wsl-4)/2;
|
|
|
|
|
draw_box(FL_THIN_DOWN_BOX, xsl+d, ysl+2, wsl-2*d, hsl-4,selection_color());
|
|
|
|
|
} else {
|
|
|
|
|
if (wsl>0 && hsl>0) draw_box(box1, xsl, ysl, wsl, hsl, selection_color());
|
2006-09-17 14:58:25 +00:00
|
|
|
|
2015-01-29 16:56:12 +00:00
|
|
|
if (type() != FL_HOR_FILL_SLIDER && type() != FL_VERT_FILL_SLIDER &&
|
|
|
|
|
Fl::is_scheme("gtk+")) {
|
2006-09-17 14:58:25 +00:00
|
|
|
if (W>H && wsl>(hsl+8)) {
|
|
|
|
|
// Draw horizontal grippers
|
2020-07-01 16:03:10 +00:00
|
|
|
int yy, hh;
|
|
|
|
|
hh = hsl-8;
|
|
|
|
|
xx = xsl+(wsl-hsl-4)/2;
|
|
|
|
|
yy = ysl+3;
|
2006-09-17 14:58:25 +00:00
|
|
|
|
2020-07-01 16:03:10 +00:00
|
|
|
fl_color(fl_darker(selection_color()));
|
|
|
|
|
fl_line(xx, yy+hh, xx+hh, yy);
|
|
|
|
|
fl_line(xx+6, yy+hh, xx+hh+6, yy);
|
|
|
|
|
fl_line(xx+12, yy+hh, xx+hh+12, yy);
|
2006-09-17 14:58:25 +00:00
|
|
|
|
|
|
|
|
xx++;
|
2020-07-01 16:03:10 +00:00
|
|
|
fl_color(fl_lighter(selection_color()));
|
|
|
|
|
fl_line(xx, yy+hh, xx+hh, yy);
|
|
|
|
|
fl_line(xx+6, yy+hh, xx+hh+6, yy);
|
|
|
|
|
fl_line(xx+12, yy+hh, xx+hh+12, yy);
|
2006-09-17 14:58:25 +00:00
|
|
|
} else if (H>W && hsl>(wsl+8)) {
|
|
|
|
|
// Draw vertical grippers
|
2020-07-01 16:03:10 +00:00
|
|
|
int yy;
|
|
|
|
|
xx = xsl+4;
|
|
|
|
|
ww = wsl-8;
|
|
|
|
|
yy = ysl+(hsl-wsl-4)/2;
|
2006-09-17 14:58:25 +00:00
|
|
|
|
2020-07-01 16:03:10 +00:00
|
|
|
fl_color(fl_darker(selection_color()));
|
|
|
|
|
fl_line(xx, yy+ww, xx+ww, yy);
|
|
|
|
|
fl_line(xx, yy+ww+6, xx+ww, yy+6);
|
|
|
|
|
fl_line(xx, yy+ww+12, xx+ww, yy+12);
|
2006-09-17 14:58:25 +00:00
|
|
|
|
|
|
|
|
yy++;
|
2020-07-01 16:03:10 +00:00
|
|
|
fl_color(fl_lighter(selection_color()));
|
|
|
|
|
fl_line(xx, yy+ww, xx+ww, yy);
|
|
|
|
|
fl_line(xx, yy+ww+6, xx+ww, yy+6);
|
|
|
|
|
fl_line(xx, yy+ww+12, xx+ww, yy+12);
|
2006-09-17 14:58:25 +00:00
|
|
|
}
|
|
|
|
|
}
|
1998-10-06 18:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
draw_label(xsl, ysl, wsl, hsl);
|
2001-08-05 14:00:15 +00:00
|
|
|
if (Fl::focus() == this) {
|
|
|
|
|
if (type() == FL_HOR_FILL_SLIDER || type() == FL_VERT_FILL_SLIDER) draw_focus();
|
|
|
|
|
else draw_focus(box1, xsl, ysl, wsl, hsl);
|
|
|
|
|
}
|
1998-10-06 18:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Fl_Slider::draw() {
|
1999-05-14 09:07:09 +00:00
|
|
|
if (damage()&FL_DAMAGE_ALL) draw_box();
|
|
|
|
|
draw(x()+Fl::box_dx(box()),
|
|
|
|
|
y()+Fl::box_dy(box()),
|
|
|
|
|
w()-Fl::box_dw(box()),
|
|
|
|
|
h()-Fl::box_dh(box()));
|
1998-10-06 18:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2025-11-26 13:07:34 +00:00
|
|
|
/** Draw tick marks.
|
|
|
|
|
\param[in] r motion range of the slider
|
|
|
|
|
\param[in] S size of the slider, horizontal or vertical
|
|
|
|
|
*/
|
|
|
|
|
void Fl_Slider::draw_ticks(const Fl_Rect& r, int /*S*/ /*, int min_spacing*/)
|
|
|
|
|
{
|
|
|
|
|
if ((ticks() == TICKS_NONE) || (num_ticks() == 0)) return;
|
|
|
|
|
|
|
|
|
|
Fl_Color black = active_r() ? FL_FOREGROUND_COLOR : FL_INACTIVE_COLOR;
|
|
|
|
|
fl_color(black);
|
|
|
|
|
int n = num_ticks();
|
|
|
|
|
double nd = (double)(n-1);
|
|
|
|
|
for (int i=0; i<n; i++) {
|
|
|
|
|
double v = i / nd;
|
|
|
|
|
if (scale() == LOG_SCALE) {
|
|
|
|
|
v = position_to_value(1.0-v);
|
|
|
|
|
v = (v - minimum()) / (maximum()-minimum());
|
|
|
|
|
}
|
|
|
|
|
if (horizontal()) {
|
|
|
|
|
int y1, y2;
|
|
|
|
|
if (ticks() & TICKS_ABOVE) y1 = r.y(); else y1 = r.y() + r.h()/2;
|
|
|
|
|
if (ticks() & TICKS_BELOW) y2 = r.b()-1; else y2 = r.y() + r.h()/2;
|
|
|
|
|
fl_yxline(r.r()-v*(r.w()-1)-1, y1, y2);
|
|
|
|
|
} else {
|
|
|
|
|
int x1, x2;
|
|
|
|
|
if (ticks() & TICKS_LEFT) x1 = r.x(); else x1 = r.x() + r.w()/2;
|
|
|
|
|
if (ticks() & TICKS_RIGHT) x2 = r.r()-1; else x2 = r.x() + r.w()/2;
|
|
|
|
|
fl_xyline(x1, r.b()-v*(r.h()-1)-1, x2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-08-09 03:17:30 +00:00
|
|
|
int Fl_Slider::handle(int event, int X, int Y, int W, int H) {
|
2010-02-20 17:40:07 +00:00
|
|
|
// Fl_Widget_Tracker wp(this);
|
1998-10-06 18:21:25 +00:00
|
|
|
switch (event) {
|
2010-02-20 17:40:07 +00:00
|
|
|
case FL_PUSH: {
|
|
|
|
|
Fl_Widget_Tracker wp(this);
|
2002-08-09 03:17:30 +00:00
|
|
|
if (!Fl::event_inside(X, Y, W, H)) return 0;
|
1998-10-06 18:21:25 +00:00
|
|
|
handle_push();
|
2010-02-20 17:40:07 +00:00
|
|
|
if (wp.deleted()) return 1; }
|
|
|
|
|
// fall through ...
|
1998-10-06 18:21:25 +00:00
|
|
|
case FL_DRAG: {
|
2000-06-15 05:37:40 +00:00
|
|
|
|
|
|
|
|
double val;
|
|
|
|
|
if (minimum() == maximum())
|
|
|
|
|
val = 0.5;
|
2025-11-26 13:07:34 +00:00
|
|
|
else
|
|
|
|
|
val = value_to_position(value());
|
2000-06-15 05:37:40 +00:00
|
|
|
|
2002-08-09 03:17:30 +00:00
|
|
|
int ww = (horizontal() ? W : H);
|
|
|
|
|
int mx = (horizontal() ? Fl::event_x()-X : Fl::event_y()-Y);
|
2000-06-15 05:37:40 +00:00
|
|
|
int S;
|
1999-12-04 12:22:37 +00:00
|
|
|
static int offcenter;
|
2000-03-17 09:38:20 +00:00
|
|
|
|
1999-12-04 12:22:37 +00:00
|
|
|
if (type() == FL_HOR_FILL_SLIDER || type() == FL_VERT_FILL_SLIDER) {
|
|
|
|
|
|
2000-06-15 05:37:40 +00:00
|
|
|
S = 0;
|
1999-12-04 12:22:37 +00:00
|
|
|
if (event == FL_PUSH) {
|
2020-07-01 16:03:10 +00:00
|
|
|
int xx = int(val*ww+.5);
|
|
|
|
|
offcenter = mx-xx;
|
|
|
|
|
if (offcenter < -10 || offcenter > 10) offcenter = 0;
|
|
|
|
|
else return 1;
|
1999-12-04 12:22:37 +00:00
|
|
|
}
|
|
|
|
|
|
2000-06-15 05:37:40 +00:00
|
|
|
} else {
|
1999-12-04 12:22:37 +00:00
|
|
|
|
2002-08-09 03:17:30 +00:00
|
|
|
S = int(slider_size_*ww+.5); if (S >= ww) return 0;
|
|
|
|
|
int T = (horizontal() ? H : W)/2+1;
|
2000-06-15 05:37:40 +00:00
|
|
|
if (type()==FL_VERT_NICE_SLIDER || type()==FL_HOR_NICE_SLIDER) T += 4;
|
|
|
|
|
if (S < T) S = T;
|
1999-12-04 12:22:37 +00:00
|
|
|
if (event == FL_PUSH) {
|
2020-07-01 16:03:10 +00:00
|
|
|
int xx = int(val*(ww-S)+.5);
|
|
|
|
|
offcenter = mx-xx;
|
|
|
|
|
if (offcenter < 0) offcenter = 0;
|
|
|
|
|
else if (offcenter > S) offcenter = S;
|
|
|
|
|
else return 1;
|
1999-12-04 12:22:37 +00:00
|
|
|
}
|
1998-10-06 18:21:25 +00:00
|
|
|
}
|
2000-06-15 05:37:40 +00:00
|
|
|
|
2002-08-09 03:17:30 +00:00
|
|
|
int xx = mx-offcenter;
|
2016-04-05 21:15:45 +00:00
|
|
|
double v = 0;
|
2002-06-29 00:10:05 +00:00
|
|
|
char tryAgain = 1;
|
|
|
|
|
while (tryAgain)
|
|
|
|
|
{
|
|
|
|
|
tryAgain = 0;
|
2002-08-09 03:17:30 +00:00
|
|
|
if (xx < 0) {
|
|
|
|
|
xx = 0;
|
2002-06-29 00:10:05 +00:00
|
|
|
offcenter = mx; if (offcenter < 0) offcenter = 0;
|
2002-08-09 03:17:30 +00:00
|
|
|
} else if (xx > (ww-S)) {
|
|
|
|
|
xx = ww-S;
|
|
|
|
|
offcenter = mx-xx; if (offcenter > S) offcenter = S;
|
2002-06-29 00:10:05 +00:00
|
|
|
}
|
2025-11-26 13:07:34 +00:00
|
|
|
// Convert position back to value using the appropriate scale
|
|
|
|
|
double pos = (ww-S) > 0 ? double(xx) / double(ww-S) : 0.0;
|
|
|
|
|
v = round(position_to_value(pos));
|
2002-06-29 00:10:05 +00:00
|
|
|
// make sure a click outside the sliderbar moves it:
|
|
|
|
|
if (event == FL_PUSH && v == value()) {
|
|
|
|
|
offcenter = S/2;
|
|
|
|
|
event = FL_DRAG;
|
|
|
|
|
tryAgain = 1;
|
|
|
|
|
}
|
1998-10-06 18:21:25 +00:00
|
|
|
}
|
|
|
|
|
handle_drag(clamp(v));
|
|
|
|
|
} return 1;
|
|
|
|
|
case FL_RELEASE:
|
|
|
|
|
handle_release();
|
|
|
|
|
return 1;
|
2010-02-20 17:40:07 +00:00
|
|
|
case FL_KEYBOARD:
|
|
|
|
|
{ Fl_Widget_Tracker wp(this);
|
|
|
|
|
switch (Fl::event_key()) {
|
2020-07-01 16:03:10 +00:00
|
|
|
case FL_Up:
|
|
|
|
|
if (horizontal()) return 0;
|
|
|
|
|
handle_push();
|
|
|
|
|
if (wp.deleted()) return 1;
|
|
|
|
|
handle_drag(clamp(increment(value(),-1)));
|
|
|
|
|
if (wp.deleted()) return 1;
|
|
|
|
|
handle_release();
|
|
|
|
|
return 1;
|
|
|
|
|
case FL_Down:
|
|
|
|
|
if (horizontal()) return 0;
|
|
|
|
|
handle_push();
|
|
|
|
|
if (wp.deleted()) return 1;
|
|
|
|
|
handle_drag(clamp(increment(value(),1)));
|
|
|
|
|
if (wp.deleted()) return 1;
|
|
|
|
|
handle_release();
|
|
|
|
|
return 1;
|
|
|
|
|
case FL_Left:
|
|
|
|
|
if (!horizontal()) return 0;
|
|
|
|
|
handle_push();
|
|
|
|
|
if (wp.deleted()) return 1;
|
|
|
|
|
handle_drag(clamp(increment(value(),-1)));
|
|
|
|
|
if (wp.deleted()) return 1;
|
|
|
|
|
handle_release();
|
|
|
|
|
return 1;
|
|
|
|
|
case FL_Right:
|
|
|
|
|
if (!horizontal()) return 0;
|
|
|
|
|
handle_push();
|
|
|
|
|
if (wp.deleted()) return 1;
|
|
|
|
|
handle_drag(clamp(increment(value(),1)));
|
|
|
|
|
if (wp.deleted()) return 1;
|
|
|
|
|
handle_release();
|
|
|
|
|
return 1;
|
|
|
|
|
default:
|
|
|
|
|
return 0;
|
2010-02-20 17:40:07 +00:00
|
|
|
}
|
2001-08-05 14:00:15 +00:00
|
|
|
}
|
2002-05-24 14:19:19 +00:00
|
|
|
// break not required because of switch...
|
2001-08-05 14:00:15 +00:00
|
|
|
case FL_FOCUS :
|
|
|
|
|
case FL_UNFOCUS :
|
2001-11-03 19:24:22 +00:00
|
|
|
if (Fl::visible_focus()) {
|
|
|
|
|
redraw();
|
|
|
|
|
return 1;
|
|
|
|
|
} else return 0;
|
2001-10-18 23:41:04 +00:00
|
|
|
case FL_ENTER :
|
|
|
|
|
case FL_LEAVE :
|
|
|
|
|
return 1;
|
1998-10-06 18:21:25 +00:00
|
|
|
default:
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-26 13:07:34 +00:00
|
|
|
|
1998-10-06 18:21:25 +00:00
|
|
|
int Fl_Slider::handle(int event) {
|
2005-07-16 08:25:06 +00:00
|
|
|
if (event == FL_PUSH && Fl::visible_focus()) {
|
|
|
|
|
Fl::focus(this);
|
|
|
|
|
redraw();
|
|
|
|
|
}
|
2002-10-24 12:53:41 +00:00
|
|
|
|
1999-05-14 09:07:09 +00:00
|
|
|
return handle(event,
|
2020-07-01 16:03:10 +00:00
|
|
|
x()+Fl::box_dx(box()),
|
|
|
|
|
y()+Fl::box_dy(box()),
|
|
|
|
|
w()-Fl::box_dw(box()),
|
|
|
|
|
h()-Fl::box_dh(box()));
|
1998-10-06 18:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2011-05-23 18:32:47 +00:00
|
|
|
|
2012-07-24 04:37:22 +00:00
|
|
|
Fl_Fill_Slider::Fl_Fill_Slider(int X,int Y,int W,int H,const char *L)
|
2020-07-01 16:03:10 +00:00
|
|
|
: Fl_Slider(X,Y,W,H,L)
|
2012-07-24 04:37:22 +00:00
|
|
|
{
|
|
|
|
|
type(FL_VERT_FILL_SLIDER);
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-23 18:32:47 +00:00
|
|
|
|
|
|
|
|
Fl_Hor_Slider::Fl_Hor_Slider(int X,int Y,int W,int H,const char *l)
|
2012-07-24 04:37:22 +00:00
|
|
|
: Fl_Slider(X,Y,W,H,l) {
|
|
|
|
|
type(FL_HOR_SLIDER);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Fl_Hor_Fill_Slider::Fl_Hor_Fill_Slider(int X,int Y,int W,int H,const char *L)
|
2020-07-01 16:03:10 +00:00
|
|
|
: Fl_Slider(X,Y,W,H,L)
|
2012-07-24 04:37:22 +00:00
|
|
|
{
|
|
|
|
|
type(FL_HOR_FILL_SLIDER);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Fl_Hor_Nice_Slider::Fl_Hor_Nice_Slider(int X,int Y,int W,int H,const char *L)
|
2020-07-01 16:03:10 +00:00
|
|
|
: Fl_Slider(X,Y,W,H,L)
|
2012-07-24 04:37:22 +00:00
|
|
|
{
|
2020-07-01 16:03:10 +00:00
|
|
|
type(FL_HOR_NICE_SLIDER);
|
2012-07-24 04:37:22 +00:00
|
|
|
box(FL_FLAT_BOX);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Fl_Nice_Slider::Fl_Nice_Slider(int X,int Y,int W,int H,const char *L)
|
|
|
|
|
: Fl_Slider(X,Y,W,H,L) {
|
2020-07-01 16:03:10 +00:00
|
|
|
type(FL_VERT_NICE_SLIDER);
|
2012-07-24 04:37:22 +00:00
|
|
|
box(FL_FLAT_BOX);
|
|
|
|
|
}
|
2025-11-26 13:07:34 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
Converts a value to a normalized position (0.0 to 1.0) based on the current scale type.
|
|
|
|
|
For linear scale, this is a simple linear interpolation.
|
|
|
|
|
For logarithmic scale, this uses logarithmic interpolation.
|
|
|
|
|
\param[in] val The value to convert.
|
|
|
|
|
\return A normalized position between 0.0 and 1.0.
|
|
|
|
|
*/
|
|
|
|
|
double Fl_Slider::value_to_position(double val) const {
|
|
|
|
|
if (minimum() == maximum()) return 0.5;
|
|
|
|
|
|
|
|
|
|
if (scale_type_ == LOG_SCALE) {
|
|
|
|
|
// For logarithmic scale, both min and max must be positive
|
|
|
|
|
if (minimum() <= 0 || maximum() <= 0 || val <= 0) {
|
|
|
|
|
// Fall back to linear if values are not suitable for log scale
|
|
|
|
|
double pos = (val - minimum()) / (maximum() - minimum());
|
|
|
|
|
if (pos > 1.0) pos = 1.0;
|
|
|
|
|
else if (pos < 0.0) pos = 0.0;
|
|
|
|
|
return pos;
|
|
|
|
|
}
|
|
|
|
|
double log_min = log(minimum());
|
|
|
|
|
double log_max = log(maximum());
|
|
|
|
|
double log_val = log(val);
|
|
|
|
|
double pos = (log_val - log_min) / (log_max - log_min);
|
|
|
|
|
if (pos > 1.0) pos = 1.0;
|
|
|
|
|
else if (pos < 0.0) pos = 0.0;
|
|
|
|
|
return pos;
|
|
|
|
|
} else {
|
|
|
|
|
// Linear scale
|
|
|
|
|
double pos = (val - minimum()) / (maximum() - minimum());
|
|
|
|
|
if (pos > 1.0) pos = 1.0;
|
|
|
|
|
else if (pos < 0.0) pos = 0.0;
|
|
|
|
|
return pos;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
Converts a normalized position (0.0 to 1.0) to a value based on the current scale type.
|
|
|
|
|
For linear scale, this is a simple linear interpolation.
|
|
|
|
|
For logarithmic scale, this uses exponential interpolation.
|
|
|
|
|
\param[in] pos The normalized position to convert.
|
|
|
|
|
\return The corresponding value.
|
|
|
|
|
*/
|
|
|
|
|
double Fl_Slider::position_to_value(double pos) const {
|
|
|
|
|
if (minimum() == maximum()) return minimum();
|
|
|
|
|
|
|
|
|
|
if (scale_type_ == LOG_SCALE) {
|
|
|
|
|
// For logarithmic scale, both min and max must be positive
|
|
|
|
|
if (minimum() <= 0 || maximum() <= 0) {
|
|
|
|
|
// Fall back to linear if values are not suitable for log scale
|
|
|
|
|
return pos * (maximum() - minimum()) + minimum();
|
|
|
|
|
}
|
|
|
|
|
double log_min = log(minimum());
|
|
|
|
|
double log_max = log(maximum());
|
|
|
|
|
return exp(pos * (log_max - log_min) + log_min);
|
|
|
|
|
} else {
|
|
|
|
|
// Linear scale
|
|
|
|
|
return pos * (maximum() - minimum()) + minimum();
|
|
|
|
|
}
|
|
|
|
|
}
|