blob: 7dd3f451f7d9e6c23c916bd561cd736d9fe8bcf0 [file] [log] [blame]
DRC2ff39b82011-07-28 08:38:59 +00001//
2// "$Id: Fl_Value_Output.cxx 7903 2010-11-28 21:06:39Z matt $"
3//
4// Value output 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// Fltk widget for drag-adjusting a floating point value.
29// This is much lighter than Fl_Value_Input because it has no text editor
30// If step() is zero then it can be used to display a floating-point value
31
32#include <FL/Fl.H>
33#include <FL/Fl_Value_Output.H>
34#include <FL/fl_draw.H>
35
36void Fl_Value_Output::draw() {
37 Fl_Boxtype b = box() ? box() : FL_DOWN_BOX;
38 int X = x()+Fl::box_dx(b);
39 int Y = y()+Fl::box_dy(b);
40 int W = w()-Fl::box_dw(b);
41 int H = h()-Fl::box_dh(b);
42 if (damage()&~FL_DAMAGE_CHILD)
43 draw_box(b, color());
44 else {
45 fl_color(color());
46 fl_rectf(X, Y, W, H);
47 }
48 char buf[128];
49 format(buf);
50 fl_color(active_r() ? textcolor() : fl_inactive(textcolor()));
51 fl_font(textfont(), textsize());
52 fl_draw(buf,X,Y,W,H,FL_ALIGN_LEFT);
53}
54
55int Fl_Value_Output::handle(int event) {
56 if (!step()) return 0;
57 double v;
58 int delta;
59 int mx = Fl::event_x();
60 static int ix, drag;
61 switch (event) {
62 case FL_PUSH:
63 ix = mx;
64 drag = Fl::event_button();
65 handle_push();
66 return 1;
67 case FL_DRAG:
68 delta = Fl::event_x()-ix;
69 if (delta > 5) delta -= 5;
70 else if (delta < -5) delta += 5;
71 else delta = 0;
72 switch (drag) {
73 case 3: v = increment(previous_value(),delta*100); break;
74 case 2: v = increment(previous_value(),delta*10); break;
75 default:v = increment(previous_value(),delta); break;
76 }
77 v = round(v);
78 handle_drag(soft()?softclamp(v):clamp(v));;
79 return 1;
80 case FL_RELEASE:
81 handle_release();
82 return 1;
83 case FL_ENTER :
84 case FL_LEAVE :
85 return 1;
86 default:
87 return 0;
88 }
89}
90
91/**
92 Creates a new Fl_Value_Output widget using the given
93 position, size, and label string. The default boxtype is FL_NO_BOX.
94 <P> Inherited destructor destroys the Valuator.
95*/
96Fl_Value_Output::Fl_Value_Output(int X, int Y, int W, int H,const char *l)
97: Fl_Valuator(X,Y,W,H,l) {
98 box(FL_NO_BOX);
99 align(FL_ALIGN_LEFT);
100 textfont_ = FL_HELVETICA;
101 textsize_ = FL_NORMAL_SIZE;
102 textcolor_ = FL_FOREGROUND_COLOR;
103 soft_ = 0;
104}
105
106//
107// End of "$Id: Fl_Value_Output.cxx 7903 2010-11-28 21:06:39Z matt $".
108//