1998-10-20 00:46:58 +04:00
|
|
|
//
|
2005-02-25 00:55:12 +03:00
|
|
|
// "$Id$"
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|
|
|
|
// Adjuster widget for the Fast Light Tool Kit (FLTK).
|
|
|
|
//
|
2011-07-19 08:49:30 +04:00
|
|
|
// Copyright 1998-2011 by Bill Spitzak and others.
|
|
|
|
//
|
|
|
|
// 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
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|
2005-04-16 04:13:17 +04:00
|
|
|
// Please report all bugs and problems on the following page:
|
|
|
|
//
|
|
|
|
// http://www.fltk.org/str.php
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|
1998-10-06 22:21:25 +04:00
|
|
|
|
|
|
|
#include <FL/Fl.H>
|
|
|
|
#include <FL/Fl_Adjuster.H>
|
|
|
|
#include <FL/Fl_Bitmap.H>
|
|
|
|
#include <FL/fl_draw.H>
|
|
|
|
|
|
|
|
#include "fastarrow.h"
|
|
|
|
static Fl_Bitmap fastarrow(fastarrow_bits, fastarrow_width, fastarrow_height);
|
|
|
|
#include "mediumarrow.h"
|
|
|
|
static Fl_Bitmap mediumarrow(mediumarrow_bits, mediumarrow_width, mediumarrow_height);
|
|
|
|
#include "slowarrow.h"
|
|
|
|
static Fl_Bitmap slowarrow(slowarrow_bits, slowarrow_width, slowarrow_height);
|
|
|
|
|
|
|
|
// changing the value does not change the appearance:
|
|
|
|
void Fl_Adjuster::value_damage() {}
|
|
|
|
|
|
|
|
void Fl_Adjuster::draw() {
|
|
|
|
int dx, dy, W, H;
|
|
|
|
if (w()>=h()) {
|
|
|
|
dx = W = w()/3;
|
|
|
|
dy = 0; H = h();
|
|
|
|
} else {
|
|
|
|
dx = 0; W = w();
|
|
|
|
dy = H = h()/3;
|
|
|
|
}
|
|
|
|
draw_box(drag==1?FL_DOWN_BOX:box(), x(), y()+2*dy, W, H, color());
|
|
|
|
draw_box(drag==2?FL_DOWN_BOX:box(), x()+dx, y()+dy, W, H, color());
|
|
|
|
draw_box(drag==3?FL_DOWN_BOX:box(), x()+2*dx, y(), W, H, color());
|
1998-12-02 21:43:28 +03:00
|
|
|
if (active_r())
|
|
|
|
fl_color(selection_color());
|
|
|
|
else
|
2001-10-29 06:44:33 +03:00
|
|
|
fl_color(fl_inactive(selection_color()));
|
1998-10-06 22:21:25 +04:00
|
|
|
fastarrow.draw(x()+(W-fastarrow_width)/2,
|
|
|
|
y()+2*dy+(H-fastarrow_height)/2, W, H);
|
|
|
|
mediumarrow.draw(x()+dx+(W-mediumarrow_width)/2,
|
|
|
|
y()+dy+(H-mediumarrow_height)/2, W, H);
|
|
|
|
slowarrow.draw(x()+2*dx+(W-slowarrow_width)/2,
|
|
|
|
y()+(H-slowarrow_width)/2, W, H);
|
2001-08-05 18:00:15 +04:00
|
|
|
if (Fl::focus() == this) draw_focus();
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int Fl_Adjuster::handle(int event) {
|
|
|
|
double v;
|
|
|
|
int delta;
|
|
|
|
int mx = Fl::event_x();
|
2010-02-20 20:40:07 +03:00
|
|
|
// Fl_Widget_Tracker wp(this);
|
1998-10-06 22:21:25 +04:00
|
|
|
switch (event) {
|
2001-08-05 18:00:15 +04:00
|
|
|
case FL_PUSH:
|
2001-12-16 19:41:48 +03:00
|
|
|
if (Fl::visible_focus()) Fl::focus(this);
|
2001-08-05 18:00:15 +04:00
|
|
|
ix = mx;
|
|
|
|
if (w()>=h())
|
|
|
|
drag = 3*(mx-x())/w() + 1;
|
1998-10-06 22:21:25 +04:00
|
|
|
else
|
2001-08-05 18:00:15 +04:00
|
|
|
drag = 3-3*(Fl::event_y()-y()-1)/h();
|
2010-02-20 20:40:07 +03:00
|
|
|
{ Fl_Widget_Tracker wp(this);
|
|
|
|
handle_push();
|
|
|
|
if (wp.deleted()) return 1;
|
|
|
|
}
|
2001-08-05 18:00:15 +04:00
|
|
|
redraw();
|
|
|
|
return 1;
|
|
|
|
case FL_DRAG:
|
|
|
|
if (w() >= h()) {
|
|
|
|
delta = x()+(drag-1)*w()/3; // left edge of button
|
|
|
|
if (mx < delta)
|
|
|
|
delta = mx-delta;
|
|
|
|
else if (mx > (delta+w()/3)) // right edge of button
|
|
|
|
delta = mx-delta-w()/3;
|
|
|
|
else
|
|
|
|
delta = 0;
|
|
|
|
} else {
|
|
|
|
if (mx < x())
|
|
|
|
delta = mx-x();
|
|
|
|
else if (mx > (x()+w()))
|
|
|
|
delta = mx-x()-w();
|
|
|
|
else
|
|
|
|
delta = 0;
|
|
|
|
}
|
1998-10-06 22:21:25 +04:00
|
|
|
switch (drag) {
|
2010-02-20 20:40:07 +03:00
|
|
|
case 3: v = increment(previous_value(), delta); break;
|
|
|
|
case 2: v = increment(previous_value(), delta*10); break;
|
|
|
|
default:v = increment(previous_value(), delta*100); break;
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
|
|
|
handle_drag(soft() ? softclamp(v) : clamp(v));
|
2001-08-05 18:00:15 +04:00
|
|
|
return 1;
|
|
|
|
case FL_RELEASE:
|
|
|
|
if (Fl::event_is_click()) { // detect click but no drag
|
|
|
|
if (Fl::event_state()&0xF0000) delta = -10;
|
|
|
|
else delta = 10;
|
|
|
|
switch (drag) {
|
2010-02-20 20:40:07 +03:00
|
|
|
case 3: v = increment(previous_value(), delta); break;
|
|
|
|
case 2: v = increment(previous_value(), delta*10); break;
|
|
|
|
default:v = increment(previous_value(), delta*100); break;
|
2001-08-05 18:00:15 +04:00
|
|
|
}
|
2010-02-20 20:40:07 +03:00
|
|
|
Fl_Widget_Tracker wp(this);
|
2001-08-05 18:00:15 +04:00
|
|
|
handle_drag(soft() ? softclamp(v) : clamp(v));
|
2010-02-20 20:40:07 +03:00
|
|
|
if (wp.deleted()) return 1;
|
2001-08-05 18:00:15 +04:00
|
|
|
}
|
|
|
|
drag = 0;
|
|
|
|
redraw();
|
|
|
|
handle_release();
|
|
|
|
return 1;
|
|
|
|
case FL_KEYBOARD :
|
|
|
|
switch (Fl::event_key()) {
|
|
|
|
case FL_Up:
|
|
|
|
if (w() > h()) return 0;
|
|
|
|
handle_drag(clamp(increment(value(),-1)));
|
|
|
|
return 1;
|
|
|
|
case FL_Down:
|
|
|
|
if (w() > h()) return 0;
|
|
|
|
handle_drag(clamp(increment(value(),1)));
|
|
|
|
return 1;
|
|
|
|
case FL_Left:
|
|
|
|
if (w() < h()) return 0;
|
|
|
|
handle_drag(clamp(increment(value(),-1)));
|
|
|
|
return 1;
|
|
|
|
case FL_Right:
|
|
|
|
if (w() < h()) return 0;
|
|
|
|
handle_drag(clamp(increment(value(),1)));
|
|
|
|
return 1;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
2002-05-24 18:19:19 +04:00
|
|
|
// break not required because of switch...
|
|
|
|
|
2001-08-05 18:00:15 +04:00
|
|
|
case FL_FOCUS:
|
|
|
|
case FL_UNFOCUS:
|
2001-11-03 22:24:22 +03:00
|
|
|
if (Fl::visible_focus()) {
|
|
|
|
redraw();
|
|
|
|
return 1;
|
|
|
|
} else return 0;
|
2002-05-12 15:12:56 +04:00
|
|
|
|
|
|
|
case FL_ENTER :
|
|
|
|
case FL_LEAVE :
|
|
|
|
return 1;
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-09-15 16:46:49 +04:00
|
|
|
/**
|
|
|
|
Creates a new Fl_Adjuster widget using the given position,
|
|
|
|
size, and label string. It looks best if one of the dimensions is 3
|
|
|
|
times the other.
|
|
|
|
<P> Inherited destructor destroys the Valuator.
|
|
|
|
*/
|
2002-08-09 05:09:49 +04:00
|
|
|
Fl_Adjuster::Fl_Adjuster(int X, int Y, int W, int H, const char* l)
|
|
|
|
: Fl_Valuator(X, Y, W, H, l) {
|
1998-10-06 22:21:25 +04:00
|
|
|
box(FL_UP_BOX);
|
|
|
|
step(1, 10000);
|
2005-10-30 20:42:21 +03:00
|
|
|
selection_color(FL_SELECTION_COLOR);
|
1998-10-06 22:21:25 +04:00
|
|
|
drag = 0;
|
|
|
|
soft_ = 1;
|
|
|
|
}
|
1998-10-20 00:46:58 +04:00
|
|
|
|
|
|
|
//
|
2005-02-25 00:55:12 +03:00
|
|
|
// End of "$Id$".
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|