2 Copyright (C) 2015 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #if !defined USE_CAIRO_IMAGE_SURFACE && !defined NDEBUG
21 #define OPTIONAL_CAIRO_IMAGE_SURFACE
25 #include "gtkmm2ext/cairo_icon.h"
26 #include "gtkmm2ext/gtk_ui.h"
28 using namespace Gtkmm2ext;
30 CairoIcon::CairoIcon (ArdourIcon::Icon t, uint32_t foreground_color)
32 , fg (foreground_color)
34 add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
37 CairoIcon::~CairoIcon ()
42 CairoIcon::set_fg (uint32_t color)
49 CairoIcon::render (cairo_t* cr , cairo_rectangle_t* area)
51 int width = get_width();
52 int height = get_height ();
54 ArdourIcon::render (cr, icon_type, width, height, Off, fg);
58 CairoIcon::on_expose_event (GdkEventExpose *ev)
60 #ifdef OPTIONAL_CAIRO_IMAGE_SURFACE
61 Cairo::RefPtr<Cairo::Context> cr;
62 if (getenv("ARDOUR_IMAGE_SURFACE")) {
64 image_surface = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, get_width(), get_height());
66 cr = Cairo::Context::create (image_surface);
68 cr = get_window()->create_cairo_context ();
70 #elif defined USE_CAIRO_IMAGE_SURFACE
73 image_surface = Cairo::ImageSurface::create (Cairo::FORMAT_ARGB32, get_width(), get_height());
76 Cairo::RefPtr<Cairo::Context> cr = Cairo::Context::create (image_surface);
78 Cairo::RefPtr<Cairo::Context> cr = get_window()->create_cairo_context ();
81 cr->rectangle (ev->area.x, ev->area.y, ev->area.width, ev->area.height);
84 cr->translate (ev->area.x, ev->area.y);
86 cairo_rectangle_t expose_area;
87 expose_area.x = ev->area.x;
88 expose_area.y = ev->area.y;
89 expose_area.width = ev->area.width;
90 expose_area.height = ev->area.height;
92 CairoIcon::render (cr->cobj(), &expose_area);
94 #ifdef OPTIONAL_CAIRO_IMAGE_SURFACE
95 if (getenv("ARDOUR_IMAGE_SURFACE")) {
97 #if defined USE_CAIRO_IMAGE_SURFACE || defined OPTIONAL_CAIRO_IMAGE_SURFACE
98 image_surface->flush();
99 /* now blit our private surface back to the GDK one */
101 Cairo::RefPtr<Cairo::Context> cairo_context = get_window()->create_cairo_context ();
103 cairo_context->rectangle (ev->area.x, ev->area.y, ev->area.width, ev->area.height);
104 cairo_context->clip ();
105 cairo_context->set_source (image_surface, 0, 0);
106 cairo_context->set_operator (Cairo::OPERATOR_SOURCE);
107 cairo_context->paint ();
109 #ifdef OPTIONAL_CAIRO_IMAGE_SURFACE