4 #include "bcresources.h"
11 // Which source image to replicate
12 #define METER_NORMAL 0
15 #define METER_YELLOW 3
19 // Region of source image to replicate
25 BC_Meter::BC_Meter(int x,
35 : BC_SubWindow(x, y, -1, -1)
37 this->use_titles = use_titles;
38 this->over_delay = over_delay;
39 this->peak_delay = peak_delay;
43 this->orientation = orientation;
44 this->pixels = pixels;
45 for(int i = 0; i < TOTAL_METER_IMAGES; i++) images[i] = 0;
46 db_titles.set_array_delete();
51 db_titles.remove_all_objects();
52 title_pixels.remove_all();
53 tick_pixels.remove_all();
54 for(int i = 0; i < TOTAL_METER_IMAGES; i++) delete images[i];
57 int BC_Meter::get_title_w()
59 return get_resources()->meter_title_w;
62 int BC_Meter::get_meter_w()
64 return get_resources()->ymeter_images[0]->get_w() + 2;
68 int BC_Meter::set_delays(int over_delay, int peak_delay)
70 this->over_delay = over_delay;
71 this->peak_delay = peak_delay;
75 int BC_Meter::initialize()
78 level_pixel = peak_pixel = 0;
83 if(orientation == METER_VERT)
85 set_images(get_resources()->ymeter_images);
87 w = images[0]->get_w();
88 if(use_titles) w += get_title_w();
92 set_images(get_resources()->xmeter_images);
93 h = images[0]->get_h();
95 if(use_titles) h += get_title_w();
98 // calibrate the db titles
101 BC_SubWindow::initialize();
107 void BC_Meter::set_images(VFrame **data)
109 for(int i = 0; i < TOTAL_METER_IMAGES; i++) delete images[i];
110 for(int i = 0; i < TOTAL_METER_IMAGES; i++)
111 images[i] = new BC_Pixmap(parent_window, data[i], PIXMAP_ALPHA);
114 int BC_Meter::reposition_window(int x, int y, int pixels)
116 if(pixels < 0) pixels = this->pixels;
117 this->pixels = pixels;
118 if(orientation == METER_VERT)
119 BC_SubWindow::reposition_window(x, y, get_w(), pixels);
121 BC_SubWindow::reposition_window(x, y, pixels, get_h());
123 //printf("BC_Meter::reposition_window 1 %d %d %d %d\n", x, y, w, h);
127 //draw_box(0, 0, w, h);
135 int BC_Meter::reset()
139 level_pixel = peak_pixel = 0;
147 int BC_Meter::button_press_event()
149 if(cursor_inside() && is_event_win())
158 int BC_Meter::reset_over()
164 int BC_Meter::change_format(int mode, int min, int max)
169 reposition_window(get_x(), get_y(), pixels);
173 int BC_Meter::level_to_pixel(float level)
178 result = (int)(pixels *
181 if(level <= min) result = 0;
185 // Not implemented anymore
193 void BC_Meter::get_divisions()
197 int division, division_step;
198 char string[BCTEXTLEN];
202 db_titles.remove_all_objects();
203 title_pixels.remove_all();
204 tick_pixels.remove_all();
208 high_division = pixels;
211 // Create tick marks and titles in one pass
212 for(int current = min; current <= max; current++)
214 if(orientation == METER_VERT)
217 current_pixel = (pixels - METER_MARGIN * 2 - 2) *
220 tick_pixels.append(current_pixel);
222 // Create titles in selected positions
226 (current - min > 4 && max - current > 4 && !(current % 5)))
228 int title_pixel = (pixels -
232 sprintf(string, "%d", labs(current));
233 new_string = new char[strlen(string) + 1];
234 strcpy(new_string, string);
235 db_titles.append(new_string);
236 title_pixels.append(title_pixel);
241 current_pixel = (pixels - METER_MARGIN * 2) *
244 tick_pixels.append(current_pixel);
245 // Titles not supported for horizontal
248 // Create color divisions
251 low_division = current_pixel;
256 medium_division = current_pixel;
261 high_division = current_pixel;
264 // if(orientation == METER_VERT)
265 // printf("BC_Meter::get_divisions %d %d %d %d\n",
266 // low_division, medium_division, high_division, pixels);
269 void BC_Meter::draw_titles()
271 if(!use_titles) return;
273 set_font(get_resources()->meter_font);
275 if(orientation == METER_HORIZ)
277 draw_top_background(parent_window, 0, 0, get_w(), get_title_w());
279 for(int i = 0; i < db_titles.total; i++)
281 draw_text(0, title_pixels.values[i], db_titles.values[i]);
284 flash(0, 0, get_w(), get_title_w());
287 if(orientation == METER_VERT)
289 draw_top_background(parent_window, 0, 0, get_title_w(), get_h());
292 for(int i = 0; i < db_titles.total; i++)
294 int title_y = pixels -
295 title_pixels.values[i];
297 title_y -= get_text_descent(SMALLFONT_3D);
299 if(i == db_titles.total - 1)
300 title_y += get_text_ascent(SMALLFONT_3D);
302 title_y += get_text_ascent(SMALLFONT_3D) / 2;
304 set_color(get_resources()->meter_font_color);
307 db_titles.values[i]);
310 for(int i = 0; i < tick_pixels.total; i++)
313 int tick_y = pixels - tick_pixels.values[i] - METER_MARGIN;
314 set_color(get_resources()->meter_font_color);
315 draw_line(get_title_w() - 10 - 1, tick_y, get_title_w() - 1, tick_y);
316 if(get_resources()->meter_3d)
319 draw_line(get_title_w() - 10, tick_y + 1, get_title_w(), tick_y + 1);
323 flash(0, 0, get_title_w(), get_h());
327 int BC_Meter::region_pixel(int region)
329 VFrame **reference_images = get_resources()->xmeter_images;
332 if(region == METER_RIGHT)
333 result = region * reference_images[0]->get_w() / 4;
335 result = region * reference_images[0]->get_w() / 4;
340 int BC_Meter::region_pixels(int region)
345 VFrame **reference_images = get_resources()->xmeter_images;
347 x1 = region * reference_images[0]->get_w() / 4;
348 x2 = (region + 1) * reference_images[0]->get_w() / 4;
349 if(region == METER_MID)
350 result = (x2 - x1) * 2;
356 void BC_Meter::draw_face()
358 VFrame **reference_images = get_resources()->xmeter_images;
359 int level_pixel = level_to_pixel(level);
360 int peak_pixel2 = level_to_pixel(peak);
361 int peak_pixel1 = peak_pixel2 - 2;
362 int left_pixel = region_pixel(METER_MID);
363 int right_pixel = pixels - region_pixels(METER_RIGHT);
365 int image_number = 0, region = 0;
366 int in_span, in_start;
367 int x = use_titles ? get_title_w() : 0;
368 int w = use_titles ? this->w - get_title_w() : this->w;
370 draw_top_background(parent_window, x, 0, w, h);
371 //printf("BC_Meter::draw_face %d %d\n", w, h);
373 while(pixel < pixels)
375 // Select image to draw
376 if(pixel < level_pixel ||
377 (pixel >= peak_pixel1 && pixel < peak_pixel2))
379 if(pixel < low_division)
380 image_number = METER_GREEN;
382 if(pixel < medium_division)
383 image_number = METER_YELLOW;
385 if(pixel < high_division)
386 image_number = METER_RED;
388 image_number = METER_WHITE;
392 image_number = METER_NORMAL;
395 // Select region of image to duplicate
396 if(pixel < left_pixel)
399 in_start = pixel + region_pixel(region);
400 in_span = region_pixels(region) - (in_start - region_pixel(region));
403 if(pixel < right_pixel)
406 in_start = region_pixel(region);
407 in_span = region_pixels(region);
411 region = METER_RIGHT;
412 in_start = (pixel - right_pixel) + region_pixel(region);
413 in_span = region_pixels(region) - (in_start - region_pixel(region));;
416 //printf("BC_Meter::draw_face region %d pixel %d pixels %d in_start %d in_span %d\n", region, pixel, pixels, in_start, in_span);
419 // Clip length to peaks
420 if(pixel < level_pixel && pixel + in_span > level_pixel)
421 in_span = level_pixel - pixel;
423 if(pixel < peak_pixel1 && pixel + in_span > peak_pixel1)
424 in_span = peak_pixel1 - pixel;
426 if(pixel < peak_pixel2 && pixel + in_span > peak_pixel2)
427 in_span = peak_pixel2 - pixel;
429 // Clip length to color changes
430 if(image_number == METER_GREEN && pixel + in_span > low_division)
431 in_span = low_division - pixel;
433 if(image_number == METER_YELLOW && pixel + in_span > medium_division)
434 in_span = medium_division - pixel;
436 if(image_number == METER_RED && pixel + in_span > high_division)
437 in_span = high_division - pixel;
439 // Clip length to regions
440 if(pixel < left_pixel && pixel + in_span > left_pixel)
441 in_span = left_pixel - pixel;
443 if(pixel < right_pixel && pixel + in_span > right_pixel)
444 in_span = right_pixel - pixel;
446 //printf("BC_Meter::draw_face image_number %d pixel %d pixels %d in_start %d in_span %d\n", image_number, pixel, pixels, in_start, in_span);
447 //printf("BC_Meter::draw_face %d %d %d %d\n", orientation, region, images[image_number]->get_h() - in_start - in_span);
448 if(orientation == METER_HORIZ)
449 draw_pixmap(images[image_number],
457 draw_pixmap(images[image_number],
459 get_h() - pixel - in_span,
463 images[image_number]->get_h() - in_start - in_span);
476 if(orientation == METER_HORIZ)
477 draw_pixmap(images[METER_OVER],
481 draw_pixmap(images[METER_OVER],
488 if(orientation == METER_HORIZ)
489 flash(0, 0, pixels, get_h());
491 flash(x, 0, w, pixels);
495 int BC_Meter::update(float new_value, int over)
504 level = db.todb(new_value); // db value
507 if(level > peak || peak_timer > peak_delay)
513 // if(orientation == METER_HORIZ)
514 // printf("BC_Meter::update %f\n", level);
515 if(over) over_timer = over_delay;
516 // only draw if window is visible