Merge branch 'ct' of git.pipapo.org:cinelerra-ct into ct
[cinelerra_cv/ct.git] / guicast / bcprogress.C
blob745219d5445e904e55f6145e151265037abd1f9f
1 #include <stdio.h>
2 #include <unistd.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, int64_t 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 int BC_ProgressBar::reposition_window(int x, int y, int w, int h)
42         if(w < 0) w = get_w();
43         if(h < 0) h = get_h();
44         BC_WindowBase::reposition_window(x, y, w, h);
45         draw(1);
48 void BC_ProgressBar::set_do_text(int value)
50         this->do_text = value;
53 int BC_ProgressBar::set_images()
55         for(int i = 0; i < 2; i++)
56                 if(images[i]) delete images[i];
58         for(int i = 0; i < 2; i++)
59         {
60                 images[i] = new BC_Pixmap(parent_window, 
61                         get_resources()->progress_images[i], 
62                         PIXMAP_ALPHA);
63         }
64         return 0;
68 int BC_ProgressBar::draw(int force)
70         char string[32];
71         int new_pixel;
73         new_pixel = (int)(((float)position / length) * get_w());
75         if(new_pixel != pixel || force)
76         {
77                 pixel = new_pixel;
78 // Clear background
79                 draw_top_background(parent_window, 0, 0, get_w(), get_h());
80                 draw_3segmenth(0, 0, pixel, 0, get_w(), images[PROGRESS_HI]);
81                 draw_3segmenth(pixel, 0, get_w() - pixel, 0, get_w(), images[PROGRESS_UP]);
84                 if(do_text)
85                 {
86                         set_font(MEDIUMFONT);
87                         set_color(get_resources()->progress_text);     // draw decimal percentage
88                         sprintf(string, "%d%%", (int)(100 * (float)position / length + 0.5 / w));
89                         draw_center_text(w / 2, h / 2 + get_text_ascent(MEDIUMFONT) / 2, string);
90                 }
91                 flash();
92         }
93         return 0;
96 int BC_ProgressBar::update(int64_t position)
98         this->position = position;
99         draw();
100         return 0;
103 int BC_ProgressBar::update_length(int64_t length)
105         this->length = length;
106         position = 0;
108         draw();
109         return 0;
113 //      Local Variables:
114 //      mode: C++
115 //      c-file-style: "linux"
116 //      End: