r663: This commit was generated by cvs2svn to compensate for changes in r662,
[cinelerra_cv.git] / guicast / bctumble.C
blob400b049a795d7a32b2f9e48a604b8d0d07a71071
1 #include "bcpixmap.h"
2 #include "bcresources.h"
3 #include "bctextbox.h"
4 #include "bctumble.h"
7 #define TUMBLE_UP 0
8 #define TUMBLE_UPHI 1
9 #define TUMBLEBOTTOM_DN 2
10 #define TUMBLETOP_DN 3
11 #define TOTAL_STATES 4
13 BC_Tumbler::BC_Tumbler(int x, int y, VFrame **data)
14  : BC_SubWindow(x, y, 0, 0, -1)
16         for(int i = 0; i < TOTAL_STATES; i++)
17                 images[i] = 0;
18         status = TUMBLE_UP;
19         repeat_count = 0;
20         this->data = data;
24 BC_Tumbler::~BC_Tumbler()
26         for(int i = 0; i < TOTAL_STATES; i ++)
27                 delete images[i];
32 int BC_Tumbler::initialize()
34 // Get the image
35         if(data)
36                 set_images(data);
37         else
38                 set_images(get_resources()->tumble_data);
39         w = images[TUMBLE_UP]->get_w();
40         h = images[TUMBLE_UP]->get_h();
42 // Create the subwindow
43         BC_SubWindow::initialize();
45 // Display the bitmap
46         draw_face();
47         return 0;
50 int BC_Tumbler::reposition_window(int x, int y)
52         BC_WindowBase::reposition_window(x, y);
53         draw_face();
54         return 0;
58 int BC_Tumbler::update_bitmaps(VFrame **data)
60         set_images(data);
61         draw_top_background(parent_window, 0, 0, w, h);
62         draw_face();
63         return 0;
66 int BC_Tumbler::set_images(VFrame **data)
68         for(int i = 0; i < TOTAL_STATES; i++)
69         {
70                 if(images[i]) delete images[i];
71                 images[i] = new BC_Pixmap(parent_window, data[i], PIXMAP_ALPHA);
72         }
74         return 0;
77 int BC_Tumbler::draw_face()
79         draw_top_background(parent_window, 0, 0, w, h);
80         images[status]->write_drawable(pixmap, 
81                         0, 
82                         0,
83                         w,
84                         h,
85                         0,
86                         0);
87         flash();
88         return 0;
91 int BC_Tumbler::repeat_event(int64_t duration)
93 //printf("BC_Tumbler::repeat_event 1 %d\n", duration);
94         if(duration == top_level->get_resources()->tooltip_delay)
95         {
96                 if(tooltip_text[0] != 0 &&
97                         status == TUMBLE_UPHI &&
98                         !tooltip_done)
99                 {
100                         show_tooltip();
101                         tooltip_done = 1;
102                         return 1;
103                 }
104         }
105         else
106         if(duration == top_level->get_resources()->tumble_duration)
107         {
108 //printf("BC_Tumbler::repeat_event 2\n");
109                 repeat_count++;
110                 if(repeat_count == 2) return 0;
111                 if(status == TUMBLETOP_DN)
112                 {
113                         handle_up_event();
114                         return 1;
115                 }
116                 else
117                 if(status == TUMBLEBOTTOM_DN)
118                 {
119                         handle_down_event();
120                         return 1;
121                 }
122         }
123         return 0;
126 int BC_Tumbler::cursor_enter_event()
128         if(top_level->event_win == win)
129         {
130                 tooltip_done = 0;
131                 if(! top_level->button_down && status == TUMBLE_UP) 
132                 {
133                         status = TUMBLE_UPHI;
134                         draw_face();
135                 }
136         }
137         return 0;
140 int BC_Tumbler::cursor_leave_event()
142         hide_tooltip();
143         if(status == TUMBLE_UPHI)
144         {
145                 status = TUMBLE_UP;
146                 draw_face();
147         }
148         return 0;
151 int BC_Tumbler::button_press_event()
153         hide_tooltip();
154         if(top_level->event_win == win)
155         {
156 //printf("BC_Tumbler::button_press_event 1 %d\n", get_buttonpress());
157                 if(get_buttonpress() == 4)
158                 {
159                         status = TUMBLETOP_DN;
160                         draw_face();
161                         flush();
162                         handle_up_event();
163 //                      repeat_count = 0;
164 //                      repeat_event(top_level->get_resources()->tumble_duration);
165                 }
166                 else
167                 if(get_buttonpress() == 5)
168                 {
169                         status = TUMBLEBOTTOM_DN;
170                         draw_face();
171                         flush();
172                         handle_down_event();
173 //                      repeat_count = 0;
174 //                      repeat_event(top_level->get_resources()->tumble_duration);
175                 }
176                 else
177                 {
178                         if(top_level->cursor_y < get_h() / 2)
179                         {
180                                 status = TUMBLETOP_DN;
181                         }
182                         else
183                         {
184                                 status = TUMBLEBOTTOM_DN;
185                         }
187                         draw_face();
188                         flush();
190                         top_level->set_repeat(top_level->get_resources()->tumble_duration);
191                         repeat_count = 0;
192                         repeat_event(top_level->get_resources()->tumble_duration);
193 //printf("BC_Tumbler::button_press_event 2 %d\n", get_buttonpress());
194                 }
195                 return 1;
196         }
197         return 0;
200 int BC_Tumbler::button_release_event()
202         hide_tooltip();
203         if(top_level->event_win == win)
204         {
205                 if(status == TUMBLEBOTTOM_DN || status == TUMBLETOP_DN)
206                 {
207                         top_level->unset_repeat(top_level->get_resources()->tumble_duration);
208                         if(cursor_inside())
209                                 status = TUMBLE_UPHI;
210                         else
211                                 status = TUMBLE_UP;
212                 }
213                 draw_face();
214         }
215         return 0;
218 int BC_Tumbler::cursor_motion_event()
220         if(top_level->button_down && top_level->event_win == win && 
221                 !cursor_inside() &&
222                 !(status == TUMBLETOP_DN || status == TUMBLEBOTTOM_DN))
223         {
224                 status = TUMBLE_UP;
225                 draw_face();
226         }
227         return 0;
233 BC_ITumbler::BC_ITumbler(BC_TextBox *textbox, int64_t min, int64_t max, int x, int y)
234  : BC_Tumbler(x, y)
236         this->textbox = textbox;
237         this->min = min;
238         this->max = max;
239         this->increment = 1;
242 BC_ITumbler::~BC_ITumbler()
246 void BC_ITumbler::set_increment(float value)
248         this->increment = (int64_t)value;
249         if(increment < 1) increment = 1;
252 int BC_ITumbler::handle_up_event()
254         int64_t value = atol(textbox->get_text());
255         value += increment;
256         if(value > max) value = max;
257         textbox->update(value);
258         textbox->handle_event();
259         return 1;
262 int BC_ITumbler::handle_down_event()
264         int64_t value = atol(textbox->get_text());
265         value -= increment;
266         if(value < min) value = min;
267         textbox->update(value);
268         textbox->handle_event();
269         return 1;
272 void BC_ITumbler::set_boundaries(int64_t min, int64_t max)
274         this->min = min;
275         this->max = max;
287 BC_FTumbler::BC_FTumbler(BC_TextBox *textbox, 
288         float min, 
289         float max, 
290         int x, 
291         int y)
292  : BC_Tumbler(x, y)
294         this->textbox = textbox;
295         this->min = min;
296         this->max = max;
297         this->increment = 1.0;
300 BC_FTumbler::~BC_FTumbler()
304 int BC_FTumbler::handle_up_event()
306         float value = atof(textbox->get_text());
307         value += increment;
308         if(value > max) value = max;
309         textbox->update(value);
310         textbox->handle_event();
311         return 1;
314 int BC_FTumbler::handle_down_event()
316         float value = atof(textbox->get_text());
317         value -= increment;
318         if(value < min) value = min;
319         textbox->update(value);
320         textbox->handle_event();
321         return 1;
324 void BC_FTumbler::set_boundaries(float min, float max)
326         this->min = min;
327         this->max = max;
330 void BC_FTumbler::set_increment(float value)
332         this->increment = value;