themes: Workaround for bug where a background color of RGB 0,0,0 in Black color schem...
[ntk.git] / src / Fl_Progress.cxx
blob192b38da77e682d20befab12f4717a9c3c586495
1 //
2 // "$Id: Fl_Progress.cxx 7903 2010-11-28 21:06:39Z matt $"
3 //
4 // Progress bar widget routines.
5 //
6 // Copyright 2000-2010 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.
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.
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.
23 // Please report all bugs and problems on the following page:
25 // http://www.fltk.org/str.php
27 // Contents:
30 // Fl_Progress::draw() - Draw the check button.
31 // Fl_Progress::Fl_Progress() - Construct a Fl_Progress widget.
35 // Include necessary header files...
38 #include <FL/Fl.H>
39 #include <FL/Fl_Progress.H>
40 #include <FL/fl_draw.H>
44 // Fl_Progress is a progress bar widget based off Fl_Widget that shows a
45 // standard progress bar...
50 // 'Fl_Progress::draw()' - Draw the progress bar.
53 /** Draws the progress bar. */
54 void Fl_Progress::draw()
56 int progress; // Size of progress bar...
57 int bx, by, bw, bh; // Box areas...
58 int tx, tw; // Temporary X + width
61 // Get the box borders...
62 bx = Fl::box_dx(box());
63 by = Fl::box_dy(box());
64 bw = Fl::box_dw(box());
65 bh = Fl::box_dh(box());
67 tx = x() + bx;
68 tw = w() - bw;
70 // Draw the progress bar...
71 if (maximum_ > minimum_)
72 progress = (int)(w() * (value_ - minimum_) / (maximum_ - minimum_) + 0.5f);
73 else
74 progress = 0;
76 // Draw the box and label...
77 if (progress > 0) {
78 Fl_Color c = labelcolor();
79 labelcolor(fl_contrast(labelcolor(), selection_color()));
81 fl_push_clip(x(), y(), progress + bx, h());
82 draw_box(box(), x(), y(), w(), h(), active_r() ? selection_color() : fl_inactive(selection_color()));
83 draw_label(tx, y() + by, tw, h() - bh);
84 fl_pop_clip();
86 labelcolor(c);
88 if (progress<w()) {
89 fl_push_clip(tx + progress, y(), w() - progress, h());
90 draw_box(box(), x(), y(), w(), h(), active_r() ? color() : fl_inactive(color()));
91 draw_label(tx, y() + by, tw, h() - bh);
92 fl_pop_clip();
94 } else {
95 draw_box(box(), x(), y(), w(), h(), active_r() ? color() : fl_inactive(color()));
96 draw_label(tx, y() + by, tw, h() - bh);
101 /**
102 The constructor creates the progress bar using the position, size, and label.
104 You can set the background color with color() and the
105 progress bar color with selection_color(), or you can set both colors
106 together with color(unsigned bg, unsigned sel).
108 The default colors are FL_BACKGROUND2_COLOR and FL_YELLOW, resp.
110 Fl_Progress::Fl_Progress(int X, int Y, int W, int H, const char* L)
111 : Fl_Widget(X, Y, W, H, L) {
112 align(FL_ALIGN_INSIDE);
113 box(FL_DOWN_BOX);
114 color(FL_BACKGROUND2_COLOR, FL_YELLOW);
115 minimum(0.0f);
116 maximum(100.0f);
117 value(0.0f);
122 // End of "$Id: Fl_Progress.cxx 7903 2010-11-28 21:06:39Z matt $".