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 // delay the 1st repeat
146 if(repeat_count > 1 && repeat_count < 5) return 0;
147 if(status == TUMBLETOP_DN)
153 if(status == TUMBLEBOTTOM_DN)
162 int BC_Tumbler::cursor_enter_event()
164 if(top_level->event_win == win)
167 if(! top_level->button_down && status == TUMBLE_UP)
169 status = TUMBLE_UPHI;
176 int BC_Tumbler::cursor_leave_event()
179 if(status == TUMBLE_UPHI)
187 int BC_Tumbler::button_press_event()
190 if(top_level->event_win == win)
192 //printf("BC_Tumbler::button_press_event 1 %d\n", get_buttonpress());
193 if(get_buttonpress() == 4)
195 status = TUMBLETOP_DN;
199 // repeat_event(top_level->get_resources()->tumble_duration);
202 if(get_buttonpress() == 5)
204 status = TUMBLEBOTTOM_DN;
208 // repeat_event(top_level->get_resources()->tumble_duration);
212 if(top_level->cursor_y < get_h() / 2)
214 status = TUMBLETOP_DN;
218 status = TUMBLEBOTTOM_DN;
223 top_level->set_repeat(top_level->get_resources()->tumble_duration);
225 repeat_event(top_level->get_resources()->tumble_duration);
226 //printf("BC_Tumbler::button_press_event 2 %d\n", get_buttonpress());
233 int BC_Tumbler::button_release_event()
236 if(top_level->event_win == win)
238 if(status == TUMBLEBOTTOM_DN || status == TUMBLETOP_DN)
240 top_level->unset_repeat(top_level->get_resources()->tumble_duration);
242 status = TUMBLE_UPHI;
251 int BC_Tumbler::cursor_motion_event()
253 if(top_level->button_down && top_level->event_win == win &&
255 !(status == TUMBLETOP_DN || status == TUMBLEBOTTOM_DN))
266 BC_ITumbler::BC_ITumbler(BC_TextBox *textbox, int64_t min, int64_t max, int x, int y)
269 this->textbox = textbox;
275 BC_ITumbler::~BC_ITumbler()
279 void BC_ITumbler::set_increment(float value)
281 this->increment = (int64_t)value;
282 if(increment < 1) increment = 1;
285 int BC_ITumbler::handle_up_event()
287 int64_t value = atol(textbox->get_text());
289 if(value > max) value = max;
290 textbox->update(value);
291 textbox->handle_event();
295 int BC_ITumbler::handle_down_event()
297 int64_t value = atol(textbox->get_text());
299 if(value < min) value = min;
300 textbox->update(value);
301 textbox->handle_event();
305 void BC_ITumbler::set_boundaries(int64_t min, int64_t max)
320 BC_FTumbler::BC_FTumbler(BC_TextBox *textbox,
327 this->textbox = textbox;
330 this->increment = 1.0;
331 this->log_floatincrement = 0;
334 BC_FTumbler::~BC_FTumbler()
338 int BC_FTumbler::handle_up_event()
340 float value = atof(textbox->get_text());
341 if (log_floatincrement) {
342 // round off to to current precision (i.e. 250 -> 200)
343 float cp = floor(log(value)/log(10) + 0.0001);
344 value = floor((value/pow(10,cp))+ 0.0001)*pow(10,cp);
349 if(value > max) value = max;
350 textbox->update(value);
351 textbox->handle_event();
355 int BC_FTumbler::handle_down_event()
357 float value = atof(textbox->get_text());
358 if (log_floatincrement) {
359 // round off to to current precision (i.e. 250 -> 200)
360 float cp = floor(log(value)/log(10));
361 value = floor(value/pow(10,cp))*pow(10,cp);
362 // Need to make it so that: [.001 .01 .1 1 10 100] => [.0001 .001 .01 .1 1 10]
363 cp = floor(log(value)/log(10)-.01);
368 if(value < min) value = min;
369 textbox->update(value);
370 textbox->handle_event();
374 void BC_FTumbler::set_boundaries(float min, float max)
380 void BC_FTumbler::set_increment(float value)
382 this->increment = value;
385 void BC_FTumbler::set_log_floatincrement(int value)
387 this->log_floatincrement = value;