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 if( window && running() ) {
64 window->lock_window();
65 window->raise_window();
66 window->unlock_window();
69 this->w = w; this->h = h;
70 this->w1 = w1; this->h1 = h1;
71 w_scale = h_scale = 1;
76 void ResizeVTrackThread::run()
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();
84 delete window; window = 0;
89 if(((w % 4) || (h % 4)) &&
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"),
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,
111 this->mwindow = mwindow;
112 this->thread = thread;
115 ResizeVTrackWindow::~ResizeVTrackWindow()
119 void ResizeVTrackWindow::create_objects()
121 lock_window("ResizeVTrackWindow::create_objects");
123 BC_Title *size_title = new BC_Title(x, y, _("Size:"));
124 add_subwindow(size_title);
125 int x1 = x + size_title->get_w();
126 int y1 = y + size_title->get_h() + 10;
127 BC_Title *scale_title = new BC_Title(x, y1, _("Scale:"));
128 add_subwindow(scale_title);
129 int x2 = x + scale_title->get_w();
130 if( x2 > x1 ) x1 = x2;
132 add_subwindow(w = new ResizeVTrackWidth(this, thread, x1, y));
133 x2 = x1 + w->get_w() + 5;
134 BC_Title *xy = new BC_Title(x2, y, _("x"));
136 int x3 = x2 + xy->get_w() + 5;
137 add_subwindow(h = new ResizeVTrackHeight(this, thread, x3, y));
138 x = x3 + h->get_w() + 5;
139 FrameSizePulldown *pulldown;
140 add_subwindow(pulldown = new FrameSizePulldown(mwindow->theme, w, h, x, y));
141 x += pulldown->get_w() + 5;
142 add_subwindow(new ResizeVTrackSwap(this, thread, x, y));
144 add_subwindow(w_scale = new ResizeVTrackScaleW(this, thread, x1, y1));
145 add_subwindow(new BC_Title(x2, y1, _("x")));
146 add_subwindow(h_scale = new ResizeVTrackScaleH(this, thread, x3, y1));
148 add_subwindow(new BC_OKButton(this));
149 add_subwindow(new BC_CancelButton(this));
156 void ResizeVTrackWindow::update(int changed_scale,
160 //printf("ResizeVTrackWindow::update %d %d %d\n", changed_scale, changed_size, changed_all);
161 if(changed_scale || changed_all)
163 thread->w = (int)(thread->w1 * thread->w_scale);
164 w->update((int64_t)thread->w);
165 thread->h = (int)(thread->h1 * thread->h_scale);
166 h->update((int64_t)thread->h);
169 if(changed_size || changed_all)
171 thread->w_scale = thread->w1 ? (double)thread->w / thread->w1 : 1.;
172 w_scale->update((float)thread->w_scale);
173 thread->h_scale = thread->h1 ? (double)thread->h / thread->h1 : 1.;
174 h_scale->update((float)thread->h_scale);
183 ResizeVTrackSwap::ResizeVTrackSwap(ResizeVTrackWindow *gui,
184 ResizeVTrackThread *thread,
187 : BC_Button(x, y, thread->mwindow->theme->get_image_set("swap_extents"))
189 this->thread = thread;
191 set_tooltip(_("Swap dimensions"));
194 int ResizeVTrackSwap::handle_event()
200 gui->w->update((int64_t)h);
201 gui->h->update((int64_t)w);
202 gui->update(0, 1, 0);
211 ResizeVTrackWidth::ResizeVTrackWidth(ResizeVTrackWindow *gui,
212 ResizeVTrackThread *thread,
215 : BC_TextBox(x, y, 90, 1, thread->w)
218 this->thread = thread;
220 int ResizeVTrackWidth::handle_event()
222 thread->w = atol(get_text());
223 gui->update(0, 1, 0);
227 ResizeVTrackHeight::ResizeVTrackHeight(ResizeVTrackWindow *gui,
228 ResizeVTrackThread *thread,
231 : BC_TextBox(x, y, 90, 1, thread->h)
234 this->thread = thread;
236 int ResizeVTrackHeight::handle_event()
238 thread->h = atol(get_text());
239 gui->update(0, 1, 0);
244 ResizeVTrackScaleW::ResizeVTrackScaleW(ResizeVTrackWindow *gui,
245 ResizeVTrackThread *thread,
248 : BC_TextBox(x, y, 90, 1, (float)thread->w_scale)
251 this->thread = thread;
253 int ResizeVTrackScaleW::handle_event()
255 thread->w_scale = atof(get_text());
256 gui->update(1, 0, 0);
260 ResizeVTrackScaleH::ResizeVTrackScaleH(ResizeVTrackWindow *gui,
261 ResizeVTrackThread *thread,
264 : BC_TextBox(x, y, 90, 1, (float)thread->h_scale)
267 this->thread = thread;
269 int ResizeVTrackScaleH::handle_event()
271 thread->h_scale = atof(get_text());
272 gui->update(1, 0, 0);
280 ResizeTrackThread::ResizeTrackThread(MWindow *mwindow)
281 : ResizeVTrackThread(mwindow)
285 ResizeTrackThread::~ResizeTrackThread()
290 void ResizeTrackThread::start_window(Track *track)
293 ResizeVTrackThread::start_window(track->track_w,
299 void ResizeTrackThread::update()
301 if( mwindow->edl->tracks->track_exists(track) )
302 mwindow->resize_track(track, w, h);
308 ResizeAssetThread::ResizeAssetThread(AssetEditWindow *fwindow)
309 : ResizeVTrackThread(fwindow->mwindow)
311 this->fwindow = fwindow;
314 ResizeAssetThread::~ResizeAssetThread()
318 void ResizeAssetThread::start_window(Asset *asset)
321 ResizeVTrackThread::start_window(asset->get_w(),
324 asset->actual_height);
327 void ResizeAssetThread::update()
329 char string[BCTEXTLEN];
332 sprintf(string, "%d", asset->width);
333 fwindow->win_width->update(string);
334 sprintf(string, "%d", asset->height);
335 fwindow->win_height->update(string);
338 ResizeAssetButton::ResizeAssetButton(AssetEditWindow *fwindow, int x, int y)
339 : BC_GenericButton(x, y, _("Resize"))
341 resize_asset_thread = 0;
342 this->fwindow = fwindow;
346 ResizeAssetButton::~ResizeAssetButton()
348 delete resize_asset_thread;
351 int ResizeAssetButton::handle_event()
353 if( !resize_asset_thread )
354 resize_asset_thread = new ResizeAssetThread(fwindow);
355 resize_asset_thread->start_window(fwindow->asset_edit->changed_params);