DRC | 2ff39b8 | 2011-07-28 08:38:59 +0000 | [diff] [blame] | 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. |
| 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 | // Contents: |
| 28 | |
| 29 | // |
| 30 | // Fl_Progress::draw() - Draw the check button. |
| 31 | // Fl_Progress::Fl_Progress() - Construct a Fl_Progress widget. |
| 32 | // |
| 33 | |
| 34 | // |
| 35 | // Include necessary header files... |
| 36 | // |
| 37 | |
| 38 | #include <FL/Fl.H> |
| 39 | #include <FL/Fl_Progress.H> |
| 40 | #include <FL/fl_draw.H> |
| 41 | |
| 42 | |
| 43 | // |
| 44 | // Fl_Progress is a progress bar widget based off Fl_Widget that shows a |
| 45 | // standard progress bar... |
| 46 | // |
| 47 | |
| 48 | |
| 49 | // |
| 50 | // 'Fl_Progress::draw()' - Draw the progress bar. |
| 51 | // |
| 52 | |
| 53 | /** Draws the progress bar. */ |
| 54 | void Fl_Progress::draw() |
| 55 | { |
| 56 | int progress; // Size of progress bar... |
| 57 | int bx, by, bw, bh; // Box areas... |
| 58 | int tx, tw; // Temporary X + width |
| 59 | |
| 60 | |
| 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()); |
| 66 | |
| 67 | tx = x() + bx; |
| 68 | tw = w() - bw; |
| 69 | |
| 70 | // Draw the progress bar... |
| 71 | if (maximum_ > minimum_) |
| 72 | progress = (int)(w() * (value_ - minimum_) / (maximum_ - minimum_) + 0.5f); |
| 73 | else |
| 74 | progress = 0; |
| 75 | |
| 76 | // Draw the box and label... |
| 77 | if (progress > 0) { |
| 78 | Fl_Color c = labelcolor(); |
| 79 | labelcolor(fl_contrast(labelcolor(), selection_color())); |
| 80 | |
| 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(); |
| 85 | |
| 86 | labelcolor(c); |
| 87 | |
| 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(); |
| 93 | } |
| 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); |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | |
| 101 | /** |
| 102 | The constructor creates the progress bar using the position, size, and label. |
| 103 | |
| 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). |
| 107 | |
| 108 | The default colors are FL_BACKGROUND2_COLOR and FL_YELLOW, resp. |
| 109 | */ |
| 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); |
| 118 | } |
| 119 | |
| 120 | |
| 121 | // |
| 122 | // End of "$Id: Fl_Progress.cxx 7903 2010-11-28 21:06:39Z matt $". |
| 123 | // |