00001 #include "edl.h"
00002 #include "edlsession.h"
00003 #include "language.h"
00004 #include "mainerror.h"
00005 #include "mainundo.h"
00006 #include "mwindow.h"
00007 #include "mwindowgui.h"
00008 #include "new.h"
00009 #include "resizetrackthread.h"
00010 #include "theme.h"
00011 #include "track.h"
00012 #include "tracks.h"
00013
00014
00015
00016
00017
00018
00019 ResizeTrackThread::ResizeTrackThread(MWindow *mwindow, int track_number)
00020 : Thread()
00021 {
00022 this->mwindow = mwindow;
00023 this->track_number = track_number;
00024 window = 0;
00025 }
00026
00027 ResizeTrackThread::~ResizeTrackThread()
00028 {
00029 if(window)
00030 {
00031 window->lock_window();
00032 window->set_done(1);
00033 window->unlock_window();
00034 }
00035
00036 Thread::join();
00037 }
00038
00039 void ResizeTrackThread::start_window(Track *track, int track_number)
00040 {
00041 this->track_number = track_number;
00042 w1 = w = track->track_w;
00043 h1 = h = track->track_h;
00044 w_scale = h_scale = 1;
00045 start();
00046 }
00047
00048
00049 void ResizeTrackThread::run()
00050 {
00051 ResizeTrackWindow *window = this->window =
00052 new ResizeTrackWindow(mwindow,
00053 this,
00054 mwindow->gui->get_abs_cursor_x(1),
00055 mwindow->gui->get_abs_cursor_y(1));
00056 window->create_objects();
00057 int result = window->run_window();
00058 this->window = 0;
00059 delete window;
00060
00061
00062 if(!result)
00063 {
00064 Track *track = mwindow->edl->tracks->get_item_number(track_number);
00065
00066 if(track)
00067 {
00068 mwindow->resize_track(track, w, h);
00069 }
00070 }
00071
00072 if(((w % 4) ||
00073 (h % 4)) &&
00074 mwindow->edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL)
00075 {
00076 MainError::show_error(
00077 _("This track's dimensions are not multiples of 4 so\n"
00078 "it can't be rendered by OpenGL."));
00079 }
00080 }
00081
00082
00083
00084
00085 ResizeTrackWindow::ResizeTrackWindow(MWindow *mwindow,
00086 ResizeTrackThread *thread,
00087 int x,
00088 int y)
00089 : BC_Window(PROGRAM_NAME ": Resize Track",
00090 x - 320 / 2,
00091 y - get_resources()->ok_images[0]->get_h() + 100 / 2,
00092 340,
00093 get_resources()->ok_images[0]->get_h() + 100,
00094 340,
00095 get_resources()->ok_images[0]->get_h() + 100,
00096 0,
00097 0,
00098 1)
00099 {
00100 this->mwindow = mwindow;
00101 this->thread = thread;
00102 }
00103
00104 ResizeTrackWindow::~ResizeTrackWindow()
00105 {
00106 }
00107
00108 void ResizeTrackWindow::create_objects()
00109 {
00110 int x = 10, y = 10;
00111
00112 add_subwindow(new BC_Title(x, y, _("Size:")));
00113 x += 50;
00114 add_subwindow(w = new ResizeTrackWidth(this,
00115 thread,
00116 x,
00117 y));
00118 x += w->get_w() + 10;
00119 add_subwindow(new BC_Title(x, y, _("x")));
00120 x += 15;
00121 add_subwindow(h = new ResizeTrackHeight(this,
00122 thread,
00123 x,
00124 y));
00125 x += h->get_w() + 5;
00126 FrameSizePulldown *pulldown;
00127 add_subwindow(pulldown = new FrameSizePulldown(mwindow,
00128 w,
00129 h,
00130 x,
00131 y));
00132 x += pulldown->get_w() + 5;
00133 add_subwindow(new ResizeTrackSwap(this, thread, x, y));
00134
00135
00136 y += 30;
00137 x = 10;
00138 add_subwindow(new BC_Title(x, y, _("Scale:")));
00139 x += 50;
00140 add_subwindow(w_scale = new ResizeTrackScaleW(this,
00141 thread,
00142 x,
00143 y));
00144 x += 100;
00145 add_subwindow(new BC_Title(x, y, _("x")));
00146 x += 15;
00147 add_subwindow(h_scale = new ResizeTrackScaleH(this,
00148 thread,
00149 x,
00150 y));
00151
00152 add_subwindow(new BC_OKButton(this));
00153 add_subwindow(new BC_CancelButton(this));
00154
00155 show_window();
00156 flush();
00157 }
00158
00159 void ResizeTrackWindow::update(int changed_scale,
00160 int changed_size,
00161 int changed_all)
00162 {
00163
00164 if(changed_scale || changed_all)
00165 {
00166 thread->w = (int)(thread->w1 * thread->w_scale);
00167 w->update((int64_t)thread->w);
00168 thread->h = (int)(thread->h1 * thread->h_scale);
00169 h->update((int64_t)thread->h);
00170 }
00171 else
00172 if(changed_size || changed_all)
00173 {
00174 thread->w_scale = (double)thread->w / thread->w1;
00175 w_scale->update((float)thread->w_scale);
00176 thread->h_scale = (double)thread->h / thread->h1;
00177 h_scale->update((float)thread->h_scale);
00178 }
00179 }
00180
00181
00182
00183
00184
00185
00186 ResizeTrackSwap::ResizeTrackSwap(ResizeTrackWindow *gui,
00187 ResizeTrackThread *thread,
00188 int x,
00189 int y)
00190 : BC_Button(x, y, thread->mwindow->theme->get_image_set("swap_extents"))
00191 {
00192 this->thread = thread;
00193 this->gui = gui;
00194 set_tooltip("Swap dimensions");
00195 }
00196
00197 int ResizeTrackSwap::handle_event()
00198 {
00199 int w = thread->w;
00200 int h = thread->h;
00201 thread->w = h;
00202 thread->h = w;
00203 gui->w->update((int64_t)h);
00204 gui->h->update((int64_t)w);
00205 gui->update(0, 1, 0);
00206 return 1;
00207 }
00208
00209
00210
00211
00212
00213
00214 ResizeTrackWidth::ResizeTrackWidth(ResizeTrackWindow *gui,
00215 ResizeTrackThread *thread,
00216 int x,
00217 int y)
00218 : BC_TextBox(x, y, 90, 1, thread->w)
00219 {
00220 this->gui = gui;
00221 this->thread = thread;
00222 }
00223 int ResizeTrackWidth::handle_event()
00224 {
00225 thread->w = atol(get_text());
00226 gui->update(0, 1, 0);
00227 return 1;
00228 }
00229
00230 ResizeTrackHeight::ResizeTrackHeight(ResizeTrackWindow *gui,
00231 ResizeTrackThread *thread,
00232 int x,
00233 int y)
00234 : BC_TextBox(x, y, 90, 1, thread->h)
00235 {
00236 this->gui = gui;
00237 this->thread = thread;
00238 }
00239 int ResizeTrackHeight::handle_event()
00240 {
00241 thread->h = atol(get_text());
00242 gui->update(0, 1, 0);
00243 return 1;
00244 }
00245
00246
00247 ResizeTrackScaleW::ResizeTrackScaleW(ResizeTrackWindow *gui,
00248 ResizeTrackThread *thread,
00249 int x,
00250 int y)
00251 : BC_TextBox(x, y, 90, 1, (float)thread->w_scale)
00252 {
00253 this->gui = gui;
00254 this->thread = thread;
00255 }
00256 int ResizeTrackScaleW::handle_event()
00257 {
00258 thread->w_scale = atof(get_text());
00259 gui->update(1, 0, 0);
00260 return 1;
00261 }
00262
00263 ResizeTrackScaleH::ResizeTrackScaleH(ResizeTrackWindow *gui,
00264 ResizeTrackThread *thread,
00265 int x,
00266 int y)
00267 : BC_TextBox(x, y, 90, 1, (float)thread->h_scale)
00268 {
00269 this->gui = gui;
00270 this->thread = thread;
00271 }
00272 int ResizeTrackScaleH::handle_event()
00273 {
00274 thread->h_scale = atof(get_text());
00275 gui->update(1, 0, 0);
00276 return 1;
00277 }
00278
00279
00280
00281
00282
00283
00284