From ab44e41dfd8b8247ed5f57a8f3fcbbf4f8457827 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Thu, 20 Mar 2014 23:50:40 +0100 Subject: change the meters into CairoWidget, add expose_area to CairoWidget::render() --- gtk2_ardour/ardour_button.cc | 2 +- gtk2_ardour/ardour_button.h | 2 +- gtk2_ardour/audio_clock.cc | 2 +- gtk2_ardour/audio_clock.h | 2 +- gtk2_ardour/button_joiner.cc | 2 +- gtk2_ardour/button_joiner.h | 2 +- gtk2_ardour/editor_summary.cc | 2 +- gtk2_ardour/editor_summary.h | 2 +- gtk2_ardour/group_tabs.cc | 2 +- gtk2_ardour/group_tabs.h | 2 +- gtk2_ardour/led.cc | 2 +- gtk2_ardour/led.h | 2 +- gtk2_ardour/shuttle_control.cc | 2 +- gtk2_ardour/shuttle_control.h | 2 +- libs/gtkmm2ext/cairo_widget.cc | 8 ++++- libs/gtkmm2ext/fastmeter.cc | 60 ++++++++++++++------------------- libs/gtkmm2ext/gtkmm2ext/cairo_widget.h | 2 +- libs/gtkmm2ext/gtkmm2ext/fastmeter.h | 11 +++--- 18 files changed, 53 insertions(+), 56 deletions(-) diff --git a/gtk2_ardour/ardour_button.cc b/gtk2_ardour/ardour_button.cc index 9d0960602e..bc10530417 100644 --- a/gtk2_ardour/ardour_button.cc +++ b/gtk2_ardour/ardour_button.cc @@ -195,7 +195,7 @@ ArdourButton::set_alignment (const float xa, const float ya) } void -ArdourButton::render (cairo_t* cr) +ArdourButton::render (cairo_t* cr, cairo_rectangle_t *) { void (*rounded_function)(cairo_t*, double, double, double, double, double); diff --git a/gtk2_ardour/ardour_button.h b/gtk2_ardour/ardour_button.h index cf47fd1d30..2f9389efed 100644 --- a/gtk2_ardour/ardour_button.h +++ b/gtk2_ardour/ardour_button.h @@ -99,7 +99,7 @@ class ArdourButton : public CairoWidget , public Gtkmm2ext::Activatable void set_fixed_colors (const uint32_t active_color, const uint32_t inactive_color); protected: - void render (cairo_t *); + void render (cairo_t *, cairo_rectangle_t *); void on_size_request (Gtk::Requisition* req); void on_size_allocate (Gtk::Allocation&); void on_style_changed (const Glib::RefPtr&); diff --git a/gtk2_ardour/audio_clock.cc b/gtk2_ardour/audio_clock.cc index 7bbc00c267..64358eaadf 100644 --- a/gtk2_ardour/audio_clock.cc +++ b/gtk2_ardour/audio_clock.cc @@ -282,7 +282,7 @@ AudioClock::set_colors () } void -AudioClock::render (cairo_t* cr) +AudioClock::render (cairo_t* cr, cairo_rectangle_t*) { /* main layout: rounded rect, plus the text */ diff --git a/gtk2_ardour/audio_clock.h b/gtk2_ardour/audio_clock.h index 96cde6ea81..83b6b5794a 100644 --- a/gtk2_ardour/audio_clock.h +++ b/gtk2_ardour/audio_clock.h @@ -85,7 +85,7 @@ class AudioClock : public CairoWidget, public ARDOUR::SessionHandlePtr static std::vector clocks; protected: - void render (cairo_t*); + void render (cairo_t*, cairo_rectangle_t*); virtual void build_ops_menu (); Gtk::Menu *ops_menu; diff --git a/gtk2_ardour/button_joiner.cc b/gtk2_ardour/button_joiner.cc index 8671dab9ab..0c60cba1db 100644 --- a/gtk2_ardour/button_joiner.cc +++ b/gtk2_ardour/button_joiner.cc @@ -99,7 +99,7 @@ ButtonJoiner::~ButtonJoiner () } void -ButtonJoiner::render (cairo_t* cr) +ButtonJoiner::render (cairo_t* cr, cairo_rectangle_t*) { double h = get_height(); diff --git a/gtk2_ardour/button_joiner.h b/gtk2_ardour/button_joiner.h index 3d136faa74..4d8b861894 100644 --- a/gtk2_ardour/button_joiner.h +++ b/gtk2_ardour/button_joiner.h @@ -36,7 +36,7 @@ class ButtonJoiner : public CairoWidget, public Gtkmm2ext::Activatable { void set_active_state (Gtkmm2ext::ActiveState); protected: - void render (cairo_t*); + void render (cairo_t*, cairo_rectangle_t*); bool on_button_release_event (GdkEventButton*); void on_size_request (Gtk::Requisition*); void on_size_allocate (Gtk::Allocation&); diff --git a/gtk2_ardour/editor_summary.cc b/gtk2_ardour/editor_summary.cc index 1c30df4f3a..0e14ad2f08 100644 --- a/gtk2_ardour/editor_summary.cc +++ b/gtk2_ardour/editor_summary.cc @@ -89,7 +89,7 @@ EditorSummary::set_session (Session* s) * @param cr Context. */ void -EditorSummary::render (cairo_t* cr) +EditorSummary::render (cairo_t* cr, cairo_rectangle_t*) { /* background (really just the dividing lines between tracks */ diff --git a/gtk2_ardour/editor_summary.h b/gtk2_ardour/editor_summary.h index f6aa804f59..87474188b1 100644 --- a/gtk2_ardour/editor_summary.h +++ b/gtk2_ardour/editor_summary.h @@ -69,7 +69,7 @@ private: bool on_leave_notify_event (GdkEventCrossing*); void centre_on_click (GdkEventButton *); - void render (cairo_t *); + void render (cairo_t *, cairo_rectangle_t*); void render_region (RegionView*, cairo_t*, double) const; void get_editor (std::pair *, std::pair *) const; void set_editor (double, double); diff --git a/gtk2_ardour/group_tabs.cc b/gtk2_ardour/group_tabs.cc index 2394b9a6c5..05e8438709 100644 --- a/gtk2_ardour/group_tabs.cc +++ b/gtk2_ardour/group_tabs.cc @@ -237,7 +237,7 @@ GroupTabs::on_button_release_event (GdkEventButton*) } void -GroupTabs::render (cairo_t* cr) +GroupTabs::render (cairo_t* cr, cairo_rectangle_t*) { if (_dragging == 0) { _tabs = compute_tabs (); diff --git a/gtk2_ardour/group_tabs.h b/gtk2_ardour/group_tabs.h index d61358ead5..0d83a553c1 100644 --- a/gtk2_ardour/group_tabs.h +++ b/gtk2_ardour/group_tabs.h @@ -108,7 +108,7 @@ private: void disable_all (); void remove_group (ARDOUR::RouteGroup *); - void render (cairo_t *); + void render (cairo_t *, cairo_rectangle_t*); void on_size_request (Gtk::Requisition *); bool on_button_press_event (GdkEventButton *); bool on_motion_notify_event (GdkEventMotion *); diff --git a/gtk2_ardour/led.cc b/gtk2_ardour/led.cc index 9a71ad736e..dca5caefc1 100644 --- a/gtk2_ardour/led.cc +++ b/gtk2_ardour/led.cc @@ -42,7 +42,7 @@ LED::~LED() } void -LED::render (cairo_t* cr) +LED::render (cairo_t* cr, cairo_rectangle_t*) { if (!_fixed_diameter) { _diameter = std::min (get_width(), get_height()); diff --git a/gtk2_ardour/led.h b/gtk2_ardour/led.h index 089c35b7a8..ef5ae7b68d 100644 --- a/gtk2_ardour/led.h +++ b/gtk2_ardour/led.h @@ -33,7 +33,7 @@ class LED : public CairoWidget void set_diameter (float); protected: - void render (cairo_t *); + void render (cairo_t *, cairo_rectangle_t*); void on_size_request (Gtk::Requisition* req); void on_realize (); diff --git a/gtk2_ardour/shuttle_control.cc b/gtk2_ardour/shuttle_control.cc index 1d150f73d6..6fdf934238 100644 --- a/gtk2_ardour/shuttle_control.cc +++ b/gtk2_ardour/shuttle_control.cc @@ -512,7 +512,7 @@ ShuttleControl::use_shuttle_fract (bool force, bool zero_ok) } void -ShuttleControl::render (cairo_t* cr) +ShuttleControl::render (cairo_t* cr, cairo_rectangle_t*) { cairo_text_extents_t extents; diff --git a/gtk2_ardour/shuttle_control.h b/gtk2_ardour/shuttle_control.h index a8c2e71d59..0b289c5180 100644 --- a/gtk2_ardour/shuttle_control.h +++ b/gtk2_ardour/shuttle_control.h @@ -87,7 +87,7 @@ class ShuttleControl : public CairoWidget, public ARDOUR::SessionHandlePtr bool on_scroll_event (GdkEventScroll*); bool on_motion_notify_event(GdkEventMotion*); - void render (cairo_t *); + void render (cairo_t *, cairo_rectangle_t*); void on_size_allocate (Gtk::Allocation&); bool on_query_tooltip (int, int, bool, const Glib::RefPtr&); diff --git a/libs/gtkmm2ext/cairo_widget.cc b/libs/gtkmm2ext/cairo_widget.cc index 70c52bf177..b7d9b08c72 100644 --- a/libs/gtkmm2ext/cairo_widget.cc +++ b/libs/gtkmm2ext/cairo_widget.cc @@ -53,7 +53,13 @@ CairoWidget::on_expose_event (GdkEventExpose *ev) cairo_set_source_rgb (cr, bg.get_red_p(), bg.get_green_p(), bg.get_blue_p()); cairo_fill (cr); - render (cr); + cairo_rectangle_t expose_area; + expose_area.x = ev->area.x; + expose_area.y = ev->area.y; + expose_area.width = ev->area.width; + expose_area.height = ev->area.height; + + render (cr, &expose_area); cairo_destroy (cr); diff --git a/libs/gtkmm2ext/fastmeter.cc b/libs/gtkmm2ext/fastmeter.cc index 5a77557222..15963df79b 100644 --- a/libs/gtkmm2ext/fastmeter.cc +++ b/libs/gtkmm2ext/fastmeter.cc @@ -504,7 +504,7 @@ FastMeter::vertical_size_allocate (Gtk::Allocation &alloc) pixwidth = request_width - 2; } - DrawingArea::on_size_allocate (alloc); + CairoWidget::on_size_allocate (alloc); } void @@ -529,31 +529,26 @@ FastMeter::horizontal_size_allocate (Gtk::Allocation &alloc) pixheight = request_height - 2; } - DrawingArea::on_size_allocate (alloc); + CairoWidget::on_size_allocate (alloc); } -bool -FastMeter::on_expose_event (GdkEventExpose* ev) +void +FastMeter::render (cairo_t* cr, cairo_rectangle_t* area) { if (orientation == Vertical) { - return vertical_expose (ev); + return vertical_expose (cr, area); } else { - return horizontal_expose (ev); + return horizontal_expose (cr, area); } } -bool -FastMeter::vertical_expose (GdkEventExpose* ev) +void +FastMeter::vertical_expose (cairo_t* cr, cairo_rectangle_t* area) { - Glib::RefPtr win = get_window (); gint top_of_meter; GdkRectangle intersection; GdkRectangle background; - - cairo_t* cr = gdk_cairo_create (get_window ()->gobj()); - - cairo_rectangle (cr, ev->area.x, ev->area.y, ev->area.width, ev->area.height); - cairo_clip (cr); + GdkRectangle eventarea; cairo_set_source_rgb (cr, 0, 0, 0); // black rounded_rectangle (cr, 0, 0, pixwidth + 2, pixheight + 2, 2); @@ -572,13 +567,18 @@ FastMeter::vertical_expose (GdkEventExpose* ev) background.width = pixrect.width; background.height = pixheight - top_of_meter; - if (gdk_rectangle_intersect (&background, &ev->area, &intersection)) { + eventarea.x = area->x; + eventarea.y = area->y; + eventarea.width = area->width; + eventarea.height = area->height; + + if (gdk_rectangle_intersect (&background, &eventarea, &intersection)) { cairo_set_source (cr, bgpattern->cobj()); cairo_rectangle (cr, intersection.x, intersection.y, intersection.width, intersection.height); cairo_fill (cr); } - if (gdk_rectangle_intersect (&pixrect, &ev->area, &intersection)) { + if (gdk_rectangle_intersect (&pixrect, &eventarea, &intersection)) { // draw the part of the meter image that we need. the area we draw is bounded "in reverse" (top->bottom) cairo_set_source (cr, fgpattern->cobj()); cairo_rectangle (cr, intersection.x, intersection.y, intersection.width, intersection.height); @@ -610,24 +610,15 @@ FastMeter::vertical_expose (GdkEventExpose* ev) last_peak_rect.width = 0; last_peak_rect.height = 0; } - - cairo_destroy (cr); - - return TRUE; } -bool -FastMeter::horizontal_expose (GdkEventExpose* ev) +void +FastMeter::horizontal_expose (cairo_t* cr, cairo_rectangle_t* area) { - Glib::RefPtr win = get_window (); gint right_of_meter; GdkRectangle intersection; GdkRectangle background; - - cairo_t* cr = gdk_cairo_create (get_window ()->gobj()); - - cairo_rectangle (cr, ev->area.x, ev->area.y, ev->area.width, ev->area.height); - cairo_clip (cr); + GdkRectangle eventarea; cairo_set_source_rgb (cr, 0, 0, 0); // black rounded_rectangle (cr, 0, 0, pixwidth + 2, pixheight + 2, 2); @@ -645,13 +636,18 @@ FastMeter::horizontal_expose (GdkEventExpose* ev) background.width = pixwidth - right_of_meter; background.height = pixheight; - if (gdk_rectangle_intersect (&background, &ev->area, &intersection)) { + eventarea.x = area->x; + eventarea.y = area->y; + eventarea.width = area->width; + eventarea.height = area->height; + + if (gdk_rectangle_intersect (&background, &eventarea, &intersection)) { cairo_set_source (cr, bgpattern->cobj()); cairo_rectangle (cr, intersection.x, intersection.y, intersection.width, intersection.height); cairo_fill (cr); } - if (gdk_rectangle_intersect (&pixrect, &ev->area, &intersection)) { + if (gdk_rectangle_intersect (&pixrect, &eventarea, &intersection)) { cairo_set_source (cr, fgpattern->cobj()); cairo_rectangle (cr, intersection.x, intersection.y, intersection.width, intersection.height); cairo_fill (cr); @@ -683,10 +679,6 @@ FastMeter::horizontal_expose (GdkEventExpose* ev) last_peak_rect.width = 0; last_peak_rect.height = 0; } - - cairo_destroy (cr); - - return TRUE; } void diff --git a/libs/gtkmm2ext/gtkmm2ext/cairo_widget.h b/libs/gtkmm2ext/gtkmm2ext/cairo_widget.h index c8927b050b..2c70f8aad2 100644 --- a/libs/gtkmm2ext/gtkmm2ext/cairo_widget.h +++ b/libs/gtkmm2ext/gtkmm2ext/cairo_widget.h @@ -69,7 +69,7 @@ public: protected: /** Render the widget to the given Cairo context */ - virtual void render (cairo_t *) = 0; + virtual void render (cairo_t *, cairo_rectangle_t*) = 0; virtual bool on_expose_event (GdkEventExpose *); void on_size_allocate (Gtk::Allocation &); void on_state_changed (Gtk::StateType); diff --git a/libs/gtkmm2ext/gtkmm2ext/fastmeter.h b/libs/gtkmm2ext/gtkmm2ext/fastmeter.h index 6802481777..650908f6a4 100644 --- a/libs/gtkmm2ext/gtkmm2ext/fastmeter.h +++ b/libs/gtkmm2ext/gtkmm2ext/fastmeter.h @@ -24,14 +24,13 @@ #include #include #include -#include -#include +#include "gtkmm2ext/cairo_widget.h" #include "gtkmm2ext/visibility.h" namespace Gtkmm2ext { -class LIBGTKMM2EXT_API FastMeter : public Gtk::DrawingArea { +class LIBGTKMM2EXT_API FastMeter : public CairoWidget { public: enum Orientation { Horizontal, @@ -67,7 +66,7 @@ class LIBGTKMM2EXT_API FastMeter : public Gtk::DrawingArea { bool get_highlight () { return highlight; } protected: - bool on_expose_event (GdkEventExpose*); + void render (cairo_t *, cairo_rectangle_t*); void on_size_request (GtkRequisition*); void on_size_allocate (Gtk::Allocation&); private: @@ -96,12 +95,12 @@ private: float current_user_level; bool highlight; - bool vertical_expose (GdkEventExpose*); + void vertical_expose (cairo_t*, cairo_rectangle_t*); void vertical_size_request (GtkRequisition*); void vertical_size_allocate (Gtk::Allocation&); void queue_vertical_redraw (const Glib::RefPtr&, float); - bool horizontal_expose (GdkEventExpose*); + void horizontal_expose (cairo_t*, cairo_rectangle_t*); void horizontal_size_request (GtkRequisition*); void horizontal_size_allocate (Gtk::Allocation&); void queue_horizontal_redraw (const Glib::RefPtr&, float); -- cgit v1.2.3