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, int orient)
37 : BC_SubWindow(x, y, 0, 0, -1)
39 for(int i = 0; i < TOTAL_STATES; i++)
44 this->orient = orient;
48 BC_Tumbler::~BC_Tumbler()
50 for(int i = 0; i < TOTAL_STATES; i ++)
55 int BC_Tumbler::calculate_w(VFrame **data)
57 VFrame **vfrms = data ? data : BC_WindowBase::get_resources()->tumble_data;
58 return vfrms[0]->get_w();
61 int BC_Tumbler::calculate_h(VFrame **data)
63 VFrame **vfrms = data ? data : BC_WindowBase::get_resources()->tumble_data;
64 return vfrms[0]->get_h();
68 int BC_Tumbler::initialize()
71 set_images(data ? data : 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)
85 BC_WindowBase::reposition_window(x, y);
91 int BC_Tumbler::update_bitmaps(VFrame **data)
94 draw_top_background(parent_window, 0, 0, w, h);
99 int BC_Tumbler::set_images(VFrame **data)
101 for(int i = 0; i < TOTAL_STATES; ++i ) {
102 if( images[i] ) delete images[i];
103 images[i] = new BC_Pixmap(parent_window, data[i], PIXMAP_ALPHA);
108 int BC_Tumbler::draw_face(int flush)
110 draw_top_background(parent_window, 0, 0, w, h);
111 pixmap->draw_pixmap(images[status], 0, 0, w, h, 0, 0);
116 int BC_Tumbler::repeat_event(int64_t duration)
118 //printf("BC_Tumbler::repeat_event 1 %d\n", duration);
119 if( duration == top_level->get_resources()->tooltip_delay ) {
120 if( tooltip_text && tooltip_text[0] != 0 && status == TUMBLE_UPHI ) {
125 else if( duration == top_level->get_resources()->tumble_duration ) {
126 //printf("BC_Tumbler::repeat_event 2\n");
127 // delay the 1st repeat
128 if( ++repeat_count > 1 && repeat_count < 5 ) return 0;
129 if( status == TUMBLETOP_DN ) { handle_up_event(); return 1; }
130 if( status == TUMBLEBOTTOM_DN) { handle_down_event(); return 1; }
135 int BC_Tumbler::cursor_enter_event()
137 if( top_level->event_win != win ) return 0;
138 if( !top_level->button_down && status == TUMBLE_UP ) {
139 status = TUMBLE_UPHI;
145 int BC_Tumbler::cursor_leave_event()
148 if( status == TUMBLE_UPHI ) {
155 int BC_Tumbler::button_press_event()
158 if( top_level->event_win != win ) return 0;
159 //printf("BC_Tumbler::button_press_event 1 %d\n", get_buttonpress());
160 if( get_buttonpress() == WHEEL_UP ) {
161 status = TUMBLETOP_DN;
165 else if( get_buttonpress() == WHEEL_DOWN ) {
166 status = TUMBLEBOTTOM_DN;
171 status = orient == TUMBLER_HORZ ?
172 top_level->cursor_x > get_w()/2 ? TUMBLETOP_DN : TUMBLEBOTTOM_DN :
173 top_level->cursor_y < get_h()/2 ? TUMBLETOP_DN : TUMBLEBOTTOM_DN ;
176 top_level->set_repeat(top_level->get_resources()->tumble_duration);
178 repeat_event(top_level->get_resources()->tumble_duration);
179 //printf("BC_Tumbler::button_press_event 2 %d\n", get_buttonpress());
184 int BC_Tumbler::button_release_event()
187 if( top_level->event_win != win ) return 0;
188 if( status == TUMBLEBOTTOM_DN || status == TUMBLETOP_DN ) {
189 top_level->unset_repeat(top_level->get_resources()->tumble_duration);
190 status = cursor_inside() ? TUMBLE_UPHI : TUMBLE_UP;
196 int BC_Tumbler::cursor_motion_event()
198 if( top_level->event_win != win ) return 0;
199 if( top_level->button_down && !cursor_inside() &&
200 !(status == TUMBLETOP_DN || status == TUMBLEBOTTOM_DN) ) {
208 BC_ITumbler::BC_ITumbler(BC_TextBox *textbox, int64_t min, int64_t max, int x, int y)
211 this->textbox = textbox;
217 BC_ITumbler::~BC_ITumbler()
221 void BC_ITumbler::set_increment(float value)
223 this->increment = (int64_t)value;
224 if(increment < 1) increment = 1;
227 int BC_ITumbler::handle_up_event()
229 int64_t value = atol(textbox->get_text());
231 if(value > max) value = max;
232 textbox->update(value);
233 textbox->handle_event();
237 int BC_ITumbler::handle_down_event()
239 int64_t value = atol(textbox->get_text());
241 if(value < min) value = min;
242 textbox->update(value);
243 textbox->handle_event();
247 void BC_ITumbler::set_boundaries(int64_t min, int64_t max)
254 BC_FTumbler::BC_FTumbler(BC_TextBox *textbox,
261 this->textbox = textbox;
264 this->increment = 1.0;
265 this->log_floatincrement = 0;
268 BC_FTumbler::~BC_FTumbler()
272 int BC_FTumbler::handle_up_event()
274 float value = atof(textbox->get_text());
275 if (log_floatincrement) {
276 // round off to to current precision (i.e. 250 -> 200)
277 float cp = floor(log(value)/log(10) + 0.0001);
278 value = floor((value/pow(10,cp))+ 0.0001)*pow(10,cp);
283 if(value > max) value = max;
284 textbox->update(value);
285 textbox->handle_event();
289 int BC_FTumbler::handle_down_event()
291 float value = atof(textbox->get_text());
292 if (log_floatincrement) {
293 // round off to to current precision (i.e. 250 -> 200)
294 float cp = floor(log(value)/log(10));
295 value = floor(value/pow(10,cp))*pow(10,cp);
296 // Need to make it so that: [.001 .01 .1 1 10 100] => [.0001 .001 .01 .1 1 10]
297 cp = floor(log(value)/log(10)-.01);
302 if(value < min) value = min;
303 textbox->update(value);
304 textbox->handle_event();
308 void BC_FTumbler::set_boundaries(float min, float max)
314 void BC_FTumbler::set_increment(float value)
316 this->increment = value;
319 void BC_FTumbler::set_log_floatincrement(int value)
321 this->log_floatincrement = value;