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 = (float)w / w1;
72 h_scale = (float)h / h1;
77 void ResizeVTrackThread::run()
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();
85 delete window; window = 0;
90 if(((w % 4) || (h % 4)) &&
91 mwindow->edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL)
93 MainError::show_error(
94 _("This track's dimensions are not multiples of 4 so\n"
95 "it can't be rendered by OpenGL."));
100 #define RSZ_W xS(330)
101 #define RSZ_H yS(120)
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)
108 this->mwindow = mwindow;
109 this->thread = thread;
112 ResizeVTrackWindow::~ResizeVTrackWindow()
116 void ResizeVTrackWindow::create_objects()
118 int xs5 = xS(5), xs10 = xS(10);
120 lock_window("ResizeVTrackWindow::create_objects");
121 int x = xs10, y = ys10;
122 BC_Title *size_title = new BC_Title(x, y, _("Size:"));
123 add_subwindow(size_title);
124 int x1 = x + size_title->get_w();
125 int y1 = y + size_title->get_h() + ys10;
126 BC_Title *scale_title = new BC_Title(x, y1, _("Scale:"));
127 add_subwindow(scale_title);
128 int x2 = x + scale_title->get_w();
129 if( x2 > x1 ) x1 = x2;
131 add_subwindow(w = new ResizeVTrackWidth(this, thread, x1, y));
132 x2 = x1 + w->get_w() + xs5;
133 BC_Title *xy = new BC_Title(x2, y, _("x"));
135 int x3 = x2 + xy->get_w() + xs5;
136 add_subwindow(h = new ResizeVTrackHeight(this, thread, x3, y));
137 x = x3 + h->get_w() + xs5;
138 FrameSizePulldown *pulldown;
139 add_subwindow(pulldown = new FrameSizePulldown(mwindow->theme, w, h, x, y));
140 x += pulldown->get_w() + xs5;
141 add_subwindow(new ResizeVTrackSwap(this, thread, x, y));
143 add_subwindow(w_scale = new ResizeVTrackScaleW(this, thread, x1, y1));
144 add_subwindow(new BC_Title(x2, y1, _("x")));
145 add_subwindow(h_scale = new ResizeVTrackScaleH(this, thread, x3, y1));
146 x = x3 + h_scale->get_w() + xs5;
147 add_subwindow(reset = new ResizeReset(this, thread, x, y1));
149 add_subwindow(new BC_OKButton(this));
150 add_subwindow(new BC_CancelButton(this));
157 void ResizeVTrackWindow::update(int changed_scale, int changed_size)
159 if( changed_scale ) {
160 thread->w = (int)(thread->w1 * thread->w_scale);
161 w->update((int64_t)thread->w);
162 thread->h = (int)(thread->h1 * thread->h_scale);
163 h->update((int64_t)thread->h);
166 thread->w_scale = thread->w1 ? (double)thread->w / thread->w1 : 1.;
167 w_scale->update((float)thread->w_scale);
168 thread->h_scale = thread->h1 ? (double)thread->h / thread->h1 : 1.;
169 h_scale->update((float)thread->h_scale);
176 ResizeVTrackSwap::ResizeVTrackSwap(ResizeVTrackWindow *gui,
177 ResizeVTrackThread *thread,
180 : BC_Button(x, y, thread->mwindow->theme->get_image_set("swap_extents"))
182 this->thread = thread;
184 set_tooltip(_("Swap dimensions"));
187 int ResizeVTrackSwap::handle_event()
193 gui->w->update((int64_t)h);
194 gui->h->update((int64_t)w);
204 ResizeVTrackWidth::ResizeVTrackWidth(ResizeVTrackWindow *gui,
205 ResizeVTrackThread *thread,
208 : BC_TextBox(x, y, xS(90), 1, thread->w)
211 this->thread = thread;
213 int ResizeVTrackWidth::handle_event()
215 thread->w = atol(get_text());
220 ResizeVTrackHeight::ResizeVTrackHeight(ResizeVTrackWindow *gui,
221 ResizeVTrackThread *thread,
224 : BC_TextBox(x, y, xS(90), 1, thread->h)
227 this->thread = thread;
229 int ResizeVTrackHeight::handle_event()
231 thread->h = atol(get_text());
237 ResizeVTrackScaleW::ResizeVTrackScaleW(ResizeVTrackWindow *gui,
238 ResizeVTrackThread *thread,
241 : BC_TextBox(x, y, xS(90), 1, (float)thread->w_scale)
244 this->thread = thread;
246 int ResizeVTrackScaleW::handle_event()
248 thread->w_scale = atof(get_text());
253 ResizeVTrackScaleH::ResizeVTrackScaleH(ResizeVTrackWindow *gui,
254 ResizeVTrackThread *thread,
257 : BC_TextBox(x, y, xS(90), 1, (float)thread->h_scale)
260 this->thread = thread;
262 int ResizeVTrackScaleH::handle_event()
264 thread->h_scale = atof(get_text());
270 ResizeReset::ResizeReset(ResizeVTrackWindow *gui,
271 ResizeVTrackThread *thread, int x, int y)
272 : BC_Button(x, y, thread->mwindow->theme->get_image_set("reset_button"))
275 this->thread = thread;
276 set_tooltip(_("Reset"));
278 int ResizeReset::handle_event()
280 thread->w = thread->w1;
281 thread->h = thread->h1;
290 ResizeTrackThread::ResizeTrackThread(MWindow *mwindow)
291 : ResizeVTrackThread(mwindow)
295 ResizeTrackThread::~ResizeTrackThread()
300 void ResizeTrackThread::start_window(Track *track)
303 ResizeVTrackThread::start_window(track->track_w,
309 void ResizeTrackThread::update()
311 if( mwindow->edl->tracks->track_exists(track) )
312 mwindow->resize_track(track, w, h);
318 ResizeAssetThread::ResizeAssetThread(AssetEditWindow *fwindow)
319 : ResizeVTrackThread(fwindow->mwindow)
321 this->fwindow = fwindow;
324 ResizeAssetThread::~ResizeAssetThread()
328 void ResizeAssetThread::start_window(Asset *asset)
331 ResizeVTrackThread::start_window(asset->get_w(),
334 asset->actual_height);
337 void ResizeAssetThread::update()
339 char string[BCTEXTLEN];
342 fwindow->lock_window("ResizeAssetThread::update");
343 sprintf(string, "%d", asset->width);
344 fwindow->win_width->update(string);
345 sprintf(string, "%d", asset->height);
346 fwindow->win_height->update(string);
347 fwindow->unlock_window();
350 ResizeAssetButton::ResizeAssetButton(AssetEditWindow *fwindow, int x, int y)
351 : BC_GenericButton(x, y, _("Resize"))
353 resize_asset_thread = 0;
354 this->fwindow = fwindow;
357 ResizeAssetButton::~ResizeAssetButton()
359 delete resize_asset_thread;
362 int ResizeAssetButton::handle_event()
364 if( !resize_asset_thread )
365 resize_asset_thread = new ResizeAssetThread(fwindow);
366 resize_asset_thread->start_window(fwindow->asset_edit->changed_params);