4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
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.
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.
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
23 #include "assetedit.h"
25 #include "edlsession.h"
27 #include "mainerror.h"
30 #include "mwindowgui.h"
32 #include "resizetrackthread.h"
42 ResizeVTrackThread::ResizeVTrackThread(MWindow *mwindow)
45 this->mwindow = mwindow;
49 ResizeVTrackThread::~ResizeVTrackThread()
53 window->lock_window();
55 window->unlock_window();
61 void ResizeVTrackThread::start_window(int w, int h, int w1, int h1)
63 this->w = w; this->h = h;
64 this->w1 = w1; this->h1 = h1;
65 w_scale = h_scale = 1;
70 void ResizeVTrackThread::run()
72 ResizeVTrackWindow *window = this->window =
73 new ResizeVTrackWindow(mwindow,
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();
90 mwindow->edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL)
92 MainError::show_error(
93 _("This track's dimensions are not multiples of 4 so\n"
94 "it can't be rendered by OpenGL."));
101 ResizeVTrackWindow::ResizeVTrackWindow(MWindow *mwindow,
102 ResizeVTrackThread *thread,
105 : BC_Window(_(PROGRAM_NAME ": Resize Track"),
107 y - get_resources()->ok_images[0]->get_h() + 100 / 2,
109 get_resources()->ok_images[0]->get_h() + 100,
111 get_resources()->ok_images[0]->get_h() + 100,
116 this->mwindow = mwindow;
117 this->thread = thread;
120 ResizeVTrackWindow::~ResizeVTrackWindow()
124 void ResizeVTrackWindow::create_objects()
128 lock_window("ResizeVTrackWindow::create_objects");
129 add_subwindow(new BC_Title(x, y, _("Size:")));
131 add_subwindow(w = new ResizeVTrackWidth(this,
135 x += w->get_w() + 10;
136 add_subwindow(new BC_Title(x, y, _("x")));
138 add_subwindow(h = new ResizeVTrackHeight(this,
143 FrameSizePulldown *pulldown;
144 add_subwindow(pulldown = new FrameSizePulldown(mwindow->theme,
149 x += pulldown->get_w() + 5;
150 add_subwindow(new ResizeVTrackSwap(this, thread, x, y));
155 add_subwindow(new BC_Title(x, y, _("Scale:")));
157 add_subwindow(w_scale = new ResizeVTrackScaleW(this,
162 add_subwindow(new BC_Title(x, y, _("x")));
164 add_subwindow(h_scale = new ResizeVTrackScaleH(this,
169 add_subwindow(new BC_OKButton(this));
170 add_subwindow(new BC_CancelButton(this));
177 void ResizeVTrackWindow::update(int changed_scale,
181 //printf("ResizeVTrackWindow::update %d %d %d\n", changed_scale, changed_size, changed_all);
182 if(changed_scale || changed_all)
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);
190 if(changed_size || changed_all)
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);
204 ResizeVTrackSwap::ResizeVTrackSwap(ResizeVTrackWindow *gui,
205 ResizeVTrackThread *thread,
208 : BC_Button(x, y, thread->mwindow->theme->get_image_set("swap_extents"))
210 this->thread = thread;
212 set_tooltip(_("Swap dimensions"));
215 int ResizeVTrackSwap::handle_event()
221 gui->w->update((int64_t)h);
222 gui->h->update((int64_t)w);
223 gui->update(0, 1, 0);
232 ResizeVTrackWidth::ResizeVTrackWidth(ResizeVTrackWindow *gui,
233 ResizeVTrackThread *thread,
236 : BC_TextBox(x, y, 90, 1, thread->w)
239 this->thread = thread;
241 int ResizeVTrackWidth::handle_event()
243 thread->w = atol(get_text());
244 gui->update(0, 1, 0);
248 ResizeVTrackHeight::ResizeVTrackHeight(ResizeVTrackWindow *gui,
249 ResizeVTrackThread *thread,
252 : BC_TextBox(x, y, 90, 1, thread->h)
255 this->thread = thread;
257 int ResizeVTrackHeight::handle_event()
259 thread->h = atol(get_text());
260 gui->update(0, 1, 0);
265 ResizeVTrackScaleW::ResizeVTrackScaleW(ResizeVTrackWindow *gui,
266 ResizeVTrackThread *thread,
269 : BC_TextBox(x, y, 90, 1, (float)thread->w_scale)
272 this->thread = thread;
274 int ResizeVTrackScaleW::handle_event()
276 thread->w_scale = atof(get_text());
277 gui->update(1, 0, 0);
281 ResizeVTrackScaleH::ResizeVTrackScaleH(ResizeVTrackWindow *gui,
282 ResizeVTrackThread *thread,
285 : BC_TextBox(x, y, 90, 1, (float)thread->h_scale)
288 this->thread = thread;
290 int ResizeVTrackScaleH::handle_event()
292 thread->h_scale = atof(get_text());
293 gui->update(1, 0, 0);
301 ResizeTrackThread::ResizeTrackThread(MWindow *mwindow)
302 : ResizeVTrackThread(mwindow)
306 ResizeTrackThread::~ResizeTrackThread()
311 void ResizeTrackThread::start_window(Track *track)
314 ResizeVTrackThread::start_window(track->track_w,
320 void ResizeTrackThread::update()
322 mwindow->resize_track(track, w, h);
328 ResizeAssetThread::ResizeAssetThread(AssetEditWindow *fwindow)
329 : ResizeVTrackThread(fwindow->mwindow)
331 this->fwindow = fwindow;
334 ResizeAssetThread::~ResizeAssetThread()
338 void ResizeAssetThread::start_window(Asset *asset)
341 ResizeVTrackThread::start_window(asset->get_w(),
344 asset->actual_height);
347 void ResizeAssetThread::update()
349 char string[BCTEXTLEN];
352 sprintf(string, "%d", asset->width);
353 fwindow->win_width->update(string);
354 sprintf(string, "%d", asset->height);
355 fwindow->win_height->update(string);
358 ResizeAssetButton::ResizeAssetButton(AssetEditWindow *fwindow, int x, int y)
359 : BC_GenericButton(x, y, _("Resize"))
361 resize_asset_thread = 0;
362 this->fwindow = fwindow;
366 ResizeAssetButton::~ResizeAssetButton()
368 delete resize_asset_thread;
371 int ResizeAssetButton::handle_event()
373 resize_asset_thread = new ResizeAssetThread(fwindow);
374 resize_asset_thread->start_window(fwindow->asset_edit->changed_params);