1 //
2 // "$Id: Fl_Value_Slider.cxx 7903 2010-11-28 21:06:39Z matt $"
3 //
4 // Value slider widget for the Fast Light Tool Kit (FLTK).
5 //
6 // Copyright 1998-2010 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
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
33 /**
34 Creates a new Fl_Value_Slider widget using the given
35 position, size, and label string. The default boxtype is FL_DOWN_BOX.
36 */
Fl_Value_Slider(int X,int Y,int W,int H,const char * l)37 Fl_Value_Slider::Fl_Value_Slider(int X, int Y, int W, int H, const char*l)
38 : Fl_Slider(X,Y,W,H,l) {
39 step(1,100);
40 textfont_ = FL_HELVETICA;
41 textsize_ = 10;
42 textcolor_ = FL_FOREGROUND_COLOR;
43 }
44
draw()45 void Fl_Value_Slider::draw() {
46 int sxx = x(), syy = y(), sww = w(), shh = h();
47 int bxx = x(), byy = y(), bww = w(), bhh = h();
48 if (horizontal()) {
49 bww = 35; sxx += 35; sww -= 35;
50 } else {
51 syy += 25; bhh = 25; shh -= 25;
52 }
53 if (damage()&FL_DAMAGE_ALL) draw_box(box(),sxx,syy,sww,shh,color());
54 Fl_Slider::draw(sxx+Fl::box_dx(box()),
55 syy+Fl::box_dy(box()),
56 sww-Fl::box_dw(box()),
57 shh-Fl::box_dh(box()));
58 draw_box(box(),bxx,byy,bww,bhh,color());
59 char buf[128];
60 format(buf);
61 fl_font(textfont(), textsize());
62 fl_color(active_r() ? textcolor() : fl_inactive(textcolor()));
63 fl_draw(buf, bxx, byy, bww, bhh, FL_ALIGN_CLIP);
64 }
65
handle(int event)66 int Fl_Value_Slider::handle(int event) {
67 if (event == FL_PUSH && Fl::visible_focus()) {
68 Fl::focus(this);
69 redraw();
70 }
71 int sxx = x(), syy = y(), sww = w(), shh = h();
72 if (horizontal()) {
73 sxx += 35; sww -= 35;
74 } else {
75 syy += 25; shh -= 25;
76 }
77 return Fl_Slider::handle(event,
78 sxx+Fl::box_dx(box()),
79 syy+Fl::box_dy(box()),
80 sww-Fl::box_dw(box()),
81 shh-Fl::box_dh(box()));
82 }
83
84 //
85 // End of "$Id: Fl_Value_Slider.cxx 7903 2010-11-28 21:06:39Z matt $".
86 //
87