r125: This commit was manufactured by cvs2svn to create tag 'r1_1_7-last'.
[cinelerra_cv/mob.git] / hvirtual / cinelerra / resizetrackthread.C
blob8b23287b8b7f5f4f1100d7f5d94d091412475e71
1 #include "edl.h"
2 #include "mainundo.h"
3 #include "mwindow.h"
4 #include "mwindowgui.h"
5 #include "new.h"
6 #include "resizetrackthread.h"
7 #include "track.h"
8 #include "tracks.h"
11 #include <libintl.h>
12 #define _(String) gettext(String)
13 #define gettext_noop(String) String
14 #define N_(String) gettext_noop (String)
20 ResizeTrackThread::ResizeTrackThread(MWindow *mwindow, int track_number)
21  : Thread()
23         this->mwindow = mwindow;
24         this->track_number = track_number;
25         window = 0;
28 ResizeTrackThread::~ResizeTrackThread()
30         if(window)
31         {
32                 window->lock_window();
33                 window->set_done(1);
34                 window->unlock_window();
35         }
37         Thread::join();
40 void ResizeTrackThread::start_window(Track *track, int track_number)
42         this->track_number = track_number;
43         w1 = w = track->track_w;
44         h1 = h = track->track_h;
45         w_scale = h_scale = 1;
46         start();
50 void ResizeTrackThread::run()
52         ResizeTrackWindow *window = this->window = 
53                 new ResizeTrackWindow(mwindow, 
54                         this,
55                         mwindow->gui->get_abs_cursor_x(),
56                         mwindow->gui->get_abs_cursor_y());
57         window->create_objects();
58         int result = window->run_window();
59         this->window = 0;
60         delete window;
63         if(!result)
64         {
65                 Track *track = mwindow->edl->tracks->get_item_number(track_number);
67                 if(track)
68                 {
69                         mwindow->resize_track(track, w, h);
70                 }
71         }
77 ResizeTrackWindow::ResizeTrackWindow(MWindow *mwindow, 
78         ResizeTrackThread *thread,
79         int x,
80         int y)
81  : BC_Window(PROGRAM_NAME ": Resize Track", 
82                                 x - 320 / 2,
83                                 y - 120 / 2,
84                                 320, 
85                                 120, 
86                                 -1, 
87                                 -1, 
88                                 0,
89                                 0, 
90                                 1)
92         this->mwindow = mwindow;
93         this->thread = thread;
96 ResizeTrackWindow::~ResizeTrackWindow()
100 void ResizeTrackWindow::create_objects()
102         int x = 10, y = 10;
104         add_subwindow(new BC_Title(x, y, _("Size:")));
105         x += 50;
106         add_subwindow(w = new ResizeTrackWidth(this, 
107                 thread,
108                 x,
109                 y));
110         x += 100;
111         add_subwindow(new BC_Title(x, y, _("x")));
112         x += 15;
113         add_subwindow(h = new ResizeTrackHeight(this, 
114                 thread,
115                 x,
116                 y));
117         x += 100;
118         add_subwindow(new FrameSizePulldown(mwindow, 
119                 w, 
120                 h, 
121                 x, 
122                 y));
124         y += 30;
125         x = 10;
126         add_subwindow(new BC_Title(x, y, _("Scale:")));
127         x += 50;
128         add_subwindow(w_scale = new ResizeTrackScaleW(this, 
129                 thread,
130                 x,
131                 y));
132         x += 100;
133         add_subwindow(new BC_Title(x, y, _("x")));
134         x += 15;
135         add_subwindow(h_scale = new ResizeTrackScaleH(this, 
136                 thread,
137                 x,
138                 y));
140         add_subwindow(new BC_OKButton(this));
141         add_subwindow(new BC_CancelButton(this));
143         show_window();
144         flush();
147 void ResizeTrackWindow::update(int changed_scale, 
148         int changed_size, 
149         int changed_all)
151 //printf("ResizeTrackWindow::update %d %d %d\n", changed_scale, changed_size, changed_all);
152         if(changed_scale || changed_all)
153         {
154                 thread->w = (int)(thread->w1 * thread->w_scale);
155                 w->update((int64_t)thread->w);
156                 thread->h = (int)(thread->h1 * thread->h_scale);
157                 h->update((int64_t)thread->h);
158         }
159         else
160         if(changed_size || changed_all)
161         {
162                 thread->w_scale = (double)thread->w / thread->w1;
163                 w_scale->update((float)thread->w_scale);
164                 thread->h_scale = (double)thread->h / thread->h1;
165                 h_scale->update((float)thread->h_scale);
166         }
173 ResizeTrackWidth::ResizeTrackWidth(ResizeTrackWindow *gui, 
174         ResizeTrackThread *thread,
175         int x,
176         int y)
177  : BC_TextBox(x, y, 90, 1, thread->w)
179         this->gui = gui;
180         this->thread = thread;
182 int ResizeTrackWidth::handle_event()
184         thread->w = atol(get_text());
185         gui->update(0, 1, 0);
186         return 1;
189 ResizeTrackHeight::ResizeTrackHeight(ResizeTrackWindow *gui, 
190         ResizeTrackThread *thread,
191         int x,
192         int y)
193  : BC_TextBox(x, y, 90, 1, thread->h)
195         this->gui = gui;
196         this->thread = thread;
198 int ResizeTrackHeight::handle_event()
200         thread->h = atol(get_text());
201         gui->update(0, 1, 0);
202         return 1;
206 ResizeTrackScaleW::ResizeTrackScaleW(ResizeTrackWindow *gui, 
207         ResizeTrackThread *thread,
208         int x,
209         int y)
210  : BC_TextBox(x, y, 90, 1, (float)thread->w_scale)
212         this->gui = gui;
213         this->thread = thread;
215 int ResizeTrackScaleW::handle_event()
217         thread->w_scale = atof(get_text());
218         gui->update(1, 0, 0);
219         return 1;
222 ResizeTrackScaleH::ResizeTrackScaleH(ResizeTrackWindow *gui, 
223         ResizeTrackThread *thread,
224         int x,
225         int y)
226  : BC_TextBox(x, y, 90, 1, (float)thread->h_scale)
228         this->gui = gui;
229         this->thread = thread;
231 int ResizeTrackScaleH::handle_event()
233         thread->h_scale = atof(get_text());
234         gui->update(1, 0, 0);
235         return 1;