add mask color radio btn sel, fix del all mask btn, fix mask dflt kfrm draw name...
[goodguy/cinelerra.git] / cinelerra-5.1 / guicast / bcprogressbox.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  *
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.
10  *
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.
15  *
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
19  *
20  */
21
22 #include "bcbutton.h"
23 #include "bcdisplayinfo.h"
24 #include "bcprogress.h"
25 #include "bcprogressbox.h"
26 #include "bcresources.h"
27 #include "bctitle.h"
28 #include "bcwindow.h"
29 #include "language.h"
30 #include "vframe.h"
31
32 BC_ProgressBox::BC_ProgressBox(int x, int y, const char *text, int64_t length)
33  : Thread(1, 0, 0)
34 {
35 // Calculate default x, y
36         if(x < 0 || y < 0)
37         {
38                 BC_DisplayInfo display_info;
39                 x = display_info.get_abs_cursor_x();
40                 y = display_info.get_abs_cursor_y();
41                 // preloads boarder data (if not already loaded)
42                 //  without reopening display, also avoids a bug in X
43                 display_info.get_top_border();
44         }
45
46         pwindow = new BC_ProgressWindow(x, y);
47         pwindow->create_objects(text, length);
48         cancelled = 0;
49 }
50
51 BC_ProgressBox::~BC_ProgressBox()
52 {
53         stop_progress();
54         delete pwindow;
55 }
56
57 void BC_ProgressBox::run()
58 {
59         int result = pwindow->run_window();
60         if(result) cancelled = 1;
61 }
62
63 int BC_ProgressBox::update(int64_t position, int lock_it)
64 {
65         if(!cancelled)
66         {
67                 if(lock_it) pwindow->lock_window("BC_ProgressBox::update");
68                 pwindow->bar->update(position);
69                 if(lock_it) pwindow->unlock_window();
70         }
71         return cancelled;
72 }
73
74 int BC_ProgressBox::update_title(const char *title, int lock_it)
75 {
76         if(lock_it) pwindow->lock_window("BC_ProgressBox::update_title");
77         pwindow->caption->update(title);
78         if(lock_it) pwindow->unlock_window();
79         return cancelled;
80 }
81
82 int BC_ProgressBox::update_length(int64_t length, int lock_it)
83 {
84         if(lock_it) pwindow->lock_window("BC_ProgressBox::update_length");
85         pwindow->bar->update_length(length);
86         if(lock_it) pwindow->unlock_window();
87         return cancelled;
88 }
89
90
91 int BC_ProgressBox::is_cancelled()
92 {
93         return cancelled;
94 }
95
96 int BC_ProgressBox::stop_progress()
97 {
98         if( Thread::running() ) {
99                 pwindow->set_done(0);
100         }
101         Thread::join();
102         return 0;
103 }
104
105 void BC_ProgressBox::lock_window()
106 {
107         pwindow->lock_window("BC_ProgressBox::lock_window");
108 }
109
110 void BC_ProgressBox::unlock_window()
111 {
112         pwindow->unlock_window();
113 }
114
115
116
117 BC_ProgressWindow::BC_ProgressWindow(int x, int y)
118  : BC_Window(_("Progress"),
119         x,
120         y,
121         340,
122         100 + get_resources()->ok_images[0]->get_h(),
123         0,
124         0,
125         0)
126 {
127 }
128
129 BC_ProgressWindow::~BC_ProgressWindow()
130 {
131 }
132
133 int BC_ProgressWindow::create_objects(const char *text, int64_t length)
134 {
135         int x = 10, y = 10;
136         lock_window("BC_ProgressWindow::create_objects");
137 // Recalculate width based on text
138         if(text)
139         {
140                 int text_w = get_text_width(MEDIUMFONT, text);
141                 int new_w = text_w + x + 10, scr_w = get_screen_w(0, -1);
142                 if(new_w > scr_w) new_w = scr_w;
143                 if(new_w > get_w()) {
144                         resize_window(new_w, get_h());
145                 }
146         }
147
148         this->text = text;
149         add_tool(caption = new BC_Title(x, y, text));
150         y += caption->get_h() + 20;
151         add_tool(bar = new BC_ProgressBar(x, y, get_w() - 20, length));
152         add_tool(new BC_CancelButton(this));
153         show_window(1);
154         unlock_window();
155         return 0;
156 }
157
158
159
160