[gegl-gtk] GeglGtkView: Add signals for drawing background and overlay
- From: Jon Nordby <jonnor src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl-gtk] GeglGtkView: Add signals for drawing background and overlay
- Date: Mon, 10 Oct 2011 17:58:41 +0000 (UTC)
commit 968ff0ff91073704c1fd3ac6a60fd6719a420a09
Author: Jon Nordby <jononor gmail com>
Date: Mon Oct 10 01:36:38 2011 +0200
GeglGtkView: Add signals for drawing background and overlay
configure.ac | 18 +++++++++
examples/c/gegl-gtk-paint.c | 29 +++++++++++++++
gegl-gtk/.gitignore | 1 +
gegl-gtk/Makefile.am | 10 ++++-
gegl-gtk/gegl-gtk-marshal.list | 1 +
gegl-gtk/gegl-gtk-view.c | 77 ++++++++++++++++++++++++++++++++++++----
6 files changed, 127 insertions(+), 9 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index ab33828..4709ca8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -218,6 +218,23 @@ AM_CONDITIONAL(HAVE_GTK3, test "$have_gtk" = "3.0")
AC_SUBST(GTK_CFLAGS)
AC_SUBST(GTK_LIBS)
+##################
+# Cairo gobject
+###################
+AC_ARG_WITH(cairo-gobject, [ --without-cairo-gobject build without Cairo GObject support])
+
+have_cairo_gobject="no"
+if test "x$with_cairo_gobject" != "xno"; then
+ PKG_CHECK_MODULES(CAIRO_GOBJECT, cairo-gobject,
+ [have_cairo_gobject="yes" AC_DEFINE(HAVE_CAIRO_GOBJECT, 1, [Define to 1 to compile for gtk2])],
+ have_cairo_gobject="no (Cairo GObject not found)")
+fi
+
+AM_CONDITIONAL(HAVE_CAIRO_GOBJECT, test "$have_cairo_gobject" = "yes")
+
+AC_SUBST(CAIRO_GOBJECT_CFLAGS)
+AC_SUBST(CAIRO_GOBJECT_LIBS)
+
########################
# Check GObject Introspection
########################
@@ -319,6 +336,7 @@ Building GEGL with prefix=$prefix
GTK+ version: $have_gtk
Documentation: $enable_gtk_doc
+ Cairo GObject: $have_cairo_gobject
GObject Introspection: $enable_introspection
Vala support: $have_vala
]);
diff --git a/examples/c/gegl-gtk-paint.c b/examples/c/gegl-gtk-paint.c
index 9dcde2a..48a5545 100644
--- a/examples/c/gegl-gtk-paint.c
+++ b/examples/c/gegl-gtk-paint.c
@@ -152,6 +152,29 @@ static gboolean paint_release (GtkWidget *widget,
return FALSE;
}
+static void
+draw_overlay (GeglGtkView *view, cairo_t *cr, GdkRectangle *rect)
+{
+ cairo_translate (cr, 200.0, 200.0);
+
+ cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 0.3);
+ cairo_rectangle (cr, 0.0, 0.0, 200.0, 50.0);
+ cairo_fill (cr);
+
+ cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 0.9);
+ cairo_translate (cr, 20.0, 20.0);
+ cairo_show_text (cr, "canvas overlay");
+ cairo_fill (cr);
+}
+
+static void
+draw_background (GeglGtkView *view, cairo_t *cr, GdkRectangle *rect)
+{
+ cairo_set_source_rgba (cr, 0.9, 0.9, 1.0, 1.0);
+ cairo_rectangle (cr, 0.0, 0.0, rect->width, rect->height);
+ cairo_fill (cr);
+}
+
gint
main (gint argc,
gchar **argv)
@@ -198,6 +221,12 @@ main (gint argc,
top = loadbuf;
}
+
+ g_signal_connect (G_OBJECT (view), "draw-overlay",
+ (GCallback) draw_overlay, NULL);
+ g_signal_connect (G_OBJECT (view), "draw-background",
+ (GCallback) draw_background, NULL);
+
eventbox = gtk_event_box_new ();
g_signal_connect (G_OBJECT (eventbox), "motion-notify-event",
diff --git a/gegl-gtk/.gitignore b/gegl-gtk/.gitignore
index ce962ec..95b99f3 100644
--- a/gegl-gtk/.gitignore
+++ b/gegl-gtk/.gitignore
@@ -2,3 +2,4 @@
*.typelib
*.vapi
gegl-gtk-enums.c
+gegl-gtk-marshal.*
diff --git a/gegl-gtk/Makefile.am b/gegl-gtk/Makefile.am
index c5feda7..82f2800 100644
--- a/gegl-gtk/Makefile.am
+++ b/gegl-gtk/Makefile.am
@@ -1,6 +1,6 @@
CLEANFILES =
-gen_sources = gegl-gtk-enums.c
+gen_sources = gegl-gtk-enums.c gegl-gtk-marshal.c gegl-gtk-marshal.h
CLEANFILES += $(gen_sources)
headers = gegl-gtk.h gegl-gtk-view.h gegl-gtk-enums.h
@@ -19,12 +19,18 @@ gegl-gtk-enums.c: $(srcdir)/gegl-gtk-enums.h
--vtail " { 0, NULL, NULL }\n };\n etype = g_ type@_register_static (\"@EnumName \", values);\n }\n return etype;\n}\n\n" \
$(srcdir)/gegl-gtk-enums.h > gegl-gtk-enums.c
+gegl-gtk-marshal.h: $(srcdir)/gegl-gtk-marshal.list
+ glib-genmarshal --prefix=gegl_gtk_marshal $(srcdir)/gegl-gtk-marshal.list --header >> gegl-gtk-marshal.h
+
+gegl-gtk-marshal.c: gegl-gtk-marshal.h
+ echo "#include \"gegl-gtk-marshal.h\"" >> gegl-gtk-marshal.c \
+ && glib-genmarshal --prefix=gegl_gtk_marshal $(srcdir)/gegl-gtk-marshal.list --body >> gegl-gtk-marshal.c
gegl_gtk_includedir=$(includedir)/gegl-gtk$(GEGL_GTK_GTK_VERSION)-$(GEGL_GTK_API_VERSION)
gegl_gtk_include_HEADERS = $(headers)
gegl_gtk_SOURCES = $(headers) $(sources) $(internal_headers) $(internal_sources)
-gegl_gtk_LIBADD = $(GTK_LIBS) $(GEGL_LIBS)
+gegl_gtk_LIBADD = $(GTK_LIBS) $(GEGL_LIBS) $(CAIRO_GOBJECT_LIBS)
gegl_gtk_CFLAGS = $(INCLUDES) $(CFLAGS)
if HAVE_GTK2
diff --git a/gegl-gtk/gegl-gtk-marshal.list b/gegl-gtk/gegl-gtk-marshal.list
new file mode 100644
index 0000000..73ccad0
--- /dev/null
+++ b/gegl-gtk/gegl-gtk-marshal.list
@@ -0,0 +1 @@
+VOID:BOXED,BOXED
diff --git a/gegl-gtk/gegl-gtk-view.c b/gegl-gtk/gegl-gtk-view.c
index cda52de..f0c3790 100644
--- a/gegl-gtk/gegl-gtk-view.c
+++ b/gegl-gtk/gegl-gtk-view.c
@@ -22,9 +22,13 @@
#include <gtk/gtk.h>
#include <gegl.h>
+#ifdef HAVE_CAIRO_GOBJECT
+#include <cairo-gobject.h>
+#endif
+
#include "gegl-gtk-view.h"
#include "internal/view-helper.h"
-
+#include "gegl-gtk-marshal.h"
/**
* This class is responsible for providing the public interface
@@ -50,6 +54,16 @@ enum
PROP_AUTOSCALE_POLICY
};
+#ifdef HAVE_CAIRO_GOBJECT
+enum
+{
+ SIGNAL_DRAW_BACKGROUND,
+ SIGNAL_DRAW_OVERLAY,
+ N_SIGNALS
+};
+
+static guint gegl_view_signals[N_SIGNALS];
+#endif
static ViewHelper *
get_private(GeglGtkView *self)
@@ -149,6 +163,28 @@ gegl_gtk_view_class_init (GeglGtkViewClass * klass)
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
+#ifdef HAVE_CAIRO_GOBJECT
+ gegl_view_signals[SIGNAL_DRAW_BACKGROUND] =
+ g_signal_new ("draw-background",
+ G_TYPE_FROM_CLASS (klass),
+ 0,
+ 0,
+ NULL,
+ NULL,
+ gegl_gtk_marshal_VOID__BOXED_BOXED,
+ G_TYPE_NONE, 2, CAIRO_GOBJECT_TYPE_CONTEXT, GDK_TYPE_RECTANGLE);
+
+ gegl_view_signals[SIGNAL_DRAW_OVERLAY] =
+ g_signal_new ("draw-overlay",
+ G_TYPE_FROM_CLASS (klass),
+ 0,
+ 0,
+ NULL,
+ NULL,
+ gegl_gtk_marshal_VOID__BOXED_BOXED,
+ G_TYPE_NONE, 2, CAIRO_GOBJECT_TYPE_CONTEXT, GDK_TYPE_RECTANGLE);
+#endif
+
}
static void
@@ -274,11 +310,38 @@ size_allocate(GtkWidget *widget, GdkRectangle *allocation, gpointer user_data)
view_helper_set_allocation(GET_PRIVATE(self), allocation);
}
+static void
+draw_implementation(GeglGtkView *self, cairo_t *cr, GdkRectangle *rect)
+{
+ ViewHelper *priv = GET_PRIVATE (self);
+
+#ifdef HAVE_CAIRO_GOBJECT
+ /* Draw background */
+ cairo_save(cr);
+ g_signal_emit(G_OBJECT(self), gegl_view_signals[SIGNAL_DRAW_BACKGROUND],
+ 0, cr, rect, NULL);
+ cairo_restore(cr);
+#endif
+
+ /* Draw the gegl node */
+ cairo_save(cr);
+ view_helper_draw(priv, cr, rect);
+ cairo_restore(cr);
+
+#ifdef HAVE_CAIRO_GOBJECT
+ /* Draw overlay */
+ cairo_save(cr);
+ g_signal_emit(G_OBJECT(self), gegl_view_signals[SIGNAL_DRAW_OVERLAY],
+ 0, cr, rect, NULL);
+ cairo_restore(cr);
+#endif
+}
+
#ifdef HAVE_GTK3
static gboolean
draw (GtkWidget * widget, cairo_t *cr)
{
- GeglGtkView *view = GEGL_GTK_VIEW (widget);
+ GeglGtkView *self = GEGL_GTK_VIEW (widget);
ViewHelper *priv = GET_PRIVATE (view);
GdkRectangle rect;
@@ -286,8 +349,8 @@ draw (GtkWidget * widget, cairo_t *cr)
return FALSE;
gdk_cairo_get_clip_rectangle (cr, &rect);
-
- view_helper_draw (priv, cr, &rect);
+
+ draw_implementation(self, cr, &rect);
return FALSE;
}
@@ -298,8 +361,8 @@ static gboolean
expose_event (GtkWidget *widget,
GdkEventExpose *event)
{
- GeglGtkView *view = GEGL_GTK_VIEW (widget);
- ViewHelper *priv = GET_PRIVATE (view);
+ GeglGtkView *self = GEGL_GTK_VIEW (widget);
+ ViewHelper *priv = GET_PRIVATE (self);
cairo_t *cr;
GdkRectangle rect;
@@ -311,7 +374,7 @@ expose_event (GtkWidget *widget,
cairo_clip (cr);
gdk_region_get_clipbox (event->region, &rect);
- view_helper_draw (priv, cr, &rect);
+ draw_implementation(self, cr, &rect);
cairo_destroy (cr);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]