initial commit
[goodguy/history.git] / cinelerra-5.0 / cinelerra / transitionpopup.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  * 
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.
10  * 
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.
15  * 
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
19  * 
20  */
21
22 #include "bcdisplayinfo.h"
23 #include "clip.h"
24 #include "edit.h"
25 #include "edl.h"
26 #include "edlsession.h"
27 #include "language.h"
28 #include "mwindow.h"
29 #include "mwindowgui.h"
30 #include "plugin.h"
31 #include "transition.h"
32 #include "track.h"
33 #include "tracks.h"
34 #include "transitionpopup.h"
35
36
37 TransitionLengthThread::TransitionLengthThread(MWindow *mwindow)
38  : BC_DialogThread()
39 {
40         this->mwindow = mwindow;
41 }
42
43 TransitionLengthThread::~TransitionLengthThread()
44 {
45 }
46
47 void TransitionLengthThread::start(Transition *transition, 
48         double length)
49 {
50         this->transition = transition;
51         this->length = this->orig_length = length;
52         BC_DialogThread::start();
53 }
54
55 BC_Window* TransitionLengthThread::new_gui()
56 {
57         BC_DisplayInfo display_info;
58         int x = display_info.get_abs_cursor_x() - 150;
59         int y = display_info.get_abs_cursor_y() - 50;
60         TransitionLengthDialog *gui = new TransitionLengthDialog(mwindow, 
61                 this,
62                 x,
63                 y);
64         gui->create_objects();
65         return gui;
66 }
67
68 void TransitionLengthThread::handle_close_event(int result)
69 {
70         if(!result)
71         {
72                 if(transition)
73                 {
74                         mwindow->set_transition_length(transition, length);
75                 }
76                 else
77                 {
78                         mwindow->set_transition_length(length);
79                 }
80         }
81 }
82
83
84
85
86
87
88
89
90
91 TransitionLengthDialog::TransitionLengthDialog(MWindow *mwindow, 
92         TransitionLengthThread *thread,
93         int x,
94         int y)
95  : BC_Window(PROGRAM_NAME ": Transition length", 
96         x,
97         y,
98         300, 
99         100, 
100         -1, 
101         -1, 
102         0,
103         0, 
104         1)
105 {
106         this->mwindow = mwindow;
107         this->thread = thread;
108 }
109
110 TransitionLengthDialog::~TransitionLengthDialog()
111 {
112 }
113
114         
115 void TransitionLengthDialog::create_objects()
116 {
117         lock_window("TransitionLengthDialog::create_objects");
118         add_subwindow(new BC_Title(10, 10, _("Seconds:")));
119         text = new TransitionLengthText(mwindow, this, 100, 10);
120         text->create_objects();
121         add_subwindow(new BC_OKButton(this));
122         add_subwindow(new BC_CancelButton(this));
123         show_window();
124         unlock_window();
125 }
126
127 int TransitionLengthDialog::close_event()
128 {
129         set_done(0);
130         return 1;
131 }
132
133
134
135
136
137
138 TransitionLengthText::TransitionLengthText(MWindow *mwindow, 
139         TransitionLengthDialog *gui,
140         int x, 
141         int y)
142  : BC_TumbleTextBox(gui, 
143         (float)gui->thread->length,
144         (float)0, 
145         (float)100, 
146         x,
147         y,
148         100)
149 {
150         this->mwindow = mwindow;
151         this->gui = gui;
152 }
153
154 int TransitionLengthText::handle_event()
155 {
156         double result = atof(get_text());
157         if(!EQUIV(result, gui->thread->length))
158         {
159                 gui->thread->length = result;
160         }
161
162         return 1;
163 }
164
165
166
167
168
169
170
171
172
173
174
175 TransitionPopup::TransitionPopup(MWindow *mwindow, MWindowGUI *gui)
176  : BC_PopupMenu(0, 
177                 0, 
178                 0, 
179                 "", 
180                 0)
181 {
182         this->mwindow = mwindow;
183         this->gui = gui;
184 }
185
186 TransitionPopup::~TransitionPopup()
187 {
188         delete length_thread;
189 //      delete dialog_thread;
190 }
191
192
193 void TransitionPopup::create_objects()
194 {
195         length_thread = new TransitionLengthThread(mwindow);
196 //      add_item(attach = new TransitionPopupAttach(mwindow, this));
197         add_item(show = new TransitionPopupShow(mwindow, this));
198         add_item(on = new TransitionPopupOn(mwindow, this));
199         add_item(length_item = new TransitionPopupLength(mwindow, this));
200         add_item(detach = new TransitionPopupDetach(mwindow, this));
201 }
202
203 int TransitionPopup::update(Transition *transition)
204 {
205         this->transition = transition;
206         this->length = transition->edit->track->from_units(transition->length);
207         show->set_checked(transition->show);
208         on->set_checked(transition->on);
209         return 0;
210 }
211
212
213
214
215
216 TransitionPopupAttach::TransitionPopupAttach(MWindow *mwindow, TransitionPopup *popup)
217  : BC_MenuItem(_("Attach..."))
218 {
219         this->mwindow = mwindow;
220         this->popup = popup;
221 }
222
223 TransitionPopupAttach::~TransitionPopupAttach()
224 {
225 }
226
227 int TransitionPopupAttach::handle_event()
228 {
229 //      popup->dialog_thread->start();
230         return 0;
231 }
232
233
234
235
236
237
238
239 TransitionPopupDetach::TransitionPopupDetach(MWindow *mwindow, TransitionPopup *popup)
240  : BC_MenuItem(_("Detach"))
241 {
242         this->mwindow = mwindow;
243         this->popup = popup;
244 }
245
246 TransitionPopupDetach::~TransitionPopupDetach()
247 {
248 }
249
250 int TransitionPopupDetach::handle_event()
251 {
252         mwindow->detach_transition(popup->transition);
253         return 1;
254 }
255
256
257 TransitionPopupOn::TransitionPopupOn(MWindow *mwindow, TransitionPopup *popup)
258  : BC_MenuItem(_("On"))
259 {
260         this->mwindow = mwindow;
261         this->popup = popup;
262 }
263
264 TransitionPopupOn::~TransitionPopupOn()
265 {
266 }
267
268 int TransitionPopupOn::handle_event()
269 {
270         popup->transition->on = !get_checked();
271         mwindow->sync_parameters(CHANGE_EDL);
272         return 1;
273 }
274
275
276
277
278
279
280 TransitionPopupShow::TransitionPopupShow(MWindow *mwindow, TransitionPopup *popup)
281  : BC_MenuItem(_("Show"))
282 {
283         this->mwindow = mwindow;
284         this->popup = popup;
285 }
286
287 TransitionPopupShow::~TransitionPopupShow()
288 {
289 }
290
291 int TransitionPopupShow::handle_event()
292 {
293         mwindow->show_plugin(popup->transition);
294         return 1;
295 }
296
297
298
299
300
301
302
303
304 TransitionPopupLength::TransitionPopupLength(MWindow *mwindow, TransitionPopup *popup)
305  : BC_MenuItem(_("Length"))
306 {
307         this->mwindow = mwindow;
308         this->popup = popup;
309 }
310
311 TransitionPopupLength::~TransitionPopupLength()
312 {
313 }
314
315 int TransitionPopupLength::handle_event()
316 {
317         popup->length_thread->start(popup->transition,
318                 popup->length);
319         return 1;
320 }
321