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++)
26 int BC_Pot::initialize()
30 data = get_resources()->pot_images;
37 BC_SubWindow::initialize();
42 int BC_Pot::reposition_window(int x, int y)
44 BC_WindowBase::reposition_window(x, y);
49 int BC_Pot::set_data(VFrame **data)
51 for(int i = 0; i < POT_STATES; i++)
52 if(images[i]) delete images[i];
54 for(int i = 0; i < POT_STATES; i++)
55 images[i] = new BC_Pixmap(parent_window, data[i], PIXMAP_ALPHA);
63 draw_top_background(parent_window, 0, 0, get_w(), get_h());
64 draw_pixmap(images[status]);
67 angle_to_coords(x1, y1, x2, y2, percentage_to_angle(get_percentage()));
68 draw_line(x1, y1, x2, y2);
74 float BC_Pot::percentage_to_angle(float percentage)
76 return percentage * (MAX_ANGLE - MIN_ANGLE) + MIN_ANGLE;
79 float BC_Pot::angle_to_percentage(float angle)
81 return (angle - MIN_ANGLE) / (MAX_ANGLE - MIN_ANGLE);
85 int BC_Pot::angle_to_coords(int &x1, int &y1, int &x2, int &y2, float angle)
87 x1 = get_resources()->pot_x1;
88 y1 = get_resources()->pot_y1;
95 while(angle < 0) angle += 360;
97 x2 = (int)(cos(angle / 360 * (2 * M_PI)) * get_resources()->pot_r + x1);
98 y2 = (int)(-sin(angle / 360 * (2 * M_PI)) * get_resources()->pot_r + y1);
102 float BC_Pot::coords_to_angle(int x2, int y2)
107 x1 = get_resources()->pot_x1;
108 y1 = get_resources()->pot_y1;
120 angle = atan((float)-y / x) / (2 * M_PI) * 360;
125 angle = 180 - atan((float)-y / -x) / (2 * M_PI) * 360;
130 angle = 180 - atan((float)-y / -x) / (2 * M_PI) * 360;
135 angle = 360 + atan((float)-y / x) / (2 * M_PI) * 360;
159 void BC_Pot::show_value_tooltip()
161 set_tooltip(get_caption());
163 keypress_tooltip_timer = 2000;
166 int BC_Pot::repeat_event(int64_t duration)
168 if(duration == top_level->get_resources()->tooltip_delay)
172 if(keypress_tooltip_timer > 0)
174 keypress_tooltip_timer -= get_resources()->tooltip_delay;
177 if(status != POT_HIGH && status != POT_DN)
183 if(status == POT_HIGH)
185 if(!tooltip_text[0] || isdigit(tooltip_text[0]))
187 set_tooltip(get_caption());
199 int BC_Pot::keypress_event()
202 switch(get_keypress())
224 show_value_tooltip();
231 int BC_Pot::cursor_enter_event()
233 if(top_level->event_win == win)
235 // Set caption if no tooltip
237 if(!top_level->button_down && status == POT_UP)
246 int BC_Pot::cursor_leave_event()
248 if(status == POT_HIGH)
257 int BC_Pot::button_press_event()
259 if(!tooltip_on) top_level->hide_tooltip();
260 if(top_level->event_win == win)
262 if(status == POT_HIGH || status == POT_UP)
264 if(get_buttonpress() == 4)
267 show_value_tooltip();
272 if(get_buttonpress() == 5)
275 show_value_tooltip();
282 start_cursor_angle = coords_to_angle(get_cursor_x(), get_cursor_y());
283 start_needle_angle = percentage_to_angle(get_percentage());
284 angle_offset = start_cursor_angle - start_needle_angle;
285 prev_angle = start_cursor_angle;
286 angle_correction = 0;
288 top_level->deactivate();
289 top_level->active_subwindow = this;
290 show_value_tooltip();
298 int BC_Pot::button_release_event()
300 if(top_level->event_win == win)
309 top_level->hide_tooltip();
317 int BC_Pot::cursor_motion_event()
319 if(top_level->button_down &&
320 top_level->event_win == win &&
323 float angle = coords_to_angle(get_cursor_x(), get_cursor_y());
325 if(prev_angle >= 0 && prev_angle < 90 &&
326 angle >= 270 && angle < 360)
328 angle_correction -= 360;
331 if(prev_angle >= 270 && prev_angle < 360 &&
332 angle >= 0 && angle < 90)
334 angle_correction += 360;
339 if(percentage_to_value(angle_to_percentage(angle + angle_correction - angle_offset)))
341 set_tooltip(get_caption());
360 BC_FPot::BC_FPot(int x,
369 this->minvalue = minvalue;
370 this->maxvalue = maxvalue;
378 int BC_FPot::increase_value()
381 if(value > maxvalue) value = maxvalue;
385 int BC_FPot::decrease_value()
388 if(value < minvalue) value = minvalue;
392 void BC_FPot::set_precision(float value)
394 this->precision = value;
397 char* BC_FPot::get_caption()
399 sprintf(caption, "%.2f", value);
403 float BC_FPot::get_percentage()
405 return (value - minvalue) / (maxvalue - minvalue);
408 int BC_FPot::percentage_to_value(float percentage)
410 float old_value = value;
411 value = percentage * (maxvalue - minvalue) + minvalue;
412 value = Units::quantize(value, precision);
413 if(value < minvalue) value = minvalue;
414 if(value > maxvalue) value = maxvalue;
415 if(value != old_value) return 1;
419 float BC_FPot::get_value()
424 void BC_FPot::update(float value)
426 if(value != this->value)
440 BC_IPot::BC_IPot(int x,
449 this->minvalue = minvalue;
450 this->maxvalue = maxvalue;
457 int BC_IPot::increase_value()
460 if(value > maxvalue) value = maxvalue;
464 int BC_IPot::decrease_value()
467 if(value < minvalue) value = minvalue;
471 char* BC_IPot::get_caption()
473 sprintf(caption, "%ld", value);
477 float BC_IPot::get_percentage()
479 return ((float)value - minvalue) / (maxvalue - minvalue);
482 int BC_IPot::percentage_to_value(float percentage)
484 int64_t old_value = value;
485 value = (int64_t)(percentage * (maxvalue - minvalue) + minvalue);
486 if(value < minvalue) value = minvalue;
487 if(value > maxvalue) value = maxvalue;
488 if(value != old_value) return 1;
492 int64_t BC_IPot::get_value()
497 void BC_IPot::update(int64_t value)
499 if(this->value != value)
512 BC_QPot::BC_QPot(int x,
518 this->value = Freq::fromfreq(value);
520 this->maxvalue = TOTALFREQS;
527 int BC_QPot::increase_value()
530 if(value > maxvalue) value = maxvalue;
534 int BC_QPot::decrease_value()
537 if(value < minvalue) value = minvalue;
541 char* BC_QPot::get_caption()
543 sprintf(caption, "%ld", Freq::tofreq(value));
547 float BC_QPot::get_percentage()
549 return ((float)value - minvalue) / (maxvalue - minvalue);
552 int BC_QPot::percentage_to_value(float percentage)
554 int64_t old_value = value;
555 value = (int64_t)(percentage * (maxvalue - minvalue) + minvalue);
556 if(value < minvalue) value = minvalue;
557 if(value > maxvalue) value = maxvalue;
558 if(value != old_value) return 1;
562 int64_t BC_QPot::get_value()
564 return Freq::tofreq(value);
567 void BC_QPot::update(int64_t value)
569 if(this->value != value)
571 this->value = Freq::fromfreq(value);
583 BC_PercentagePot::BC_PercentagePot(int x,
592 this->minvalue = minvalue;
593 this->maxvalue = maxvalue;
596 BC_PercentagePot::~BC_PercentagePot()
600 int BC_PercentagePot::increase_value()
603 if(value > maxvalue) value = maxvalue;
607 int BC_PercentagePot::decrease_value()
610 if(value < minvalue) value = minvalue;
614 char* BC_PercentagePot::get_caption()
616 sprintf(caption, "%d%%", (int)(get_percentage() * 100 + 0.5));
620 float BC_PercentagePot::get_percentage()
622 return (value - minvalue) / (maxvalue - minvalue);
625 int BC_PercentagePot::percentage_to_value(float percentage)
627 float old_value = value;
628 value = percentage * (maxvalue - minvalue) + minvalue;
629 if(value < minvalue) value = minvalue;
630 if(value > maxvalue) value = maxvalue;
631 if(value != old_value) return 1;
635 float BC_PercentagePot::get_value()
640 void BC_PercentagePot::update(float value)
642 if(this->value != value)