GLx4 w/h mult of 4 is not req, cwdw crop input range checks, fix cropp.png dir, chang...
[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
100
101
102 ResizeVTrackWindow::ResizeVTrackWindow(MWindow *mwindow,
103         ResizeVTrackThread *thread,
104         int x,
105         int y)
106  : BC_Window(_(PROGRAM_NAME ": Resize Track"),
107                                 x - 320 / 2, y - get_resources()->ok_images[0]->get_h() + 100 / 2,
108                                 400, get_resources()->ok_images[0]->get_h() + 100,
109                                 400, get_resources()->ok_images[0]->get_h() + 100,
110                                 0, 0, 1)
111 {
112         this->mwindow = mwindow;
113         this->thread = thread;
114 }
115
116 ResizeVTrackWindow::~ResizeVTrackWindow()
117 {
118 }
119
120 void ResizeVTrackWindow::create_objects()
121 {
122         lock_window("ResizeVTrackWindow::create_objects");
123         int x = 10, y = 10;
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         if( mwindow->edl->tracks->track_exists(track) )
303                 mwindow->resize_track(track, w, h);
304 }
305
306
307
308
309 ResizeAssetThread::ResizeAssetThread(AssetEditWindow *fwindow)
310  : ResizeVTrackThread(fwindow->mwindow)
311 {
312         this->fwindow = fwindow;
313 }
314
315 ResizeAssetThread::~ResizeAssetThread()
316 {
317 }
318
319 void ResizeAssetThread::start_window(Asset *asset)
320 {
321         this->asset = asset;
322         ResizeVTrackThread::start_window(asset->get_w(),
323                 asset->get_h(),
324                 asset->actual_width,
325                 asset->actual_height);
326 }
327
328 void ResizeAssetThread::update()
329 {
330         char string[BCTEXTLEN];
331         asset->width = w;
332         asset->height = h;
333         fwindow->lock_window("ResizeAssetThread::update");
334         sprintf(string, "%d", asset->width);
335         fwindow->win_width->update(string);
336         sprintf(string, "%d", asset->height);
337         fwindow->win_height->update(string);
338         fwindow->unlock_window();
339 }
340
341 ResizeAssetButton::ResizeAssetButton(AssetEditWindow *fwindow, int x, int y)
342  : BC_GenericButton(x, y, _("Resize"))
343 {
344         resize_asset_thread = 0;
345         this->fwindow = fwindow;
346 }
347
348 ResizeAssetButton::~ResizeAssetButton()
349 {
350         delete resize_asset_thread;
351 }
352
353 int ResizeAssetButton::handle_event()
354 {
355         if( !resize_asset_thread )
356                 resize_asset_thread = new ResizeAssetThread(fwindow);
357         resize_asset_thread->start_window(fwindow->asset_edit->changed_params);
358         return 1;
359 }
360
361