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