Towards a consistent render() API.

This fixes an -Woverloaded-virtual ambiguity introduced in b5e613d45

  void render (cairo_t*, cairo_rectagle*)
  void render (Cairo::RefPtr<Cairo::Context> const&, cairo_rectangle_t*)

ArdourCanvas prefers cairomm and CairoWidget itself uses Cairo::Context,
this improves overall API consistency.
This commit is contained in:
Robin Gareus 2017-03-20 17:11:56 +01:00
parent 3294b82e25
commit d06de26a4f
30 changed files with 55 additions and 49 deletions

View file

@ -44,7 +44,6 @@
#define BASELINESTRETCH (1.25) #define BASELINESTRETCH (1.25)
#define TRACKHEADERBTNW (3.10) #define TRACKHEADERBTNW (3.10)
using namespace Gdk;
using namespace Gtk; using namespace Gtk;
using namespace Glib; using namespace Glib;
using namespace PBD; using namespace PBD;
@ -256,8 +255,10 @@ ArdourButton::set_alignment (const float xa, const float ya)
* ARDOUR_UI_UTILS::render_vector_icon() * ARDOUR_UI_UTILS::render_vector_icon()
*/ */
void void
ArdourButton::render (cairo_t* cr, cairo_rectangle_t *) ArdourButton::render (Cairo::RefPtr<Cairo::Context> const& ctx, cairo_rectangle_t*)
{ {
cairo_t* cr = ctx->cobj();
uint32_t text_color; uint32_t text_color;
uint32_t led_color; uint32_t led_color;

View file

@ -127,7 +127,7 @@ class ArdourButton : public CairoWidget , public Gtkmm2ext::Activatable
float char_avg_pixel_width() { if (_char_pixel_width < 1) recalc_char_pixel_geometry() ; return _char_avg_pixel_width; } float char_avg_pixel_width() { if (_char_pixel_width < 1) recalc_char_pixel_geometry() ; return _char_avg_pixel_width; }
protected: protected:
void render (cairo_t *, cairo_rectangle_t *); void render (Cairo::RefPtr<Cairo::Context> const&, cairo_rectangle_t*);
void on_size_request (Gtk::Requisition* req); void on_size_request (Gtk::Requisition* req);
void on_size_allocate (Gtk::Allocation&); void on_size_allocate (Gtk::Allocation&);
void on_style_changed (const Glib::RefPtr<Gtk::Style>&); void on_style_changed (const Glib::RefPtr<Gtk::Style>&);

View file

@ -46,7 +46,6 @@
#include "pbd/i18n.h" #include "pbd/i18n.h"
using namespace Gtkmm2ext; using namespace Gtkmm2ext;
using namespace Gdk;
using namespace Gtk; using namespace Gtk;
using namespace Glib; using namespace Glib;
using namespace PBD; using namespace PBD;
@ -79,8 +78,9 @@ ArdourKnob::~ArdourKnob()
} }
void void
ArdourKnob::render (cairo_t* cr, cairo_rectangle_t *) ArdourKnob::render (Cairo::RefPtr<Cairo::Context> const& ctx, cairo_rectangle_t*)
{ {
cairo_t* cr = ctx->cobj();
cairo_pattern_t* shade_pattern; cairo_pattern_t* shade_pattern;
float width = get_width(); float width = get_width();

View file

@ -91,7 +91,7 @@ public:
void color_handler (); void color_handler ();
protected: protected:
void render (cairo_t *, cairo_rectangle_t *); void render (Cairo::RefPtr<Cairo::Context> const&, cairo_rectangle_t*);
void on_size_request (Gtk::Requisition* req); void on_size_request (Gtk::Requisition* req);
void on_size_allocate (Gtk::Allocation&); void on_size_allocate (Gtk::Allocation&);
void on_style_changed (const Glib::RefPtr<Gtk::Style>&); void on_style_changed (const Glib::RefPtr<Gtk::Style>&);

View file

@ -27,12 +27,12 @@ public:
ArdourVSpacer (float r = 0.75f) : CairoWidget (), ratio (r) {} ArdourVSpacer (float r = 0.75f) : CairoWidget (), ratio (r) {}
protected: protected:
void render (cairo_t* cr, cairo_rectangle_t* r) { void render (Cairo::RefPtr<Cairo::Context> const& ctx, cairo_rectangle_t* r) {
float h = r->height * ratio; float h = r->height * ratio;
float t = .5f * (r->height - h); float t = .5f * (r->height - h);
cairo_rectangle (cr, 0, t, 1, h); ctx->rectangle (0, t, 1, h);
cairo_set_source_rgb (cr, 0, 0, 0); ctx->set_source_rgb (0, 0, 0);
cairo_fill (cr); ctx->fill ();
} }
void on_size_request (Gtk::Requisition* req) { void on_size_request (Gtk::Requisition* req) {

View file

@ -275,8 +275,9 @@ AudioClock::set_scale (double x, double y)
} }
void void
AudioClock::render (cairo_t* cr, cairo_rectangle_t*) AudioClock::render (Cairo::RefPtr<Cairo::Context> const& ctx, cairo_rectangle_t*)
{ {
cairo_t* cr = ctx->cobj();
/* main layout: rounded rect, plus the text */ /* main layout: rounded rect, plus the text */
if (_need_bg) { if (_need_bg) {

View file

@ -102,7 +102,7 @@ class AudioClock : public CairoWidget, public ARDOUR::SessionHandlePtr
static std::vector<AudioClock*> clocks; static std::vector<AudioClock*> clocks;
protected: protected:
void render (cairo_t*, cairo_rectangle_t*); void render (Cairo::RefPtr<Cairo::Context> const&, cairo_rectangle_t*);
bool get_is_duration () const { return is_duration; } ; bool get_is_duration () const { return is_duration; } ;
virtual void build_ops_menu (); virtual void build_ops_menu ();

View file

@ -101,8 +101,9 @@ ButtonJoiner::~ButtonJoiner ()
} }
void void
ButtonJoiner::render (cairo_t* cr, cairo_rectangle_t*) ButtonJoiner::render (Cairo::RefPtr<Cairo::Context> const& ctx, cairo_rectangle_t*)
{ {
cairo_t* cr = ctx->cobj();
double h = get_height(); double h = get_height();
if (!get_active()) { if (!get_active()) {

View file

@ -36,7 +36,7 @@ class ButtonJoiner : public CairoWidget, public Gtkmm2ext::Activatable {
void set_active_state (Gtkmm2ext::ActiveState); void set_active_state (Gtkmm2ext::ActiveState);
protected: protected:
void render (cairo_t*, cairo_rectangle_t*); void render (Cairo::RefPtr<Cairo::Context> const&, cairo_rectangle_t*);
bool on_button_release_event (GdkEventButton*); bool on_button_release_event (GdkEventButton*);
void on_size_request (Gtk::Requisition*); void on_size_request (Gtk::Requisition*);
void on_size_allocate (Gtk::Allocation&); void on_size_allocate (Gtk::Allocation&);

View file

@ -211,8 +211,9 @@ EditorSummary::render_background_image ()
* @param cr Context. * @param cr Context.
*/ */
void void
EditorSummary::render (cairo_t* cr, cairo_rectangle_t*) EditorSummary::render (Cairo::RefPtr<Cairo::Context> const& ctx, cairo_rectangle_t*)
{ {
cairo_t* cr = ctx->cobj();
if (_session == 0) { if (_session == 0) {
return; return;

View file

@ -73,7 +73,7 @@ private:
bool on_leave_notify_event (GdkEventCrossing*); bool on_leave_notify_event (GdkEventCrossing*);
void centre_on_click (GdkEventButton *); void centre_on_click (GdkEventButton *);
void render (cairo_t *, cairo_rectangle_t*); void render (Cairo::RefPtr<Cairo::Context> const&, cairo_rectangle_t*);
void render_region (RegionView*, cairo_t*, double) const; void render_region (RegionView*, cairo_t*, double) const;
void get_editor (std::pair<double, double> *, std::pair<double, double> *) const; void get_editor (std::pair<double, double> *, std::pair<double, double> *) const;
void set_editor (double, double); void set_editor (double, double);

View file

@ -46,12 +46,12 @@ protected:
virtual void overlay (cairo_t* cr, cairo_rectangle_t* r) {} virtual void overlay (cairo_t* cr, cairo_rectangle_t* r) {}
virtual void render (cairo_t* cr, cairo_rectangle_t* r) virtual void render (Cairo::RefPtr<Cairo::Context> const& ctx, cairo_rectangle_t* r)
{ {
cairo_rectangle (cr, r->x, r->y, r->width, r->height); ctx->rectangle (r->x, r->y, r->width, r->height);
cairo_clip (cr); ctx->clip ();
background (cr, r); background (ctx->cobj(), r);
overlay (cr, r); overlay (ctx->cobj(), r);
} }
Cairo::RefPtr<Cairo::ImageSurface> _surface; Cairo::RefPtr<Cairo::ImageSurface> _surface;

View file

@ -241,8 +241,9 @@ GroupTabs::on_button_release_event (GdkEventButton*)
} }
void void
GroupTabs::render (cairo_t* cr, cairo_rectangle_t*) GroupTabs::render (Cairo::RefPtr<Cairo::Context> const& ctx, cairo_rectangle_t*)
{ {
cairo_t* cr = ctx->cobj();
if (_dragging == 0) { if (_dragging == 0) {
_tabs = compute_tabs (); _tabs = compute_tabs ();
} }

View file

@ -115,7 +115,7 @@ private:
void disable_all (); void disable_all ();
void remove_group (ARDOUR::RouteGroup *); void remove_group (ARDOUR::RouteGroup *);
void render (cairo_t *, cairo_rectangle_t*); void render (Cairo::RefPtr<Cairo::Context> const&, cairo_rectangle_t*);
void on_size_request (Gtk::Requisition *); void on_size_request (Gtk::Requisition *);
bool on_button_press_event (GdkEventButton *); bool on_button_press_event (GdkEventButton *);
bool on_motion_notify_event (GdkEventMotion *); bool on_motion_notify_event (GdkEventMotion *);

View file

@ -42,8 +42,9 @@ LED::~LED()
} }
void void
LED::render (cairo_t* cr, cairo_rectangle_t*) LED::render (Cairo::RefPtr<Cairo::Context> const& ctx, cairo_rectangle_t*)
{ {
cairo_t* cr = ctx->cobj();
if (!_fixed_diameter) { if (!_fixed_diameter) {
_diameter = std::min (get_width(), get_height()); _diameter = std::min (get_width(), get_height());
} }

View file

@ -33,7 +33,7 @@ class LED : public CairoWidget
void set_diameter (float); void set_diameter (float);
protected: protected:
void render (cairo_t *, cairo_rectangle_t*); void render (Cairo::RefPtr<Cairo::Context> const&, cairo_rectangle_t*);
void on_size_request (Gtk::Requisition* req); void on_size_request (Gtk::Requisition* req);
void on_realize (); void on_realize ();

View file

@ -405,8 +405,9 @@ struct LocationMarkerSort {
}; };
void void
MiniTimeline::render (cairo_t* cr, cairo_rectangle_t*) MiniTimeline::render (Cairo::RefPtr<Cairo::Context> const& ctx, cairo_rectangle_t*)
{ {
cairo_t* cr = ctx->cobj();
// TODO cache, set_colors() // TODO cache, set_colors()
ArdourCanvas::Color base = UIConfiguration::instance().color ("ruler base"); ArdourCanvas::Color base = UIConfiguration::instance().color ("ruler base");
ArdourCanvas::Color text = UIConfiguration::instance().color ("ruler text"); ArdourCanvas::Color text = UIConfiguration::instance().color ("ruler text");

View file

@ -67,7 +67,7 @@ private:
void draw_dots (cairo_t*, int left, int right, int y, ArdourCanvas::Color); void draw_dots (cairo_t*, int left, int right, int y, ArdourCanvas::Color);
int draw_mark (cairo_t*, int x0, int x1, const std::string&, bool& prelight); int draw_mark (cairo_t*, int x0, int x1, const std::string&, bool& prelight);
void render (cairo_t*, cairo_rectangle_t*); void render (Cairo::RefPtr<Cairo::Context> const&, cairo_rectangle_t*);
void format_time (framepos_t when); void format_time (framepos_t when);
bool on_button_press_event (GdkEventButton*); bool on_button_press_event (GdkEventButton*);

View file

@ -570,8 +570,9 @@ ShuttleControl::set_colors ()
} }
void void
ShuttleControl::render (cairo_t* cr, cairo_rectangle_t*) ShuttleControl::render (Cairo::RefPtr<Cairo::Context> const& ctx, cairo_rectangle_t*)
{ {
cairo_t* cr = ctx->cobj();
// center slider line // center slider line
float yc = get_height() / 2; float yc = get_height() / 2;
float lw = 3; float lw = 3;

View file

@ -93,7 +93,7 @@ protected:
bool on_scroll_event (GdkEventScroll*); bool on_scroll_event (GdkEventScroll*);
bool on_motion_notify_event(GdkEventMotion*); bool on_motion_notify_event(GdkEventMotion*);
void render (cairo_t *, cairo_rectangle_t*); void render (Cairo::RefPtr<Cairo::Context> const&, cairo_rectangle_t*);
void on_size_allocate (Gtk::Allocation&); void on_size_allocate (Gtk::Allocation&);
bool on_query_tooltip (int, int, bool, const Glib::RefPtr<Gtk::Tooltip>&); bool on_query_tooltip (int, int, bool, const Glib::RefPtr<Gtk::Tooltip>&);

View file

@ -104,7 +104,7 @@ Widget::render (Rect const & area, Cairo::RefPtr<Cairo::Context> context) const
//context->rectangle (draw.x0, draw.y0, draw.width(), draw.height()); //context->rectangle (draw.x0, draw.y0, draw.width(), draw.height());
//context->clip (); //context->clip ();
_widget.render (context->cobj(), &crect); _widget.render (context, &crect);
context->restore (); context->restore ();
} }

View file

@ -195,7 +195,7 @@ CairoWidget::on_expose_event (GdkEventExpose *ev)
cr->fill (); cr->fill ();
} }
render (cr->cobj(), &expose_area); render (cr, &expose_area);
#ifdef USE_CAIRO_IMAGE_SURFACE_FOR_CAIRO_WIDGET #ifdef USE_CAIRO_IMAGE_SURFACE_FOR_CAIRO_WIDGET
if(get_visible_window ()) { if(get_visible_window ()) {
@ -283,7 +283,7 @@ CairoWidget::on_expose_event (GdkEventExpose *ev)
expose_area.width = ev->area.width; expose_area.width = ev->area.width;
expose_area.height = ev->area.height; expose_area.height = ev->area.height;
render (cr->cobj(), &expose_area); render (cr, &expose_area);
#ifdef OPTIONAL_CAIRO_IMAGE_SURFACE #ifdef OPTIONAL_CAIRO_IMAGE_SURFACE
if (getenv("ARDOUR_IMAGE_SURFACE")) { if (getenv("ARDOUR_IMAGE_SURFACE")) {

View file

@ -184,8 +184,9 @@ Fader::set_touch_cursor (const Glib::RefPtr<Gdk::Pixbuf>& touch_cursor)
} }
void void
Fader::render (cairo_t* cr, cairo_rectangle_t*) Fader::render (Cairo::RefPtr<Cairo::Context> const& ctx, cairo_rectangle_t*)
{ {
cairo_t* cr = ctx->cobj();
double xscale = 1.0; double xscale = 1.0;
double yscale = 1.0; double yscale = 1.0;

View file

@ -544,12 +544,12 @@ FastMeter::horizontal_size_allocate (Gtk::Allocation &alloc)
} }
void void
FastMeter::render (cairo_t* cr, cairo_rectangle_t* area) FastMeter::render (Cairo::RefPtr<Cairo::Context> const& ctx, cairo_rectangle_t* area)
{ {
if (orientation == Vertical) { if (orientation == Vertical) {
return vertical_expose (cr, area); return vertical_expose (ctx->cobj(), area);
} else { } else {
return horizontal_expose (cr, area); return horizontal_expose (ctx->cobj(), area);
} }
} }

View file

@ -20,6 +20,7 @@
#ifndef __gtk2_ardour_cairo_widget_h__ #ifndef __gtk2_ardour_cairo_widget_h__
#define __gtk2_ardour_cairo_widget_h__ #define __gtk2_ardour_cairo_widget_h__
#include <cairomm/context.h>
#include <cairomm/surface.h> #include <cairomm/surface.h>
#include <gtkmm/eventbox.h> #include <gtkmm/eventbox.h>
@ -81,12 +82,6 @@ public:
static void provide_background_for_cairo_widget (Gtk::Widget& w, const Gdk::Color& bg); static void provide_background_for_cairo_widget (Gtk::Widget& w, const Gdk::Color& bg);
virtual void render (cairo_t *, cairo_rectangle_t*) = 0;
virtual void render (Cairo::RefPtr<Cairo::Context> const & ctx, cairo_rectangle_t* r) {
render (ctx->cobj(), r);
}
uint32_t background_color (); uint32_t background_color ();
static void set_flat_buttons (bool yn); static void set_flat_buttons (bool yn);

View file

@ -62,7 +62,7 @@ class LIBGTKMM2EXT_API Fader : public CairoWidget
void on_size_request (GtkRequisition*); void on_size_request (GtkRequisition*);
void on_size_allocate (Gtk::Allocation& alloc); void on_size_allocate (Gtk::Allocation& alloc);
void render (cairo_t* cr, cairo_rectangle_t*); void render (Cairo::RefPtr<Cairo::Context> const&, cairo_rectangle_t*);
bool on_button_press_event (GdkEventButton*); bool on_button_press_event (GdkEventButton*);
bool on_button_release_event (GdkEventButton*); bool on_button_release_event (GdkEventButton*);
bool on_motion_notify_event (GdkEventMotion*); bool on_motion_notify_event (GdkEventMotion*);

View file

@ -65,9 +65,9 @@ class LIBGTKMM2EXT_API FastMeter : public CairoWidget {
void set_hold_count (long); void set_hold_count (long);
void set_highlight (bool); void set_highlight (bool);
bool get_highlight () { return highlight; } bool get_highlight () { return highlight; }
void render (Cairo::RefPtr<Cairo::Context> const&, cairo_rectangle_t*);
protected: protected:
void render (cairo_t *, cairo_rectangle_t*);
void on_size_request (GtkRequisition*); void on_size_request (GtkRequisition*);
void on_size_allocate (Gtk::Allocation&); void on_size_allocate (Gtk::Allocation&);
private: private:

View file

@ -58,7 +58,7 @@ class LIBGTKMM2EXT_API PixFader : public CairoWidget
void on_size_request (GtkRequisition*); void on_size_request (GtkRequisition*);
void on_size_allocate (Gtk::Allocation& alloc); void on_size_allocate (Gtk::Allocation& alloc);
void render (cairo_t *, cairo_rectangle_t*); void render (Cairo::RefPtr<Cairo::Context> const&, cairo_rectangle_t*);
bool on_grab_broken_event (GdkEventGrabBroken*); bool on_grab_broken_event (GdkEventGrabBroken*);
bool on_button_press_event (GdkEventButton*); bool on_button_press_event (GdkEventButton*);
bool on_button_release_event (GdkEventButton*); bool on_button_release_event (GdkEventButton*);

View file

@ -205,8 +205,10 @@ PixFader::create_patterns ()
} }
void void
PixFader::render (cairo_t *cr, cairo_rectangle_t* area) PixFader::render (Cairo::RefPtr<Cairo::Context> const& ctx, cairo_rectangle_t* area)
{ {
cairo_t* cr = ctx->cobj();
if (!_pattern) { if (!_pattern) {
create_patterns(); create_patterns();
} }

View file

@ -542,12 +542,12 @@ FastMeter::horizontal_size_allocate (Gtk::Allocation &alloc)
} }
void void
FastMeter::render (cairo_t* cr, cairo_rectangle_t* area) FastMeter::render (Cairo::RefPtr<Cairo::Context> const& ctx, cairo_rectangle_t* area)
{ {
if (orientation == Vertical) { if (orientation == Vertical) {
return vertical_expose (cr, area); return vertical_expose (cr->cobj(), area);
} else { } else {
return horizontal_expose (cr, area); return horizontal_expose (cr->cobj(), area);
} }
} }