convert CairoIcon into a NO_WINDOW widget that just draws into its parent widget
This commit is contained in:
parent
0ac1755394
commit
5e0337a4a3
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -20,8 +20,9 @@
|
|||
#ifndef __gtk2_ardour_cairo_icon_h__
|
||||
#define __gtk2_ardour_cairo_icon_h__
|
||||
|
||||
#include <gtkmm/bin.h>
|
||||
|
||||
#include "gtkmm2ext/visibility.h"
|
||||
#include "gtkmm2ext/cairo_widget.h"
|
||||
#include "gtkmm2ext/ardour_icon.h"
|
||||
|
||||
/** A parent class for icons that are rendered using Cairo but need to be
|
||||
|
@ -30,7 +31,7 @@
|
|||
|
||||
namespace Gtkmm2ext {
|
||||
|
||||
class LIBGTKMM2EXT_API CairoIcon : public CairoWidget
|
||||
class LIBGTKMM2EXT_API CairoIcon : public Gtk::Bin
|
||||
{
|
||||
public:
|
||||
CairoIcon (Gtkmm2ext::ArdourIcon::Icon, uint32_t fg = 0x000000ff);
|
||||
|
@ -38,8 +39,11 @@ public:
|
|||
|
||||
void render (cairo_t *, cairo_rectangle_t*);
|
||||
void set_fg (uint32_t fg);
|
||||
|
||||
bool on_expose_event (GdkEventExpose*);
|
||||
|
||||
private:
|
||||
Cairo::RefPtr<Cairo::Surface> image_surface;
|
||||
ArdourIcon::Icon icon_type;
|
||||
uint32_t fg;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user