From 3168a35852b42623d7f8587f336572a6aa2466b3 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Thu, 21 Feb 2008 02:24:11 +0000 Subject: more meter optimization git-svn-id: svn://localhost/ardour2/branches/2.0-ongoing@3095 d708f5d6-7413-0410-9779-e7cbd77b26cf --- libs/gtkmm2ext/fastmeter.cc | 56 +++++++++++++++++------------------- libs/gtkmm2ext/gtkmm2ext/fastmeter.h | 1 + 2 files changed, 27 insertions(+), 30 deletions(-) (limited to 'libs') diff --git a/libs/gtkmm2ext/fastmeter.cc b/libs/gtkmm2ext/fastmeter.cc index c30387d1ed..94e6bffd91 100644 --- a/libs/gtkmm2ext/fastmeter.cc +++ b/libs/gtkmm2ext/fastmeter.cc @@ -56,6 +56,8 @@ FastMeter::FastMeter (long hold, unsigned long dimen, Orientation o, int len, in hold_state = 0; current_peak = 0; current_level = 0; + last_peak_rect.width = 0; + last_peak_rect.height = 0; rgb0 = clr0; rgb1 = clr1; rgb2 = clr2; @@ -381,15 +383,21 @@ FastMeter::vertical_expose (GdkEventExpose* ev) } // draw peak bar - if (hold_state && intersection.width > 0) { - gint y = pixheight - (gint) floor (pixheight * current_peak); - int h = min(3, pixheight - y); + + if (hold_state) { + last_peak_rect.x = 0; + last_peak_rect.width = pixwidth; + last_peak_rect.y = pixheight - (gint) floor (pixheight * current_peak); + last_peak_rect.height = min(3, pixheight - last_peak_rect.y); get_window()->draw_pixbuf (get_style()->get_fg_gc(get_state()), pixbuf, - intersection.x, y, - intersection.x, y, - intersection.width, h, + 0, last_peak_rect.y, + 0, last_peak_rect.y, + pixwidth, last_peak_rect.height, Gdk::RGB_DITHER_NONE, 0, 0); + } else { + last_peak_rect.width = 0; + last_peak_rect.height = 0; } return TRUE; @@ -465,10 +473,8 @@ FastMeter::set (float lvl) return; } - queue_draw (); -#if 0 - Glib::Refptr win; + Glib::RefPtr win; if ((win = get_window()) == 0) { queue_draw (); @@ -483,14 +489,9 @@ FastMeter::set (float lvl) rect.x = 0; rect.width = pixwidth; - rect.height = newtop; + rect.height = new_top; rect.y = pixheight - new_top; - background.x = 0; - background.y = 0; - background.width = pixrect.width; - background.height = pixheight - top_of_meter; - if (current_level > old_level) { /* colored/pixbuf got larger, just draw the new section */ /* rect.y stays where it is because of X coordinates */ @@ -501,7 +502,7 @@ FastMeter::set (float lvl) rect.height = pixrect.y - rect.y; } else { /* it got smaller, compute the difference */ - /* rect.y becomes old.y (the smaller value) + /* rect.y becomes old.y (the smaller value) */ rect.y = pixrect.y; /* rect.height is the old.y (smaller) minus the new.y (larger) */ @@ -514,21 +515,18 @@ FastMeter::set (float lvl) /* ok, first region to draw ... */ - region = gdk_region_rect (&rect); + region = gdk_region_rectangle (&rect); } else { region = gdk_region_new (); } - if (hold_state) { - rect.x = 0; - rect.width = pixwidth; - - /* redraw the last place where the peak hold bar was */ - - rect.y = pixheight - (gint) floor (pixheight * old_peak); - rect.height = min(3, pixheight - y); - - gdk_region_union_rect (region, &rect); + /* redraw the last place where the peak hold bar was; + the expose will draw the new one whether its part of + expose region or not. + */ + + if (last_peak_rect.width * last_peak_rect.height != 0) { + gdk_region_union_with_rect (region, &last_peak_rect); } if (rect.height == 0 && !hold_state) { @@ -536,9 +534,7 @@ FastMeter::set (float lvl) return; } - gdk_window_invalidate_region (win->gobj(), ®ion); -#endif - + gdk_window_invalidate_region (win->gobj(), region, true); } void diff --git a/libs/gtkmm2ext/gtkmm2ext/fastmeter.h b/libs/gtkmm2ext/gtkmm2ext/fastmeter.h index d6617c6c7f..b8441aacae 100644 --- a/libs/gtkmm2ext/gtkmm2ext/fastmeter.h +++ b/libs/gtkmm2ext/gtkmm2ext/fastmeter.h @@ -59,6 +59,7 @@ class FastMeter : public Gtk::DrawingArea { Orientation orientation; GdkRectangle pixrect; + GdkRectangle last_peak_rect; gint request_width; gint request_height; unsigned long hold_cnt; -- cgit v1.2.3