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