[gtk+/wip/renderops: 7/9] inspector: Handle outline rendering in snapshots



commit 2f90e1a7d99650a3226c6d7b0e7df085f7543635
Author: Benjamin Otte <otte redhat com>
Date:   Wed Jul 1 06:07:02 2015 +0200

    inspector: Handle outline rendering in snapshots

 gtk/inspector/Makefile.inc                |    2 +
 gtk/inspector/gtkrenderoperationoutline.c |  126 +++++++++++++++++++++++++++++
 gtk/inspector/gtkrenderoperationoutline.h |   65 +++++++++++++++
 gtk/inspector/recordingrenderops.c        |   21 +++++
 4 files changed, 214 insertions(+), 0 deletions(-)
---
diff --git a/gtk/inspector/Makefile.inc b/gtk/inspector/Makefile.inc
index 9407306..275fe5b 100644
--- a/gtk/inspector/Makefile.inc
+++ b/gtk/inspector/Makefile.inc
@@ -13,6 +13,7 @@ inspector_c_sources =                         \
         inspector/gtkrenderoperationbackground.c        \
         inspector/gtkrenderoperationborder.c            \
         inspector/gtkrenderoperationcairo.c             \
+        inspector/gtkrenderoperationoutline.c           \
         inspector/gtkrenderoperationwidget.c            \
        inspector/gtktreemodelcssnode.c \
        inspector/init.c                \
@@ -51,6 +52,7 @@ inspector_h_sources =                         \
         inspector/gtkrenderoperationbackground.h        \
         inspector/gtkrenderoperationborder.h            \
         inspector/gtkrenderoperationcairo.h             \
+        inspector/gtkrenderoperationoutline.h           \
         inspector/gtkrenderoperationwidget.h            \
        inspector/gtktreemodelcssnode.h \
        inspector/init.h                \
diff --git a/gtk/inspector/gtkrenderoperationoutline.c b/gtk/inspector/gtkrenderoperationoutline.c
new file mode 100644
index 0000000..ec92cbd
--- /dev/null
+++ b/gtk/inspector/gtkrenderoperationoutline.c
@@ -0,0 +1,126 @@
+/*
+ * Copyright © 2015 Benjamin Otte <otte gnome org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Benjamin Otte <otte gnome org>
+ */
+
+#include "config.h"
+
+#include "gtkrenderoperationoutline.h"
+
+#include <math.h>
+
+#include "gtkcssstyleprivate.h"
+#include "gtkcssnumbervalueprivate.h"
+#include "gtkrenderborderprivate.h"
+
+G_DEFINE_TYPE (GtkRenderOperationOutline, gtk_render_operation_outline, GTK_TYPE_RENDER_OPERATION)
+
+static void
+gtk_render_operation_outline_get_clip (GtkRenderOperation    *operation,
+                                       cairo_rectangle_int_t *clip)
+{
+  GtkRenderOperationOutline *oper = GTK_RENDER_OPERATION_OUTLINE (operation);
+  double offset, border_width;
+
+  border_width = _gtk_css_number_value_get (gtk_css_style_get_value (oper->style, 
GTK_CSS_PROPERTY_OUTLINE_WIDTH), 100);
+  offset = _gtk_css_number_value_get (gtk_css_style_get_value (oper->style, 
GTK_CSS_PROPERTY_OUTLINE_OFFSET), 100);
+  
+  clip->x = floor (- border_width - offset);
+  clip->y = floor (- border_width - offset);
+  clip->width = ceil (oper->width + border_width + offset) - clip->x;
+  clip->height = ceil (oper->height + border_width + offset) - clip->y;
+}
+
+static void
+gtk_render_operation_outline_get_matrix (GtkRenderOperation *operation,
+                                         cairo_matrix_t     *matrix)
+{
+  GtkRenderOperationOutline *oper = GTK_RENDER_OPERATION_OUTLINE (operation);
+
+  cairo_matrix_init_translate (matrix, oper->x, oper->y);
+}
+
+static char *
+gtk_render_operation_outline_describe (GtkRenderOperation *operation)
+{
+  return g_strdup ("CSS outline");
+}
+
+static void
+gtk_render_operation_outline_draw (GtkRenderOperation *operation,
+                                   cairo_t            *cr)
+{
+  GtkRenderOperationOutline *oper = GTK_RENDER_OPERATION_OUTLINE (operation);
+
+  gtk_css_style_render_outline (oper->style,
+                                cr,
+                                0, 0, 
+                                oper->width,
+                                oper->height);
+}
+
+static void
+gtk_render_operation_outline_finalize (GObject *object)
+{
+  GtkRenderOperationOutline *oper = GTK_RENDER_OPERATION_OUTLINE (object);
+
+  g_object_unref (oper->style);
+
+  G_OBJECT_CLASS (gtk_render_operation_outline_parent_class)->finalize (object);
+}
+
+static void
+gtk_render_operation_outline_class_init (GtkRenderOperationOutlineClass *klass)
+{
+  GtkRenderOperationClass *operation_class = GTK_RENDER_OPERATION_CLASS (klass);
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+  object_class->finalize = gtk_render_operation_outline_finalize;
+
+  operation_class->get_clip = gtk_render_operation_outline_get_clip;
+  operation_class->get_matrix = gtk_render_operation_outline_get_matrix;
+  operation_class->describe = gtk_render_operation_outline_describe;
+  operation_class->draw = gtk_render_operation_outline_draw;
+}
+
+static void
+gtk_render_operation_outline_init (GtkRenderOperationOutline *image)
+{
+}
+
+GtkRenderOperation *
+gtk_render_operation_outline_new (GtkCssStyle      *style,
+                                  double            x,
+                                  double            y,
+                                  double            width,
+                                  double            height)
+{
+  GtkRenderOperationOutline *result;
+
+  g_return_val_if_fail (GTK_IS_CSS_STYLE (style), NULL);
+
+  result = g_object_new (GTK_TYPE_RENDER_OPERATION_OUTLINE, NULL);
+  
+  result->style = g_object_ref (style);
+  result->x = x;
+  result->y = y;
+  result->width = width;
+  result->height = height;
+ 
+  return GTK_RENDER_OPERATION (result);
+}
+
diff --git a/gtk/inspector/gtkrenderoperationoutline.h b/gtk/inspector/gtkrenderoperationoutline.h
new file mode 100644
index 0000000..37127e7
--- /dev/null
+++ b/gtk/inspector/gtkrenderoperationoutline.h
@@ -0,0 +1,65 @@
+/*
+ * Copyright © 2015 Red Hat Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Benjamin Otte <otte gnome org>
+ */
+
+#ifndef __GTK_RENDER_OPERATION_OUTLINE_PRIVATE_H__
+#define __GTK_RENDER_OPERATION_OUTLINE_PRIVATE_H__
+
+#include "gtkrenderoperation.h"
+
+#include "gtkcsstypesprivate.h"
+
+G_BEGIN_DECLS
+
+#define GTK_TYPE_RENDER_OPERATION_OUTLINE           (gtk_render_operation_outline_get_type ())
+#define GTK_RENDER_OPERATION_OUTLINE(obj)           (G_TYPE_CHECK_INSTANCE_CAST (obj, 
GTK_TYPE_RENDER_OPERATION_OUTLINE, GtkRenderOperationOutline))
+#define GTK_RENDER_OPERATION_OUTLINE_CLASS(cls)     (G_TYPE_CHECK_CLASS_CAST (cls, 
GTK_TYPE_RENDER_OPERATION_OUTLINE, GtkRenderOperationOutlineClass))
+#define GTK_IS_RENDER_OPERATION_OUTLINE(obj)        (G_TYPE_CHECK_INSTANCE_TYPE (obj, 
GTK_TYPE_RENDER_OPERATION_OUTLINE))
+#define GTK_IS_RENDER_OPERATION_OUTLINE_CLASS(obj)  (G_TYPE_CHECK_CLASS_TYPE (obj, 
GTK_TYPE_RENDER_OPERATION_OUTLINE))
+#define GTK_RENDER_OPERATION_OUTLINE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), 
GTK_TYPE_RENDER_OPERATION_OUTLINE, GtkRenderOperationOutlineClass))
+
+typedef struct _GtkRenderOperationOutline           GtkRenderOperationOutline;
+typedef struct _GtkRenderOperationOutlineClass      GtkRenderOperationOutlineClass;
+
+struct _GtkRenderOperationOutline
+{
+  GtkRenderOperation parent;
+  
+  GtkCssStyle      *style;
+  double            x;
+  double            y;
+  double            width;
+  double            height;
+};
+
+struct _GtkRenderOperationOutlineClass
+{
+  GtkRenderOperationClass parent_class;
+};
+
+GType                   gtk_render_operation_outline_get_type         (void) G_GNUC_CONST;
+
+GtkRenderOperation *    gtk_render_operation_outline_new              (GtkCssStyle            *style,
+                                                                      double                  x,
+                                                                      double                  y,
+                                                                      double                  width,
+                                                                      double                  height);
+
+G_END_DECLS
+
+#endif /* __GTK_RENDER_OPERATION_OUTLINE_PRIVATE_H__ */
diff --git a/gtk/inspector/recordingrenderops.c b/gtk/inspector/recordingrenderops.c
index 3bf8e9c..509acb8 100644
--- a/gtk/inspector/recordingrenderops.c
+++ b/gtk/inspector/recordingrenderops.c
@@ -24,6 +24,7 @@
 #include "gtkrenderoperationbackground.h"
 #include "gtkrenderoperationborder.h"
 #include "gtkrenderoperationcairo.h"
+#include "gtkrenderoperationoutline.h"
 #include "gtkrenderoperationwidget.h"
 #include "gtkwidget.h"
 
@@ -142,6 +143,25 @@ gtk_recording_render_ops_draw_border (GtkRenderOps     *ops,
   g_object_unref (oper);
 }
 
+static void
+gtk_recording_render_ops_draw_outline (GtkRenderOps     *ops,
+                                       GtkCssStyle      *style,
+                                       cairo_t          *cr,
+                                       gdouble           x,
+                                       gdouble           y,
+                                       gdouble           width,
+                                       gdouble           height)
+{
+  GtkRecordingRenderOps *record = GTK_RECORDING_RENDER_OPS (ops);
+  GtkRenderOperation *oper;
+
+  gtk_recording_render_ops_save_snapshot (record, cr);
+
+  oper = gtk_render_operation_outline_new (style, x, y, width, height);
+  gtk_render_operation_widget_add_operation (record->widgets->data, oper);
+  g_object_unref (oper);
+}
+
 static cairo_t *
 gtk_recording_render_ops_begin_draw_widget (GtkRenderOps *ops,
                                             GtkWidget    *widget,
@@ -197,6 +217,7 @@ gtk_recording_render_ops_class_init (GtkRecordingRenderOpsClass *klass)
   ops_class->end_draw_widget = gtk_recording_render_ops_end_draw_widget;
   ops_class->draw_background = gtk_recording_render_ops_draw_background;
   ops_class->draw_border = gtk_recording_render_ops_draw_border;
+  ops_class->draw_outline = gtk_recording_render_ops_draw_outline;
 }
 
 static void


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]