diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2015-07-25 08:40:40 -0400 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2016-02-22 15:31:23 -0500 |
commit | 5e0337a4a34ba8e37245cf4b7eaece2b93c553a1 (patch) | |
tree | c9adad8f7521a5d4df6f04a690948bc7228824f7 /libs/gtkmm2ext/cairo_icon.cc | |
parent | 0ac1755394e2c90014514d3df32e7897528247fa (diff) |
convert CairoIcon into a NO_WINDOW widget that just draws into its parent widget
Diffstat (limited to 'libs/gtkmm2ext/cairo_icon.cc')
-rw-r--r-- | libs/gtkmm2ext/cairo_icon.cc | 66 |
1 files changed, 64 insertions, 2 deletions
diff --git a/libs/gtkmm2ext/cairo_icon.cc b/libs/gtkmm2ext/cairo_icon.cc index 2011e6968e..24450e3300 100644 --- a/libs/gtkmm2ext/cairo_icon.cc +++ b/libs/gtkmm2ext/cairo_icon.cc @@ -17,6 +17,11 @@ */ +#if !defined USE_CAIRO_IMAGE_SURFACE && !defined NDEBUG +#define OPTIONAL_CAIRO_IMAGE_SURFACE +#endif + + #include "gtkmm2ext/cairo_icon.h" #include "gtkmm2ext/gtk_ui.h" @@ -26,8 +31,7 @@ CairoIcon::CairoIcon (ArdourIcon::Icon t, uint32_t foreground_color) : icon_type (t) , fg (foreground_color) { - set_draw_background (false); - set_widget_prelight (false); + add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK); } CairoIcon::~CairoIcon () @@ -51,3 +55,61 @@ CairoIcon::render (cairo_t* cr , cairo_rectangle_t* area) ArdourIcon::render (cr, icon_type, width, height, Off, fg); } +bool +CairoIcon::on_expose_event (GdkEventExpose *ev) +{ +#ifdef OPTIONAL_CAIRO_IMAGE_SURFACE + Cairo::RefPtr<Cairo::Context> cr; + if (getenv("ARDOUR_IMAGE_SURFACE")) { + if (!image_surface) { + image_surface = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, get_width(), get_height()); + } + cr = Cairo::Context::create (image_surface); + } else { + cr = get_window()->create_cairo_context (); + } +#elif defined USE_CAIRO_IMAGE_SURFACE + + if (!image_surface) { + image_surface = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, get_width(), get_height()); + } + + Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create (image_surface); +#else + Cairo::RefPtr<Cairo::Context> cr = get_window()->create_cairo_context (); +#endif + + cr->rectangle (ev->area.x, ev->area.y, ev->area.width, ev->area.height); + cr->clip (); + + cr->translate (ev->area.x, ev->area.y); + + 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; + + CairoIcon::render (cr->cobj(), &expose_area); + +#ifdef OPTIONAL_CAIRO_IMAGE_SURFACE + if (getenv("ARDOUR_IMAGE_SURFACE")) { +#endif +#if defined USE_CAIRO_IMAGE_SURFACE || defined OPTIONAL_CAIRO_IMAGE_SURFACE + image_surface->flush(); + /* now blit our private surface back to the GDK one */ + + Cairo::RefPtr<Cairo::Context> cairo_context = get_window()->create_cairo_context (); + + cairo_context->rectangle (ev->area.x, ev->area.y, ev->area.width, ev->area.height); + cairo_context->clip (); + cairo_context->set_source (image_surface, 0, 0); + cairo_context->set_operator (Cairo::OPERATOR_SOURCE); + cairo_context->paint (); +#endif +#ifdef OPTIONAL_CAIRO_IMAGE_SURFACE + } +#endif + + return true; +} |