initial commit
[goodguy/cinelerra.git] / cinelerra-5.1 / plugins / interpolatevideo / interpolatewindow.C
1 /*
2  * CINELERRA
3  * Copyright (C) 1997-2011 Adam Williams <broadcast at earthling dot net>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  * *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  *
19  */
20
21
22
23 #include "interpolatevideo.h"
24 #include "interpolatewindow.h"
25 #include "language.h"
26 #include "theme.h"
27
28
29
30
31
32
33
34
35 InterpolateVideoWindow::InterpolateVideoWindow(InterpolateVideo *plugin)
36  : PluginClientWindow(plugin,
37         250,
38         250,
39         250,
40         250,
41         0)
42 {
43         this->plugin = plugin;
44 }
45
46 InterpolateVideoWindow::~InterpolateVideoWindow()
47 {
48 }
49
50 void InterpolateVideoWindow::create_objects()
51 {
52         int x = 10, y = 10;
53
54         BC_Title *title;
55
56
57         add_subwindow(title = new BC_Title(x, y, _("Input frames per second:")));
58         y += title->get_h() + plugin->get_theme()->widget_border;
59         add_subwindow(rate = new InterpolateVideoRate(plugin,
60                 this,
61                 x,
62                 y));
63         add_subwindow(rate_menu = new InterpolateVideoRateMenu(plugin,
64                 this,
65                 x + rate->get_w() + 5,
66                 y));
67         y += rate->get_h() + plugin->get_theme()->widget_border;
68         add_subwindow(keyframes = new InterpolateVideoKeyframes(plugin,
69                 this,
70                 x,
71                 y));
72         y += keyframes->get_h() + plugin->get_theme()->widget_border;
73         add_subwindow(flow = new InterpolateVideoFlow(plugin,
74                 this,
75                 x,
76                 y));
77
78         y += flow->get_h() + plugin->get_theme()->widget_border;
79         add_subwindow(vectors = new InterpolateVideoVectors(plugin,
80                 this,
81                 x,
82                 y));
83
84         y += vectors->get_h() + plugin->get_theme()->widget_border;
85         add_subwindow(radius_title = new BC_Title(x, y, _("Search radius:")));
86         add_subwindow(radius = new InterpolateVideoRadius(plugin,
87                 this,
88                 x + radius_title->get_w() + plugin->get_theme()->widget_border,
89                 y));
90
91         y += radius->get_h() + plugin->get_theme()->widget_border;
92         add_subwindow(size_title = new BC_Title(x, y, _("Macroblock size:")));
93         add_subwindow(size = new InterpolateVideoSize(plugin,
94                 this,
95                 x + size_title->get_w() + plugin->get_theme()->widget_border,
96                 y));
97
98
99         update_enabled();
100         show_window();
101 }
102
103 void InterpolateVideoWindow::update_enabled()
104 {
105         if(plugin->config.use_keyframes)
106         {
107                 rate->disable();
108         }
109         else
110         {
111                 rate->enable();
112         }
113
114         if(plugin->config.optic_flow)
115         {
116                 vectors->enable();
117                 radius->enable();
118                 size->enable();
119                 radius_title->set_color(get_resources()->default_text_color);
120                 size_title->set_color(get_resources()->default_text_color);
121         }
122         else
123         {
124                 vectors->disable();
125                 radius->disable();
126                 size->disable();
127                 radius_title->set_color(get_resources()->disabled_text_color);
128                 size_title->set_color(get_resources()->disabled_text_color);
129         }
130 }
131
132
133
134
135
136
137
138
139
140
141
142
143
144 InterpolateVideoRate::InterpolateVideoRate(InterpolateVideo *plugin,
145         InterpolateVideoWindow *gui,
146         int x,
147         int y)
148  : BC_TextBox(x,
149         y,
150         90,
151         1,
152         (float)plugin->config.input_rate)
153 {
154         this->plugin = plugin;
155         this->gui = gui;
156 }
157
158 int InterpolateVideoRate::handle_event()
159 {
160         plugin->config.input_rate = Units::atoframerate(get_text());
161         plugin->send_configure_change();
162         return 1;
163 }
164
165
166
167
168 InterpolateVideoRateMenu::InterpolateVideoRateMenu(InterpolateVideo *plugin,
169         InterpolateVideoWindow *gui,
170         int x,
171         int y)
172  : BC_ListBox(x,
173         y,
174         100,
175         200,
176         LISTBOX_TEXT,
177         &plugin->get_theme()->frame_rates,
178         0,
179         0,
180         1,
181         0,
182         1)
183 {
184         this->plugin = plugin;
185         this->gui = gui;
186 }
187
188 int InterpolateVideoRateMenu::handle_event()
189 {
190         char *text = get_selection(0, 0)->get_text();
191         plugin->config.input_rate = atof(text);
192         gui->rate->update(text);
193         plugin->send_configure_change();
194         return 1;
195 }
196
197
198
199
200 InterpolateVideoKeyframes::InterpolateVideoKeyframes(InterpolateVideo *plugin,
201         InterpolateVideoWindow *gui,
202         int x,
203         int y)
204  : BC_CheckBox(x,
205         y,
206         plugin->config.use_keyframes,
207         _("Use keyframes as input"))
208 {
209         this->plugin = plugin;
210         this->gui = gui;
211 }
212 int InterpolateVideoKeyframes::handle_event()
213 {
214         plugin->config.use_keyframes = get_value();
215         gui->update_enabled();
216         plugin->send_configure_change();
217         return 1;
218 }
219
220
221
222
223 InterpolateVideoFlow::InterpolateVideoFlow(InterpolateVideo *plugin,
224         InterpolateVideoWindow *gui,
225         int x,
226         int y)
227  : BC_CheckBox(x,
228         y,
229         plugin->config.optic_flow,
230         _("Use optic flow"))
231 {
232         this->plugin = plugin;
233         this->gui = gui;
234 }
235 int InterpolateVideoFlow::handle_event()
236 {
237         plugin->config.optic_flow = get_value();
238         gui->update_enabled();
239         plugin->send_configure_change();
240         return 1;
241 }
242
243
244
245 InterpolateVideoVectors::InterpolateVideoVectors(InterpolateVideo *plugin,
246         InterpolateVideoWindow *gui,
247         int x,
248         int y)
249  : BC_CheckBox(x,
250         y,
251         plugin->config.draw_vectors,
252         _("Draw motion vectors"))
253 {
254         this->plugin = plugin;
255         this->gui = gui;
256 }
257 int InterpolateVideoVectors::handle_event()
258 {
259         plugin->config.draw_vectors = get_value();
260         plugin->send_configure_change();
261         return 1;
262 }
263
264
265
266
267
268
269 InterpolateVideoRadius::InterpolateVideoRadius(InterpolateVideo *plugin,
270         InterpolateVideoWindow *gui,
271         int x,
272         int y)
273  : BC_IPot(x,
274         y,
275         plugin->config.search_radius,
276         MIN_SEARCH_RADIUS,
277         MAX_SEARCH_RADIUS)
278 {
279         this->plugin = plugin;
280         this->gui = gui;
281 }
282 int InterpolateVideoRadius::handle_event()
283 {
284         plugin->config.search_radius = get_value();
285         plugin->send_configure_change();
286         return 1;
287 }
288
289
290
291
292
293
294
295
296
297 InterpolateVideoSize::InterpolateVideoSize(InterpolateVideo *plugin,
298         InterpolateVideoWindow *gui,
299         int x,
300         int y)
301  : BC_IPot(x,
302         y,
303         plugin->config.macroblock_size,
304         MIN_MACROBLOCK_SIZE,
305         MAX_MACROBLOCK_SIZE)
306 {
307         this->plugin = plugin;
308         this->gui = gui;
309 }
310 int InterpolateVideoSize::handle_event()
311 {
312         plugin->config.macroblock_size = get_value();
313         plugin->send_configure_change();
314         return 1;
315 }
316
317
318
319
320
321
322
323