2 #include "bcresources.h"
17 BC_Slider::BC_Slider(int x,
20 int pointer_motion_range,
25 : BC_SubWindow(x, y, 0, 0, -1)
27 this->images = images;
28 this->show_number = show_number;
29 this->vertical = vertical;
30 this->pointer_motion_range = pointer_motion_range;
31 this->pixels = pixels;
32 this->button_pixel = button_pixel;
33 this->use_caption = use_caption;
36 pixmaps = new BC_Pixmap*[SLIDER_IMAGES];
37 for(int i = 0; i < SLIDER_IMAGES; i++)
46 BC_Slider::~BC_Slider()
48 for(int i = 0; i < SLIDER_IMAGES; i++)
50 if(pixmaps[i]) delete pixmaps[i];
52 if(pixmaps) delete [] pixmaps;
55 int BC_Slider::initialize()
59 this->images = vertical ?
60 BC_WindowBase::get_resources()->vertical_slider_data :
61 BC_WindowBase::get_resources()->horizontal_slider_data;
68 w = images[SLIDER_BG_UP]->get_w();
74 h = images[SLIDER_BG_UP]->get_h();
77 text_height = get_text_height(SMALLFONT);
78 button_pixel = value_to_pixel();
80 BC_SubWindow::initialize();
85 int BC_Slider::get_span(int vertical)
89 return BC_WindowBase::get_resources()->vertical_slider_data[0]->get_w();
93 return BC_WindowBase::get_resources()->horizontal_slider_data[0]->get_h();
97 int BC_Slider::draw_face()
100 draw_top_background(parent_window, 0, 0, get_w(), get_h());
108 pixmaps[SLIDER_IMAGES / 2 + status]);
109 draw_pixmap(pixmaps[status], 0, button_pixel);
114 draw_text(0, h, get_caption());
119 int y = get_h() / 2 - pixmaps[SLIDER_IMAGES / 2 + status]->get_h() / 2;
123 pixmaps[SLIDER_IMAGES / 2 + status]);
124 draw_pixmap(pixmaps[status], button_pixel, 0);
129 draw_text(0, h, get_caption());
137 int BC_Slider::set_images(VFrame **images)
139 for(int i = 0; i < SLIDER_IMAGES; i++)
141 if(pixmaps[i]) delete pixmaps[i];
142 pixmaps[i] = new BC_Pixmap(parent_window, images[i], PIXMAP_ALPHA);
147 int BC_Slider::get_button_pixels()
149 return vertical ? pixmaps[SLIDER_UP]->get_h() :
150 pixmaps[SLIDER_UP]->get_w();
153 void BC_Slider::show_value_tooltip()
155 //printf("BC_Slider::show_value_tooltip %s\n", get_caption());
156 set_tooltip(get_caption());
157 keypress_tooltip_timer = 2000;
162 int BC_Slider::repeat_event(int64_t duration)
164 if(duration == top_level->get_resources()->tooltip_delay)
168 if(keypress_tooltip_timer > 0)
170 keypress_tooltip_timer -= get_resources()->tooltip_delay;
173 if(status != SLIDER_HI && status != SLIDER_DN)
179 if(status == SLIDER_HI)
181 if(!tooltip_text[0] || isdigit(tooltip_text[0]))
183 set_tooltip(get_caption());
188 //printf("BC_Slider::repeat_event 1 %s\n", tooltip_text);
189 set_tooltip(get_caption());
200 int BC_Slider::keypress_event()
203 if(!active || !enabled) return 0;
204 if(ctrl_down() || shift_down()) return 0;
206 switch(get_keypress())
209 increase_value_big();
213 decrease_value_big();
229 show_value_tooltip();
235 int BC_Slider::cursor_enter_event()
237 //printf("BC_Slider::cursor_enter_event 1\n");
238 if(top_level->event_win == win && status == SLIDER_UP)
244 //printf("BC_Slider::cursor_enter_event 2\n");
248 int BC_Slider::cursor_leave_event()
250 if(status == SLIDER_HI)
259 int BC_Slider::deactivate()
265 int BC_Slider::activate()
267 top_level->active_subwindow = this;
271 int BC_Slider::button_press_event()
276 if(!tooltip_on) top_level->hide_tooltip();
277 if(status == SLIDER_HI)
279 if(get_buttonpress() == 4)
283 show_value_tooltip();
287 if(get_buttonpress() == 5)
291 show_value_tooltip();
295 if(get_buttonpress() == 1)
300 init_selection(top_level->cursor_x, top_level->cursor_y);
301 top_level->deactivate();
303 show_value_tooltip();
311 int BC_Slider::button_release_event()
321 top_level->hide_tooltip();
329 int BC_Slider::cursor_motion_event()
333 int old_pixel = button_pixel;
334 int result = update_selection(top_level->cursor_x, top_level->cursor_y);
335 if(button_pixel != old_pixel) draw_face();
339 set_tooltip(get_caption());
346 int BC_Slider::reposition_window(int x, int y, int w, int h)
348 BC_SubWindow::reposition_window(x, y, w, h);
349 button_pixel = value_to_pixel();
355 int BC_Slider::get_pointer_motion_range()
357 return pointer_motion_range;
364 BC_ISlider::BC_ISlider(int x,
368 int pointer_motion_range,
378 pointer_motion_range,
384 this->minvalue = minvalue;
385 this->maxvalue = maxvalue;
387 this->output = output;
390 int BC_ISlider::value_to_pixel()
392 if(maxvalue == minvalue) return 0;
396 return (int)((1.0 - (double)(value - minvalue) / (maxvalue - minvalue)) *
397 (get_h() - get_button_pixels()));
399 return (int)((double)(value - minvalue) / (maxvalue - minvalue) *
400 (get_w() - get_button_pixels()));
404 int BC_ISlider::update(int64_t value)
406 if(this->value != value)
409 int old_pixel = button_pixel;
410 button_pixel = value_to_pixel();
411 if(button_pixel != old_pixel) draw_face();
416 int BC_ISlider::update(int pointer_motion_range,
421 this->minvalue = minvalue;
422 this->maxvalue = maxvalue;
424 this->pointer_motion_range = pointer_motion_range;
426 int old_pixel = button_pixel;
427 button_pixel = value_to_pixel();
428 if(button_pixel != old_pixel) draw_face();
433 int64_t BC_ISlider::get_value()
438 int64_t BC_ISlider::get_length()
440 return maxvalue - minvalue;
443 char* BC_ISlider::get_caption()
445 sprintf(caption, "%ld", value);
449 int BC_ISlider::increase_value()
452 if(value > maxvalue) value = maxvalue;
453 button_pixel = value_to_pixel();
457 int BC_ISlider::decrease_value()
460 if(value < minvalue) value = minvalue;
461 button_pixel = value_to_pixel();
465 int BC_ISlider::increase_value_big()
468 if(value > maxvalue) value = maxvalue;
469 button_pixel = value_to_pixel();
473 int BC_ISlider::decrease_value_big()
476 if(value < minvalue) value = minvalue;
477 button_pixel = value_to_pixel();
481 int BC_ISlider::init_selection(int cursor_x, int cursor_y)
485 min_pixel = -(int)((1.0 - (double)(value - minvalue) / (maxvalue - minvalue)) * pointer_motion_range);
486 min_pixel += cursor_y;
490 min_pixel = -(int)((double)(value - minvalue) / (maxvalue - minvalue) * pointer_motion_range);
491 min_pixel += cursor_x;
493 max_pixel = min_pixel + pointer_motion_range;
497 int BC_ISlider::update_selection(int cursor_x, int cursor_y)
499 int64_t old_value = value;
503 value = (int64_t)((1.0 - (double)(cursor_y - min_pixel) /
504 pointer_motion_range) *
505 (maxvalue - minvalue) +
510 value = (int64_t)((double)(cursor_x - min_pixel) /
511 pointer_motion_range *
512 (maxvalue - minvalue) +
516 if(value > maxvalue) value = maxvalue;
517 if(value < minvalue) value = minvalue;
518 button_pixel = value_to_pixel();
520 if(old_value != value)
527 int BC_ISlider::handle_event()
529 if(output) *output = get_value();
540 BC_FSlider::BC_FSlider(int x,
544 int pointer_motion_range,
553 pointer_motion_range,
559 this->minvalue = minvalue;
560 this->maxvalue = maxvalue;
562 this->precision = 0.1;
563 this->small_change = 0.1;
564 this->big_change = 1.0;
567 int BC_FSlider::value_to_pixel()
569 //printf("BC_FSlider::value_to_pixel %f %f\n", maxvalue, minvalue);
570 if(maxvalue == minvalue) return 0;
573 return (int)((1.0 - (double)(value - minvalue) / (maxvalue - minvalue)) *
574 (get_h() - get_button_pixels()));
576 return (int)((double)(value - minvalue) / (maxvalue - minvalue) *
577 (get_w() - get_button_pixels()));
581 int BC_FSlider::update(float value)
583 if(this->value != value)
586 int old_pixel = button_pixel;
587 button_pixel = value_to_pixel();
588 //printf("BC_FSlider::update 1 %f %d\n", value, button_pixel);
589 if(button_pixel != old_pixel) draw_face();
594 int BC_FSlider::update(int pointer_motion_range, float value, float minvalue, float maxvalue)
596 this->minvalue = minvalue;
597 this->maxvalue = maxvalue;
599 this->pointer_motion_range = pointer_motion_range;
600 int old_pixel = button_pixel;
601 button_pixel = value_to_pixel();
602 if(button_pixel != old_pixel) draw_face();
607 float BC_FSlider::get_value()
612 float BC_FSlider::get_length()
614 return maxvalue - minvalue;
617 char* BC_FSlider::get_caption()
619 sprintf(caption, "%.02f", value);
623 int BC_FSlider::increase_value()
625 value += small_change;
626 if(value > maxvalue) value = maxvalue;
627 button_pixel = value_to_pixel();
631 int BC_FSlider::decrease_value()
633 value -= small_change;
634 if(value < minvalue) value = minvalue;
635 button_pixel = value_to_pixel();
639 int BC_FSlider::increase_value_big()
642 if(value > maxvalue) value = maxvalue;
643 button_pixel = value_to_pixel();
647 int BC_FSlider::decrease_value_big()
650 if(value < minvalue) value = minvalue;
651 button_pixel = value_to_pixel();
655 int BC_FSlider::init_selection(int cursor_x, int cursor_y)
659 min_pixel = -(int)((1.0 - (double)(value - minvalue) / (maxvalue - minvalue)) * pointer_motion_range);
660 min_pixel += cursor_y;
664 min_pixel = -(int)((double)(value - minvalue) / (maxvalue - minvalue) * pointer_motion_range);
665 min_pixel += cursor_x;
667 max_pixel = min_pixel + pointer_motion_range;
671 int BC_FSlider::update_selection(int cursor_x, int cursor_y)
673 float old_value = value;
678 value = ((1.0 - (double)(cursor_y - min_pixel) /
679 pointer_motion_range) *
680 (maxvalue - minvalue) +
685 value = ((double)(cursor_x - min_pixel) /
686 pointer_motion_range *
687 (maxvalue - minvalue) +
691 value = Units::quantize(value, precision);
692 if(value > maxvalue) value = maxvalue;
693 if(value < minvalue) value = minvalue;
694 button_pixel = value_to_pixel();
695 // printf("BC_FSlider::update_selection 1 %d %d %d %d %f %f\n",
696 // pointer_motion_range,
703 if(old_value != value)
710 void BC_FSlider::set_precision(float value)
712 this->precision = value;
715 void BC_FSlider::set_pagination(float small_change, float big_change)
717 this->small_change = small_change;
718 this->big_change = big_change;
723 BC_PercentageSlider::BC_PercentageSlider(int x,
727 int pointer_motion_range,
737 pointer_motion_range,
746 char* BC_PercentageSlider::get_caption()
748 sprintf(caption, "%.0f%%", floor((value - minvalue) / (maxvalue - minvalue) * 100));