a0052ea1fb16d30c7fdc5a45998f20c56cec576c
[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         xS(250),
38         yS(250),
39         xS(250),
40         yS(250),
41         0)
42 {
43         this->plugin = plugin;
44 }
45
46 InterpolateVideoWindow::~InterpolateVideoWindow()
47 {
48 }
49
50 void InterpolateVideoWindow::create_objects()
51 {
52         int xs5 = xS(5), xs10 = xS(10);
53         int ys10 = yS(10);
54         int x = xs10, y = ys10;
55
56         BC_Title *title;
57
58
59         add_subwindow(title = new BC_Title(x, y, _("Input frames per second:")));
60         y += title->get_h() + plugin->get_theme()->widget_border;
61         add_subwindow(rate = new InterpolateVideoRate(plugin,
62                 this,
63                 x,
64                 y));
65         add_subwindow(rate_menu = new InterpolateVideoRateMenu(plugin,
66                 this,
67                 x + rate->get_w() + xs5,
68                 y));
69         y += rate->get_h() + plugin->get_theme()->widget_border;
70         add_subwindow(keyframes = new InterpolateVideoKeyframes(plugin,
71                 this,
72                 x,
73                 y));
74         y += keyframes->get_h() + plugin->get_theme()->widget_border;
75         add_subwindow(flow = new InterpolateVideoFlow(plugin,
76                 this,
77                 x,
78                 y));
79
80         y += flow->get_h() + plugin->get_theme()->widget_border;
81         add_subwindow(vectors = new InterpolateVideoVectors(plugin,
82                 this,
83                 x,
84                 y));
85
86         y += vectors->get_h() + plugin->get_theme()->widget_border;
87         add_subwindow(radius_title = new BC_Title(x, y, _("Search radius:")));
88         add_subwindow(radius = new InterpolateVideoRadius(plugin,
89                 this,
90                 x + radius_title->get_w() + plugin->get_theme()->widget_border,
91                 y));
92
93         y += radius->get_h() + plugin->get_theme()->widget_border;
94         add_subwindow(size_title = new BC_Title(x, y, _("Macroblock size:")));
95         add_subwindow(size = new InterpolateVideoSize(plugin,
96                 this,
97                 x + size_title->get_w() + plugin->get_theme()->widget_border,
98                 y));
99
100
101         update_enabled();
102         show_window();
103 }
104
105 void InterpolateVideoWindow::update_enabled()
106 {
107         if(plugin->config.use_keyframes)
108         {
109                 rate->disable();
110         }
111         else
112         {
113                 rate->enable();
114         }
115
116         if(plugin->config.optic_flow)
117         {
118                 vectors->enable();
119                 radius->enable();
120                 size->enable();
121                 radius_title->set_color(get_resources()->default_text_color);
122                 size_title->set_color(get_resources()->default_text_color);
123         }
124         else
125         {
126                 vectors->disable();
127                 radius->disable();
128                 size->disable();
129                 radius_title->set_color(get_resources()->disabled_text_color);
130                 size_title->set_color(get_resources()->disabled_text_color);
131         }
132 }
133
134
135
136
137
138
139
140
141
142
143
144
145
146 InterpolateVideoRate::InterpolateVideoRate(InterpolateVideo *plugin,
147         InterpolateVideoWindow *gui,
148         int x,
149         int y)
150  : BC_TextBox(x,
151         y,
152         xS(90),
153         1,
154         (float)plugin->config.input_rate)
155 {
156         this->plugin = plugin;
157         this->gui = gui;
158 }
159
160 int InterpolateVideoRate::handle_event()
161 {
162         plugin->config.input_rate = Units::atoframerate(get_text());
163         plugin->send_configure_change();
164         return 1;
165 }
166
167
168
169
170 InterpolateVideoRateMenu::InterpolateVideoRateMenu(InterpolateVideo *plugin,
171         InterpolateVideoWindow *gui,
172         int x,
173         int y)
174  : BC_ListBox(x,
175         y,
176         xS(100),
177         yS(200),
178         LISTBOX_TEXT,
179         &plugin->get_theme()->frame_rates,
180         0,
181         0,
182         1,
183         0,
184         1)
185 {
186         this->plugin = plugin;
187         this->gui = gui;
188 }
189
190 int InterpolateVideoRateMenu::handle_event()
191 {
192         char *text = get_selection(0, 0)->get_text();
193         plugin->config.input_rate = atof(text);
194         gui->rate->update(text);
195         plugin->send_configure_change();
196         return 1;
197 }
198
199
200
201
202 InterpolateVideoKeyframes::InterpolateVideoKeyframes(InterpolateVideo *plugin,
203         InterpolateVideoWindow *gui,
204         int x,
205         int y)
206  : BC_CheckBox(x,
207         y,
208         plugin->config.use_keyframes,
209         _("Use keyframes as input"))
210 {
211         this->plugin = plugin;
212         this->gui = gui;
213 }
214 int InterpolateVideoKeyframes::handle_event()
215 {
216         plugin->config.use_keyframes = get_value();
217         gui->update_enabled();
218         plugin->send_configure_change();
219         return 1;
220 }
221
222
223
224
225 InterpolateVideoFlow::InterpolateVideoFlow(InterpolateVideo *plugin,
226         InterpolateVideoWindow *gui,
227         int x,
228         int y)
229  : BC_CheckBox(x,
230         y,
231         plugin->config.optic_flow,
232         _("Use optic flow"))
233 {
234         this->plugin = plugin;
235         this->gui = gui;
236 }
237 int InterpolateVideoFlow::handle_event()
238 {
239         plugin->config.optic_flow = get_value();
240         gui->update_enabled();
241         plugin->send_configure_change();
242         return 1;
243 }
244
245
246
247 InterpolateVideoVectors::InterpolateVideoVectors(InterpolateVideo *plugin,
248         InterpolateVideoWindow *gui,
249         int x,
250         int y)
251  : BC_CheckBox(x,
252         y,
253         plugin->config.draw_vectors,
254         _("Draw motion vectors"))
255 {
256         this->plugin = plugin;
257         this->gui = gui;
258 }
259 int InterpolateVideoVectors::handle_event()
260 {
261         plugin->config.draw_vectors = get_value();
262         plugin->send_configure_change();
263         return 1;
264 }
265
266
267
268
269
270
271 InterpolateVideoRadius::InterpolateVideoRadius(InterpolateVideo *plugin,
272         InterpolateVideoWindow *gui,
273         int x,
274         int y)
275  : BC_IPot(x,
276         y,
277         plugin->config.search_radius,
278         MIN_SEARCH_RADIUS,
279         MAX_SEARCH_RADIUS)
280 {
281         this->plugin = plugin;
282         this->gui = gui;
283 }
284 int InterpolateVideoRadius::handle_event()
285 {
286         plugin->config.search_radius = get_value();
287         plugin->send_configure_change();
288         return 1;
289 }
290
291
292
293
294
295
296
297
298
299 InterpolateVideoSize::InterpolateVideoSize(InterpolateVideo *plugin,
300         InterpolateVideoWindow *gui,
301         int x,
302         int y)
303  : BC_IPot(x,
304         y,
305         plugin->config.macroblock_size,
306         MIN_MACROBLOCK_SIZE,
307         MAX_MACROBLOCK_SIZE)
308 {
309         this->plugin = plugin;
310         this->gui = gui;
311 }
312 int InterpolateVideoSize::handle_event()
313 {
314         plugin->config.macroblock_size = get_value();
315         plugin->send_configure_change();
316         return 1;
317 }
318
319
320
321
322
323
324
325