2 #include "bcresources.h"
14 BC_Pot::BC_Pot(int x, int y, VFrame **data)
15 : BC_SubWindow(x, y, -1, -1, -1)
18 for(int i = 0; i < POT_STATES; i++)
27 int BC_Pot::calculate_h()
29 return BC_WindowBase::get_resources()->pot_images[0]->get_h();
32 int BC_Pot::initialize()
36 data = get_resources()->pot_images;
43 BC_SubWindow::initialize();
48 int BC_Pot::reposition_window(int x, int y)
50 BC_WindowBase::reposition_window(x, y);
55 int BC_Pot::set_data(VFrame **data)
57 for(int i = 0; i < POT_STATES; i++)
58 if(images[i]) delete images[i];
60 for(int i = 0; i < POT_STATES; i++)
61 images[i] = new BC_Pixmap(parent_window, data[i], PIXMAP_ALPHA);
66 void BC_Pot::set_use_caption(int value)
74 draw_top_background(parent_window, 0, 0, get_w(), get_h());
75 draw_pixmap(images[status]);
76 set_color(get_resources()->pot_needle_color);
78 angle_to_coords(x1, y1, x2, y2, percentage_to_angle(get_percentage()));
79 draw_line(x1, y1, x2, y2);
85 float BC_Pot::percentage_to_angle(float percentage)
87 return percentage * (MAX_ANGLE - MIN_ANGLE) + MIN_ANGLE;
90 float BC_Pot::angle_to_percentage(float angle)
92 return (angle - MIN_ANGLE) / (MAX_ANGLE - MIN_ANGLE);
96 int BC_Pot::angle_to_coords(int &x1, int &y1, int &x2, int &y2, float angle)
98 BC_Resources *resources = get_resources();
99 x1 = resources->pot_x1;
100 y1 = resources->pot_y1;
103 x1 += resources->pot_offset;
104 y1 += resources->pot_offset;
107 while(angle < 0) angle += 360;
109 x2 = (int)(cos(angle / 360 * (2 * M_PI)) * resources->pot_r + x1);
110 y2 = (int)(-sin(angle / 360 * (2 * M_PI)) * resources->pot_r + y1);
114 float BC_Pot::coords_to_angle(int x2, int y2)
119 x1 = get_resources()->pot_x1;
120 y1 = get_resources()->pot_y1;
132 angle = atan((float)-y / x) / (2 * M_PI) * 360;
137 angle = 180 - atan((float)-y / -x) / (2 * M_PI) * 360;
142 angle = 180 - atan((float)-y / -x) / (2 * M_PI) * 360;
147 angle = 360 + atan((float)-y / x) / (2 * M_PI) * 360;
171 void BC_Pot::show_value_tooltip()
175 set_tooltip(get_caption());
177 keypress_tooltip_timer = 2000;
181 int BC_Pot::repeat_event(int64_t duration)
183 if(duration == top_level->get_resources()->tooltip_delay)
187 if(keypress_tooltip_timer > 0)
189 keypress_tooltip_timer -= get_resources()->tooltip_delay;
192 if(status != POT_HIGH && status != POT_DN)
198 if(status == POT_HIGH)
202 if(!tooltip_text[0] || isdigit(tooltip_text[0]))
204 set_tooltip(get_caption());
217 int BC_Pot::keypress_event()
220 switch(get_keypress())
242 show_value_tooltip();
249 int BC_Pot::cursor_enter_event()
251 if(top_level->event_win == win)
254 if(!top_level->button_down && status == POT_UP)
263 int BC_Pot::cursor_leave_event()
265 if(status == POT_HIGH)
274 int BC_Pot::button_press_event()
276 if(!tooltip_on) top_level->hide_tooltip();
277 if(top_level->event_win == win)
279 if(status == POT_HIGH || status == POT_UP)
281 if(get_buttonpress() == 4)
284 show_value_tooltip();
289 if(get_buttonpress() == 5)
292 show_value_tooltip();
299 start_cursor_angle = coords_to_angle(get_cursor_x(), get_cursor_y());
300 start_needle_angle = percentage_to_angle(get_percentage());
301 angle_offset = start_cursor_angle - start_needle_angle;
302 prev_angle = start_cursor_angle;
303 angle_correction = 0;
305 top_level->deactivate();
306 top_level->active_subwindow = this;
307 show_value_tooltip();
315 int BC_Pot::button_release_event()
317 if(top_level->event_win == win)
326 top_level->hide_tooltip();
335 int BC_Pot::cursor_motion_event()
337 if(top_level->button_down &&
338 top_level->event_win == win &&
341 float angle = coords_to_angle(get_cursor_x(), get_cursor_y());
343 if(prev_angle >= 0 && prev_angle < 90 &&
344 angle >= 270 && angle < 360)
346 angle_correction -= 360;
349 if(prev_angle >= 270 && prev_angle < 360 &&
350 angle >= 0 && angle < 90)
352 angle_correction += 360;
357 if(percentage_to_value(
358 angle_to_percentage(angle + angle_correction - angle_offset)))
360 set_tooltip(get_caption());
379 BC_FPot::BC_FPot(int x,
388 this->minvalue = minvalue;
389 this->maxvalue = maxvalue;
397 int BC_FPot::increase_value()
400 if(value > maxvalue) value = maxvalue;
404 int BC_FPot::decrease_value()
407 if(value < minvalue) value = minvalue;
411 void BC_FPot::set_precision(float value)
413 this->precision = value;
416 char* BC_FPot::get_caption()
418 sprintf(caption, "%.2f", value);
422 float BC_FPot::get_percentage()
424 return (value - minvalue) / (maxvalue - minvalue);
427 int BC_FPot::percentage_to_value(float percentage)
429 float old_value = value;
430 value = percentage * (maxvalue - minvalue) + minvalue;
431 value = Units::quantize(value, precision);
432 if(value < minvalue) value = minvalue;
433 if(value > maxvalue) value = maxvalue;
434 if(value != old_value) return 1;
438 float BC_FPot::get_value()
443 void BC_FPot::update(float value)
445 if(value != this->value)
452 void BC_FPot::update(float value, float minvalue, float maxvalue)
454 if(value != this->value ||
455 minvalue != this->minvalue ||
456 maxvalue != this->maxvalue)
459 this->minvalue = minvalue;
460 this->maxvalue = maxvalue;
472 BC_IPot::BC_IPot(int x,
481 this->minvalue = minvalue;
482 this->maxvalue = maxvalue;
489 int BC_IPot::increase_value()
492 if(value > maxvalue) value = maxvalue;
496 int BC_IPot::decrease_value()
499 if(value < minvalue) value = minvalue;
503 char* BC_IPot::get_caption()
505 sprintf(caption, "%ld", value);
509 float BC_IPot::get_percentage()
511 return ((float)value - minvalue) / (maxvalue - minvalue);
514 int BC_IPot::percentage_to_value(float percentage)
516 int64_t old_value = value;
517 value = (int64_t)(percentage * (maxvalue - minvalue) + minvalue);
518 if(value < minvalue) value = minvalue;
519 if(value > maxvalue) value = maxvalue;
520 if(value != old_value) return 1;
524 int64_t BC_IPot::get_value()
529 void BC_IPot::update(int64_t value)
531 if(this->value != value)
538 void BC_IPot::update(int64_t value, int64_t minvalue, int64_t maxvalue)
540 if(this->value != value ||
541 this->minvalue != minvalue ||
542 this->maxvalue != maxvalue)
545 this->minvalue = minvalue;
546 this->maxvalue = maxvalue;
556 BC_QPot::BC_QPot(int x,
562 this->value = Freq::fromfreq(value);
564 this->maxvalue = TOTALFREQS;
571 int BC_QPot::increase_value()
574 if(value > maxvalue) value = maxvalue;
578 int BC_QPot::decrease_value()
581 if(value < minvalue) value = minvalue;
585 char* BC_QPot::get_caption()
587 sprintf(caption, "%ld", Freq::tofreq(value));
591 float BC_QPot::get_percentage()
593 return ((float)value - minvalue) / (maxvalue - minvalue);
596 int BC_QPot::percentage_to_value(float percentage)
598 int64_t old_value = value;
599 value = (int64_t)(percentage * (maxvalue - minvalue) + minvalue);
600 if(value < minvalue) value = minvalue;
601 if(value > maxvalue) value = maxvalue;
602 if(value != old_value) return 1;
606 int64_t BC_QPot::get_value()
608 return Freq::tofreq(value);
611 void BC_QPot::update(int64_t value)
613 if(this->value != value)
615 this->value = Freq::fromfreq(value);
627 BC_PercentagePot::BC_PercentagePot(int x,
636 this->minvalue = minvalue;
637 this->maxvalue = maxvalue;
640 BC_PercentagePot::~BC_PercentagePot()
644 int BC_PercentagePot::increase_value()
647 if(value > maxvalue) value = maxvalue;
651 int BC_PercentagePot::decrease_value()
654 if(value < minvalue) value = minvalue;
658 char* BC_PercentagePot::get_caption()
660 sprintf(caption, "%d%%", (int)(get_percentage() * 100 + 0.5));
664 float BC_PercentagePot::get_percentage()
666 return (value - minvalue) / (maxvalue - minvalue);
669 int BC_PercentagePot::percentage_to_value(float percentage)
671 float old_value = value;
672 value = percentage * (maxvalue - minvalue) + minvalue;
673 if(value < minvalue) value = minvalue;
674 if(value > maxvalue) value = maxvalue;
675 if(value != old_value) return 1;
679 float BC_PercentagePot::get_value()
684 void BC_PercentagePot::update(float value)
686 if(this->value != value)