2001-08-11 18:49:51 +04:00
|
|
|
//
|
|
|
|
// Progress bar widget routines.
|
|
|
|
//
|
2010-11-29 00:06:39 +03:00
|
|
|
// Copyright 2000-2010 by Michael Sweet.
|
2001-08-11 18:49:51 +04:00
|
|
|
//
|
2011-07-19 08:49:30 +04:00
|
|
|
// This library is free software. Distribution and use rights are outlined in
|
|
|
|
// the file "COPYING" which should have been included with this file. If this
|
|
|
|
// file is missing or damaged, see the license at:
|
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// https://www.fltk.org/COPYING.php
|
2001-08-11 18:49:51 +04:00
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// Please see the following page on how to report bugs and issues:
|
2005-04-16 04:13:17 +04:00
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// https://www.fltk.org/bugs.php
|
2001-08-11 18:49:51 +04:00
|
|
|
//
|
|
|
|
// Contents:
|
2008-09-15 04:27:28 +04:00
|
|
|
|
2001-08-11 18:49:51 +04:00
|
|
|
//
|
|
|
|
// Fl_Progress::draw() - Draw the check button.
|
|
|
|
// Fl_Progress::Fl_Progress() - Construct a Fl_Progress widget.
|
|
|
|
//
|
|
|
|
|
|
|
|
//
|
|
|
|
// Include necessary header files...
|
|
|
|
//
|
|
|
|
|
|
|
|
#include <FL/Fl.H>
|
|
|
|
#include <FL/Fl_Progress.H>
|
|
|
|
#include <FL/fl_draw.H>
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// Fl_Progress is a progress bar widget based off Fl_Widget that shows a
|
|
|
|
// standard progress bar...
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
//
|
2009-06-27 13:29:36 +04:00
|
|
|
// 'Fl_Progress::draw()' - Draw the progress bar.
|
2001-08-11 18:49:51 +04:00
|
|
|
//
|
|
|
|
|
2008-10-31 19:30:07 +03:00
|
|
|
/** Draws the progress bar. */
|
2001-08-11 18:49:51 +04:00
|
|
|
void Fl_Progress::draw()
|
|
|
|
{
|
2020-07-01 19:03:10 +03:00
|
|
|
int progress; // Size of progress bar...
|
|
|
|
int bx, by, bw, bh; // Box areas...
|
|
|
|
int tx, tw; // Temporary X + width
|
2001-08-11 18:49:51 +04:00
|
|
|
|
|
|
|
|
|
|
|
// Get the box borders...
|
|
|
|
bx = Fl::box_dx(box());
|
|
|
|
by = Fl::box_dy(box());
|
|
|
|
bw = Fl::box_dw(box());
|
|
|
|
bh = Fl::box_dh(box());
|
|
|
|
|
2001-12-06 21:12:35 +03:00
|
|
|
tx = x() + bx;
|
|
|
|
tw = w() - bw;
|
2001-08-11 18:49:51 +04:00
|
|
|
|
|
|
|
// Draw the progress bar...
|
|
|
|
if (maximum_ > minimum_)
|
2006-11-12 23:44:12 +03:00
|
|
|
progress = (int)(w() * (value_ - minimum_) / (maximum_ - minimum_) + 0.5f);
|
2001-08-11 18:49:51 +04:00
|
|
|
else
|
|
|
|
progress = 0;
|
|
|
|
|
2005-03-21 22:52:53 +03:00
|
|
|
// Draw the box and label...
|
|
|
|
if (progress > 0) {
|
|
|
|
Fl_Color c = labelcolor();
|
2009-06-27 13:29:36 +04:00
|
|
|
labelcolor(fl_contrast(labelcolor(), selection_color()));
|
2005-03-21 22:52:53 +03:00
|
|
|
|
2008-12-06 17:59:52 +03:00
|
|
|
fl_push_clip(x(), y(), progress + bx, h());
|
2009-06-27 13:29:36 +04:00
|
|
|
draw_box(box(), x(), y(), w(), h(), active_r() ? selection_color() : fl_inactive(selection_color()));
|
2005-03-21 22:52:53 +03:00
|
|
|
draw_label(tx, y() + by, tw, h() - bh);
|
2001-12-06 21:12:35 +03:00
|
|
|
fl_pop_clip();
|
2001-08-11 18:49:51 +04:00
|
|
|
|
2005-03-21 22:52:53 +03:00
|
|
|
labelcolor(c);
|
|
|
|
|
2006-11-12 23:44:12 +03:00
|
|
|
if (progress<w()) {
|
2008-12-06 17:59:52 +03:00
|
|
|
fl_push_clip(tx + progress, y(), w() - progress, h());
|
2006-11-12 23:44:12 +03:00
|
|
|
draw_box(box(), x(), y(), w(), h(), active_r() ? color() : fl_inactive(color()));
|
|
|
|
draw_label(tx, y() + by, tw, h() - bh);
|
|
|
|
fl_pop_clip();
|
|
|
|
}
|
2005-03-21 22:52:53 +03:00
|
|
|
} else {
|
2006-11-12 23:44:12 +03:00
|
|
|
draw_box(box(), x(), y(), w(), h(), active_r() ? color() : fl_inactive(color()));
|
2005-03-21 22:52:53 +03:00
|
|
|
draw_label(tx, y() + by, tw, h() - bh);
|
|
|
|
}
|
2001-08-11 18:49:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-07-01 19:03:10 +03:00
|
|
|
/**
|
2009-06-27 13:29:36 +04:00
|
|
|
The constructor creates the progress bar using the position, size, and label.
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2009-06-27 13:29:36 +04:00
|
|
|
You can set the background color with color() and the
|
|
|
|
progress bar color with selection_color(), or you can set both colors
|
|
|
|
together with color(unsigned bg, unsigned sel).
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2009-06-27 13:29:36 +04:00
|
|
|
The default colors are FL_BACKGROUND2_COLOR and FL_YELLOW, resp.
|
2008-09-15 04:27:28 +04:00
|
|
|
*/
|
2009-06-27 13:29:36 +04:00
|
|
|
Fl_Progress::Fl_Progress(int X, int Y, int W, int H, const char* L)
|
|
|
|
: Fl_Widget(X, Y, W, H, L) {
|
2001-08-11 18:49:51 +04:00
|
|
|
align(FL_ALIGN_INSIDE);
|
|
|
|
box(FL_DOWN_BOX);
|
2002-04-11 14:46:19 +04:00
|
|
|
color(FL_BACKGROUND2_COLOR, FL_YELLOW);
|
2001-08-11 18:49:51 +04:00
|
|
|
minimum(0.0f);
|
|
|
|
maximum(100.0f);
|
|
|
|
value(0.0f);
|
|
|
|
}
|