rework android-rmt display, add a few buttons
[goodguy/history.git] / cinelerra-5.0 / cinelerra / keyframegui.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 "bchash.h"
23 #include "bcsignals.h"
24 #include "edl.h"
25 #include "keyframe.h"
26 #include "keyframes.h"
27 #include "keyframegui.h"
28 #include "keys.h"
29 #include "language.h"
30 #include "localsession.h"
31 #include "mainsession.h"
32 #include "mainundo.h"
33 #include "mwindow.h"
34 #include "mwindowgui.h"
35 #include "plugin.h"
36 #include "presets.h"
37 #include "theme.h"
38 #include "trackcanvas.h"
39 #include "tracks.h"
40
41
42
43
44 KeyFrameThread::KeyFrameThread(MWindow *mwindow)
45  : BC_DialogThread()
46 {
47         this->mwindow = mwindow;
48         plugin = 0;
49         keyframe = 0;
50         keyframe_data = new ArrayList<BC_ListBoxItem*>[KEYFRAME_COLUMNS];
51         plugin_title[0] = 0;
52         window_title[0] = 0;
53         column_titles[0] = (char*)_("Parameter");
54         column_titles[1] = (char*)_("Value");
55         column_width[0] = 0;
56         column_width[1] = 0;
57         presets_data = new ArrayList<BC_ListBoxItem*>;
58         presets_db = new PresetsDB;
59 }
60
61 KeyFrameThread::~KeyFrameThread()
62 {
63         close_window();
64         for(int i = 0; i < KEYFRAME_COLUMNS; i++)
65                 keyframe_data[i].remove_all_objects();
66         delete [] keyframe_data;
67         presets_data->remove_all_objects();
68         delete presets_data;
69 }
70
71
72 #ifdef EDIT_KEYFRAME
73 void KeyFrameThread::update_values()
74 {
75 // Get the current selection before deleting the tables
76         int selection = -1;
77         for(int i = 0; i < keyframe_data[0].size(); i++)
78         {
79                 if(keyframe_data[0].get(i)->get_selected()) 
80                 {
81                         selection = i;
82                         break;
83                 }
84         }
85
86         for(int i = 0; i < KEYFRAME_COLUMNS; i++)
87                 keyframe_data[i].remove_all_objects();
88
89
90 // Must lock main window to read keyframe
91         mwindow->gui->lock_window("KeyFrameThread::update_values");
92         if(!plugin || !mwindow->edl->tracks->plugin_exists(plugin)) 
93         {
94                 mwindow->gui->unlock_window();
95                 return;
96         }
97
98         KeyFrame *keyframe = 0;
99         if(this->keyframe && plugin->keyframe_exists(this->keyframe))
100         {
101 // If user edited a specific keyframe, use it.
102                 keyframe = this->keyframe;
103         }
104         else
105         if(plugin->track)
106         {
107 // Use currently highlighted keyframe
108                 keyframe = plugin->get_prev_keyframe(
109                         plugin->track->to_units(
110                                 mwindow->edl->local_session->get_selectionstart(1), 0),
111                         PLAY_FORWARD);
112         }
113
114         if(keyframe)
115         {
116                 BC_Hash hash;
117                 char *text = 0, *extra = 0;
118                 keyframe->get_contents(&hash, &text, &extra);
119                 
120                 for(int i = 0; i < hash.size(); i++)
121                 {
122                         keyframe_data[0].append(new BC_ListBoxItem(hash.get_key(i)));
123                         keyframe_data[1].append(new BC_ListBoxItem(hash.get_value(i)));
124                 }
125                 keyframe_data[0].append(new BC_ListBoxItem((char*)_("TEXT")));
126                 keyframe_data[1].append(new BC_ListBoxItem(text));
127                 
128                 delete [] text;
129                 delete [] extra;
130         }
131
132         column_width[0] = mwindow->session->keyframedialog_column1;
133         column_width[1] = mwindow->session->keyframedialog_column2;
134         if(selection >= 0 && selection < keyframe_data[0].size())
135         {
136                 for(int i = 0; i < KEYFRAME_COLUMNS; i++)
137                         keyframe_data[i].get(selection)->set_selected(1);
138         }
139         mwindow->gui->unlock_window();
140 }
141 #endif
142
143
144 void KeyFrameThread::start_window(Plugin *plugin, KeyFrame *keyframe)
145 {
146
147         if(!BC_DialogThread::is_running())
148         {
149                 if(!mwindow->edl->tracks->plugin_exists(plugin)) return;
150                 this->keyframe = keyframe;
151                 this->plugin = plugin;
152                 plugin->calculate_title(plugin_title, 0);
153                 sprintf(window_title, _(PROGRAM_NAME ": %s Keyframe"), plugin_title);
154                 presets_db->load();
155                 calculate_preset_list();
156
157 #ifdef EDIT_KEYFRAME
158                 update_values();
159 #endif
160                 mwindow->gui->unlock_window();
161                 BC_DialogThread::start();
162                 mwindow->gui->lock_window("KeyFrameThread::start_window");
163         }
164         else
165         {
166                 BC_DialogThread::start();
167         }
168 }
169
170 BC_Window* KeyFrameThread::new_gui()
171 {
172         mwindow->gui->lock_window("KeyFrameThread::new_gui");
173         
174         int x = mwindow->gui->get_abs_cursor_x(0) - 
175                 mwindow->session->plugindialog_w / 2;
176         int y = mwindow->gui->get_abs_cursor_y(0) - 
177                 mwindow->session->plugindialog_h / 2;
178
179         KeyFrameWindow *window = new KeyFrameWindow(mwindow, 
180                 this, 
181                 x, 
182                 y,
183                 window_title);
184
185         window->create_objects();
186         
187         
188         mwindow->gui->unlock_window();
189
190         return window;
191 }
192
193 void KeyFrameThread::handle_done_event(int result)
194 {
195 // Apply the preset
196         if(!result)
197         {
198                 const char *title = ((KeyFrameWindow*)get_gui())->preset_text->get_text();
199                 apply_preset(title);
200                 apply_value();
201         }
202 }
203
204 void KeyFrameThread::handle_close_event(int result)
205 {
206         plugin = 0;
207         keyframe = 0;
208 }
209
210
211
212 void KeyFrameThread::calculate_preset_list()
213 {
214         presets_data->remove_all_objects();
215         int total_presets = presets_db->get_total_presets(plugin_title);
216         for(int i = 0; i < total_presets; i++)
217         {
218                 presets_data->append(new BC_ListBoxItem(presets_db->get_preset_title(
219                         plugin_title,
220                         i)));
221         }
222 }
223
224
225 void KeyFrameThread::update_gui(int update_value_text)
226 {
227 #ifdef EDIT_KEYFRAME
228         if(BC_DialogThread::is_running())
229         {
230                 mwindow->gui->lock_window("KeyFrameThread::update_gui");
231                 update_values();
232                 mwindow->gui->unlock_window();
233
234                 lock_window("KeyFrameThread::update_gui");
235                 KeyFrameWindow *window = (KeyFrameWindow*)get_gui();
236                 if(window)
237                 {
238                         window->lock_window("KeyFrameThread::update_gui");
239                         window->keyframe_list->update(keyframe_data,
240                                 (const char **)column_titles,
241                                 column_width,
242                                 KEYFRAME_COLUMNS,
243                                 window->keyframe_list->get_xposition(),
244                                 window->keyframe_list->get_yposition(),
245                                 window->keyframe_list->get_highlighted_item());
246                         if( update_value_text )
247                         {
248                                 int selection_number = window->keyframe_list->get_selection_number(0, 0);
249                                 if( selection_number >= 0 && selection_number < keyframe_data[1].size())
250                                 {
251                                         char *edit_value = keyframe_data[1].get(selection_number)->get_text();
252                                         window->value_text->update(edit_value);
253                                 }
254                         }
255                         window->unlock_window();
256                 }
257                 unlock_window();
258         }
259 #endif
260 }
261
262 void KeyFrameThread::save_preset(const char *title)
263 {
264         get_gui()->unlock_window();
265         mwindow->gui->lock_window("KeyFrameThread::save_preset");
266         
267 // Test EDL for plugin existence
268         if(!mwindow->edl->tracks->plugin_exists(plugin))
269         {
270                 mwindow->gui->unlock_window();
271                 get_gui()->lock_window("KeyFrameThread::save_preset 2");
272                 return;
273         }
274
275
276 // Get current plugin keyframe
277         EDL *edl = mwindow->edl;
278         Track *track = plugin->track;
279         KeyFrame *keyframe = plugin->get_prev_keyframe(
280                         track->to_units(edl->local_session->get_selectionstart(1), 0), 
281                         PLAY_FORWARD);
282
283 // Send to database
284         presets_db->save_preset(plugin_title, title, keyframe->get_data());
285
286         mwindow->gui->unlock_window();
287         get_gui()->lock_window("KeyFrameThread::save_preset 2");
288
289
290 // Update list
291         calculate_preset_list();
292         ((KeyFrameWindow*)get_gui())->preset_list->update(presets_data,
293                 0,
294                 0,
295                 1);
296 }
297
298 void KeyFrameThread::delete_preset(const char *title)
299 {
300         get_gui()->unlock_window();
301         mwindow->gui->lock_window("KeyFrameThread::save_preset");
302         
303 // Test EDL for plugin existence
304         if(!mwindow->edl->tracks->plugin_exists(plugin))
305         {
306                 mwindow->gui->unlock_window();
307                 get_gui()->lock_window("KeyFrameThread::delete_preset 1");
308                 return;
309         }
310
311         presets_db->delete_preset(plugin_title, title);
312         
313         mwindow->gui->unlock_window();
314         get_gui()->lock_window("KeyFrameThread::delete_preset 2");
315
316
317 // Update list
318         calculate_preset_list();
319         ((KeyFrameWindow*)get_gui())->preset_list->update(presets_data,
320                 0,
321                 0,
322                 1);
323 }
324
325
326 void KeyFrameThread::apply_preset(const char *title)
327 {
328         if(presets_db->preset_exists(plugin_title, title))
329         {
330                 get_gui()->unlock_window();
331                 mwindow->gui->lock_window("KeyFrameThread::apply_preset");
332
333 // Test EDL for plugin existence
334                 if(!mwindow->edl->tracks->plugin_exists(plugin))
335                 {
336                         mwindow->gui->unlock_window();
337                         get_gui()->lock_window("KeyFrameThread::delete_preset 1");
338                         return;
339                 }
340
341                 mwindow->undo->update_undo_before();
342
343
344 #ifdef USE_KEYFRAME_SPANNING
345                 KeyFrame keyframe;
346                 presets_db->load_preset(plugin_title, title, &keyframe);
347                 plugin->keyframes->update_parameter(&keyframe);
348 #else
349                 KeyFrame *keyframe = plugin->get_keyframe();
350                 presets_db->load_preset(plugin_title, title, keyframe);
351 #endif
352                 mwindow->save_backup();
353                 mwindow->undo->update_undo_after(_("apply preset"), LOAD_AUTOMATION); 
354
355                 mwindow->update_plugin_guis(0);
356                 mwindow->gui->draw_overlays(1);
357                 mwindow->sync_parameters(CHANGE_PARAMS);
358
359
360                 update_gui(1);
361                 mwindow->gui->unlock_window();
362                 get_gui()->lock_window("KeyFrameThread::apply_preset");
363         }
364 }
365
366 #ifdef EDIT_KEYFRAME
367 void KeyFrameThread::apply_value()
368 {
369         const char *text = 0;
370         BC_Hash hash;
371         KeyFrameWindow *window = (KeyFrameWindow*)get_gui();
372         int selection = window->keyframe_list->get_selection_number(0, 0);
373 //printf("KeyFrameThread::apply_value %d %d\n", __LINE__, selection);
374         if(selection < 0) return;
375         
376         if(selection == keyframe_data[0].size() - 1)
377                 text = window->value_text->get_text();
378         else
379         {
380                 char *key = keyframe_data[0].get(selection)->get_text();
381                 const char *value = window->value_text->get_text();
382                 hash.update(key, value);
383         }
384
385         get_gui()->unlock_window();
386         mwindow->gui->lock_window("KeyFrameThread::apply_value");
387         if(plugin && mwindow->edl->tracks->plugin_exists(plugin))
388         {
389                 mwindow->undo->update_undo_before();
390                 if(mwindow->session->keyframedialog_all)
391                 {
392 // Search for all keyframes in selection but don't create a new one.
393                         Track *track = plugin->track;
394                         int64_t start = track->to_units(mwindow->edl->local_session->get_selectionstart(0), 0);
395                         int64_t end = track->to_units(mwindow->edl->local_session->get_selectionend(0), 0);
396                         int got_it = 0;
397                         for(KeyFrame *current = (KeyFrame*)plugin->keyframes->last;
398                                 current;
399                                 current = (KeyFrame*)PREVIOUS)
400                         {
401                                 got_it = 1;
402                                 if(current && current->position < end)
403                                 {
404                                         current->update_parameter(&hash, text, 0);
405 // Stop at beginning of range
406                                         if(current->position <= start) break;
407                                 }
408                         }
409
410                         if(!got_it)
411                         {
412                                 KeyFrame* keyframe = (KeyFrame*)plugin->keyframes->default_auto;
413                                 keyframe->update_parameter(&hash, text, 0);
414                         }
415                 }
416                 else
417                 {
418 // Create new keyframe if enabled
419                         KeyFrame *keyframe = plugin->get_keyframe();
420                         keyframe->update_parameter(&hash, text, 0);
421                 }
422         }
423         else
424         {
425 printf("KeyFrameThread::apply_value %d: plugin doesn't exist\n", __LINE__);
426         }
427
428         mwindow->save_backup();
429         mwindow->undo->update_undo_after(_("edit keyframe"), LOAD_AUTOMATION); 
430
431         mwindow->update_plugin_guis(0);
432         mwindow->gui->draw_overlays(1);
433         mwindow->sync_parameters(CHANGE_PARAMS);
434
435
436
437         mwindow->gui->unlock_window();
438
439         update_gui(0);
440
441         get_gui()->lock_window("KeyFrameThread::apply_value");
442 }
443 #endif
444
445
446
447 KeyFrameWindow::KeyFrameWindow(MWindow *mwindow,
448         KeyFrameThread *thread,
449         int x,
450         int y,
451         char *title_string)
452  : BC_Window(title_string, 
453         x,
454         y,
455         mwindow->session->keyframedialog_w, 
456         mwindow->session->keyframedialog_h, 
457         320, 
458         240,
459         1,
460         0,
461         1)
462 {
463         this->mwindow = mwindow;
464         this->thread = thread;
465 }
466
467 void KeyFrameWindow::create_objects()
468 {
469         Theme *theme = mwindow->theme;
470
471         theme->get_keyframedialog_sizes(this);
472         thread->column_width[0] = mwindow->session->keyframedialog_column1;
473         thread->column_width[1] = mwindow->session->keyframedialog_column2;
474         lock_window("KeyFrameWindow::create_objects");
475
476 #ifdef EDIT_KEYFRAME
477
478
479         add_subwindow(title1 = new BC_Title(theme->keyframe_list_x,
480                 theme->keyframe_list_y - 
481                         BC_Title::calculate_h(this, (char*)"Py", LARGEFONT) - 
482                         theme->widget_border,
483                 _("Keyframe parameters:"),
484                 LARGEFONT));
485         add_subwindow(keyframe_list = new KeyFrameList(thread,
486                 this,
487                 theme->keyframe_list_x,
488                 theme->keyframe_list_y,
489                 theme->keyframe_list_w, 
490                 theme->keyframe_list_h));
491 //      add_subwindow(title2 = new BC_Title(theme->keyframe_text_x,
492 //              theme->keyframe_text_y - BC_Title::calculate_h(this, "P") - theme->widget_border,
493 //              _("Global Text:")));
494 //      add_subwindow(keyframe_text = new KeyFrameText(thread,
495 //              this,
496 //              theme->keyframe_text_x,
497 //              theme->keyframe_text_y,
498 //              theme->keyframe_text_w));
499         add_subwindow(title3 = new BC_Title(theme->keyframe_value_x,
500                 theme->keyframe_value_y - BC_Title::calculate_h(this, (char*)"P") - theme->widget_border,
501                 _("Edit value:")));
502         add_subwindow(value_text = new KeyFrameValue(thread,
503                 this,
504                 theme->keyframe_value_x,
505                 theme->keyframe_value_y,
506                 theme->keyframe_value_w));
507         add_subwindow(all_toggle = new KeyFrameAll(thread,
508                 this, 
509                 theme->keyframe_all_x,
510                 theme->keyframe_all_y));
511
512 #endif
513
514
515
516         add_subwindow(title4 = new BC_Title(theme->presets_list_x,
517                 theme->presets_list_y - 
518                         BC_Title::calculate_h(this, (char*)"Py", LARGEFONT) - 
519                         theme->widget_border,
520                 _("Presets:"),
521                 LARGEFONT));
522         add_subwindow(preset_list = new KeyFramePresetsList(thread,
523                 this,
524                 theme->presets_list_x,
525                 theme->presets_list_y,
526                 theme->presets_list_w, 
527                 theme->presets_list_h));
528         add_subwindow(title5 = new BC_Title(theme->presets_text_x,
529                 theme->presets_text_y - BC_Title::calculate_h(this, (char*)"P") - theme->widget_border,
530                 _("Preset title:")));
531         add_subwindow(preset_text = new KeyFramePresetsText(thread,
532                 this,
533                 theme->presets_text_x,
534                 theme->presets_text_y,
535                 theme->presets_text_w));
536         add_subwindow(delete_preset = new KeyFramePresetsDelete(thread,
537                 this,
538                 theme->presets_delete_x,
539                 theme->presets_delete_y));
540         add_subwindow(save_preset = new KeyFramePresetsSave(thread,
541                 this,
542                 theme->presets_save_x,
543                 theme->presets_save_y));
544         add_subwindow(apply_preset = new KeyFramePresetsApply(thread,
545                 this,
546                 theme->presets_apply_x,
547                 theme->presets_apply_y));
548
549
550
551
552         add_subwindow(new KeyFramePresetsOK(thread, this));
553         add_subwindow(new BC_CancelButton(this));
554
555         show_window();
556         unlock_window();
557 }
558
559 int KeyFrameWindow::resize_event(int w, int h)
560 {
561         Theme *theme = mwindow->theme;
562         mwindow->session->keyframedialog_w = w;
563         mwindow->session->keyframedialog_h = h;
564         theme->get_keyframedialog_sizes(this);
565
566 #ifdef EDIT_KEYFRAME
567
568         title1->reposition_window(theme->keyframe_list_x,
569                 theme->keyframe_list_y - BC_Title::calculate_h(this, (char*)"P") - theme->widget_border);
570 //      title2->reposition_window(theme->keyframe_text_x,
571 //              theme->keyframe_text_y - BC_Title::calculate_h(this, (char*)"P") - theme->widget_border);
572         title3->reposition_window(theme->keyframe_value_x,
573                 theme->keyframe_value_y - BC_Title::calculate_h(this, (char*)"P") - theme->widget_border);
574         keyframe_list->reposition_window(theme->keyframe_list_x,
575                 theme->keyframe_list_y,
576                 theme->keyframe_list_w, 
577                 theme->keyframe_list_h);
578 //      text->reposition_window(theme->keyframe_text_x,
579 //              theme->keyframe_text_y,
580 //              theme->keyframe_text_w);
581         value_text->reposition_window(theme->keyframe_value_x,
582                 theme->keyframe_value_y,
583                 theme->keyframe_value_w);
584         all_toggle->reposition_window(theme->keyframe_all_x,
585                 theme->keyframe_all_y);
586
587 #endif // EDIT_KEYFRAME
588
589
590
591
592         title4->reposition_window(theme->presets_list_x,
593                 theme->presets_list_y - BC_Title::calculate_h(this, (char*)"P") - theme->widget_border);
594         title5->reposition_window(theme->presets_text_x,
595                 theme->presets_text_y - BC_Title::calculate_h(this, (char*)"P") - theme->widget_border);
596         preset_list->reposition_window(theme->presets_list_x,
597                 theme->presets_list_y,
598                 theme->presets_list_w, 
599                 theme->presets_list_h);
600         preset_text->reposition_window(theme->presets_text_x,
601                 theme->presets_text_y,
602                 theme->presets_text_w);
603         delete_preset->reposition_window(theme->presets_delete_x,
604                 theme->presets_delete_y);
605         save_preset->reposition_window(theme->presets_save_x,
606                 theme->presets_save_y);
607         apply_preset->reposition_window(theme->presets_apply_x,
608                 theme->presets_apply_y);
609
610         return 0;
611 }
612
613
614
615
616 #ifdef EDIT_KEYFRAME
617
618
619 KeyFrameList::KeyFrameList(KeyFrameThread *thread,
620         KeyFrameWindow *window,
621         int x,
622         int y,
623         int w, 
624         int h)
625  : BC_ListBox(x, 
626                 y, 
627                 w, 
628                 h,
629                 LISTBOX_TEXT,
630                 thread->keyframe_data,
631                 (const char **)thread->column_titles,
632                 thread->column_width,
633                 KEYFRAME_COLUMNS)
634 {
635         this->thread = thread;
636         this->window = window;
637 }
638
639 int KeyFrameList::selection_changed()
640 {
641         window->value_text->update(
642                 thread->keyframe_data[1].get(get_selection_number(0, 0))->get_text());
643         return 0;
644 }
645
646 int KeyFrameList::handle_event()
647 {
648         window->set_done(0);
649         return 0;
650 }
651
652 int KeyFrameList::column_resize_event()
653 {
654         thread->mwindow->session->keyframedialog_column1 = get_column_width(0);
655         thread->mwindow->session->keyframedialog_column2 = get_column_width(1);
656         return 1;
657 }
658
659
660
661
662 // KeyFrameText::KeyFrameText(KeyFrameThread *thread,
663 //      KeyFrameWindow *window,
664 //      int x,
665 //      int y,
666 //      int w)
667 //  : BC_TextBox(x, 
668 //      y, 
669 //      w, 
670 //      1, 
671 //      "")
672 // {
673 //      this->thread = thread;
674 //      this->window = window;
675 // }
676 // 
677 // int KeyFrameText::handle_event()
678 // {
679 //      return 0;
680 // }
681
682
683
684 KeyFrameValue::KeyFrameValue(KeyFrameThread *thread,
685         KeyFrameWindow *window,
686         int x,
687         int y,
688         int w)
689  : BC_TextBox(x, 
690         y, 
691         w, 
692         1, 
693         (char*)"")
694 {
695         this->thread = thread;
696         this->window = window;
697 }
698
699 int KeyFrameValue::handle_event()
700 {
701         thread->update_values();
702         return 0;
703 }
704
705
706
707
708
709 KeyFrameAll::KeyFrameAll(KeyFrameThread *thread,
710         KeyFrameWindow *window,
711         int x,
712         int y)
713  : BC_CheckBox(x, 
714         y, 
715         thread->mwindow->session->keyframedialog_all, 
716         _("Apply to all selected keyframes"))
717 {
718         this->thread = thread;
719         this->window = window;
720 }
721
722 int KeyFrameAll::handle_event()
723 {
724         thread->mwindow->session->keyframedialog_all = get_value();
725         return 1;
726 }
727
728 #endif // EDIT_KEYFRAME
729
730
731
732
733
734
735
736
737
738
739 KeyFramePresetsList::KeyFramePresetsList(KeyFrameThread *thread,
740         KeyFrameWindow *window,
741         int x,
742         int y,
743         int w, 
744         int h)
745  : BC_ListBox(x, 
746                 y, 
747                 w, 
748                 h,
749                 LISTBOX_TEXT,
750                 thread->presets_data)
751 {
752         this->thread = thread;
753         this->window = window;
754 }
755
756 int KeyFramePresetsList::selection_changed()
757 {
758         if(get_selection_number(0, 0) >= 0)
759                 window->preset_text->update(
760                         thread->presets_data->get(get_selection_number(0, 0))->get_text());
761         return 0;
762 }
763
764 int KeyFramePresetsList::handle_event()
765 {
766         thread->apply_preset(window->preset_text->get_text());
767         window->set_done(0);
768         return 0;
769 }
770
771
772
773
774
775
776
777
778
779
780 KeyFramePresetsText::KeyFramePresetsText(KeyFrameThread *thread,
781         KeyFrameWindow *window,
782         int x,
783         int y,
784         int w)
785  : BC_TextBox(x, 
786         y, 
787         w, 
788         1, 
789         (char*)"")
790 {
791         this->thread = thread;
792         this->window = window;
793 }
794
795 int KeyFramePresetsText::handle_event()
796 {
797         return 0;
798 }
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816 KeyFramePresetsDelete::KeyFramePresetsDelete(KeyFrameThread *thread,
817         KeyFrameWindow *window,
818         int x,
819         int y)
820  : BC_GenericButton(x, y, _("Delete"))
821 {
822         this->thread = thread;
823         this->window = window;
824 }
825
826 int KeyFramePresetsDelete::handle_event()
827 {
828         thread->delete_preset(window->preset_text->get_text());
829         return 1;
830 }
831
832
833
834
835
836
837
838 KeyFramePresetsSave::KeyFramePresetsSave(KeyFrameThread *thread,
839         KeyFrameWindow *window,
840         int x,
841         int y)
842 : BC_GenericButton(x, y, _("Save"))
843 {
844         this->thread = thread;
845         this->window = window;
846 }
847
848 int KeyFramePresetsSave::handle_event()
849 {
850         thread->save_preset(window->preset_text->get_text());
851         return 1;
852 }
853
854
855
856
857
858
859
860
861 KeyFramePresetsApply::KeyFramePresetsApply(KeyFrameThread *thread,
862         KeyFrameWindow *window,
863         int x,
864         int y)
865  : BC_GenericButton(x, y, _("Apply"))
866 {
867         this->thread = thread;
868         this->window = window;
869 }
870
871 int KeyFramePresetsApply::handle_event()
872 {
873         thread->apply_preset(window->preset_text->get_text());
874         return 1;
875 }
876
877
878 KeyFramePresetsOK::KeyFramePresetsOK(KeyFrameThread *thread,
879         KeyFrameWindow *window)
880  : BC_OKButton(window)
881 {
882         this->thread = thread;
883         this->window = window;
884 }
885
886 int KeyFramePresetsOK::keypress_event()
887 {
888         if(get_keypress() == RETURN)
889         {
890 // Apply the preset
891                 if(thread->presets_db->preset_exists(thread->plugin_title, 
892                         window->preset_text->get_text()))
893                 {
894                         window->set_done(0);
895                         return 1;
896                 }
897                 else
898 // Save the preset
899                 {
900                         thread->save_preset(window->preset_text->get_text());
901                         return 1;
902                 }
903         }
904         return 0;
905 }
906
907
908
909
910
911
912