9 #include "bcprogress.h"
11 #include "bcresources.h"
13 BC_ProgressBar::BC_ProgressBar(int x, int y, int w, long length, int do_text)
14 : BC_SubWindow(x, y, w, 0, -1)
16 this->length = length;
17 this->do_text = do_text;
20 for(int i = 0; i < 2; i++) images[i] = 0;
24 BC_ProgressBar::~BC_ProgressBar()
26 for(int i = 0; i < 2; i++)
27 if (images[i]) delete images[i];
30 int BC_ProgressBar::initialize()
33 h = images[PROGRESS_UP]->get_h();
35 BC_SubWindow::initialize();
40 void BC_ProgressBar::set_do_text(int value)
42 this->do_text = value;
45 int BC_ProgressBar::set_images()
47 for(int i = 0; i < 2; i++)
48 if(images[i]) delete images[i];
50 for(int i = 0; i < 2; i++)
51 images[i] = new BC_Pixmap(parent_window,
52 get_resources()->progress_images[i],
58 int BC_ProgressBar::draw(int force)
63 new_pixel = (int)(((float)position / length) * get_w());
65 if(new_pixel != pixel || force)
69 draw_top_background(parent_window, 0, 0, get_w(), get_h());
70 draw_3segmenth(0, 0, pixel, 0, get_w(), images[PROGRESS_HI]);
71 draw_3segmenth(pixel, 0, get_w() - pixel, 0, get_w(), images[PROGRESS_UP]);
77 set_color(BLACK); // draw decimal percentage
78 sprintf(string, "%d%%", (int)(100 * (float)position / length + 0.5 / w));
79 draw_center_text(w / 2, h / 2 + get_text_ascent(MEDIUMFONT) / 2, string);
86 int BC_ProgressBar::update(long position)
88 this->position = position;
93 int BC_ProgressBar::update_length(long length)
95 this->length = length;