fltk 1.3.0rc3
About: FLTK (Fast Light Tool Kit) is a cross-platform C++ GUI toolkit for UNIX/Linux (X11), Microsoft Windows, and MacOS X. Release candidate.
  SfR Fresh Dox: fltk-1.3.0rc3-source.tar.gz ("inofficial" and yet experimental doxygen-generated source code documentation)  

Fl_Progress.cxx

Go to the documentation of this file.
00001 //
00002 // "$Id: Fl_Progress.cxx 7903 2010-11-28 21:06:39Z matt $"
00003 //
00004 // Progress bar widget routines.
00005 //
00006 // Copyright 2000-2010 by Michael Sweet.
00007 //
00008 // This library is free software; you can redistribute it and/or
00009 // modify it under the terms of the GNU Library General Public
00010 // License as published by the Free Software Foundation; either
00011 // version 2 of the License, or (at your option) any later version.
00012 //
00013 // This library is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016 // Library General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU Library General Public
00019 // License along with this library; if not, write to the Free Software
00020 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00021 // USA.
00022 //
00023 // Please report all bugs and problems on the following page:
00024 //
00025 //     http://www.fltk.org/str.php
00026 //
00027 // Contents:
00028 
00029 //
00030 //   Fl_Progress::draw()        - Draw the check button.
00031 //   Fl_Progress::Fl_Progress() - Construct a Fl_Progress widget.
00032 //
00033 
00034 //
00035 // Include necessary header files...
00036 //
00037 
00038 #include <FL/Fl.H>
00039 #include <FL/Fl_Progress.H>
00040 #include <FL/fl_draw.H>
00041 
00042 
00043 //
00044 // Fl_Progress is a progress bar widget based off Fl_Widget that shows a
00045 // standard progress bar...
00046 //
00047 
00048 
00049 //
00050 // 'Fl_Progress::draw()' - Draw the progress bar.
00051 //
00052 
00054 void Fl_Progress::draw()
00055 {
00056   int   progress;       // Size of progress bar...
00057   int   bx, by, bw, bh; // Box areas...
00058   int   tx, tw;         // Temporary X + width
00059 
00060 
00061   // Get the box borders...
00062   bx = Fl::box_dx(box());
00063   by = Fl::box_dy(box());
00064   bw = Fl::box_dw(box());
00065   bh = Fl::box_dh(box());
00066 
00067   tx = x() + bx;
00068   tw = w() - bw;
00069 
00070   // Draw the progress bar...
00071   if (maximum_ > minimum_)
00072     progress = (int)(w() * (value_ - minimum_) / (maximum_ - minimum_) + 0.5f);
00073   else
00074     progress = 0;
00075 
00076   // Draw the box and label...
00077   if (progress > 0) {
00078     Fl_Color c = labelcolor();
00079     labelcolor(fl_contrast(labelcolor(), selection_color()));
00080 
00081     fl_push_clip(x(), y(), progress + bx, h());
00082       draw_box(box(), x(), y(), w(), h(), active_r() ? selection_color() : fl_inactive(selection_color()));
00083       draw_label(tx, y() + by, tw, h() - bh);
00084     fl_pop_clip();
00085 
00086     labelcolor(c);
00087 
00088     if (progress<w()) {
00089       fl_push_clip(tx + progress, y(), w() - progress, h());
00090         draw_box(box(), x(), y(), w(), h(), active_r() ? color() : fl_inactive(color()));
00091         draw_label(tx, y() + by, tw, h() - bh);
00092       fl_pop_clip();
00093     }
00094   } else {
00095     draw_box(box(), x(), y(), w(), h(), active_r() ? color() : fl_inactive(color()));
00096     draw_label(tx, y() + by, tw, h() - bh);
00097   }
00098 }
00099 
00100 
00110 Fl_Progress::Fl_Progress(int X, int Y, int W, int H, const char* L)
00111 : Fl_Widget(X, Y, W, H, L) {
00112   align(FL_ALIGN_INSIDE);
00113   box(FL_DOWN_BOX);
00114   color(FL_BACKGROUND2_COLOR, FL_YELLOW);
00115   minimum(0.0f);
00116   maximum(100.0f);
00117   value(0.0f);
00118 }
00119 
00120 
00121 //
00122 // End of "$Id: Fl_Progress.cxx 7903 2010-11-28 21:06:39Z matt $".
00123 //