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"),
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()
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;
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"));
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));
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));
149 add_subwindow(new BC_OKButton(this));
150 add_subwindow(new BC_CancelButton(this));
157 void ResizeVTrackWindow::update(int changed_scale,
161 //printf("ResizeVTrackWindow::update %d %d %d\n", changed_scale, changed_size, changed_all);
162 if(changed_scale || changed_all)
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);
170 if(changed_size || changed_all)
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);
184 ResizeVTrackSwap::ResizeVTrackSwap(ResizeVTrackWindow *gui,
185 ResizeVTrackThread *thread,
188 : BC_Button(x, y, thread->mwindow->theme->get_image_set("swap_extents"))
190 this->thread = thread;
192 set_tooltip(_("Swap dimensions"));
195 int ResizeVTrackSwap::handle_event()
201 gui->w->update((int64_t)h);
202 gui->h->update((int64_t)w);
203 gui->update(0, 1, 0);
212 ResizeVTrackWidth::ResizeVTrackWidth(ResizeVTrackWindow *gui,
213 ResizeVTrackThread *thread,
216 : BC_TextBox(x, y, 90, 1, thread->w)
219 this->thread = thread;
221 int ResizeVTrackWidth::handle_event()
223 thread->w = atol(get_text());
224 gui->update(0, 1, 0);
228 ResizeVTrackHeight::ResizeVTrackHeight(ResizeVTrackWindow *gui,
229 ResizeVTrackThread *thread,
232 : BC_TextBox(x, y, 90, 1, thread->h)
235 this->thread = thread;
237 int ResizeVTrackHeight::handle_event()
239 thread->h = atol(get_text());
240 gui->update(0, 1, 0);
245 ResizeVTrackScaleW::ResizeVTrackScaleW(ResizeVTrackWindow *gui,
246 ResizeVTrackThread *thread,
249 : BC_TextBox(x, y, 90, 1, (float)thread->w_scale)
252 this->thread = thread;
254 int ResizeVTrackScaleW::handle_event()
256 thread->w_scale = atof(get_text());
257 gui->update(1, 0, 0);
261 ResizeVTrackScaleH::ResizeVTrackScaleH(ResizeVTrackWindow *gui,
262 ResizeVTrackThread *thread,
265 : BC_TextBox(x, y, 90, 1, (float)thread->h_scale)
268 this->thread = thread;
270 int ResizeVTrackScaleH::handle_event()
272 thread->h_scale = atof(get_text());
273 gui->update(1, 0, 0);
281 ResizeTrackThread::ResizeTrackThread(MWindow *mwindow)
282 : ResizeVTrackThread(mwindow)
286 ResizeTrackThread::~ResizeTrackThread()
291 void ResizeTrackThread::start_window(Track *track)
294 ResizeVTrackThread::start_window(track->track_w,
300 void ResizeTrackThread::update()
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 resize_asset_thread = new ResizeAssetThread(fwindow);
354 resize_asset_thread->start_window(fwindow->asset_edit->changed_params);