4 #include "bcresources.h"
11 #define METER_NORMAL 0
14 #define METER_YELLOW 3
22 BC_Meter::BC_Meter(int x,
31 : BC_SubWindow(x, y, -1, -1)
33 this->use_titles = use_titles;
34 this->over_delay = over_delay;
35 this->peak_delay = peak_delay;
38 this->orientation = orientation;
39 this->pixels = pixels;
40 for(int i = 0; i < TOTAL_METER_IMAGES; i++) images[i] = 0;
50 for(int i = 0; i < meter_titles; i++) delete [] db_titles[i];
53 if(title_pixel) delete [] title_pixel;
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, float min)
168 reposition_window(get_x(), get_y(), pixels);
172 int BC_Meter::level_to_pixel(float level)
177 result = pixels - 4 - (int)((level / min) * (pixels - 4));
178 if(level == 0) result = pixels;
182 result = (int)(level * (pixels - 4));
189 void BC_Meter::get_divisions()
193 float division, division_step;
198 for(int i = 0; i < meter_titles; i++) delete [] db_titles[i];
201 if(title_pixel) delete [] title_pixel;
203 meter_titles = labs((int)(min / 5)) + 1;
204 title_pixel = new int[meter_titles];
208 db_titles = new char*[meter_titles];
209 for(i = 0; i < meter_titles; i++) db_titles[i] = 0;
212 division = METER_MARGIN;
213 division_step = (float)(pixels - METER_MARGIN * 3) / (meter_titles - 1);
214 j = 0; // number for title
215 j_step = min / (meter_titles - 1);
217 for(i = 0; i < meter_titles; i++)
222 sprintf(string, "%.0f", fabs(-j));
223 db_titles[i] = new char[strlen(string) + 1];
224 strcpy(db_titles[i], string);
227 title_pixel[i] = (int)(division);
229 division += division_step;
233 medium_division = pixels - title_pixel[(meter_titles-1)*1/6];
234 low_division = pixels - title_pixel[(meter_titles-1)*2/5];
237 void BC_Meter::draw_titles()
239 if(!use_titles) return;
241 set_font(get_resources()->meter_font);
243 if(orientation == METER_HORIZ)
245 draw_top_background(parent_window, 0, 0, get_w(), get_title_w());
247 for(int i = 0; i < meter_titles; i++)
249 draw_text(0, title_pixel[i], db_titles[i]);
252 flash(0, 0, get_w(), get_title_w());
255 if(orientation == METER_VERT)
257 draw_top_background(parent_window, 0, 0, get_title_w(), get_h());
260 for(int i = 0; i < meter_titles; i++)
263 if(i < meter_titles - 1)
265 for(int j = 0; j < 6; j++)
272 y2 = title_pixel[i + 1];
273 y = (int)((float)(y2 - y1) * j / 5 + 0.5) + y1;
277 set_color(get_resources()->meter_font_color);
278 draw_line(get_title_w() - 10 - 1, y, get_title_w() - 1, y);
279 if(get_resources()->meter_3d)
282 draw_line(get_title_w() - 10, y + 1, get_title_w(), y + 1);
287 set_color(get_resources()->meter_font_color);
288 draw_line(get_title_w() - 5 - 1, y, get_title_w() - 1, y);
289 if(get_resources()->meter_3d)
292 draw_line(get_title_w() - 5, y + 1, get_title_w(), y + 1);
298 set_color(get_resources()->meter_font_color);
300 draw_text(0, title_pixel[i] + get_text_height(SMALLFONT_3D) / 2, db_titles[i]);
302 draw_text(0, title_pixel[i] + get_text_height(SMALLFONT_3D) / 2, db_titles[i]);
305 flash(0, 0, get_title_w(), get_h());
309 int BC_Meter::region_pixel(int region)
311 VFrame **reference_images = get_resources()->xmeter_images;
314 if(region == METER_RIGHT)
315 result = region * reference_images[0]->get_w() / 4;
317 result = region * reference_images[0]->get_w() / 4;
322 int BC_Meter::region_pixels(int region)
327 VFrame **reference_images = get_resources()->xmeter_images;
329 x1 = region * reference_images[0]->get_w() / 4;
330 x2 = (region + 1) * reference_images[0]->get_w() / 4;
331 if(region == METER_MID)
332 result = (x2 - x1) * 2;
338 void BC_Meter::draw_face()
340 VFrame **reference_images = get_resources()->xmeter_images;
341 int level_pixel = level_to_pixel(level);
342 int peak_pixel2 = level_to_pixel(peak);
343 int peak_pixel1 = peak_pixel2 - 2;
344 int left_pixel = region_pixel(METER_MID);
345 int right_pixel = pixels - region_pixels(METER_RIGHT);
347 int image_number = 0, region = 0;
348 int in_span, in_start;
349 int x = use_titles ? get_title_w() : 0;
350 int w = use_titles ? this->w - get_title_w() : this->w;
352 draw_top_background(parent_window, x, 0, w, h);
353 //printf("BC_Meter::draw_face %d %d\n", w, h);
355 while(pixel < pixels)
357 // Select image to draw
358 if(pixel < level_pixel ||
359 (pixel >= peak_pixel1 && pixel < peak_pixel2))
361 if(pixel < low_division)
362 image_number = METER_GREEN;
364 if(pixel < medium_division)
365 image_number = METER_YELLOW;
367 image_number = METER_RED;
371 image_number = METER_NORMAL;
374 // Select region of image to duplicate
375 if(pixel < left_pixel)
378 in_start = pixel + region_pixel(region);
379 in_span = region_pixels(region) - (in_start - region_pixel(region));
382 if(pixel < right_pixel)
385 in_start = region_pixel(region);
386 in_span = region_pixels(region);
390 region = METER_RIGHT;
391 in_start = (pixel - right_pixel) + region_pixel(region);
392 in_span = region_pixels(region) - (in_start - region_pixel(region));;
395 //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);
398 // Clip length to peaks
399 if(pixel < level_pixel && pixel + in_span > level_pixel)
400 in_span = level_pixel - pixel;
402 if(pixel < peak_pixel1 && pixel + in_span > peak_pixel1)
403 in_span = peak_pixel1 - pixel;
405 if(pixel < peak_pixel2 && pixel + in_span > peak_pixel2)
406 in_span = peak_pixel2 - pixel;
408 // Clip length to color changes
409 if(image_number == METER_GREEN && pixel + in_span > low_division)
410 in_span = low_division - pixel;
412 if(image_number == METER_YELLOW && pixel + in_span > medium_division)
413 in_span = medium_division - pixel;
415 // Clip length to regions
416 if(pixel < left_pixel && pixel + in_span > left_pixel)
417 in_span = left_pixel - pixel;
419 if(pixel < right_pixel && pixel + in_span > right_pixel)
420 in_span = right_pixel - pixel;
422 //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);
423 //printf("BC_Meter::draw_face %d %d %d %d\n", orientation, region, images[image_number]->get_h() - in_start - in_span);
424 if(orientation == METER_HORIZ)
425 draw_pixmap(images[image_number],
433 draw_pixmap(images[image_number],
435 get_h() - pixel - in_span,
439 images[image_number]->get_h() - in_start - in_span);
447 if(orientation == METER_HORIZ)
448 draw_pixmap(images[METER_OVER],
452 draw_pixmap(images[METER_OVER],
459 if(orientation == METER_HORIZ)
460 flash(0, 0, pixels, get_h());
462 flash(x, 0, w, pixels);
465 int BC_Meter::update(float new_value, int over)
474 level = db.todb(new_value); // db value
477 if(level > peak || peak_timer > peak_delay)
483 //printf("BC_Meter::update %f\n", level);
484 if(over) over_timer = over_delay;
485 // only draw if window is visible