4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
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.
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.
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
23 #include "bcresources.h"
24 #include "bctextbox.h"
32 #define TUMBLEBOTTOM_DN 2
33 #define TUMBLETOP_DN 3
34 #define TOTAL_STATES 4
36 BC_Tumbler::BC_Tumbler(int x, int y, VFrame **data)
37 : BC_SubWindow(x, y, 0, 0, -1)
39 for(int i = 0; i < TOTAL_STATES; i++)
47 BC_Tumbler::~BC_Tumbler()
49 for(int i = 0; i < TOTAL_STATES; i ++)
54 int BC_Tumbler::calculate_w()
56 return BC_WindowBase::get_resources()->tumble_data[0]->get_w();
59 int BC_Tumbler::calculate_h()
61 return BC_WindowBase::get_resources()->tumble_data[0]->get_h();
65 int BC_Tumbler::initialize()
71 set_images(get_resources()->tumble_data);
72 w = images[TUMBLE_UP]->get_w();
73 h = images[TUMBLE_UP]->get_h();
75 // Create the subwindow
76 BC_SubWindow::initialize();
83 int BC_Tumbler::reposition_window(int x, int y, int w, int h)
86 printf("BC_Tumbler::reposition_window - w & h haven't been implemented yet!! (probably never will be)");
88 BC_WindowBase::reposition_window(x, y);
94 int BC_Tumbler::update_bitmaps(VFrame **data)
97 draw_top_background(parent_window, 0, 0, w, h);
102 int BC_Tumbler::set_images(VFrame **data)
104 for(int i = 0; i < TOTAL_STATES; i++)
106 if(images[i]) delete images[i];
107 images[i] = new BC_Pixmap(parent_window, data[i], PIXMAP_ALPHA);
113 int BC_Tumbler::draw_face(int flush)
115 draw_top_background(parent_window, 0, 0, w, h);
116 pixmap->draw_pixmap(images[status],
127 int BC_Tumbler::repeat_event(int64_t duration)
129 //printf("BC_Tumbler::repeat_event 1 %d\n", duration);
130 if(duration == top_level->get_resources()->tooltip_delay)
132 if(tooltip_text && tooltip_text[0] != 0 &&
133 status == TUMBLE_UPHI && !tooltip_done)
141 if(duration == top_level->get_resources()->tumble_duration)
143 //printf("BC_Tumbler::repeat_event 2\n");
145 if(repeat_count == 2) return 0;
146 if(status == TUMBLETOP_DN)
152 if(status == TUMBLEBOTTOM_DN)
161 int BC_Tumbler::cursor_enter_event()
163 if(top_level->event_win == win)
166 if(! top_level->button_down && status == TUMBLE_UP)
168 status = TUMBLE_UPHI;
175 int BC_Tumbler::cursor_leave_event()
178 if(status == TUMBLE_UPHI)
186 int BC_Tumbler::button_press_event()
189 if(top_level->event_win == win)
191 //printf("BC_Tumbler::button_press_event 1 %d\n", get_buttonpress());
192 if(get_buttonpress() == 4)
194 status = TUMBLETOP_DN;
198 // repeat_event(top_level->get_resources()->tumble_duration);
201 if(get_buttonpress() == 5)
203 status = TUMBLEBOTTOM_DN;
207 // repeat_event(top_level->get_resources()->tumble_duration);
211 if(top_level->cursor_y < get_h() / 2)
213 status = TUMBLETOP_DN;
217 status = TUMBLEBOTTOM_DN;
222 top_level->set_repeat(top_level->get_resources()->tumble_duration);
224 repeat_event(top_level->get_resources()->tumble_duration);
225 //printf("BC_Tumbler::button_press_event 2 %d\n", get_buttonpress());
232 int BC_Tumbler::button_release_event()
235 if(top_level->event_win == win)
237 if(status == TUMBLEBOTTOM_DN || status == TUMBLETOP_DN)
239 top_level->unset_repeat(top_level->get_resources()->tumble_duration);
241 status = TUMBLE_UPHI;
250 int BC_Tumbler::cursor_motion_event()
252 if(top_level->button_down && top_level->event_win == win &&
254 !(status == TUMBLETOP_DN || status == TUMBLEBOTTOM_DN))
265 BC_ITumbler::BC_ITumbler(BC_TextBox *textbox, int64_t min, int64_t max, int x, int y)
268 this->textbox = textbox;
274 BC_ITumbler::~BC_ITumbler()
278 void BC_ITumbler::set_increment(float value)
280 this->increment = (int64_t)value;
281 if(increment < 1) increment = 1;
284 int BC_ITumbler::handle_up_event()
286 int64_t value = atol(textbox->get_text());
288 if(value > max) value = max;
289 textbox->update(value);
290 textbox->handle_event();
294 int BC_ITumbler::handle_down_event()
296 int64_t value = atol(textbox->get_text());
298 if(value < min) value = min;
299 textbox->update(value);
300 textbox->handle_event();
304 void BC_ITumbler::set_boundaries(int64_t min, int64_t max)
319 BC_FTumbler::BC_FTumbler(BC_TextBox *textbox,
326 this->textbox = textbox;
329 this->increment = 1.0;
330 this->log_floatincrement = 0;
333 BC_FTumbler::~BC_FTumbler()
337 int BC_FTumbler::handle_up_event()
339 float value = atof(textbox->get_text());
340 if (log_floatincrement) {
341 // round off to to current precision (i.e. 250 -> 200)
342 float cp = floor(log(value)/log(10) + 0.0001);
343 value = floor((value/pow(10,cp))+ 0.0001)*pow(10,cp);
348 if(value > max) value = max;
349 textbox->update(value);
350 textbox->handle_event();
354 int BC_FTumbler::handle_down_event()
356 float value = atof(textbox->get_text());
357 if (log_floatincrement) {
358 // round off to to current precision (i.e. 250 -> 200)
359 float cp = floor(log(value)/log(10));
360 value = floor(value/pow(10,cp))*pow(10,cp);
361 // Need to make it so that: [.001 .01 .1 1 10 100] => [.0001 .001 .01 .1 1 10]
362 cp = floor(log(value)/log(10)-.01);
367 if(value < min) value = min;
368 textbox->update(value);
369 textbox->handle_event();
373 void BC_FTumbler::set_boundaries(float min, float max)
379 void BC_FTumbler::set_increment(float value)
381 this->increment = value;
384 void BC_FTumbler::set_log_floatincrement(int value)
386 this->log_floatincrement = value;