1 //
2 // "$Id$"
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. Distribution and use rights are outlined in
9 // the file "COPYING" which should have been included with this file. If this
10 // file is missing or damaged, see the license at:
11 //
12 // http://www.fltk.org/COPYING.php
13 //
14 // Please report all bugs and problems on the following page:
15 //
16 // http://www.fltk.org/str.php
17 //
18
19 #include <FL/Fl.H>
20 #include <FL/Fl_Value_Slider.H>
21 #include <FL/Fl_Hor_Value_Slider.H>
22 #include <FL/fl_draw.H>
23 #include <math.h>
24
25 /**
26 Creates a new Fl_Value_Slider widget using the given
27 position, size, and label string. The default boxtype is FL_DOWN_BOX.
28 */
Fl_Value_Slider(int X,int Y,int W,int H,const char * l)29 Fl_Value_Slider::Fl_Value_Slider(int X, int Y, int W, int H, const char*l)
30 : Fl_Slider(X,Y,W,H,l) {
31 step(1,100);
32 textfont_ = FL_HELVETICA;
33 textsize_ = 10;
34 textcolor_ = FL_FOREGROUND_COLOR;
35 }
36
draw()37 void Fl_Value_Slider::draw() {
38 int sxx = x(), syy = y(), sww = w(), shh = h();
39 int bxx = x(), byy = y(), bww = w(), bhh = h();
40 if (horizontal()) {
41 bww = 35; sxx += 35; sww -= 35;
42 } else {
43 syy += 25; bhh = 25; shh -= 25;
44 }
45 if (damage()&FL_DAMAGE_ALL) draw_box(box(),sxx,syy,sww,shh,color());
46 Fl_Slider::draw(sxx+Fl::box_dx(box()),
47 syy+Fl::box_dy(box()),
48 sww-Fl::box_dw(box()),
49 shh-Fl::box_dh(box()));
50 draw_box(box(),bxx,byy,bww,bhh,color());
51 char buf[128];
52 format(buf);
53 fl_font(textfont(), textsize());
54 fl_color(active_r() ? textcolor() : fl_inactive(textcolor()));
55 fl_draw(buf, bxx, byy, bww, bhh, FL_ALIGN_CLIP);
56 }
57
handle(int event)58 int Fl_Value_Slider::handle(int event) {
59 if (event == FL_PUSH && Fl::visible_focus()) {
60 Fl::focus(this);
61 redraw();
62 }
63 int sxx = x(), syy = y(), sww = w(), shh = h();
64 if (horizontal()) {
65 sxx += 35; sww -= 35;
66 } else {
67 syy += 25; shh -= 25;
68 }
69 return Fl_Slider::handle(event,
70 sxx+Fl::box_dx(box()),
71 syy+Fl::box_dy(box()),
72 sww-Fl::box_dw(box()),
73 shh-Fl::box_dh(box()));
74 }
75
76
Fl_Hor_Value_Slider(int X,int Y,int W,int H,const char * l)77 Fl_Hor_Value_Slider::Fl_Hor_Value_Slider(int X,int Y,int W,int H,const char *l)
78 : Fl_Value_Slider(X,Y,W,H,l) {
79 type(FL_HOR_SLIDER);
80 }
81
82
83 //
84 // End of "$Id$".
85 //
86