remove whitespace at eol
[goodguy/history.git] / cinelerra-5.1 / plugins / timeavg / timeavgwindow.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 "language.h"
24 #include "timeavgwindow.h"
25
26
27
28 #define MAX_FRAMES 1024
29
30
31 TimeAvgWindow::TimeAvgWindow(TimeAvgMain *client)
32  : PluginClientWindow(client, 250, 400, 250, 400, 0)
33 {
34         this->client = client;
35 }
36
37 TimeAvgWindow::~TimeAvgWindow()
38 {
39 }
40
41 void TimeAvgWindow::create_objects()
42 {
43         int x = 10, y = 10;
44         BC_Bar *bar;
45         BC_Title *title;
46
47         add_tool(title = new BC_Title(x, y, _("Frame count:")));
48         y += title->get_h() + 5;
49         add_tool(total_frames = new TimeAvgSlider(client, x, y));
50         y += 30;
51         add_tool(paranoid = new TimeAvgParanoid(client, x, y));
52         y += 30;
53         add_tool(no_subtract = new TimeAvgNoSubtract(client, x, y));
54         y += 30;
55         add_tool(bar = new BC_Bar(x, y, get_w() - x * 2));
56         y += bar->get_h() + 5;
57
58
59
60         add_tool(avg = new TimeAvgAvg(client, this, x, y));
61         y += 30;
62         add_tool(accum = new TimeAvgAccum(client, this, x, y));
63         y += 30;
64         add_tool(bar = new BC_Bar(x, y, get_w() - x * 2));
65         y += bar->get_h() + 5;
66
67
68
69         add_tool(replace = new TimeAvgReplace(client, this, x, y));
70         y += 30;
71         add_tool(new BC_Title(x, y, _("Threshold:")));
72         y += title->get_h() + 5;
73         add_tool(threshold = new TimeThresholdSlider(client, x, y));
74         y += 30;
75         add_tool(new BC_Title(x, y, _("Border:")));
76         y += title->get_h() + 5;
77         add_tool(border = new TimeBorderSlider(client, x, y));
78         y += 30;
79
80
81
82         add_tool(bar = new BC_Bar(x, y, get_w() - x * 2));
83         y += bar->get_h() + 5;
84
85
86         add_tool(greater = new TimeAvgGreater(client, this, x, y));
87         y += 30;
88         add_tool(less = new TimeAvgLess(client, this, x, y));
89         y += 30;
90
91         update_toggles();
92         show_window();
93         flush();
94 }
95
96 void TimeAvgWindow::update_toggles()
97 {
98         avg->update(client->config.mode == TimeAvgConfig::AVERAGE);
99         accum->update(client->config.mode == TimeAvgConfig::ACCUMULATE);
100         replace->update(client->config.mode == TimeAvgConfig::REPLACE);
101         greater->update(client->config.mode == TimeAvgConfig::GREATER);
102         less->update(client->config.mode == TimeAvgConfig::LESS);
103
104 //      if(client->config.mode == TimeAvgConfig::AVERAGE ||
105 //              client->config.mode == TimeAvgConfig::ACCUMULATE)
106 //      {
107 //              no_subtract->enable();
108 //      }
109 //      else
110 //      {
111 //              no_subtract->disable();
112 //      }
113
114         if(client->config.mode == TimeAvgConfig::REPLACE)
115         {
116                 threshold->enable();
117                 border->enable();
118         }
119         else
120         {
121                 threshold->disable();
122                 border->disable();
123         }
124 }
125
126
127 TimeAvgSlider::TimeAvgSlider(TimeAvgMain *client, int x, int y)
128  : BC_ISlider(x,
129         y,
130         0,
131         190,
132         200,
133         1,
134         MAX_FRAMES,
135         client->config.frames)
136 {
137         this->client = client;
138 }
139 TimeAvgSlider::~TimeAvgSlider()
140 {
141 }
142 int TimeAvgSlider::handle_event()
143 {
144         int result = get_value();
145         if(result < 1) result = 1;
146         client->config.frames = result;
147         client->send_configure_change();
148         return 1;
149 }
150
151
152
153 TimeThresholdSlider::TimeThresholdSlider(TimeAvgMain *client, int x, int y)
154  : BC_ISlider(x,
155         y,
156         0,
157         190,
158         200,
159         1,
160         255,
161         client->config.threshold)
162 {
163         this->client = client;
164 }
165 TimeThresholdSlider::~TimeThresholdSlider()
166 {
167 }
168 int TimeThresholdSlider::handle_event()
169 {
170         int result = get_value();
171         if(result < 1) result = 1;
172         client->config.threshold = result;
173         client->send_configure_change();
174         return 1;
175 }
176
177
178 TimeBorderSlider::TimeBorderSlider(TimeAvgMain *client, int x, int y)
179  : BC_ISlider(x,
180         y,
181         0,
182         190,
183         200,
184         0,
185         8,
186         client->config.border)
187 {
188         this->client = client;
189 }
190 TimeBorderSlider::~TimeBorderSlider()
191 {
192 }
193 int TimeBorderSlider::handle_event()
194 {
195         int result = get_value();
196         if(result < 0) result = 0;
197         client->config.border = result;
198         client->send_configure_change();
199         return 1;
200 }
201
202
203
204
205 TimeAvgAvg::TimeAvgAvg(TimeAvgMain *client, TimeAvgWindow *gui, int x, int y)
206  : BC_Radial(x, y,
207         client->config.mode == TimeAvgConfig::AVERAGE,
208         _("Average"))
209 {
210         this->client = client;
211         this->gui = gui;
212 }
213 int TimeAvgAvg::handle_event()
214 {
215         int result = get_value(); (void)result;
216         client->config.mode = TimeAvgConfig::AVERAGE;
217         gui->update_toggles();
218         client->send_configure_change();
219         return 1;
220 }
221
222
223
224
225 TimeAvgAccum::TimeAvgAccum(TimeAvgMain *client, TimeAvgWindow *gui, int x, int y)
226  : BC_Radial(x, y,
227         client->config.mode == TimeAvgConfig::ACCUMULATE,
228         _("Accumulate"))
229 {
230         this->client = client;
231         this->gui = gui;
232 }
233 int TimeAvgAccum::handle_event()
234 {
235         int result = get_value(); (void)result;
236         client->config.mode = TimeAvgConfig::ACCUMULATE;
237         gui->update_toggles();
238         client->send_configure_change();
239         return 1;
240 }
241
242
243
244 TimeAvgReplace::TimeAvgReplace(TimeAvgMain *client, TimeAvgWindow *gui, int x, int y)
245  : BC_Radial(x, y,
246         client->config.mode == TimeAvgConfig::REPLACE,
247         _("Replace"))
248 {
249         this->client = client;
250         this->gui = gui;
251 }
252 int TimeAvgReplace::handle_event()
253 {
254         int result = get_value(); (void)result;
255         client->config.mode = TimeAvgConfig::REPLACE;
256         gui->update_toggles();
257         client->send_configure_change();
258         return 1;
259 }
260
261
262 TimeAvgGreater::TimeAvgGreater(TimeAvgMain *client, TimeAvgWindow *gui, int x, int y)
263  : BC_Radial(x, y,
264         client->config.mode == TimeAvgConfig::GREATER,
265         _("Greater"))
266 {
267         this->client = client;
268         this->gui = gui;
269 }
270 int TimeAvgGreater::handle_event()
271 {
272         int result = get_value(); (void)result;
273         client->config.mode = TimeAvgConfig::GREATER;
274         gui->update_toggles();
275         client->send_configure_change();
276         return 1;
277 }
278
279
280 TimeAvgLess::TimeAvgLess(TimeAvgMain *client, TimeAvgWindow *gui, int x, int y)
281  : BC_Radial(x, y,
282         client->config.mode == TimeAvgConfig::LESS,
283         _("Less"))
284 {
285         this->client = client;
286         this->gui = gui;
287 }
288 int TimeAvgLess::handle_event()
289 {
290         int result = get_value(); (void)result;
291         client->config.mode = TimeAvgConfig::LESS;
292         gui->update_toggles();
293         client->send_configure_change();
294         return 1;
295 }
296
297
298
299 TimeAvgParanoid::TimeAvgParanoid(TimeAvgMain *client, int x, int y)
300  : BC_CheckBox(x, y,
301         client->config.paranoid,
302         _("Restart for every frame"))
303 {
304         this->client = client;
305 }
306 int TimeAvgParanoid::handle_event()
307 {
308         int result = get_value();
309         client->config.paranoid = result;
310         client->send_configure_change();
311         return 1;
312 }
313
314
315
316
317
318 TimeAvgNoSubtract::TimeAvgNoSubtract(TimeAvgMain *client, int x, int y)
319  : BC_CheckBox(x, y,
320         client->config.nosubtract,
321         _("Don't buffer frames"))
322 {
323         this->client = client;
324 }
325 int TimeAvgNoSubtract::handle_event()
326 {
327         int result = get_value();
328         client->config.nosubtract = result;
329         client->send_configure_change();
330         return 1;
331 }
332
333
334