prevent popup deactivation while button_down
[goodguy/history.git] / cinelerra-5.1 / cinelerra / resizetrackthread.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 "asset.h"
23 #include "assetedit.h"
24 #include "edl.h"
25 #include "edlsession.h"
26 #include "language.h"
27 #include "mainerror.h"
28 #include "mainundo.h"
29 #include "mwindow.h"
30 #include "mwindowgui.h"
31 #include "new.h"
32 #include "resizetrackthread.h"
33 #include "theme.h"
34 #include "track.h"
35 #include "tracks.h"
36
37
38
39
40
41
42 ResizeVTrackThread::ResizeVTrackThread(MWindow *mwindow)
43  : Thread(1, 0, 0)
44 {
45         this->mwindow = mwindow;
46         window = 0;
47 }
48
49 ResizeVTrackThread::~ResizeVTrackThread()
50 {
51         if(window)
52         {
53                 window->lock_window();
54                 window->set_done(1);
55                 window->unlock_window();
56         }
57
58         Thread::join();
59 }
60
61 void ResizeVTrackThread::start_window(int w, int h, int w1, int h1)
62 {
63         this->w = w;    this->h = h;
64         this->w1 = w1;  this->h1 = h1;
65         w_scale = h_scale = 1;
66         start();
67 }
68
69
70 void ResizeVTrackThread::run()
71 {
72         ResizeVTrackWindow *window = this->window = 
73                 new ResizeVTrackWindow(mwindow, 
74                         this,
75                         mwindow->gui->get_abs_cursor_x(1),
76                         mwindow->gui->get_abs_cursor_y(1));
77         window->create_objects();
78         int result = window->run_window();
79         this->window = 0;
80         delete window;
81
82
83         if(!result)
84         {
85                 update();
86         }
87
88         if(((w % 4) || 
89                 (h % 4)) && 
90                 mwindow->edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL)
91         {
92                 MainError::show_error(
93                         _("This track's dimensions are not multiples of 4 so\n"
94                         "it can't be rendered by OpenGL."));
95         }
96 }
97
98
99
100
101 ResizeVTrackWindow::ResizeVTrackWindow(MWindow *mwindow, 
102         ResizeVTrackThread *thread,
103         int x,
104         int y)
105  : BC_Window(_(PROGRAM_NAME ": Resize Track"), 
106                                 x - 320 / 2,
107                                 y - get_resources()->ok_images[0]->get_h() + 100 / 2,
108                                 340, 
109                                 get_resources()->ok_images[0]->get_h() + 100, 
110                                 340, 
111                                 get_resources()->ok_images[0]->get_h() + 100, 
112                                 0,
113                                 0, 
114                                 1)
115 {
116         this->mwindow = mwindow;
117         this->thread = thread;
118 }
119
120 ResizeVTrackWindow::~ResizeVTrackWindow()
121 {
122 }
123
124 void ResizeVTrackWindow::create_objects()
125 {
126         int x = 10, y = 10;
127
128         lock_window("ResizeVTrackWindow::create_objects");
129         add_subwindow(new BC_Title(x, y, _("Size:")));
130         x += 50;
131         add_subwindow(w = new ResizeVTrackWidth(this, 
132                 thread,
133                 x,
134                 y));
135         x += w->get_w() + 10;
136         add_subwindow(new BC_Title(x, y, _("x")));
137         x += 15;
138         add_subwindow(h = new ResizeVTrackHeight(this, 
139                 thread,
140                 x,
141                 y));
142         x += h->get_w() + 5;
143         FrameSizePulldown *pulldown;
144         add_subwindow(pulldown = new FrameSizePulldown(mwindow->theme, 
145                 w, 
146                 h, 
147                 x, 
148                 y));
149         x += pulldown->get_w() + 5;
150         add_subwindow(new ResizeVTrackSwap(this, thread, x, y));
151
152
153         y += 30;
154         x = 10;
155         add_subwindow(new BC_Title(x, y, _("Scale:")));
156         x += 50;
157         add_subwindow(w_scale = new ResizeVTrackScaleW(this, 
158                 thread,
159                 x,
160                 y));
161         x += 100;
162         add_subwindow(new BC_Title(x, y, _("x")));
163         x += 15;
164         add_subwindow(h_scale = new ResizeVTrackScaleH(this, 
165                 thread,
166                 x,
167                 y));
168
169         add_subwindow(new BC_OKButton(this));
170         add_subwindow(new BC_CancelButton(this));
171
172         show_window();
173         flush();
174         unlock_window();
175 }
176
177 void ResizeVTrackWindow::update(int changed_scale, 
178         int changed_size, 
179         int changed_all)
180 {
181 //printf("ResizeVTrackWindow::update %d %d %d\n", changed_scale, changed_size, changed_all);
182         if(changed_scale || changed_all)
183         {
184                 thread->w = (int)(thread->w1 * thread->w_scale);
185                 w->update((int64_t)thread->w);
186                 thread->h = (int)(thread->h1 * thread->h_scale);
187                 h->update((int64_t)thread->h);
188         }
189         else
190         if(changed_size || changed_all)
191         {
192                 thread->w_scale = thread->w1 ? (double)thread->w / thread->w1 : 1.;
193                 w_scale->update((float)thread->w_scale);
194                 thread->h_scale = thread->h1 ? (double)thread->h / thread->h1 : 1.;
195                 h_scale->update((float)thread->h_scale);
196         }
197 }
198
199
200
201
202
203
204 ResizeVTrackSwap::ResizeVTrackSwap(ResizeVTrackWindow *gui, 
205         ResizeVTrackThread *thread, 
206         int x, 
207         int y)
208  : BC_Button(x, y, thread->mwindow->theme->get_image_set("swap_extents"))
209 {
210         this->thread = thread;
211         this->gui = gui;
212         set_tooltip(_("Swap dimensions"));
213 }
214
215 int ResizeVTrackSwap::handle_event()
216 {
217         int w = thread->w;
218         int h = thread->h;
219         thread->w = h;
220         thread->h = w;
221         gui->w->update((int64_t)h);
222         gui->h->update((int64_t)w);
223         gui->update(0, 1, 0);
224         return 1;
225 }
226
227
228
229
230
231
232 ResizeVTrackWidth::ResizeVTrackWidth(ResizeVTrackWindow *gui, 
233         ResizeVTrackThread *thread,
234         int x,
235         int y)
236  : BC_TextBox(x, y, 90, 1, thread->w)
237 {
238         this->gui = gui;
239         this->thread = thread;
240 }
241 int ResizeVTrackWidth::handle_event()
242 {
243         thread->w = atol(get_text());
244         gui->update(0, 1, 0);
245         return 1;
246 }
247
248 ResizeVTrackHeight::ResizeVTrackHeight(ResizeVTrackWindow *gui, 
249         ResizeVTrackThread *thread,
250         int x,
251         int y)
252  : BC_TextBox(x, y, 90, 1, thread->h)
253 {
254         this->gui = gui;
255         this->thread = thread;
256 }
257 int ResizeVTrackHeight::handle_event()
258 {
259         thread->h = atol(get_text());
260         gui->update(0, 1, 0);
261         return 1;
262 }
263
264
265 ResizeVTrackScaleW::ResizeVTrackScaleW(ResizeVTrackWindow *gui, 
266         ResizeVTrackThread *thread,
267         int x,
268         int y)
269  : BC_TextBox(x, y, 90, 1, (float)thread->w_scale)
270 {
271         this->gui = gui;
272         this->thread = thread;
273 }
274 int ResizeVTrackScaleW::handle_event()
275 {
276         thread->w_scale = atof(get_text());
277         gui->update(1, 0, 0);
278         return 1;
279 }
280
281 ResizeVTrackScaleH::ResizeVTrackScaleH(ResizeVTrackWindow *gui, 
282         ResizeVTrackThread *thread,
283         int x,
284         int y)
285  : BC_TextBox(x, y, 90, 1, (float)thread->h_scale)
286 {
287         this->gui = gui;
288         this->thread = thread;
289 }
290 int ResizeVTrackScaleH::handle_event()
291 {
292         thread->h_scale = atof(get_text());
293         gui->update(1, 0, 0);
294         return 1;
295 }
296
297
298
299
300
301 ResizeTrackThread::ResizeTrackThread(MWindow *mwindow)
302  : ResizeVTrackThread(mwindow)
303 {
304 }
305
306 ResizeTrackThread::~ResizeTrackThread()
307 {
308 }
309
310
311 void ResizeTrackThread::start_window(Track *track)
312 {
313         this->track= track;
314         ResizeVTrackThread::start_window(track->track_w,
315                 track->track_h,
316                 track->track_w,
317                 track->track_h);
318 }
319
320 void ResizeTrackThread::update()
321 {
322         mwindow->resize_track(track, w, h);
323 }
324
325
326
327
328 ResizeAssetThread::ResizeAssetThread(AssetEditWindow *fwindow)
329  : ResizeVTrackThread(fwindow->mwindow)
330 {
331         this->fwindow = fwindow;
332 }
333
334 ResizeAssetThread::~ResizeAssetThread()
335 {
336 }
337
338 void ResizeAssetThread::start_window(Asset *asset)
339 {
340         this->asset = asset;
341         ResizeVTrackThread::start_window(asset->get_w(),
342                 asset->get_h(),
343                 asset->actual_width,
344                 asset->actual_height);
345 }
346
347 void ResizeAssetThread::update()
348 {
349         char string[BCTEXTLEN];
350         asset->width = w;
351         asset->height = h;
352         sprintf(string, "%d", asset->width);
353         fwindow->win_width->update(string);
354         sprintf(string, "%d", asset->height);
355         fwindow->win_height->update(string);
356 }
357
358 ResizeAssetButton::ResizeAssetButton(AssetEditWindow *fwindow, int x, int y)
359  : BC_GenericButton(x, y, _("Resize"))
360 {
361         resize_asset_thread = 0;
362         this->fwindow = fwindow;
363         set_underline(0);
364 }
365
366 ResizeAssetButton::~ResizeAssetButton()
367 {
368         delete resize_asset_thread;
369 }
370
371 int ResizeAssetButton::handle_event()
372 {
373         resize_asset_thread = new ResizeAssetThread(fwindow);
374         resize_asset_thread->start_window(fwindow->asset_edit->changed_params);
375         return 1;
376 }
377
378