18 new shapewipe transitions from rafa, rework savefile/confirm for nested edl edits
[goodguy/cinelerra.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         if( window && running() ) {
64                 window->lock_window();
65                 window->raise_window();
66                 window->unlock_window();
67                 return;
68         }
69         this->w = w;    this->h = h;
70         this->w1 = w1;  this->h1 = h1;
71         w_scale = h_scale = 1;
72         start();
73 }
74
75
76 void ResizeVTrackThread::run()
77 {
78         window = new ResizeVTrackWindow(mwindow, this,
79                         mwindow->gui->get_abs_cursor_x(1),
80                         mwindow->gui->get_abs_cursor_y(1));
81         window->create_objects();
82         int result = window->run_window();
83
84         delete window;  window = 0;
85         if(!result) {
86                 update();
87         }
88 #ifdef GLx4
89         if(((w % 4) || (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 #endif
97 }
98
99 #define RSZ_W xS(320)
100 #define RSZ_H yS(120)
101
102 ResizeVTrackWindow::ResizeVTrackWindow(MWindow *mwindow,
103                 ResizeVTrackThread *thread, int x, int y)
104  : BC_Window(_(PROGRAM_NAME ": Resize Track"), x-RSZ_W/2, y-RSZ_H/2,
105                 RSZ_W, RSZ_H, RSZ_W, RSZ_H, 0, 0, 1)
106 {
107         this->mwindow = mwindow;
108         this->thread = thread;
109 }
110
111 ResizeVTrackWindow::~ResizeVTrackWindow()
112 {
113 }
114
115 void ResizeVTrackWindow::create_objects()
116 {
117         int xs5 = xS(5), xs10 = xS(10);
118         int ys10 = yS(10);
119         lock_window("ResizeVTrackWindow::create_objects");
120         int x = xs10, y = ys10;
121         BC_Title *size_title = new BC_Title(x, y, _("Size:"));
122         add_subwindow(size_title);
123         int x1 = x + size_title->get_w();
124         int y1 = y + size_title->get_h() + ys10;
125         BC_Title *scale_title = new BC_Title(x, y1, _("Scale:"));
126         add_subwindow(scale_title);
127         int x2 = x + scale_title->get_w();
128         if( x2 > x1 ) x1 = x2;
129         x1 += ys10;
130         add_subwindow(w = new ResizeVTrackWidth(this, thread, x1, y));
131         x2 = x1 + w->get_w() + xs5;
132         BC_Title *xy = new BC_Title(x2, y, _("x"));
133         add_subwindow(xy);
134         int x3 = x2 + xy->get_w() + xs5;
135         add_subwindow(h = new ResizeVTrackHeight(this, thread, x3, y));
136         x = x3 + h->get_w() + xs5;
137         FrameSizePulldown *pulldown;
138         add_subwindow(pulldown = new FrameSizePulldown(mwindow->theme, w, h, x, y));
139         x += pulldown->get_w() + xs5;
140         add_subwindow(new ResizeVTrackSwap(this, thread, x, y));
141
142         add_subwindow(w_scale = new ResizeVTrackScaleW(this, thread, x1, y1));
143         add_subwindow(new BC_Title(x2, y1, _("x")));
144         add_subwindow(h_scale = new ResizeVTrackScaleH(this, thread, x3, y1));
145
146         add_subwindow(new BC_OKButton(this));
147         add_subwindow(new BC_CancelButton(this));
148
149         show_window();
150         flush();
151         unlock_window();
152 }
153
154 void ResizeVTrackWindow::update(int changed_scale,
155         int changed_size,
156         int changed_all)
157 {
158 //printf("ResizeVTrackWindow::update %d %d %d\n", changed_scale, changed_size, changed_all);
159         if(changed_scale || changed_all)
160         {
161                 thread->w = (int)(thread->w1 * thread->w_scale);
162                 w->update((int64_t)thread->w);
163                 thread->h = (int)(thread->h1 * thread->h_scale);
164                 h->update((int64_t)thread->h);
165         }
166         else
167         if(changed_size || changed_all)
168         {
169                 thread->w_scale = thread->w1 ? (double)thread->w / thread->w1 : 1.;
170                 w_scale->update((float)thread->w_scale);
171                 thread->h_scale = thread->h1 ? (double)thread->h / thread->h1 : 1.;
172                 h_scale->update((float)thread->h_scale);
173         }
174 }
175
176
177
178
179
180
181 ResizeVTrackSwap::ResizeVTrackSwap(ResizeVTrackWindow *gui,
182         ResizeVTrackThread *thread,
183         int x,
184         int y)
185  : BC_Button(x, y, thread->mwindow->theme->get_image_set("swap_extents"))
186 {
187         this->thread = thread;
188         this->gui = gui;
189         set_tooltip(_("Swap dimensions"));
190 }
191
192 int ResizeVTrackSwap::handle_event()
193 {
194         int w = thread->w;
195         int h = thread->h;
196         thread->w = h;
197         thread->h = w;
198         gui->w->update((int64_t)h);
199         gui->h->update((int64_t)w);
200         gui->update(0, 1, 0);
201         return 1;
202 }
203
204
205
206
207
208
209 ResizeVTrackWidth::ResizeVTrackWidth(ResizeVTrackWindow *gui,
210         ResizeVTrackThread *thread,
211         int x,
212         int y)
213  : BC_TextBox(x, y, xS(90), 1, thread->w)
214 {
215         this->gui = gui;
216         this->thread = thread;
217 }
218 int ResizeVTrackWidth::handle_event()
219 {
220         thread->w = atol(get_text());
221         gui->update(0, 1, 0);
222         return 1;
223 }
224
225 ResizeVTrackHeight::ResizeVTrackHeight(ResizeVTrackWindow *gui,
226         ResizeVTrackThread *thread,
227         int x,
228         int y)
229  : BC_TextBox(x, y, xS(90), 1, thread->h)
230 {
231         this->gui = gui;
232         this->thread = thread;
233 }
234 int ResizeVTrackHeight::handle_event()
235 {
236         thread->h = atol(get_text());
237         gui->update(0, 1, 0);
238         return 1;
239 }
240
241
242 ResizeVTrackScaleW::ResizeVTrackScaleW(ResizeVTrackWindow *gui,
243         ResizeVTrackThread *thread,
244         int x,
245         int y)
246  : BC_TextBox(x, y, xS(90), 1, (float)thread->w_scale)
247 {
248         this->gui = gui;
249         this->thread = thread;
250 }
251 int ResizeVTrackScaleW::handle_event()
252 {
253         thread->w_scale = atof(get_text());
254         gui->update(1, 0, 0);
255         return 1;
256 }
257
258 ResizeVTrackScaleH::ResizeVTrackScaleH(ResizeVTrackWindow *gui,
259         ResizeVTrackThread *thread,
260         int x,
261         int y)
262  : BC_TextBox(x, y, xS(90), 1, (float)thread->h_scale)
263 {
264         this->gui = gui;
265         this->thread = thread;
266 }
267 int ResizeVTrackScaleH::handle_event()
268 {
269         thread->h_scale = atof(get_text());
270         gui->update(1, 0, 0);
271         return 1;
272 }
273
274
275
276
277
278 ResizeTrackThread::ResizeTrackThread(MWindow *mwindow)
279  : ResizeVTrackThread(mwindow)
280 {
281 }
282
283 ResizeTrackThread::~ResizeTrackThread()
284 {
285 }
286
287
288 void ResizeTrackThread::start_window(Track *track)
289 {
290         this->track= track;
291         ResizeVTrackThread::start_window(track->track_w,
292                 track->track_h,
293                 track->track_w,
294                 track->track_h);
295 }
296
297 void ResizeTrackThread::update()
298 {
299         if( mwindow->edl->tracks->track_exists(track) )
300                 mwindow->resize_track(track, w, h);
301 }
302
303
304
305
306 ResizeAssetThread::ResizeAssetThread(AssetEditWindow *fwindow)
307  : ResizeVTrackThread(fwindow->mwindow)
308 {
309         this->fwindow = fwindow;
310 }
311
312 ResizeAssetThread::~ResizeAssetThread()
313 {
314 }
315
316 void ResizeAssetThread::start_window(Asset *asset)
317 {
318         this->asset = asset;
319         ResizeVTrackThread::start_window(asset->get_w(),
320                 asset->get_h(),
321                 asset->actual_width,
322                 asset->actual_height);
323 }
324
325 void ResizeAssetThread::update()
326 {
327         char string[BCTEXTLEN];
328         asset->width = w;
329         asset->height = h;
330         fwindow->lock_window("ResizeAssetThread::update");
331         sprintf(string, "%d", asset->width);
332         fwindow->win_width->update(string);
333         sprintf(string, "%d", asset->height);
334         fwindow->win_height->update(string);
335         fwindow->unlock_window();
336 }
337
338 ResizeAssetButton::ResizeAssetButton(AssetEditWindow *fwindow, int x, int y)
339  : BC_GenericButton(x, y, _("Resize"))
340 {
341         resize_asset_thread = 0;
342         this->fwindow = fwindow;
343 }
344
345 ResizeAssetButton::~ResizeAssetButton()
346 {
347         delete resize_asset_thread;
348 }
349
350 int ResizeAssetButton::handle_event()
351 {
352         if( !resize_asset_thread )
353                 resize_asset_thread = new ResizeAssetThread(fwindow);
354         resize_asset_thread->start_window(fwindow->asset_edit->changed_params);
355         return 1;
356 }
357
358