2 #include "bcresources.h"
10 #define TUMBLEBOTTOM_DN 2
11 #define TUMBLETOP_DN 3
12 #define TOTAL_STATES 4
14 BC_Tumbler::BC_Tumbler(int x, int y, VFrame **data)
15 : BC_SubWindow(x, y, 0, 0, -1)
17 for(int i = 0; i < TOTAL_STATES; i++)
25 BC_Tumbler::~BC_Tumbler()
27 for(int i = 0; i < TOTAL_STATES; i ++)
33 int BC_Tumbler::initialize()
39 set_images(get_resources()->tumble_data);
40 w = images[TUMBLE_UP]->get_w();
41 h = images[TUMBLE_UP]->get_h();
43 // Create the subwindow
44 BC_SubWindow::initialize();
51 int BC_Tumbler::reposition_window(int x, int y, int w, int h)
54 printf("BC_Tumbler::reposition_window - w & h haven't been implemented yet!! (probably never will be)");
56 BC_WindowBase::reposition_window(x, y);
62 int BC_Tumbler::update_bitmaps(VFrame **data)
65 draw_top_background(parent_window, 0, 0, w, h);
70 int BC_Tumbler::set_images(VFrame **data)
72 for(int i = 0; i < TOTAL_STATES; i++)
74 if(images[i]) delete images[i];
75 images[i] = new BC_Pixmap(parent_window, data[i], PIXMAP_ALPHA);
81 int BC_Tumbler::draw_face()
83 draw_top_background(parent_window, 0, 0, w, h);
84 pixmap->draw_pixmap(images[status],
95 int BC_Tumbler::repeat_event(int64_t duration)
97 //printf("BC_Tumbler::repeat_event 1 %d\n", duration);
98 if(duration == top_level->get_resources()->tooltip_delay)
100 if(tooltip_text[0] != 0 &&
101 status == TUMBLE_UPHI &&
110 if(duration == top_level->get_resources()->tumble_duration)
112 //printf("BC_Tumbler::repeat_event 2\n");
114 if(repeat_count == 2) return 0;
115 if(status == TUMBLETOP_DN)
121 if(status == TUMBLEBOTTOM_DN)
130 int BC_Tumbler::cursor_enter_event()
132 if(top_level->event_win == win)
135 if(! top_level->button_down && status == TUMBLE_UP)
137 status = TUMBLE_UPHI;
144 int BC_Tumbler::cursor_leave_event()
147 if(status == TUMBLE_UPHI)
155 int BC_Tumbler::button_press_event()
158 if(top_level->event_win == win)
160 //printf("BC_Tumbler::button_press_event 1 %d\n", get_buttonpress());
161 if(get_buttonpress() == 4)
163 status = TUMBLETOP_DN;
168 // repeat_event(top_level->get_resources()->tumble_duration);
171 if(get_buttonpress() == 5)
173 status = TUMBLEBOTTOM_DN;
178 // repeat_event(top_level->get_resources()->tumble_duration);
182 if(top_level->cursor_y < get_h() / 2)
184 status = TUMBLETOP_DN;
188 status = TUMBLEBOTTOM_DN;
194 top_level->set_repeat(top_level->get_resources()->tumble_duration);
196 repeat_event(top_level->get_resources()->tumble_duration);
197 //printf("BC_Tumbler::button_press_event 2 %d\n", get_buttonpress());
204 int BC_Tumbler::button_release_event()
207 if(top_level->event_win == win)
209 if(status == TUMBLEBOTTOM_DN || status == TUMBLETOP_DN)
211 top_level->unset_repeat(top_level->get_resources()->tumble_duration);
213 status = TUMBLE_UPHI;
222 int BC_Tumbler::cursor_motion_event()
224 if(top_level->button_down && top_level->event_win == win &&
226 !(status == TUMBLETOP_DN || status == TUMBLEBOTTOM_DN))
237 BC_ITumbler::BC_ITumbler(BC_TextBox *textbox, int64_t min, int64_t max, int x, int y)
240 this->textbox = textbox;
246 BC_ITumbler::~BC_ITumbler()
250 void BC_ITumbler::set_increment(float value)
252 this->increment = (int64_t)value;
253 if(increment < 1) increment = 1;
256 int BC_ITumbler::handle_up_event()
258 int64_t value = atol(textbox->get_text());
260 if(value > max) value = max;
261 textbox->update(value);
262 textbox->handle_event();
266 int BC_ITumbler::handle_down_event()
268 int64_t value = atol(textbox->get_text());
270 if(value < min) value = min;
271 textbox->update(value);
272 textbox->handle_event();
276 void BC_ITumbler::set_boundaries(int64_t min, int64_t max)
291 BC_FTumbler::BC_FTumbler(BC_TextBox *textbox,
298 this->textbox = textbox;
301 this->increment = 1.0;
302 this->log_floatincrement = 0;
305 BC_FTumbler::~BC_FTumbler()
309 int BC_FTumbler::handle_up_event()
311 float value = atof(textbox->get_text());
312 if (log_floatincrement) {
313 // round off to to current precision (i.e. 250 -> 200)
314 float cp = floor(log(value)/log(10) + 0.0001);
315 value = floor((value/pow(10,cp))+ 0.0001)*pow(10,cp);
320 if(value > max) value = max;
321 textbox->update(value);
322 textbox->handle_event();
326 int BC_FTumbler::handle_down_event()
328 float value = atof(textbox->get_text());
329 if (log_floatincrement) {
330 // round off to to current precision (i.e. 250 -> 200)
331 float cp = floor(log(value)/log(10));
332 value = floor(value/pow(10,cp))*pow(10,cp);
333 // Need to make it so that: [.001 .01 .1 1 10 100] => [.0001 .001 .01 .1 1 10]
334 cp = floor(log(value)/log(10)-.01);
339 if(value < min) value = min;
340 textbox->update(value);
341 textbox->handle_event();
345 void BC_FTumbler::set_boundaries(float min, float max)
351 void BC_FTumbler::set_increment(float value)
353 this->increment = value;
356 void BC_FTumbler::set_log_floatincrement(int value)
358 this->log_floatincrement = value;
363 // c-file-style: "linux"