ffmpeg api3 upgrade, rework bs filts, rm faac/d, fixes
[goodguy/history.git] / cinelerra-5.1 / guicast / bctumble.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 "bcpixmap.h"
23 #include "bcresources.h"
24 #include "bctextbox.h"
25 #include "bctumble.h"
26 #include "math.h"
27 #include "vframe.h"
28
29
30 #define TUMBLE_UP 0
31 #define TUMBLE_UPHI 1
32 #define TUMBLEBOTTOM_DN 2
33 #define TUMBLETOP_DN 3
34 #define TOTAL_STATES 4
35
36 BC_Tumbler::BC_Tumbler(int x, int y, VFrame **data)
37  : BC_SubWindow(x, y, 0, 0, -1)
38 {
39         for(int i = 0; i < TOTAL_STATES; i++)
40                 images[i] = 0;
41         status = TUMBLE_UP;
42         repeat_count = 0;
43         this->data = data;
44 }
45
46
47 BC_Tumbler::~BC_Tumbler()
48 {
49         for(int i = 0; i < TOTAL_STATES; i ++)
50                 delete images[i];
51 }
52
53
54 int BC_Tumbler::calculate_w()
55 {
56         return BC_WindowBase::get_resources()->tumble_data[0]->get_w();
57 }
58
59 int BC_Tumbler::calculate_h()
60 {
61         return BC_WindowBase::get_resources()->tumble_data[0]->get_h();
62 }
63
64
65 int BC_Tumbler::initialize()
66 {
67 // Get the image
68         if(data)
69                 set_images(data);
70         else
71                 set_images(get_resources()->tumble_data);
72         w = images[TUMBLE_UP]->get_w();
73         h = images[TUMBLE_UP]->get_h();
74
75 // Create the subwindow
76         BC_SubWindow::initialize();
77
78 // Display the bitmap
79         draw_face(0);
80         return 0;
81 }
82
83 int BC_Tumbler::reposition_window(int x, int y, int w, int h)
84 {
85         if (w > 0 || h > 0)
86                 printf("BC_Tumbler::reposition_window - w & h haven't been implemented yet!! (probably never will be)");
87
88         BC_WindowBase::reposition_window(x, y);
89         draw_face(0);
90         return 0;
91 }
92
93
94 int BC_Tumbler::update_bitmaps(VFrame **data)
95 {
96         set_images(data);
97         draw_top_background(parent_window, 0, 0, w, h);
98         draw_face(1);
99         return 0;
100 }
101
102 int BC_Tumbler::set_images(VFrame **data)
103 {
104         for(int i = 0; i < TOTAL_STATES; i++)
105         {
106                 if(images[i]) delete images[i];
107                 images[i] = new BC_Pixmap(parent_window, data[i], PIXMAP_ALPHA);
108         }
109
110         return 0;
111 }
112
113 int BC_Tumbler::draw_face(int flush)
114 {
115         draw_top_background(parent_window, 0, 0, w, h);
116         pixmap->draw_pixmap(images[status],
117                         0,
118                         0,
119                         w,
120                         h,
121                         0,
122                         0);
123         flash(flush);
124         return 0;
125 }
126
127 int BC_Tumbler::repeat_event(int64_t duration)
128 {
129 //printf("BC_Tumbler::repeat_event 1 %d\n", duration);
130         if(duration == top_level->get_resources()->tooltip_delay)
131         {
132                 if(tooltip_text && tooltip_text[0] != 0 &&
133                         status == TUMBLE_UPHI)
134                 {
135                         show_tooltip();
136                         return 1;
137                 }
138         }
139         else
140         if(duration == top_level->get_resources()->tumble_duration)
141         {
142 //printf("BC_Tumbler::repeat_event 2\n");
143                 repeat_count++;
144 // delay the 1st repeat
145                 if(repeat_count > 1 && repeat_count < 5) return 0;
146                 if(status == TUMBLETOP_DN)
147                 {
148                         handle_up_event();
149                         return 1;
150                 }
151                 else
152                 if(status == TUMBLEBOTTOM_DN)
153                 {
154                         handle_down_event();
155                         return 1;
156                 }
157         }
158         return 0;
159 }
160
161 int BC_Tumbler::cursor_enter_event()
162 {
163         if(top_level->event_win == win)
164         {
165                 if(! top_level->button_down && status == TUMBLE_UP)
166                 {
167                         status = TUMBLE_UPHI;
168                         draw_face(1);
169                 }
170         }
171         return 0;
172 }
173
174 int BC_Tumbler::cursor_leave_event()
175 {
176         hide_tooltip();
177         if(status == TUMBLE_UPHI)
178         {
179                 status = TUMBLE_UP;
180                 draw_face(1);
181         }
182         return 0;
183 }
184
185 int BC_Tumbler::button_press_event()
186 {
187         hide_tooltip();
188         if(top_level->event_win == win)
189         {
190 //printf("BC_Tumbler::button_press_event 1 %d\n", get_buttonpress());
191                 if(get_buttonpress() == 4)
192                 {
193                         status = TUMBLETOP_DN;
194                         draw_face(1);
195                         handle_up_event();
196 //                      repeat_count = 0;
197 //                      repeat_event(top_level->get_resources()->tumble_duration);
198                 }
199                 else
200                 if(get_buttonpress() == 5)
201                 {
202                         status = TUMBLEBOTTOM_DN;
203                         draw_face(1);
204                         handle_down_event();
205 //                      repeat_count = 0;
206 //                      repeat_event(top_level->get_resources()->tumble_duration);
207                 }
208                 else
209                 {
210                         if(top_level->cursor_y < get_h() / 2)
211                         {
212                                 status = TUMBLETOP_DN;
213                         }
214                         else
215                         {
216                                 status = TUMBLEBOTTOM_DN;
217                         }
218
219                         draw_face(1);
220
221                         top_level->set_repeat(top_level->get_resources()->tumble_duration);
222                         repeat_count = 0;
223                         repeat_event(top_level->get_resources()->tumble_duration);
224 //printf("BC_Tumbler::button_press_event 2 %d\n", get_buttonpress());
225                 }
226                 return 1;
227         }
228         return 0;
229 }
230
231 int BC_Tumbler::button_release_event()
232 {
233         hide_tooltip();
234         if(top_level->event_win == win)
235         {
236                 if(status == TUMBLEBOTTOM_DN || status == TUMBLETOP_DN)
237                 {
238                         top_level->unset_repeat(top_level->get_resources()->tumble_duration);
239                         if(cursor_inside())
240                                 status = TUMBLE_UPHI;
241                         else
242                                 status = TUMBLE_UP;
243                 }
244                 draw_face(1);
245         }
246         return 0;
247 }
248
249 int BC_Tumbler::cursor_motion_event()
250 {
251         if(top_level->button_down && top_level->event_win == win &&
252                 !cursor_inside() &&
253                 !(status == TUMBLETOP_DN || status == TUMBLEBOTTOM_DN))
254         {
255                 status = TUMBLE_UP;
256                 draw_face(1);
257         }
258         return 0;
259 }
260
261
262
263
264 BC_ITumbler::BC_ITumbler(BC_TextBox *textbox, int64_t min, int64_t max, int x, int y)
265  : BC_Tumbler(x, y)
266 {
267         this->textbox = textbox;
268         this->min = min;
269         this->max = max;
270         this->increment = 1;
271 }
272
273 BC_ITumbler::~BC_ITumbler()
274 {
275 }
276
277 void BC_ITumbler::set_increment(float value)
278 {
279         this->increment = (int64_t)value;
280         if(increment < 1) increment = 1;
281 }
282
283 int BC_ITumbler::handle_up_event()
284 {
285         int64_t value = atol(textbox->get_text());
286         value += increment;
287         if(value > max) value = max;
288         textbox->update(value);
289         textbox->handle_event();
290         return 1;
291 }
292
293 int BC_ITumbler::handle_down_event()
294 {
295         int64_t value = atol(textbox->get_text());
296         value -= increment;
297         if(value < min) value = min;
298         textbox->update(value);
299         textbox->handle_event();
300         return 1;
301 }
302
303 void BC_ITumbler::set_boundaries(int64_t min, int64_t max)
304 {
305         this->min = min;
306         this->max = max;
307 }
308
309
310
311
312
313
314
315
316
317
318 BC_FTumbler::BC_FTumbler(BC_TextBox *textbox,
319         float min,
320         float max,
321         int x,
322         int y)
323  : BC_Tumbler(x, y)
324 {
325         this->textbox = textbox;
326         this->min = min;
327         this->max = max;
328         this->increment = 1.0;
329         this->log_floatincrement = 0;
330 }
331
332 BC_FTumbler::~BC_FTumbler()
333 {
334 }
335
336 int BC_FTumbler::handle_up_event()
337 {
338         float value = atof(textbox->get_text());
339         if (log_floatincrement) {
340                 // round off to to current precision (i.e. 250 -> 200)
341                 float cp = floor(log(value)/log(10) + 0.0001);
342                 value = floor((value/pow(10,cp))+ 0.0001)*pow(10,cp);
343                 value += pow(10,cp);
344         }
345         else
346         value += increment;
347         if(value > max) value = max;
348         textbox->update(value);
349         textbox->handle_event();
350         return 1;
351 }
352
353 int BC_FTumbler::handle_down_event()
354 {
355         float value = atof(textbox->get_text());
356         if (log_floatincrement) {
357                 // round off to to current precision (i.e. 250 -> 200)
358                 float cp = floor(log(value)/log(10));
359                 value = floor(value/pow(10,cp))*pow(10,cp);
360                 // Need to make it so that: [.001 .01 .1 1 10 100] => [.0001 .001 .01 .1 1 10]
361                 cp = floor(log(value)/log(10)-.01);
362                 value -= pow(10,cp);
363         }
364         else
365         value -= increment;
366         if(value < min) value = min;
367         textbox->update(value);
368         textbox->handle_event();
369         return 1;
370 }
371
372 void BC_FTumbler::set_boundaries(float min, float max)
373 {
374         this->min = min;
375         this->max = max;
376 }
377
378 void BC_FTumbler::set_increment(float value)
379 {
380         this->increment = value;
381 }
382
383 void BC_FTumbler::set_log_floatincrement(int value)
384 {
385         this->log_floatincrement = value;
386 }