From 5da78ac0c5a33f66b7314b57eade828e9c2dc538 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Tue, 30 Jun 2015 02:33:18 +0200 Subject: [PATCH] inspector: Add a description vfunc for render operations --- gtk/inspector/gtkrenderoperation.c | 15 +++++++++++++++ gtk/inspector/gtkrenderoperation.h | 2 ++ gtk/inspector/gtkrenderoperationcairo.c | 7 +++++++ gtk/inspector/gtkrenderoperationwidget.c | 10 ++++++++++ gtk/inspector/gtkrenderoperationwidget.h | 1 + gtk/inspector/snapshot.c | 6 ++++-- 6 files changed, 39 insertions(+), 2 deletions(-) diff --git a/gtk/inspector/gtkrenderoperation.c b/gtk/inspector/gtkrenderoperation.c index 5e0520d942..e2950c7270 100644 --- a/gtk/inspector/gtkrenderoperation.c +++ b/gtk/inspector/gtkrenderoperation.c @@ -37,6 +37,12 @@ gtk_render_operation_real_get_matrix (GtkRenderOperation *operation, cairo_matrix_init_identity (matrix); } +static char * +gtk_render_operation_real_describe (GtkRenderOperation *operation) +{ + return g_strdup (G_OBJECT_TYPE_NAME (operation)); +} + static void gtk_render_operation_real_draw (GtkRenderOperation *operation, cairo_t *cr) @@ -48,6 +54,7 @@ gtk_render_operation_class_init (GtkRenderOperationClass *klass) { klass->get_clip = gtk_render_operation_real_get_clip; klass->get_matrix = gtk_render_operation_real_get_matrix; + klass->describe = gtk_render_operation_real_describe; klass->draw = gtk_render_operation_real_draw; } @@ -76,6 +83,14 @@ gtk_render_operation_get_matrix (GtkRenderOperation *operation, GTK_RENDER_OPERATION_GET_CLASS (operation)->get_matrix (operation, matrix); } +char * +gtk_render_operation_describe (GtkRenderOperation *operation) +{ + g_return_val_if_fail (GTK_IS_RENDER_OPERATION (operation), NULL); + + return GTK_RENDER_OPERATION_GET_CLASS (operation)->describe (operation); +} + void gtk_render_operation_draw (GtkRenderOperation *operation, cairo_t *cr) diff --git a/gtk/inspector/gtkrenderoperation.h b/gtk/inspector/gtkrenderoperation.h index e12f0d2f90..9597a8e7d4 100644 --- a/gtk/inspector/gtkrenderoperation.h +++ b/gtk/inspector/gtkrenderoperation.h @@ -50,6 +50,7 @@ struct _GtkRenderOperationClass void (* get_matrix) (GtkRenderOperation *operation, cairo_matrix_t *matrix); + char * (* describe) (GtkRenderOperation *operation); void (* draw) (GtkRenderOperation *operation, cairo_t *cr); }; @@ -61,6 +62,7 @@ void gtk_render_operation_get_clip (GtkRenderOperation void gtk_render_operation_get_matrix (GtkRenderOperation *operation, cairo_matrix_t *matrix); +char * gtk_render_operation_describe (GtkRenderOperation *operation); void gtk_render_operation_draw (GtkRenderOperation *operation, cairo_t *cr); diff --git a/gtk/inspector/gtkrenderoperationcairo.c b/gtk/inspector/gtkrenderoperationcairo.c index ce9e30fcad..1116bbd576 100644 --- a/gtk/inspector/gtkrenderoperationcairo.c +++ b/gtk/inspector/gtkrenderoperationcairo.c @@ -45,6 +45,12 @@ gtk_render_operation_cairo_get_clip (GtkRenderOperation *operation, clip->height = ceil (extents.y + extents.height) - clip->y; } +static char * +gtk_render_operation_cairo_describe (GtkRenderOperation *operation) +{ + return g_strdup ("custom rendering"); +} + static void gtk_render_operation_cairo_draw (GtkRenderOperation *operation, cairo_t *cr) @@ -74,6 +80,7 @@ gtk_render_operation_cairo_class_init (GtkRenderOperationCairoClass *klass) object_class->finalize = gtk_render_operation_cairo_finalize; operation_class->get_clip = gtk_render_operation_cairo_get_clip; + operation_class->describe = gtk_render_operation_cairo_describe; operation_class->draw = gtk_render_operation_cairo_draw; } diff --git a/gtk/inspector/gtkrenderoperationwidget.c b/gtk/inspector/gtkrenderoperationwidget.c index c1d151b4b5..9a7c73e21b 100644 --- a/gtk/inspector/gtkrenderoperationwidget.c +++ b/gtk/inspector/gtkrenderoperationwidget.c @@ -41,6 +41,14 @@ gtk_render_operation_widget_get_matrix (GtkRenderOperation *operation, *matrix = oper->matrix; } +static char * +gtk_render_operation_widget_describe (GtkRenderOperation *operation) +{ + GtkRenderOperationWidget *oper = GTK_RENDER_OPERATION_WIDGET (operation); + + return g_strdup (g_type_name (oper->widget_type)); +} + static void gtk_render_operation_widget_draw (GtkRenderOperation *operation, cairo_t *cr) @@ -81,6 +89,7 @@ gtk_render_operation_widget_class_init (GtkRenderOperationWidgetClass *klass) operation_class->get_clip = gtk_render_operation_widget_get_clip; operation_class->get_matrix = gtk_render_operation_widget_get_matrix; + operation_class->describe = gtk_render_operation_widget_describe; operation_class->draw = gtk_render_operation_widget_draw; } @@ -100,6 +109,7 @@ gtk_render_operation_widget_new (GtkWidget *widget, result = g_object_new (GTK_TYPE_RENDER_OPERATION_WIDGET, NULL); + result->widget_type = G_OBJECT_TYPE (widget); gtk_widget_get_allocation (widget, &result->widget_allocation); gtk_widget_get_clip (widget, &result->widget_clip); result->widget_clip.x -= result->widget_allocation.x; diff --git a/gtk/inspector/gtkrenderoperationwidget.h b/gtk/inspector/gtkrenderoperationwidget.h index 652840d153..cdd0c900cf 100644 --- a/gtk/inspector/gtkrenderoperationwidget.h +++ b/gtk/inspector/gtkrenderoperationwidget.h @@ -40,6 +40,7 @@ struct _GtkRenderOperationWidget { GtkRenderOperation parent; + GType widget_type; GtkAllocation widget_allocation; GtkAllocation widget_clip; cairo_matrix_t matrix; diff --git a/gtk/inspector/snapshot.c b/gtk/inspector/snapshot.c index 4c9ee59e3f..1892270881 100644 --- a/gtk/inspector/snapshot.c +++ b/gtk/inspector/snapshot.c @@ -161,13 +161,15 @@ gtk_inspector_snapshot_fill_listbox (GtkInspectorSnapshot *snapshot, guint depth) { GtkWidget *label, *row; - char *text; + char *text, *description; - text = g_strdup_printf ("%*s %s", 2 * depth, "", G_OBJECT_TYPE_NAME (oper)); + description = gtk_render_operation_describe (oper); + text = g_strdup_printf ("%*s %s", 2 * depth, "", description); label = gtk_label_new (text); gtk_label_set_xalign (GTK_LABEL (label), 0.0); gtk_widget_show (label); g_free (text); + g_free (description); row = gtk_list_box_row_new (); gtk_container_add (GTK_CONTAINER (row), label);