r125: This commit was manufactured by cvs2svn to create tag 'r1_1_7-last'.
[cinelerra_cv/mob.git] / hvirtual / guicast / bctumble.C
blob92119dae4d40a949052a7373a9416b7f6e5bc8f4
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)
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;
23 BC_Tumbler::~BC_Tumbler()
25         for(int i = 0; i < TOTAL_STATES; i ++)
26                 delete images[i];
31 int BC_Tumbler::initialize()
33 // Get the image
34         set_images(get_resources()->tumble_data);
35         w = images[TUMBLE_UP]->get_w();
36         h = images[TUMBLE_UP]->get_h();
38 // Create the subwindow
39         BC_SubWindow::initialize();
41 // Display the bitmap
42         draw_face();
43         return 0;
46 int BC_Tumbler::reposition_window(int x, int y)
48         BC_WindowBase::reposition_window(x, y);
49         draw_face();
50         return 0;
54 int BC_Tumbler::update_bitmaps(VFrame **data)
56         set_images(data);
57         draw_top_background(parent_window, 0, 0, w, h);
58         draw_face();
59         return 0;
62 int BC_Tumbler::set_images(VFrame **data)
64         for(int i = 0; i < TOTAL_STATES; i++)
65         {
66                 if(images[i]) delete images[i];
67                 images[i] = new BC_Pixmap(parent_window, data[i], PIXMAP_ALPHA);
68         }
70         return 0;
73 int BC_Tumbler::draw_face()
75         draw_top_background(parent_window, 0, 0, w, h);
76         images[status]->write_drawable(pixmap, 
77                         0, 
78                         0,
79                         w,
80                         h,
81                         0,
82                         0);
83         flash();
84         return 0;
87 int BC_Tumbler::repeat_event(int64_t duration)
89 //printf("BC_Tumbler::repeat_event 1 %d\n", duration);
90         if(duration == top_level->get_resources()->tooltip_delay)
91         {
92                 if(tooltip_text[0] != 0 &&
93                         status == TUMBLE_UPHI &&
94                         !tooltip_done)
95                 {
96                         show_tooltip();
97                         tooltip_done = 1;
98                         return 1;
99                 }
100         }
101         else
102         if(duration == top_level->get_resources()->tumble_duration)
103         {
104 //printf("BC_Tumbler::repeat_event 2\n");
105                 repeat_count++;
106                 if(repeat_count == 2) return 0;
107                 if(status == TUMBLETOP_DN)
108                 {
109                         handle_up_event();
110                         return 1;
111                 }
112                 else
113                 if(status == TUMBLEBOTTOM_DN)
114                 {
115                         handle_down_event();
116                         return 1;
117                 }
118         }
119         return 0;
122 int BC_Tumbler::cursor_enter_event()
124         if(top_level->event_win == win)
125         {
126                 tooltip_done = 0;
127                 if(! top_level->button_down && status == TUMBLE_UP) 
128                 {
129                         status = TUMBLE_UPHI;
130                         draw_face();
131                 }
132         }
133         return 0;
136 int BC_Tumbler::cursor_leave_event()
138         hide_tooltip();
139         if(status == TUMBLE_UPHI)
140         {
141                 status = TUMBLE_UP;
142                 draw_face();
143         }
144         return 0;
147 int BC_Tumbler::button_press_event()
149         hide_tooltip();
150         if(top_level->event_win == win)
151         {
152 //printf("BC_Tumbler::button_press_event 1 %d\n", get_buttonpress());
153                 if(get_buttonpress() == 4)
154                 {
155                         status = TUMBLETOP_DN;
156                         draw_face();
157                         flush();
158                         handle_up_event();
159 //                      repeat_count = 0;
160 //                      repeat_event(top_level->get_resources()->tumble_duration);
161                 }
162                 else
163                 if(get_buttonpress() == 5)
164                 {
165                         status = TUMBLEBOTTOM_DN;
166                         draw_face();
167                         flush();
168                         handle_down_event();
169 //                      repeat_count = 0;
170 //                      repeat_event(top_level->get_resources()->tumble_duration);
171                 }
172                 else
173                 {
174                         if(top_level->cursor_y < get_h() / 2)
175                         {
176                                 status = TUMBLETOP_DN;
177                         }
178                         else
179                         {
180                                 status = TUMBLEBOTTOM_DN;
181                         }
183                         draw_face();
184                         flush();
186                         top_level->set_repeat(top_level->get_resources()->tumble_duration);
187                         repeat_count = 0;
188                         repeat_event(top_level->get_resources()->tumble_duration);
189 //printf("BC_Tumbler::button_press_event 2 %d\n", get_buttonpress());
190                 }
191                 return 1;
192         }
193         return 0;
196 int BC_Tumbler::button_release_event()
198         hide_tooltip();
199         if(top_level->event_win == win)
200         {
201                 if(status == TUMBLEBOTTOM_DN || status == TUMBLETOP_DN)
202                 {
203                         top_level->unset_repeat(top_level->get_resources()->tumble_duration);
204                         if(cursor_inside())
205                                 status = TUMBLE_UPHI;
206                         else
207                                 status = TUMBLE_UP;
208                 }
209                 draw_face();
210         }
211         return 0;
214 int BC_Tumbler::cursor_motion_event()
216         if(top_level->button_down && top_level->event_win == win && 
217                 !cursor_inside() &&
218                 !(status == TUMBLETOP_DN || status == TUMBLEBOTTOM_DN))
219         {
220                 status = TUMBLE_UP;
221                 draw_face();
222         }
223         return 0;
229 BC_ITumbler::BC_ITumbler(BC_TextBox *textbox, int64_t min, int64_t max, int x, int y)
230  : BC_Tumbler(x, y)
232         this->textbox = textbox;
233         this->min = min;
234         this->max = max;
237 BC_ITumbler::~BC_ITumbler()
241 int BC_ITumbler::handle_up_event()
243         int64_t value = atol(textbox->get_text());
244         value++;
245         if(value > max) value = max;
246         textbox->update(value);
247         textbox->handle_event();
248         return 1;
251 int BC_ITumbler::handle_down_event()
253         int64_t value = atol(textbox->get_text());
254         value--;
255         if(value < min) value = min;
256         textbox->update(value);
257         textbox->handle_event();
258         return 1;
261 void BC_ITumbler::set_boundaries(int64_t min, int64_t max)
263         this->min = min;
264         this->max = max;
276 BC_FTumbler::BC_FTumbler(BC_TextBox *textbox, 
277         float min, 
278         float max, 
279         int x, 
280         int y)
281  : BC_Tumbler(x, y)
283         this->textbox = textbox;
284         this->min = min;
285         this->max = max;
286         this->increment = 1.0;
289 BC_FTumbler::~BC_FTumbler()
293 int BC_FTumbler::handle_up_event()
295         float value = atof(textbox->get_text());
296         value += increment;
297         if(value > max) value = max;
298         textbox->update(value);
299         textbox->handle_event();
300         return 1;
303 int BC_FTumbler::handle_down_event()
305         float value = atof(textbox->get_text());
306         value -= increment;
307         if(value < min) value = min;
308         textbox->update(value);
309         textbox->handle_event();
310         return 1;
313 void BC_FTumbler::set_boundaries(float min, float max)
315         this->min = min;
316         this->max = max;
319 void BC_FTumbler::set_increment(float value)
321         this->increment = increment;