update cin.po, goog xlat update xx.po
[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, y - get_resources()->ok_images[0]->get_h() + 100 / 2,
107                                 400, get_resources()->ok_images[0]->get_h() + 100,
108                                 400, get_resources()->ok_images[0]->get_h() + 100,
109                                 0, 0, 1)
110 {
111         this->mwindow = mwindow;
112         this->thread = thread;
113 }
114
115 ResizeVTrackWindow::~ResizeVTrackWindow()
116 {
117 }
118
119 void ResizeVTrackWindow::create_objects()
120 {
121         int x = 10, y = 10;
122
123         lock_window("ResizeVTrackWindow::create_objects");
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() + 10;
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 += 10;
133         add_subwindow(w = new ResizeVTrackWidth(this, thread, x1, y));
134         x2 = x1 + w->get_w() + 5;
135         BC_Title *xy = new BC_Title(x2, y, _("x"));
136         add_subwindow(xy);
137         int x3 = x2 + xy->get_w() + 5;
138         add_subwindow(h = new ResizeVTrackHeight(this, thread, x3, y));
139         x = x3 + h->get_w() + 5;
140         FrameSizePulldown *pulldown;
141         add_subwindow(pulldown = new FrameSizePulldown(mwindow->theme, w, h, x, y));
142         x += pulldown->get_w() + 5;
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
149         add_subwindow(new BC_OKButton(this));
150         add_subwindow(new BC_CancelButton(this));
151
152         show_window();
153         flush();
154         unlock_window();
155 }
156
157 void ResizeVTrackWindow::update(int changed_scale, 
158         int changed_size, 
159         int changed_all)
160 {
161 //printf("ResizeVTrackWindow::update %d %d %d\n", changed_scale, changed_size, changed_all);
162         if(changed_scale || changed_all)
163         {
164                 thread->w = (int)(thread->w1 * thread->w_scale);
165                 w->update((int64_t)thread->w);
166                 thread->h = (int)(thread->h1 * thread->h_scale);
167                 h->update((int64_t)thread->h);
168         }
169         else
170         if(changed_size || changed_all)
171         {
172                 thread->w_scale = thread->w1 ? (double)thread->w / thread->w1 : 1.;
173                 w_scale->update((float)thread->w_scale);
174                 thread->h_scale = thread->h1 ? (double)thread->h / thread->h1 : 1.;
175                 h_scale->update((float)thread->h_scale);
176         }
177 }
178
179
180
181
182
183
184 ResizeVTrackSwap::ResizeVTrackSwap(ResizeVTrackWindow *gui, 
185         ResizeVTrackThread *thread, 
186         int x, 
187         int y)
188  : BC_Button(x, y, thread->mwindow->theme->get_image_set("swap_extents"))
189 {
190         this->thread = thread;
191         this->gui = gui;
192         set_tooltip(_("Swap dimensions"));
193 }
194
195 int ResizeVTrackSwap::handle_event()
196 {
197         int w = thread->w;
198         int h = thread->h;
199         thread->w = h;
200         thread->h = w;
201         gui->w->update((int64_t)h);
202         gui->h->update((int64_t)w);
203         gui->update(0, 1, 0);
204         return 1;
205 }
206
207
208
209
210
211
212 ResizeVTrackWidth::ResizeVTrackWidth(ResizeVTrackWindow *gui, 
213         ResizeVTrackThread *thread,
214         int x,
215         int y)
216  : BC_TextBox(x, y, 90, 1, thread->w)
217 {
218         this->gui = gui;
219         this->thread = thread;
220 }
221 int ResizeVTrackWidth::handle_event()
222 {
223         thread->w = atol(get_text());
224         gui->update(0, 1, 0);
225         return 1;
226 }
227
228 ResizeVTrackHeight::ResizeVTrackHeight(ResizeVTrackWindow *gui, 
229         ResizeVTrackThread *thread,
230         int x,
231         int y)
232  : BC_TextBox(x, y, 90, 1, thread->h)
233 {
234         this->gui = gui;
235         this->thread = thread;
236 }
237 int ResizeVTrackHeight::handle_event()
238 {
239         thread->h = atol(get_text());
240         gui->update(0, 1, 0);
241         return 1;
242 }
243
244
245 ResizeVTrackScaleW::ResizeVTrackScaleW(ResizeVTrackWindow *gui, 
246         ResizeVTrackThread *thread,
247         int x,
248         int y)
249  : BC_TextBox(x, y, 90, 1, (float)thread->w_scale)
250 {
251         this->gui = gui;
252         this->thread = thread;
253 }
254 int ResizeVTrackScaleW::handle_event()
255 {
256         thread->w_scale = atof(get_text());
257         gui->update(1, 0, 0);
258         return 1;
259 }
260
261 ResizeVTrackScaleH::ResizeVTrackScaleH(ResizeVTrackWindow *gui, 
262         ResizeVTrackThread *thread,
263         int x,
264         int y)
265  : BC_TextBox(x, y, 90, 1, (float)thread->h_scale)
266 {
267         this->gui = gui;
268         this->thread = thread;
269 }
270 int ResizeVTrackScaleH::handle_event()
271 {
272         thread->h_scale = atof(get_text());
273         gui->update(1, 0, 0);
274         return 1;
275 }
276
277
278
279
280
281 ResizeTrackThread::ResizeTrackThread(MWindow *mwindow)
282  : ResizeVTrackThread(mwindow)
283 {
284 }
285
286 ResizeTrackThread::~ResizeTrackThread()
287 {
288 }
289
290
291 void ResizeTrackThread::start_window(Track *track)
292 {
293         this->track= track;
294         ResizeVTrackThread::start_window(track->track_w,
295                 track->track_h,
296                 track->track_w,
297                 track->track_h);
298 }
299
300 void ResizeTrackThread::update()
301 {
302         mwindow->resize_track(track, w, h);
303 }
304
305
306
307
308 ResizeAssetThread::ResizeAssetThread(AssetEditWindow *fwindow)
309  : ResizeVTrackThread(fwindow->mwindow)
310 {
311         this->fwindow = fwindow;
312 }
313
314 ResizeAssetThread::~ResizeAssetThread()
315 {
316 }
317
318 void ResizeAssetThread::start_window(Asset *asset)
319 {
320         this->asset = asset;
321         ResizeVTrackThread::start_window(asset->get_w(),
322                 asset->get_h(),
323                 asset->actual_width,
324                 asset->actual_height);
325 }
326
327 void ResizeAssetThread::update()
328 {
329         char string[BCTEXTLEN];
330         asset->width = w;
331         asset->height = h;
332         sprintf(string, "%d", asset->width);
333         fwindow->win_width->update(string);
334         sprintf(string, "%d", asset->height);
335         fwindow->win_height->update(string);
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         set_underline(0);
344 }
345
346 ResizeAssetButton::~ResizeAssetButton()
347 {
348         delete resize_asset_thread;
349 }
350
351 int ResizeAssetButton::handle_event()
352 {
353         resize_asset_thread = new ResizeAssetThread(fwindow);
354         resize_asset_thread->start_window(fwindow->asset_edit->changed_params);
355         return 1;
356 }
357
358