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)
140 if(duration == top_level->get_resources()->tumble_duration)
142 //printf("BC_Tumbler::repeat_event 2\n");
144 // delay the 1st repeat
145 if(repeat_count > 1 && repeat_count < 5) 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)
165 if(! top_level->button_down && status == TUMBLE_UP)
167 status = TUMBLE_UPHI;
174 int BC_Tumbler::cursor_leave_event()
177 if(status == TUMBLE_UPHI)
185 int BC_Tumbler::button_press_event()
188 if(top_level->event_win == win)
190 //printf("BC_Tumbler::button_press_event 1 %d\n", get_buttonpress());
191 if(get_buttonpress() == 4)
193 status = TUMBLETOP_DN;
197 // repeat_event(top_level->get_resources()->tumble_duration);
200 if(get_buttonpress() == 5)
202 status = TUMBLEBOTTOM_DN;
206 // repeat_event(top_level->get_resources()->tumble_duration);
210 if(top_level->cursor_y < get_h() / 2)
212 status = TUMBLETOP_DN;
216 status = TUMBLEBOTTOM_DN;
221 top_level->set_repeat(top_level->get_resources()->tumble_duration);
223 repeat_event(top_level->get_resources()->tumble_duration);
224 //printf("BC_Tumbler::button_press_event 2 %d\n", get_buttonpress());
231 int BC_Tumbler::button_release_event()
234 if(top_level->event_win == win)
236 if(status == TUMBLEBOTTOM_DN || status == TUMBLETOP_DN)
238 top_level->unset_repeat(top_level->get_resources()->tumble_duration);
240 status = TUMBLE_UPHI;
249 int BC_Tumbler::cursor_motion_event()
251 if(top_level->button_down && top_level->event_win == win &&
253 !(status == TUMBLETOP_DN || status == TUMBLEBOTTOM_DN))
264 BC_ITumbler::BC_ITumbler(BC_TextBox *textbox, int64_t min, int64_t max, int x, int y)
267 this->textbox = textbox;
273 BC_ITumbler::~BC_ITumbler()
277 void BC_ITumbler::set_increment(float value)
279 this->increment = (int64_t)value;
280 if(increment < 1) increment = 1;
283 int BC_ITumbler::handle_up_event()
285 int64_t value = atol(textbox->get_text());
287 if(value > max) value = max;
288 textbox->update(value);
289 textbox->handle_event();
293 int BC_ITumbler::handle_down_event()
295 int64_t value = atol(textbox->get_text());
297 if(value < min) value = min;
298 textbox->update(value);
299 textbox->handle_event();
303 void BC_ITumbler::set_boundaries(int64_t min, int64_t max)
318 BC_FTumbler::BC_FTumbler(BC_TextBox *textbox,
325 this->textbox = textbox;
328 this->increment = 1.0;
329 this->log_floatincrement = 0;
332 BC_FTumbler::~BC_FTumbler()
336 int BC_FTumbler::handle_up_event()
338 float value = atof(textbox->get_text());
339 if (log_floatincrement) {
340 // round off to to current precision (i.e. 250 -> 200)
341 float cp = floor(log(value)/log(10) + 0.0001);
342 value = floor((value/pow(10,cp))+ 0.0001)*pow(10,cp);
347 if(value > max) value = max;
348 textbox->update(value);
349 textbox->handle_event();
353 int BC_FTumbler::handle_down_event()
355 float value = atof(textbox->get_text());
356 if (log_floatincrement) {
357 // round off to to current precision (i.e. 250 -> 200)
358 float cp = floor(log(value)/log(10));
359 value = floor(value/pow(10,cp))*pow(10,cp);
360 // Need to make it so that: [.001 .01 .1 1 10 100] => [.0001 .001 .01 .1 1 10]
361 cp = floor(log(value)/log(10)-.01);
366 if(value < min) value = min;
367 textbox->update(value);
368 textbox->handle_event();
372 void BC_FTumbler::set_boundaries(float min, float max)
378 void BC_FTumbler::set_increment(float value)
380 this->increment = value;
383 void BC_FTumbler::set_log_floatincrement(int value)
385 this->log_floatincrement = value;