r1053: Add Russian translation.
[cinelerra_cv.git] / guicast / bcprogressbox.C
blob432a9a6ca1f176930e8ccab3d51939c42313e64e
1 #include "bcbutton.h"
2 #include "bcdisplayinfo.h"
3 #include "bcprogress.h"
4 #include "bcprogressbox.h"
5 #include "bcresources.h"
6 #include "bctitle.h"
7 #include "bcwindow.h"
8 #include "vframe.h"
10 BC_ProgressBox::BC_ProgressBox(int x, int y, char *text, int64_t length)
11  : Thread()
13         set_synchronous(1);
15 // Calculate default x, y
16         if(x < 0 || y < 0)
17         {
18                 BC_DisplayInfo display_info;
19                 x = display_info.get_abs_cursor_x();
20                 y = display_info.get_abs_cursor_y();
21         }
23         pwindow = new BC_ProgressWindow(x, y);
24         pwindow->create_objects(text, length);
25         cancelled = 0;
28 BC_ProgressBox::~BC_ProgressBox()
30         delete pwindow;
33 void BC_ProgressBox::run()
35         int result = pwindow->run_window();
36         if(result) cancelled = 1;
39 int BC_ProgressBox::update(int64_t position, int lock_it)
41         if(!cancelled)
42         {
43                 if(lock_it) pwindow->lock_window("BC_ProgressBox::update");
44                 pwindow->bar->update(position);
45                 if(lock_it) pwindow->unlock_window();
46         }
47         return cancelled;
50 int BC_ProgressBox::update_title(char *title, int lock_it)
52         if(lock_it) pwindow->lock_window("BC_ProgressBox::update_title");
53         pwindow->caption->update(title);
54         if(lock_it) pwindow->unlock_window();
55         return cancelled;
58 int BC_ProgressBox::update_length(int64_t length, int lock_it)
60         if(lock_it) pwindow->lock_window("BC_ProgressBox::update_length");
61         pwindow->bar->update_length(length);
62         if(lock_it) pwindow->unlock_window();
63         return cancelled;
67 int BC_ProgressBox::is_cancelled()
69         return cancelled;
72 int BC_ProgressBox::stop_progress()
74         pwindow->set_done(0);
75         Thread::join();
76         return 0;
79 void BC_ProgressBox::lock_window()
81         pwindow->lock_window("BC_ProgressBox::lock_window");
84 void BC_ProgressBox::unlock_window()
86         pwindow->unlock_window();
91 BC_ProgressWindow::BC_ProgressWindow(int x, int y)
92  : BC_Window("Progress", 
93         x, 
94         y, 
95         340, 
96         100 + get_resources()->ok_images[0]->get_h(), 
97         0, 
98         0, 
99         0)
103 BC_ProgressWindow::~BC_ProgressWindow()
107 int BC_ProgressWindow::create_objects(char *text, int64_t length)
109         int x = 10, y = 10;
111 // Recalculate width based on text
112         if(text)
113         {
114                 int text_w = get_text_width(MEDIUMFONT, text);
115                 int new_w = text_w + x + 10;
117                 if(new_w > get_root_w()) new_w = get_root_w();
118                 if(new_w > get_w())
119                 {
120                         resize_window(new_w, get_h());
121                 }
122         }
124         this->text = text;
125         add_tool(caption = new BC_Title(x, y, text));
126         y += caption->get_h() + 20;
127         add_tool(bar = new BC_ProgressBar(x, y, get_w() - 20, length));
128         add_tool(new BC_CancelButton(this));
130         return 0;