4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 #include "bcprogress.h"
32 #include "bcresources.h"
35 BC_ProgressBar::BC_ProgressBar(int x, int y, int w, int64_t length, int do_text)
36 : BC_SubWindow(x, y, w, 0, -1)
38 this->length = length;
39 this->do_text = do_text;
42 for(int i = 0; i < 2; i++) images[i] = 0;
46 BC_ProgressBar::~BC_ProgressBar()
48 for(int i = 0; i < 2; i++)
49 if (images[i]) delete images[i];
52 int BC_ProgressBar::calculate_h()
54 return BC_WindowBase::get_resources()->
55 progress_images[PROGRESS_UP]->get_h();
59 int BC_ProgressBar::initialize()
64 BC_SubWindow::initialize();
69 int BC_ProgressBar::reposition_window(int x, int y, int w, int h)
71 if(w < 0) w = get_w();
72 if(h < 0) h = get_h();
73 BC_WindowBase::reposition_window(x, y, w, h);
78 void BC_ProgressBar::set_do_text(int value)
80 this->do_text = value;
83 int BC_ProgressBar::set_images()
85 for(int i = 0; i < 2; i++)
86 if(images[i]) delete images[i];
88 for(int i = 0; i < 2; i++)
90 images[i] = new BC_Pixmap(parent_window,
91 get_resources()->progress_images[i],
98 int BC_ProgressBar::draw(int force, int flush)
103 new_pixel = (int)(((float)position / length) * get_w());
105 if(new_pixel != pixel || force)
109 draw_top_background(parent_window, 0, 0, get_w(), get_h());
110 draw_3segmenth(0, 0, pixel, 0, get_w(), images[PROGRESS_HI]);
111 draw_3segmenth(pixel, 0, get_w() - pixel, 0, get_w(), images[PROGRESS_UP]);
116 float pos = position > length ? (float)1 :
117 length > 0 && position > 0 ? (float)position / length :
119 set_font(MEDIUMFONT);
120 set_color(get_resources()->progress_text); // draw decimal percentage
121 sprintf(string, "%d%%", (int)(100 * pos + 0.5f));
122 draw_center_text(w / 2, h / 2 + get_text_ascent(MEDIUMFONT) / 2, string);
129 int BC_ProgressBar::update(int64_t position)
131 this->position = position;
136 int BC_ProgressBar::update_length(int64_t length)
138 this->length = length;