1 //
2 // "$Id: Fl_Value_Slider.cxx 5190 2006-06-09 16:16:34Z mike $"
3 //
4 // Value slider widget for the Fast Light Tool Kit (FLTK).
5 //
6 // Copyright 1998-2005 by Bill Spitzak and others.
7 //
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Library General Public
10 // License as published by the Free Software Foundation; either
11 // version 2 of the License, or (at your option) any later version.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Library General Public License for more details.
17 //
18 // You should have received a copy of the GNU Library General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
21 // USA.
22 //
23 // Please report all bugs and problems on the following page:
24 //
25 // http://www.fltk.org/str.php
26 //
27
28 #include <FL/Fl.H>
29 #include <FL/Fl_Value_Slider.H>
30 #include <FL/fl_draw.H>
31 #include <math.h>
32
Fl_Value_Slider(int X,int Y,int W,int H,const char * l)33 Fl_Value_Slider::Fl_Value_Slider(int X, int Y, int W, int H, const char*l)
34 : Fl_Slider(X,Y,W,H,l) {
35 step(1,100);
36 textfont_ = FL_HELVETICA;
37 textsize_ = 10;
38 textcolor_ = FL_FOREGROUND_COLOR;
39 }
40
draw()41 void Fl_Value_Slider::draw() {
42 int sxx = x(), syy = y(), sww = w(), shh = h();
43 int bxx = x(), byy = y(), bww = w(), bhh = h();
44 if (horizontal()) {
45 bww = 35; sxx += 35; sww -= 35;
46 } else {
47 syy += 25; bhh = 25; shh -= 25;
48 }
49 if (damage()&FL_DAMAGE_ALL) draw_box(box(),sxx,syy,sww,shh,color());
50 Fl_Slider::draw(sxx+Fl::box_dx(box()),
51 syy+Fl::box_dy(box()),
52 sww-Fl::box_dw(box()),
53 shh-Fl::box_dh(box()));
54 draw_box(box(),bxx,byy,bww,bhh,color());
55 char buf[128];
56 format(buf);
57 fl_font(textfont(), textsize());
58 fl_color(active_r() ? textcolor() : fl_inactive(textcolor()));
59 fl_draw(buf, bxx, byy, bww, bhh, FL_ALIGN_CLIP);
60 }
61
handle(int event)62 int Fl_Value_Slider::handle(int event) {
63 if (event == FL_PUSH && Fl::visible_focus()) {
64 Fl::focus(this);
65 redraw();
66 }
67 int sxx = x(), syy = y(), sww = w(), shh = h();
68 if (horizontal()) {
69 sxx += 35; sww -= 35;
70 } else {
71 syy += 25; shh -= 25;
72 }
73 return Fl_Slider::handle(event,
74 sxx+Fl::box_dx(box()),
75 syy+Fl::box_dy(box()),
76 sww-Fl::box_dw(box()),
77 shh-Fl::box_dh(box()));
78 }
79
80 //
81 // End of "$Id: Fl_Value_Slider.cxx 5190 2006-06-09 16:16:34Z mike $".
82 //
83