r877: Fix files that were missing from a make dist tarball.
[cinelerra_cv.git] / guicast / bctumble.C
blob771de50a0aed4626420c03984dc157bd3679a573
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, int w, int h)
52         if (w > 0 || h > 0) 
53                 printf("BC_Tumbler::reposition_window - w & h haven't been implemented yet!! (probably never will be)");
55         BC_WindowBase::reposition_window(x, y);
56         draw_face();
57         return 0;
61 int BC_Tumbler::update_bitmaps(VFrame **data)
63         set_images(data);
64         draw_top_background(parent_window, 0, 0, w, h);
65         draw_face();
66         return 0;
69 int BC_Tumbler::set_images(VFrame **data)
71         for(int i = 0; i < TOTAL_STATES; i++)
72         {
73                 if(images[i]) delete images[i];
74                 images[i] = new BC_Pixmap(parent_window, data[i], PIXMAP_ALPHA);
75         }
77         return 0;
80 int BC_Tumbler::draw_face()
82         draw_top_background(parent_window, 0, 0, w, h);
83         pixmap->draw_pixmap(images[status], 
84                         0, 
85                         0,
86                         w,
87                         h,
88                         0,
89                         0);
90         flash();
91         return 0;
94 int BC_Tumbler::repeat_event(int64_t duration)
96 //printf("BC_Tumbler::repeat_event 1 %d\n", duration);
97         if(duration == top_level->get_resources()->tooltip_delay)
98         {
99                 if(tooltip_text[0] != 0 &&
100                         status == TUMBLE_UPHI &&
101                         !tooltip_done)
102                 {
103                         show_tooltip();
104                         tooltip_done = 1;
105                         return 1;
106                 }
107         }
108         else
109         if(duration == top_level->get_resources()->tumble_duration)
110         {
111 //printf("BC_Tumbler::repeat_event 2\n");
112                 repeat_count++;
113                 if(repeat_count == 2) return 0;
114                 if(status == TUMBLETOP_DN)
115                 {
116                         handle_up_event();
117                         return 1;
118                 }
119                 else
120                 if(status == TUMBLEBOTTOM_DN)
121                 {
122                         handle_down_event();
123                         return 1;
124                 }
125         }
126         return 0;
129 int BC_Tumbler::cursor_enter_event()
131         if(top_level->event_win == win)
132         {
133                 tooltip_done = 0;
134                 if(! top_level->button_down && status == TUMBLE_UP) 
135                 {
136                         status = TUMBLE_UPHI;
137                         draw_face();
138                 }
139         }
140         return 0;
143 int BC_Tumbler::cursor_leave_event()
145         hide_tooltip();
146         if(status == TUMBLE_UPHI)
147         {
148                 status = TUMBLE_UP;
149                 draw_face();
150         }
151         return 0;
154 int BC_Tumbler::button_press_event()
156         hide_tooltip();
157         if(top_level->event_win == win)
158         {
159 //printf("BC_Tumbler::button_press_event 1 %d\n", get_buttonpress());
160                 if(get_buttonpress() == 4)
161                 {
162                         status = TUMBLETOP_DN;
163                         draw_face();
164                         flush();
165                         handle_up_event();
166 //                      repeat_count = 0;
167 //                      repeat_event(top_level->get_resources()->tumble_duration);
168                 }
169                 else
170                 if(get_buttonpress() == 5)
171                 {
172                         status = TUMBLEBOTTOM_DN;
173                         draw_face();
174                         flush();
175                         handle_down_event();
176 //                      repeat_count = 0;
177 //                      repeat_event(top_level->get_resources()->tumble_duration);
178                 }
179                 else
180                 {
181                         if(top_level->cursor_y < get_h() / 2)
182                         {
183                                 status = TUMBLETOP_DN;
184                         }
185                         else
186                         {
187                                 status = TUMBLEBOTTOM_DN;
188                         }
190                         draw_face();
191                         flush();
193                         top_level->set_repeat(top_level->get_resources()->tumble_duration);
194                         repeat_count = 0;
195                         repeat_event(top_level->get_resources()->tumble_duration);
196 //printf("BC_Tumbler::button_press_event 2 %d\n", get_buttonpress());
197                 }
198                 return 1;
199         }
200         return 0;
203 int BC_Tumbler::button_release_event()
205         hide_tooltip();
206         if(top_level->event_win == win)
207         {
208                 if(status == TUMBLEBOTTOM_DN || status == TUMBLETOP_DN)
209                 {
210                         top_level->unset_repeat(top_level->get_resources()->tumble_duration);
211                         if(cursor_inside())
212                                 status = TUMBLE_UPHI;
213                         else
214                                 status = TUMBLE_UP;
215                 }
216                 draw_face();
217         }
218         return 0;
221 int BC_Tumbler::cursor_motion_event()
223         if(top_level->button_down && top_level->event_win == win && 
224                 !cursor_inside() &&
225                 !(status == TUMBLETOP_DN || status == TUMBLEBOTTOM_DN))
226         {
227                 status = TUMBLE_UP;
228                 draw_face();
229         }
230         return 0;
236 BC_ITumbler::BC_ITumbler(BC_TextBox *textbox, int64_t min, int64_t max, int x, int y)
237  : BC_Tumbler(x, y)
239         this->textbox = textbox;
240         this->min = min;
241         this->max = max;
242         this->increment = 1;
245 BC_ITumbler::~BC_ITumbler()
249 void BC_ITumbler::set_increment(float value)
251         this->increment = (int64_t)value;
252         if(increment < 1) increment = 1;
255 int BC_ITumbler::handle_up_event()
257         int64_t value = atol(textbox->get_text());
258         value += increment;
259         if(value > max) value = max;
260         textbox->update(value);
261         textbox->handle_event();
262         return 1;
265 int BC_ITumbler::handle_down_event()
267         int64_t value = atol(textbox->get_text());
268         value -= increment;
269         if(value < min) value = min;
270         textbox->update(value);
271         textbox->handle_event();
272         return 1;
275 void BC_ITumbler::set_boundaries(int64_t min, int64_t max)
277         this->min = min;
278         this->max = max;
290 BC_FTumbler::BC_FTumbler(BC_TextBox *textbox, 
291         float min, 
292         float max, 
293         int x, 
294         int y)
295  : BC_Tumbler(x, y)
297         this->textbox = textbox;
298         this->min = min;
299         this->max = max;
300         this->increment = 1.0;
303 BC_FTumbler::~BC_FTumbler()
307 int BC_FTumbler::handle_up_event()
309         float value = atof(textbox->get_text());
310         value += increment;
311         if(value > max) value = max;
312         textbox->update(value);
313         textbox->handle_event();
314         return 1;
317 int BC_FTumbler::handle_down_event()
319         float value = atof(textbox->get_text());
320         value -= increment;
321         if(value < min) value = min;
322         textbox->update(value);
323         textbox->handle_event();
324         return 1;
327 void BC_FTumbler::set_boundaries(float min, float max)
329         this->min = min;
330         this->max = max;
333 void BC_FTumbler::set_increment(float value)
335         this->increment = value;