update german translation
[ardour.git] / libs / gtkmm2ext / cairo_icon.cc
index 2011e6968efc20a6d6f1139c7c945c34d9270120..11b37264c2a0d9f9a9627c1afef11559e489ba46 100644 (file)
 
 */
 
+#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;
+}