2f9a5dbadc39c29c322264d437b5b3010c81cfc6
[goodguy/history.git] / cinelerra-5.1 / cinelerra / effectlist.C
1 /*
2  * CINELERRA
3  * Copyright (C) 2006 Pierre Dumuid
4  * Copyright (C) 1997-2012 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 "awindow.h"
23 #include "awindowgui.h"
24 #include "clip.h"
25 #include "cstrdup.h"
26 #include "effectlist.h"
27 #include "guicast.h"
28 #include "language.h"
29 #include "mwindow.h"
30 #include "pluginserver.h"
31
32 EffectTipDialog::EffectTipDialog(MWindow *mwindow, AWindow *awindow)
33  : BC_DialogThread()
34 {
35         this->mwindow = mwindow;
36         this->awindow = awindow;
37         effect = 0;
38         text = 0;
39 }
40
41 EffectTipDialog::~EffectTipDialog()
42 {
43         close_window();
44         delete [] effect;
45         delete [] text;
46 }
47
48 void EffectTipDialog::start(int x, int y, const char *effect, const char *text)
49 {
50         close_window();
51         AWindowGUI *gui = awindow->gui;
52         char string[BCTEXTLEN];
53         sprintf(string, _("Effect info: %s"), _(effect));
54         int effect_w = BC_Title::calculate_w(gui, string);
55         int text_w = BC_Title::calculate_w(gui, text);
56         int text_h = BC_Title::calculate_h(gui, text);
57         this->w = bmax(text_w + 30, bmax(effect_w + 30, 120));
58         this->h = bmax(text_h + 100, 120);
59         this->x = x - this->w / 2;
60         this->y = y - this->h / 2;
61         delete [] this->effect;  this->effect = cstrdup(string);
62         delete [] this->text;    this->text = cstrdup(text);
63         BC_DialogThread::start();
64 }
65
66 BC_Window* EffectTipDialog::new_gui()
67 {
68         AWindowGUI *gui = awindow->gui;
69         effect_gui = new EffectTipWindow(gui, this);
70         effect_gui->create_objects();
71         return effect_gui;
72 };
73
74
75 EffectTipWindow::EffectTipWindow(AWindowGUI *gui, EffectTipDialog *thread)
76  : BC_Window(_(PROGRAM_NAME ": Effect Info"),
77         thread->x + thread->w/2, thread->y + thread->h/2,
78         thread->w, thread->h, thread->w, thread->h, 0, 0, 1)
79 {
80         this->gui = gui;
81         this->thread = thread;
82 }
83 EffectTipWindow::~EffectTipWindow()
84 {
85 }
86
87 void EffectTipWindow::create_objects()
88 {
89         int x = 10, y = 10;
90         BC_Title *title;
91         add_subwindow(title = new BC_Title(x, y, thread->effect));
92         y += title->get_h() + 10;
93         add_subwindow(tip_text = new BC_Title(x+5, y, thread->text));
94         add_subwindow(new BC_OKButton(this));
95         show_window(1);
96 };
97
98 EffectTipItem::EffectTipItem(AWindowGUI *gui)
99  : BC_MenuItem(_("Info"))
100 {
101         this->gui = gui;
102 }
103 EffectTipItem::~EffectTipItem()
104 {
105 }
106
107 int EffectTipItem::handle_event()
108 {
109         AssetPicon *result = (AssetPicon*)gui->asset_list->get_selection(0,0);
110         if( result && result->plugin ) {
111                 const char *info = result->plugin->tip;
112                 if( !info ) info = _("No info available");
113                 int cur_x, cur_y;
114                 gui->get_abs_cursor(cur_x, cur_y, 0);
115                 gui->awindow->effect_tip->start(cur_x, cur_y,
116                         result->plugin->title, info);
117         }
118         return 1;
119 }
120
121
122 EffectListMenu::EffectListMenu(MWindow *mwindow, AWindowGUI *gui)
123  : BC_PopupMenu(0, 0, 0, "", 0)
124 {
125         this->mwindow = mwindow;
126         this->gui = gui;
127 }
128
129 EffectListMenu:: ~EffectListMenu()
130 {
131 }
132
133 void EffectListMenu::create_objects()
134 {
135         add_item(new EffectTipItem(gui));
136         add_item(format = new AWindowListFormat(mwindow, gui));
137         add_item(new AWindowListSort(mwindow, gui));
138 }
139
140 void EffectListMenu::update()
141 {
142         format->update();
143 }
144