r854: Merge 2.1:
[cinelerra_cv/ct.git] / cinelerra / resizetrackthread.C
blob80837b58dcc22131fa423c6c8d696b64bf006fa7
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 "track.h"
11 #include "tracks.h"
18 ResizeTrackThread::ResizeTrackThread(MWindow *mwindow, int track_number)
19  : Thread()
21         this->mwindow = mwindow;
22         this->track_number = track_number;
23         window = 0;
26 ResizeTrackThread::~ResizeTrackThread()
28         if(window)
29         {
30                 window->lock_window();
31                 window->set_done(1);
32                 window->unlock_window();
33         }
35         Thread::join();
38 void ResizeTrackThread::start_window(Track *track, int track_number)
40         this->track_number = track_number;
41         w1 = w = track->track_w;
42         h1 = h = track->track_h;
43         w_scale = h_scale = 1;
44         start();
48 void ResizeTrackThread::run()
50         ResizeTrackWindow *window = this->window = 
51                 new ResizeTrackWindow(mwindow, 
52                         this,
53                         mwindow->gui->get_abs_cursor_x(1),
54                         mwindow->gui->get_abs_cursor_y(1));
55         window->create_objects();
56         int result = window->run_window();
57         this->window = 0;
58         delete window;
61         if(!result)
62         {
63                 Track *track = mwindow->edl->tracks->get_item_number(track_number);
65                 if(track)
66                 {
67                         mwindow->resize_track(track, w, h);
68                 }
69         }
71         if(((w % 4) || 
72                 (h % 4)) && 
73                 mwindow->edl->session->playback_config->vconfig->driver == PLAYBACK_X11_GL)
74         {
75                 MainError::show_error(
76                         _("This track's dimensions are not multiples of 4 so\n"
77                         "it can't be rendered by OpenGL."));
78         }
84 ResizeTrackWindow::ResizeTrackWindow(MWindow *mwindow, 
85         ResizeTrackThread *thread,
86         int x,
87         int y)
88  : BC_Window(PROGRAM_NAME ": Resize Track", 
89                                 x - 320 / 2,
90                                 y - get_resources()->ok_images[0]->get_h() + 100 / 2,
91                                 320, 
92                                 get_resources()->ok_images[0]->get_h() + 100, 
93                                 320, 
94                                 get_resources()->ok_images[0]->get_h() + 100, 
95                                 0,
96                                 0, 
97                                 1)
99         this->mwindow = mwindow;
100         this->thread = thread;
103 ResizeTrackWindow::~ResizeTrackWindow()
107 void ResizeTrackWindow::create_objects()
109         int x = 10, y = 10;
111         add_subwindow(new BC_Title(x, y, _("Size:")));
112         x += 50;
113         add_subwindow(w = new ResizeTrackWidth(this, 
114                 thread,
115                 x,
116                 y));
117         x += 100;
118         add_subwindow(new BC_Title(x, y, _("x")));
119         x += 15;
120         add_subwindow(h = new ResizeTrackHeight(this, 
121                 thread,
122                 x,
123                 y));
124         x += 100;
125         add_subwindow(new FrameSizePulldown(mwindow, 
126                 w, 
127                 h, 
128                 x, 
129                 y));
131         y += 30;
132         x = 10;
133         add_subwindow(new BC_Title(x, y, _("Scale:")));
134         x += 50;
135         add_subwindow(w_scale = new ResizeTrackScaleW(this, 
136                 thread,
137                 x,
138                 y));
139         x += 100;
140         add_subwindow(new BC_Title(x, y, _("x")));
141         x += 15;
142         add_subwindow(h_scale = new ResizeTrackScaleH(this, 
143                 thread,
144                 x,
145                 y));
147         add_subwindow(new BC_OKButton(this));
148         add_subwindow(new BC_CancelButton(this));
150         show_window();
151         flush();
154 void ResizeTrackWindow::update(int changed_scale, 
155         int changed_size, 
156         int changed_all)
158 //printf("ResizeTrackWindow::update %d %d %d\n", changed_scale, changed_size, changed_all);
159         if(changed_scale || changed_all)
160         {
161                 thread->w = (int)(thread->w1 * thread->w_scale);
162                 w->update((int64_t)thread->w);
163                 thread->h = (int)(thread->h1 * thread->h_scale);
164                 h->update((int64_t)thread->h);
165         }
166         else
167         if(changed_size || changed_all)
168         {
169                 thread->w_scale = (double)thread->w / thread->w1;
170                 w_scale->update((float)thread->w_scale);
171                 thread->h_scale = (double)thread->h / thread->h1;
172                 h_scale->update((float)thread->h_scale);
173         }
180 ResizeTrackWidth::ResizeTrackWidth(ResizeTrackWindow *gui, 
181         ResizeTrackThread *thread,
182         int x,
183         int y)
184  : BC_TextBox(x, y, 90, 1, thread->w)
186         this->gui = gui;
187         this->thread = thread;
189 int ResizeTrackWidth::handle_event()
191         thread->w = atol(get_text());
192         gui->update(0, 1, 0);
193         return 1;
196 ResizeTrackHeight::ResizeTrackHeight(ResizeTrackWindow *gui, 
197         ResizeTrackThread *thread,
198         int x,
199         int y)
200  : BC_TextBox(x, y, 90, 1, thread->h)
202         this->gui = gui;
203         this->thread = thread;
205 int ResizeTrackHeight::handle_event()
207         thread->h = atol(get_text());
208         gui->update(0, 1, 0);
209         return 1;
213 ResizeTrackScaleW::ResizeTrackScaleW(ResizeTrackWindow *gui, 
214         ResizeTrackThread *thread,
215         int x,
216         int y)
217  : BC_TextBox(x, y, 90, 1, (float)thread->w_scale)
219         this->gui = gui;
220         this->thread = thread;
222 int ResizeTrackScaleW::handle_event()
224         thread->w_scale = atof(get_text());
225         gui->update(1, 0, 0);
226         return 1;
229 ResizeTrackScaleH::ResizeTrackScaleH(ResizeTrackWindow *gui, 
230         ResizeTrackThread *thread,
231         int x,
232         int y)
233  : BC_TextBox(x, y, 90, 1, (float)thread->h_scale)
235         this->gui = gui;
236         this->thread = thread;
238 int ResizeTrackScaleH::handle_event()
240         thread->h_scale = atof(get_text());
241         gui->update(1, 0, 0);
242         return 1;