r125: This commit was manufactured by cvs2svn to create tag 'r1_1_7-last'.
[cinelerra_cv/mob.git] / hvirtual / guicast / bcprogress.C
blobfe4cc0bdb4aea3ee6f383ba6f6f1877f8d825b80
1 #include <stdio.h>
4 #define PROGRESS_UP 0
5 #define PROGRESS_HI 1
7 #include "colors.h"
8 #include "fonts.h"
9 #include "bcprogress.h"
10 #include "bcpixmap.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;
18         position = 0;
19         pixel = 0;
20         for(int i = 0; i < 2; i++) images[i] = 0;
21         do_text = 1;
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()
32         set_images();
33         h = images[PROGRESS_UP]->get_h();
35         BC_SubWindow::initialize();
36         draw(1);
37         return 0;
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], 
53                         PIXMAP_ALPHA);
54         return 0;
58 int BC_ProgressBar::draw(int force)
60         char string[32];
61         int new_pixel;
63         new_pixel = (int)(((float)position / length) * get_w());
65         if(new_pixel != pixel || force)
66         {
67                 pixel = new_pixel;
68 // Clear background
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]);
74                 if(do_text)
75                 {
76                         set_font(MEDIUMFONT);
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);
80                 }
81                 flash();
82         }
83         return 0;
86 int BC_ProgressBar::update(long position)
88         this->position = position;
89         draw();
90         return 0;
93 int BC_ProgressBar::update_length(long length)
95         this->length = length;
96         position = 0;
98         draw();
99         return 0;