r999: maintainers added to README_en.
[cinelerra_cv/mob.git] / cinelerra / resizetrackthread.C
blob206342b487f4c43a494488b506356d96819c5fc3
1 #include "edl.h"
2 #include "edlsession.h"
3 #include "language.h"
4 #include "mainerror.h"
5 #include "mainundo.h"
6 #include "mwindow.h"
7 #include "mwindowgui.h"
8 #include "new.h"
9 #include "resizetrackthread.h"
10 #include "theme.h"
11 #include "track.h"
12 #include "tracks.h"
19 ResizeTrackThread::ResizeTrackThread(MWindow *mwindow, int track_number)
20  : Thread()
22         this->mwindow = mwindow;
23         this->track_number = track_number;
24         window = 0;
27 ResizeTrackThread::~ResizeTrackThread()
29         if(window)
30         {
31                 window->lock_window();
32                 window->set_done(1);
33                 window->unlock_window();
34         }
36         Thread::join();
39 void ResizeTrackThread::start_window(Track *track, int track_number)
41         this->track_number = track_number;
42         w1 = w = track->track_w;
43         h1 = h = track->track_h;
44         w_scale = h_scale = 1;
45         start();
49 void ResizeTrackThread::run()
51         ResizeTrackWindow *window = this->window = 
52                 new ResizeTrackWindow(mwindow, 
53                         this,
54                         mwindow->gui->get_abs_cursor_x(1),
55                         mwindow->gui->get_abs_cursor_y(1));
56         window->create_objects();
57         int result = window->run_window();
58         this->window = 0;
59         delete window;
62         if(!result)
63         {
64                 Track *track = mwindow->edl->tracks->get_item_number(track_number);
66                 if(track)
67                 {
68                         mwindow->resize_track(track, w, h);
69                 }
70         }
72         if(((w % 4) || 
73                 (h % 4)) && 
74                 mwindow->edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL)
75         {
76                 MainError::show_error(
77                         _("This track's dimensions are not multiples of 4 so\n"
78                         "it can't be rendered by OpenGL."));
79         }
85 ResizeTrackWindow::ResizeTrackWindow(MWindow *mwindow, 
86         ResizeTrackThread *thread,
87         int x,
88         int y)
89  : BC_Window(PROGRAM_NAME ": Resize Track", 
90                                 x - 320 / 2,
91                                 y - get_resources()->ok_images[0]->get_h() + 100 / 2,
92                                 340, 
93                                 get_resources()->ok_images[0]->get_h() + 100, 
94                                 340, 
95                                 get_resources()->ok_images[0]->get_h() + 100, 
96                                 0,
97                                 0, 
98                                 1)
100         this->mwindow = mwindow;
101         this->thread = thread;
104 ResizeTrackWindow::~ResizeTrackWindow()
108 void ResizeTrackWindow::create_objects()
110         int x = 10, y = 10;
112         add_subwindow(new BC_Title(x, y, _("Size:")));
113         x += 50;
114         add_subwindow(w = new ResizeTrackWidth(this, 
115                 thread,
116                 x,
117                 y));
118         x += w->get_w() + 10;
119         add_subwindow(new BC_Title(x, y, _("x")));
120         x += 15;
121         add_subwindow(h = new ResizeTrackHeight(this, 
122                 thread,
123                 x,
124                 y));
125         x += h->get_w() + 5;
126         FrameSizePulldown *pulldown;
127         add_subwindow(pulldown = new FrameSizePulldown(mwindow, 
128                 w, 
129                 h, 
130                 x, 
131                 y));
132         x += pulldown->get_w() + 5;
133         add_subwindow(new ResizeTrackSwap(this, thread, x, y));
136         y += 30;
137         x = 10;
138         add_subwindow(new BC_Title(x, y, _("Scale:")));
139         x += 50;
140         add_subwindow(w_scale = new ResizeTrackScaleW(this, 
141                 thread,
142                 x,
143                 y));
144         x += 100;
145         add_subwindow(new BC_Title(x, y, _("x")));
146         x += 15;
147         add_subwindow(h_scale = new ResizeTrackScaleH(this, 
148                 thread,
149                 x,
150                 y));
152         add_subwindow(new BC_OKButton(this));
153         add_subwindow(new BC_CancelButton(this));
155         show_window();
156         flush();
159 void ResizeTrackWindow::update(int changed_scale, 
160         int changed_size, 
161         int changed_all)
163 //printf("ResizeTrackWindow::update %d %d %d\n", changed_scale, changed_size, changed_all);
164         if(changed_scale || changed_all)
165         {
166                 thread->w = (int)(thread->w1 * thread->w_scale);
167                 w->update((int64_t)thread->w);
168                 thread->h = (int)(thread->h1 * thread->h_scale);
169                 h->update((int64_t)thread->h);
170         }
171         else
172         if(changed_size || changed_all)
173         {
174                 thread->w_scale = (double)thread->w / thread->w1;
175                 w_scale->update((float)thread->w_scale);
176                 thread->h_scale = (double)thread->h / thread->h1;
177                 h_scale->update((float)thread->h_scale);
178         }
186 ResizeTrackSwap::ResizeTrackSwap(ResizeTrackWindow *gui, 
187         ResizeTrackThread *thread, 
188         int x, 
189         int y)
190  : BC_Button(x, y, thread->mwindow->theme->get_image_set("swap_extents"))
192         this->thread = thread;
193         this->gui = gui;
194         set_tooltip("Swap dimensions");
197 int ResizeTrackSwap::handle_event()
199         int w = thread->w;
200         int h = thread->h;
201         thread->w = h;
202         thread->h = w;
203         gui->w->update((int64_t)h);
204         gui->h->update((int64_t)w);
205         gui->update(0, 1, 0);
206         return 1;
214 ResizeTrackWidth::ResizeTrackWidth(ResizeTrackWindow *gui, 
215         ResizeTrackThread *thread,
216         int x,
217         int y)
218  : BC_TextBox(x, y, 90, 1, thread->w)
220         this->gui = gui;
221         this->thread = thread;
223 int ResizeTrackWidth::handle_event()
225         thread->w = atol(get_text());
226         gui->update(0, 1, 0);
227         return 1;
230 ResizeTrackHeight::ResizeTrackHeight(ResizeTrackWindow *gui, 
231         ResizeTrackThread *thread,
232         int x,
233         int y)
234  : BC_TextBox(x, y, 90, 1, thread->h)
236         this->gui = gui;
237         this->thread = thread;
239 int ResizeTrackHeight::handle_event()
241         thread->h = atol(get_text());
242         gui->update(0, 1, 0);
243         return 1;
247 ResizeTrackScaleW::ResizeTrackScaleW(ResizeTrackWindow *gui, 
248         ResizeTrackThread *thread,
249         int x,
250         int y)
251  : BC_TextBox(x, y, 90, 1, (float)thread->w_scale)
253         this->gui = gui;
254         this->thread = thread;
256 int ResizeTrackScaleW::handle_event()
258         thread->w_scale = atof(get_text());
259         gui->update(1, 0, 0);
260         return 1;
263 ResizeTrackScaleH::ResizeTrackScaleH(ResizeTrackWindow *gui, 
264         ResizeTrackThread *thread,
265         int x,
266         int y)
267  : BC_TextBox(x, y, 90, 1, (float)thread->h_scale)
269         this->gui = gui;
270         this->thread = thread;
272 int ResizeTrackScaleH::handle_event()
274         thread->h_scale = atof(get_text());
275         gui->update(1, 0, 0);
276         return 1;