4 #include "bcresources.h"
8 #include "rotateframe.h"
24 : BC_SubWindow(x, y, -1, -1, -1)
26 this->virtual_r = virtual_r;
27 this->maxvalue = maxvalue;
28 this->total_values = total_values;
29 this->values = new float[total_values];
30 memcpy(this->values, values, sizeof(float) * total_values);
31 this->value_positions = new int[total_values];
32 memcpy(this->value_positions, value_positions, sizeof(int) * total_values);
33 this->value_x = new int[total_values];
34 this->value_y = new int[total_values];
35 this->stick_x = stick_x;
36 this->stick_y = stick_y;
37 get_channel_positions(value_x,
42 if(stick_x < 0 || stick_y < 0)
43 calculate_stick_position(total_values,
53 memset(images, 0, sizeof(BC_Pixmap*) * PAN_IMAGES);
58 //printf("BC_Pan::~BC_Pan 1\n");
60 //printf("BC_Pan::~BC_Pan 1\n");
61 delete [] value_positions;
62 //printf("BC_Pan::~BC_Pan 1\n");
64 //printf("BC_Pan::~BC_Pan 1\n");
66 //printf("BC_Pan::~BC_Pan 1\n");
67 if(popup) delete popup;
68 //printf("BC_Pan::~BC_Pan 1\n");
70 //printf("BC_Pan::~BC_Pan 1\n");
72 for(int i = 0; i < PAN_IMAGES; i++)
73 if(images[i]) delete images[i];
74 //printf("BC_Pan::~BC_Pan 2\n");
77 int BC_Pan::initialize()
79 set_images(get_resources()->pan_data);
81 BC_SubWindow::initialize();
82 temp_channel = new VFrame(0,
83 get_resources()->pan_data[PAN_CHANNEL]->get_w(),
84 get_resources()->pan_data[PAN_CHANNEL]->get_h(),
85 get_resources()->pan_data[PAN_CHANNEL]->get_color_model());
86 rotater = new RotateFrame(1,
87 get_resources()->pan_data[PAN_CHANNEL]->get_w(),
88 get_resources()->pan_data[PAN_CHANNEL]->get_h());
93 void BC_Pan::set_images(VFrame **data)
95 for(int i = 0; i < PAN_IMAGES; i++)
97 if(images[i]) delete images[i];
98 images[i] = new BC_Pixmap(parent_window, data[i], PIXMAP_ALPHA);
100 w = images[PAN_UP]->get_w();
101 h = images[PAN_UP]->get_h();
104 int BC_Pan::button_press_event()
106 // there are two modes of operation...
108 { if (popup->is_event_win() && get_button_down() && get_buttonpress() == 1)
111 x_origin = popup->get_cursor_x();
112 y_origin = popup->get_cursor_y();
113 stick_x_origin = stick_x;
114 stick_y_origin = stick_y;
122 if(is_event_win() && get_button_down() && get_buttonpress() == 1)
127 x_origin = get_cursor_x();
128 y_origin = get_cursor_y();
129 stick_x_origin = stick_x;
130 stick_y_origin = stick_y;
137 int BC_Pan::cursor_motion_event()
139 if(popup && get_button_down() && get_buttonpress() == 1)
141 stick_x = stick_x_origin + get_cursor_x() - x_origin;
142 stick_y = stick_y_origin + get_cursor_y() - y_origin;
143 CLAMP(stick_x, 0, virtual_r * 2);
144 CLAMP(stick_y, 0, virtual_r * 2);
153 int BC_Pan::button_release_event()
165 int BC_Pan::repeat_event(int64_t duration)
167 if(duration == top_level->get_resources()->tooltip_delay &&
168 tooltip_text[0] != 0 &&
180 int BC_Pan::cursor_enter_event()
182 if(is_event_win() && !highlighted)
191 int BC_Pan::cursor_leave_event()
204 int BC_Pan::deactivate()
206 if(popup) delete popup;
212 int BC_Pan::activate(int popup_x, int popup_y)
218 if (popup_x < 0 || popup_y < 0)
220 XTranslateCoordinates(top_level->display,
228 x -= (images[PAN_POPUP]->get_w() - get_w()) / 2;
229 y -= (images[PAN_POPUP]->get_h() - get_h()) / 2;
233 XTranslateCoordinates(top_level->display,
241 x -= images[PAN_POPUP]->get_w() / 2;
242 y -= images[PAN_POPUP]->get_h() / 2;
247 if (popup) delete popup;
248 popup = new BC_Popup(this,
251 images[PAN_POPUP]->get_w(),
252 images[PAN_POPUP]->get_h(),
261 int BC_Pan::update(int x, int y)
274 void BC_Pan::draw_popup()
276 popup->draw_background(0, 0, popup->get_w(), popup->get_h());
280 float scale = (float)(popup->get_w() -
281 get_resources()->pan_data[PAN_CHANNEL]->get_w()) /
283 set_color(get_resources()->pan_text_color);
286 for(int i = 0; i < total_values; i++)
288 x1 = (int)(value_x[i] * scale);
289 y1 = (int)(value_y[i] * scale);
290 rotate_angle = value_positions[i];
291 rotate_angle = -rotate_angle;
292 while(rotate_angle < 0) rotate_angle += 360;
293 rotater->rotate(temp_channel,
294 get_resources()->pan_data[PAN_CHANNEL],
297 BC_Pixmap *temp_pixmap = new BC_Pixmap(popup,
300 popup->draw_pixmap(temp_pixmap, x1, y1);
303 char string[BCTEXTLEN];
304 float value = values[i] + 0.005;
305 sprintf(string, "%.1f", value);
306 popup->draw_text(x1, y1 + get_text_height(SMALLFONT), string);
309 x1 = (int)(stick_x * scale);
310 y1 = (int)(stick_y * scale);
311 popup->draw_pixmap(images[PAN_STICK], x1, y1);
320 draw_top_background(parent_window, 0, 0, w, h);
322 draw_pixmap(images[highlighted ? PAN_HI : PAN_UP]);
323 get_channel_positions(value_x,
330 int x1, y1, x2, y2, w, h, j;
331 float scale = (float)(get_w() - PICON_W) / (virtual_r * 2);
334 for(int i = 0; i < total_values; i++)
336 // printf("BC_Pan::draw 1 %d %d %d %d\n",
338 // value_positions[i],
341 x1 = (int)(value_x[i] * scale);
342 y1 = (int)(value_y[i] * scale);
343 //printf("BC_Pan::draw 2 %d %d\n", x1, y1);
344 CLAMP(x1, 0, get_w() - PICON_W);
345 CLAMP(y1, 0, get_h() - PICON_H);
346 draw_pixmap(images[PAN_CHANNEL_SMALL], x1, y1);
347 // draw_box(x1, y1, PICON_W, PICON_H);
352 x1 = (int)(stick_x * scale);
353 y1 = (int)(stick_y * scale);
355 //printf("BC_Pan::draw 2 %d %d\n", x1, y1);
356 CLAMP(x1, 0, get_w() - PICON_W);
357 CLAMP(y1, 0, get_h() - PICON_H);
359 draw_pixmap(images[PAN_STICK_SMALL], x1, y1);
360 // x2 = x1 + PICON_W;
361 // y2 = y1 + PICON_H;
362 // draw_line(x1, y1, x2, y2);
363 // draw_line(x2, y1, x1, y2);
368 int BC_Pan::stick_to_values()
370 return stick_to_values(values,
379 int BC_Pan::stick_to_values(float *values,
381 int *value_positions,
387 // find shortest distance to a channel
388 float shortest = 2 * virtual_r, test_distance;
390 int *value_x = new int[total_values];
391 int *value_y = new int[total_values];
393 get_channel_positions(value_x, value_y, value_positions, virtual_r, total_values);
394 for(i = 0; i < total_values; i++)
396 if((test_distance = distance(stick_x,
399 value_y[i])) < shortest)
400 shortest = test_distance;
403 // get values for channels
406 for(i = 0; i < total_values; i++)
408 if(distance(stick_x, value_x[i], stick_y, value_y[i]) == shortest)
409 values[i] = maxvalue;
416 for(i = 0; i < total_values; i++)
418 values[i] = shortest;
419 values[i] -= (float)(distance(stick_x,
422 value_y[i]) - shortest);
423 if(values[i] < 0) values[i] = 0;
424 values[i] = values[i] / shortest * maxvalue;
428 for(i = 0; i < total_values; i++)
430 values[i] = Units::quantize10(values[i]);
439 float BC_Pan::distance(int x1, int x2, int y1, int y2)
441 return hypot(x2 - x1, y2 - y1);
444 int BC_Pan::change_channels(int new_channels, int *value_positions)
447 delete this->value_positions;
451 values = new float[new_channels];
452 this->value_positions = new int[new_channels];
453 value_x = new int[new_channels];
454 value_y = new int[new_channels];
455 total_values = new_channels;
456 for(int i = 0; i < new_channels; i++)
458 this->value_positions[i] = value_positions[i];
460 get_channel_positions(value_x,
470 int BC_Pan::get_channel_positions(int *value_x,
472 int *value_positions,
476 for(int i = 0; i < total_values; i++)
478 rdtoxy(value_x[i], value_y[i], value_positions[i], virtual_r);
483 int BC_Pan::get_total_values()
488 float BC_Pan::get_value(int channel)
490 return values[channel];
493 int BC_Pan::get_stick_x()
498 int BC_Pan::get_stick_y()
503 float* BC_Pan::get_values()
508 int BC_Pan::rdtoxy(int &x, int &y, int a, int virtual_r)
510 float radians = (float)a / 360 * 2 * M_PI;
512 y = (int)(sin(radians) * virtual_r);
513 x = (int)(cos(radians) * virtual_r);
519 void BC_Pan::calculate_stick_position(int total_values,
520 int *value_positions,
527 // use highest value as location of stick
528 float highest_value = 0;
532 for(i = 0; i < total_values; i++)
534 if(values[i] > highest_value)
536 highest_value = values[i];
537 angle = value_positions[i];
541 rdtoxy(stick_x, stick_y, angle, virtual_r);