1 //
2 // progress.cxx
3 //
4 // Progress bar widget routines.
5 //
6 // Based on Fl_Progress widget, Copyright 2000-2005 by Michael Sweet.
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 General Public License
19 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 // ----------------------------------------------------------------------------
21
22 #include <config.h>
23
24 #include <FL/Fl.H>
25 #include <FL/fl_draw.H>
26
27 #include "progress.h"
28
29 //
30 // progress is a progress bar widget based off Fl_Widget that shows a
31 // standard progress bar in either horizontal or vertical format
32 //
33 // if direction == VERTICAL the indicator goes from lower to upper
34 // if direction == HORIZONTAL the indicator goes from left to right
35
draw()36 void Progress::draw()
37 {
38 int progress; // Size of progress bar...
39 int bx, by, bw, bh; // Box areas...
40 int tx, tw; // Temporary X + width
41 int th;
42
43
44 // Get the box borders...
45 bx = Fl::box_dx(box());
46 by = Fl::box_dy(box());
47 bw = Fl::box_dw(box());
48 bh = Fl::box_dh(box());
49
50 tx = x() + bx;
51 tw = w() - bw;
52 th = h() - bh;
53
54 // Draw the progress bar...
55 if (maximum_ > minimum_)
56 progress = (int)((direction == HORIZONTAL ? tw : th) * (value_ - minimum_) / (maximum_ - minimum_) + 0.5f);
57 else
58 progress = 0;
59
60 // Draw the box and label...
61 if (progress > 0) {
62 Fl_Color c = labelcolor();
63 labelcolor(fl_contrast(labelcolor(), color2()));
64
65 if (direction == HORIZONTAL) {
66 fl_clip(x(), y(), progress, h());
67 draw_box(box(), x(), y(), w(), h(), active_r() ? color2() : fl_inactive(color2()));
68 draw_label(tx, y() + by, tw, h() - bh);
69 fl_pop_clip();
70
71 labelcolor(c);
72
73 fl_clip(x() + progress, y(), tw - progress, h());
74 draw_box(box(), x(), y(), w(), h(), active_r() ? color() : fl_inactive(color()));
75 draw_label(tx, y() + by, tw, h() - bh);
76 fl_pop_clip();
77 } else {
78 fl_clip(x(), y(), w(), h() - progress);
79 draw_box(box(), x(), y(), w(), h(), active_r() ? color() : fl_inactive(color()));
80 // draw_label(tx, y() + by, tw, h() - bh);
81 fl_pop_clip();
82
83 labelcolor(c);
84
85 fl_clip(x(), y() + h() - progress, w(), progress );
86 draw_box(box(), x(), y(), w(), h(), active_r() ? color2() : fl_inactive(color2()));
87 // draw_label(tx, y() + by, tw, h() - bh);
88 fl_pop_clip();
89 }
90 } else {
91 draw_box(box(), x(), y(), w(), h(), color());
92 if (direction == HORIZONTAL)
93 draw_label(tx, y() + by, tw, h() - bh);
94 }
95 }
96
97
Progress(int X,int Y,int W,int H,const char * l)98 Progress::Progress(int X, int Y, int W, int H, const char* l)
99 : Fl_Widget(X, Y, W, H, l)
100 {
101 align(FL_ALIGN_INSIDE);
102 box(FL_DOWN_BOX);
103 color(FL_BACKGROUND2_COLOR, FL_YELLOW);
104 minimum(0.0f);
105 maximum(100.0f);
106 value(0.0f);
107 direction = HORIZONTAL;
108 }
109
110
111 //
112 // End of "$Id: Progress.cxx 4288 2005-04-16 00:13:17Z mike $".
113 //
114