1998-10-20 00:46:58 +04:00
|
|
|
//
|
1999-05-14 13:07:09 +04:00
|
|
|
// "$Id: Fl_Scrollbar.cxx,v 1.7.2.1 1999/05/14 09:07:07 bill Exp $"
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|
|
|
|
// Scroll bar widget for the Fast Light Tool Kit (FLTK).
|
|
|
|
//
|
1999-01-07 22:18:01 +03:00
|
|
|
// Copyright 1998-1999 by Bill Spitzak and others.
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Library General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Library General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Library General Public
|
|
|
|
// License along with this library; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
// USA.
|
|
|
|
//
|
|
|
|
// Please report all bugs and problems to "fltk-bugs@easysw.com".
|
|
|
|
//
|
1998-10-06 22:21:25 +04:00
|
|
|
|
|
|
|
#include <FL/Fl.H>
|
|
|
|
#include <FL/Fl_Scrollbar.H>
|
|
|
|
#include <FL/fl_draw.H>
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
#define INITIALREPEAT .5
|
|
|
|
#define REPEAT .05
|
|
|
|
|
|
|
|
void Fl_Scrollbar::increment_cb() {
|
|
|
|
handle_drag(clamp(value() + (
|
|
|
|
((pushed_>1) == (maximum()>=minimum())) ? linesize_ : -linesize_)));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Fl_Scrollbar::timeout_cb(void* v) {
|
|
|
|
Fl_Scrollbar* s = (Fl_Scrollbar*)v;
|
|
|
|
s->increment_cb();
|
|
|
|
Fl::add_timeout(REPEAT, timeout_cb, s);
|
|
|
|
}
|
|
|
|
|
|
|
|
int Fl_Scrollbar::handle(int event) {
|
|
|
|
if (!pushed_) {
|
|
|
|
if (horizontal()) {
|
|
|
|
if (w() < 3*h()) return Fl_Slider::handle(event);
|
|
|
|
if (Fl_Slider::handle(event, x()+h(), y(), w()-2*h(), h())) return 1;
|
|
|
|
} else {
|
|
|
|
if (h() < 3*w()) return Fl_Slider::handle(event);
|
|
|
|
if (Fl_Slider::handle(event, x(), y()+w(), w(), h()-2*w())) return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
switch (event) {
|
|
|
|
case FL_RELEASE:
|
|
|
|
if (pushed_) {
|
|
|
|
Fl::remove_timeout(timeout_cb, this);
|
|
|
|
pushed_ = 0;
|
|
|
|
redraw();
|
|
|
|
}
|
|
|
|
handle_release();
|
|
|
|
return 1;
|
|
|
|
case FL_PUSH:
|
|
|
|
if (horizontal()) {
|
|
|
|
if (Fl::event_inside(x(), y(), h(), h())) pushed_ = 1;
|
|
|
|
if (Fl::event_inside(x()+w()-h(), y(), h(), h())) pushed_ = 2;
|
|
|
|
} else {
|
|
|
|
if (Fl::event_inside(x(), y(), w(), w())) pushed_ = 1;
|
|
|
|
if (Fl::event_inside(x(), y()+h()-w(), w(), w())) pushed_ = 2;
|
|
|
|
}
|
|
|
|
if (pushed_) {
|
|
|
|
handle_push();
|
|
|
|
Fl::add_timeout(INITIALREPEAT, timeout_cb, this);
|
|
|
|
increment_cb();
|
|
|
|
redraw();
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
case FL_DRAG:
|
|
|
|
return pushed_;
|
|
|
|
case FL_SHORTCUT: {
|
|
|
|
int v = value();
|
|
|
|
int ls = maximum()>=minimum() ? linesize_ : -linesize_;
|
|
|
|
if (horizontal()) {
|
|
|
|
switch (Fl::event_key()) {
|
|
|
|
case FL_Left:
|
|
|
|
v -= ls;
|
|
|
|
break;
|
|
|
|
case FL_Right:
|
|
|
|
v += ls;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
} else { // vertical
|
|
|
|
switch (Fl::event_key()) {
|
|
|
|
case FL_Up:
|
|
|
|
v -= ls;
|
|
|
|
break;
|
|
|
|
case FL_Down:
|
|
|
|
v += ls;
|
|
|
|
break;
|
|
|
|
case FL_Page_Up:
|
|
|
|
if (slider_size() >= 1.0) return 0;
|
|
|
|
v -= int((maximum()-minimum())*slider_size()/(1.0-slider_size()));
|
|
|
|
v += ls;
|
|
|
|
break;
|
|
|
|
case FL_Page_Down:
|
|
|
|
if (slider_size() >= 1.0) return 0;
|
|
|
|
v += int((maximum()-minimum())*slider_size()/(1.0-slider_size()));
|
|
|
|
v -= ls;
|
|
|
|
break;
|
|
|
|
case FL_Home:
|
|
|
|
v = int(minimum());
|
|
|
|
break;
|
|
|
|
case FL_End:
|
|
|
|
v = int(maximum());
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
v = int(clamp(v));
|
|
|
|
if (v != value()) {
|
|
|
|
Fl_Slider::value(v);
|
|
|
|
value_damage();
|
|
|
|
do_callback();
|
|
|
|
}
|
|
|
|
return 1;}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Fl_Scrollbar::draw() {
|
1999-05-14 13:07:09 +04:00
|
|
|
if (damage()&FL_DAMAGE_ALL) draw_box();
|
|
|
|
int X = x()+Fl::box_dx(box());
|
|
|
|
int Y = y()+Fl::box_dy(box());
|
|
|
|
int W = w()-Fl::box_dw(box());
|
|
|
|
int H = h()-Fl::box_dh(box());
|
1998-10-06 22:21:25 +04:00
|
|
|
if (horizontal()) {
|
1999-05-14 13:07:09 +04:00
|
|
|
if (W < 3*H) {Fl_Slider::draw(X,Y,W,H); return;}
|
|
|
|
Fl_Slider::draw(X+H,Y,W-2*H,H);
|
1998-10-19 21:53:09 +04:00
|
|
|
if (damage()&FL_DAMAGE_ALL) {
|
1998-10-06 22:21:25 +04:00
|
|
|
draw_box((pushed_&1) ? down(slider()) : slider(),
|
1999-05-14 13:07:09 +04:00
|
|
|
X, Y, H, H, selection_color());
|
1998-10-06 22:21:25 +04:00
|
|
|
draw_box((pushed_&2) ? down(slider()) : slider(),
|
1999-05-14 13:07:09 +04:00
|
|
|
X+W-H, Y, H, H, selection_color());
|
1998-10-21 21:53:13 +04:00
|
|
|
if (active_r())
|
|
|
|
fl_color(labelcolor());
|
|
|
|
else
|
1998-12-02 21:43:28 +03:00
|
|
|
fl_color(inactive(labelcolor()));
|
1999-05-14 13:07:09 +04:00
|
|
|
int w1 = (H-1)|1; // use odd sizes only
|
|
|
|
int Y1 = Y+w1/2;
|
|
|
|
int W1 = w1/3;
|
|
|
|
int X1 = X+w1/2+W1/2;
|
|
|
|
fl_polygon(X1-W1, Y1, X1, Y1-W1, X1, Y1+W1);
|
|
|
|
X1 = X+W-(X1-X)-1;
|
|
|
|
fl_polygon(X1+W1, Y1, X1, Y1+W1, X1, Y1-W1);
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
|
|
|
} else { // vertical
|
1999-05-14 13:07:09 +04:00
|
|
|
if (H < 3*W) {Fl_Slider::draw(X,Y,W,H); return;}
|
|
|
|
Fl_Slider::draw(X,Y+W,W,H-2*W);
|
1998-10-19 21:53:09 +04:00
|
|
|
if (damage()&FL_DAMAGE_ALL) {
|
1998-10-06 22:21:25 +04:00
|
|
|
draw_box((pushed_&1) ? down(slider()) : slider(),
|
1999-05-14 13:07:09 +04:00
|
|
|
X, Y, W, W, selection_color());
|
1998-10-06 22:21:25 +04:00
|
|
|
draw_box((pushed_&2) ? down(slider()) : slider(),
|
1999-05-14 13:07:09 +04:00
|
|
|
X, Y+H-W, W, W, selection_color());
|
1998-10-21 21:53:13 +04:00
|
|
|
if (active_r())
|
|
|
|
fl_color(labelcolor());
|
|
|
|
else
|
|
|
|
fl_color(labelcolor() | 8);
|
1999-05-14 13:07:09 +04:00
|
|
|
int w1 = (W-1)|1; // use odd sizes only
|
|
|
|
int X1 = X+w1/2;
|
|
|
|
int W1 = w1/3;
|
|
|
|
int Y1 = Y+w1/2+W1/2;
|
|
|
|
fl_polygon(X1, Y1-W1, X1+W1, Y1, X1-W1, Y1);
|
|
|
|
Y1 = Y+H-(Y1-Y)-1;
|
|
|
|
fl_polygon(X1, Y1+W1, X1-W1, Y1, X1+W1, Y1);
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Fl_Scrollbar::Fl_Scrollbar(int X, int Y, int W, int H, const char* L)
|
|
|
|
: Fl_Slider(X, Y, W, H, L)
|
|
|
|
{
|
|
|
|
box(FL_FLAT_BOX);
|
|
|
|
color(FL_DARK2);
|
|
|
|
slider(FL_UP_BOX);
|
|
|
|
linesize_ = 16;
|
|
|
|
pushed_ = 0;
|
|
|
|
step(1);
|
|
|
|
}
|
1998-10-20 00:46:58 +04:00
|
|
|
|
|
|
|
//
|
1999-05-14 13:07:09 +04:00
|
|
|
// End of "$Id: Fl_Scrollbar.cxx,v 1.7.2.1 1999/05/14 09:07:07 bill Exp $".
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|