[gtk+/rendering-cleanup-next: 140/154] gtk-demo: Port offscreen example to draw vfunc
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/rendering-cleanup-next: 140/154] gtk-demo: Port offscreen example to draw vfunc
- Date: Tue, 14 Sep 2010 15:58:26 +0000 (UTC)
commit fdd2eac39792f83cc07724e59dcf081fdb022a49
Author: Benjamin Otte <otte redhat com>
Date: Fri Sep 10 23:41:13 2010 +0200
gtk-demo: Port offscreen example to draw vfunc
demos/gtk-demo/offscreen_window2.c | 105 +++++++++++++++--------------------
1 files changed, 45 insertions(+), 60 deletions(-)
---
diff --git a/demos/gtk-demo/offscreen_window2.c b/demos/gtk-demo/offscreen_window2.c
index 04edae2..a6ad8dd 100644
--- a/demos/gtk-demo/offscreen_window2.c
+++ b/demos/gtk-demo/offscreen_window2.c
@@ -41,8 +41,8 @@ static void gtk_mirror_bin_size_allocate (GtkWidget *widget,
GtkAllocation *allocation);
static gboolean gtk_mirror_bin_damage (GtkWidget *widget,
GdkEventExpose *event);
-static gboolean gtk_mirror_bin_expose (GtkWidget *widget,
- GdkEventExpose *offscreen);
+static gboolean gtk_mirror_bin_draw (GtkWidget *widget,
+ cairo_t *cr);
static void gtk_mirror_bin_add (GtkContainer *container,
GtkWidget *child);
@@ -88,7 +88,7 @@ gtk_mirror_bin_class_init (GtkMirrorBinClass *klass)
widget_class->unrealize = gtk_mirror_bin_unrealize;
widget_class->size_request = gtk_mirror_bin_size_request;
widget_class->size_allocate = gtk_mirror_bin_size_allocate;
- widget_class->expose_event = gtk_mirror_bin_expose;
+ widget_class->draw = gtk_mirror_bin_draw;
g_signal_override_class_closure (g_signal_lookup ("damage-event", GTK_TYPE_WIDGET),
GTK_TYPE_MIRROR_BIN,
@@ -375,78 +375,63 @@ gtk_mirror_bin_damage (GtkWidget *widget,
}
static gboolean
-gtk_mirror_bin_expose (GtkWidget *widget,
- GdkEventExpose *event)
+gtk_mirror_bin_draw (GtkWidget *widget,
+ cairo_t *cr)
{
GtkMirrorBin *bin = GTK_MIRROR_BIN (widget);
GdkWindow *window;
gint width, height;
- if (gtk_widget_is_drawable (widget))
+ window = gtk_widget_get_window (widget);
+ if (gtk_cairo_should_draw_window (cr, window))
{
- window = gtk_widget_get_window (widget);
- if (event->window == window)
- {
- cairo_surface_t *surface;
- cairo_t *cr;
- cairo_matrix_t matrix;
- cairo_pattern_t *mask;
-
- if (bin->child && gtk_widget_get_visible (bin->child))
- {
- surface = gdk_offscreen_window_get_surface (bin->offscreen_window);
- gdk_drawable_get_size (bin->offscreen_window, &width, &height);
+ cairo_surface_t *surface;
+ cairo_matrix_t matrix;
+ cairo_pattern_t *mask;
- cr = gdk_cairo_create (window);
-
- cairo_save (cr);
-
- cairo_rectangle (cr, 0, 0, width, height);
- cairo_clip (cr);
+ if (bin->child && gtk_widget_get_visible (bin->child))
+ {
+ surface = gdk_offscreen_window_get_surface (bin->offscreen_window);
+ gdk_drawable_get_size (bin->offscreen_window, &width, &height);
- /* paint the offscreen child */
- cairo_set_source_surface (cr, surface, 0, 0);
- cairo_paint (cr);
+ /* paint the offscreen child */
+ cairo_set_source_surface (cr, surface, 0, 0);
+ cairo_paint (cr);
- cairo_restore (cr);
+ cairo_matrix_init (&matrix, 1.0, 0.0, 0.3, 1.0, 0.0, 0.0);
+ cairo_matrix_scale (&matrix, 1.0, -1.0);
+ cairo_matrix_translate (&matrix, -10, - 3 * height - 10);
+ cairo_transform (cr, &matrix);
- cairo_matrix_init (&matrix, 1.0, 0.0, 0.3, 1.0, 0.0, 0.0);
- cairo_matrix_scale (&matrix, 1.0, -1.0);
- cairo_matrix_translate (&matrix, -10, - 3 * height - 10);
- cairo_transform (cr, &matrix);
+ cairo_set_source_surface (cr, surface, 0, height);
- cairo_rectangle (cr, 0, height, width, height);
- cairo_clip (cr);
+ /* create linear gradient as mask-pattern to fade out the source */
+ mask = cairo_pattern_create_linear (0.0, height, 0.0, 2*height);
+ cairo_pattern_add_color_stop_rgba (mask, 0.0, 0.0, 0.0, 0.0, 0.0);
+ cairo_pattern_add_color_stop_rgba (mask, 0.25, 0.0, 0.0, 0.0, 0.01);
+ cairo_pattern_add_color_stop_rgba (mask, 0.5, 0.0, 0.0, 0.0, 0.25);
+ cairo_pattern_add_color_stop_rgba (mask, 0.75, 0.0, 0.0, 0.0, 0.5);
+ cairo_pattern_add_color_stop_rgba (mask, 1.0, 0.0, 0.0, 0.0, 1.0);
- cairo_set_source_surface (cr, surface, 0, height);
+ /* paint the reflection */
+ cairo_mask (cr, mask);
- /* create linear gradient as mask-pattern to fade out the source */
- mask = cairo_pattern_create_linear (0.0, height, 0.0, 2*height);
- cairo_pattern_add_color_stop_rgba (mask, 0.0, 0.0, 0.0, 0.0, 0.0);
- cairo_pattern_add_color_stop_rgba (mask, 0.25, 0.0, 0.0, 0.0, 0.01);
- cairo_pattern_add_color_stop_rgba (mask, 0.5, 0.0, 0.0, 0.0, 0.25);
- cairo_pattern_add_color_stop_rgba (mask, 0.75, 0.0, 0.0, 0.0, 0.5);
- cairo_pattern_add_color_stop_rgba (mask, 1.0, 0.0, 0.0, 0.0, 1.0);
+ cairo_pattern_destroy (mask);
+ }
+ }
+ else if (gtk_cairo_should_draw_window (cr, bin->offscreen_window))
+ {
+ gdk_drawable_get_size (bin->offscreen_window, &width, &height);
- /* paint the reflection */
- cairo_mask (cr, mask);
+ gtk_cairo_paint_flat_box (gtk_widget_get_style (widget), cr,
+ GTK_STATE_NORMAL, GTK_SHADOW_NONE,
+ widget, "blah",
+ 0, 0, width, height);
- cairo_pattern_destroy (mask);
- cairo_destroy (cr);
- }
- }
- else if (event->window == bin->offscreen_window)
- {
- gtk_paint_flat_box (gtk_widget_get_style (widget), event->window,
- GTK_STATE_NORMAL, GTK_SHADOW_NONE,
- &event->area, widget, "blah",
- 0, 0, -1, -1);
-
- if (bin->child)
- gtk_container_propagate_expose (GTK_CONTAINER (widget),
- bin->child,
- event);
- }
+ if (bin->child)
+ gtk_container_propagate_draw (GTK_CONTAINER (widget),
+ bin->child,
+ cr);
}
return FALSE;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]