[gtk/wip/baedert/nodeeditor: 2/16] Add GtkDiffPaintable and use it in the magnifier
- From: Timm Bäder <baedert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/baedert/nodeeditor: 2/16] Add GtkDiffPaintable and use it in the magnifier
- Date: Mon, 22 Apr 2019 10:18:47 +0000 (UTC)
commit ec827e1907aeaaf3c9455e8ec1871654f5e2c47e
Author: Benjamin Otte <otte redhat com>
Date: Sun Mar 10 23:46:19 2019 +0100
Add GtkDiffPaintable and use it in the magnifier
This is supposed to show diffs, but works only semi-well because we
fallback on GL for blend nodes, so the diffs are actually with cairo
renderings. Oops.
gtk/gtkdiffpaintable.c | 326 ++++++++++++++++++++++++++++++++++++++
gtk/gtkdiffpaintableprivate.h | 43 +++++
gtk/gtkrendererpaintable.c | 321 +++++++++++++++++++++++++++++++++++++
gtk/gtkrendererpaintableprivate.h | 43 +++++
gtk/inspector/magnifier.c | 24 ++-
gtk/meson.build | 1 +
6 files changed, 752 insertions(+), 6 deletions(-)
---
diff --git a/gtk/gtkdiffpaintable.c b/gtk/gtkdiffpaintable.c
new file mode 100644
index 0000000000..5f7add5ce9
--- /dev/null
+++ b/gtk/gtkdiffpaintable.c
@@ -0,0 +1,326 @@
+/*
+ * Copyright © 2019 Benjamin Otte
+ *
+ * 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 "gtkdiffpaintableprivate.h"
+
+#include "gtkintl.h"
+#include "gtksnapshot.h"
+
+struct _GtkDiffPaintable
+{
+ GObject parent_instance;
+
+ GdkPaintable *first;
+ GdkPaintable *second;
+};
+
+struct _GtkDiffPaintableClass
+{
+ GObjectClass parent_class;
+};
+
+enum {
+ PROP_0,
+ PROP_FIRST,
+ PROP_SECOND,
+ N_PROPS
+};
+
+static GParamSpec *properties[N_PROPS] = { NULL, };
+
+static void
+gtk_diff_paintable_paintable_snapshot (GdkPaintable *paintable,
+ GdkSnapshot *snapshot,
+ double width,
+ double height)
+{
+ GtkDiffPaintable *self = GTK_DIFF_PAINTABLE (paintable);
+ float amplify[16] = { 4, 0, 0, 0,
+ 0, 4, 0, 0,
+ 0, 0, 4, 0,
+ 0, 0, 0, 1 };
+ graphene_matrix_t matrix;
+
+ graphene_matrix_init_from_float (&matrix, amplify);
+
+ gtk_snapshot_push_color_matrix (snapshot, &matrix, graphene_vec4_zero ());
+
+ gtk_snapshot_push_blend (snapshot, GSK_BLEND_MODE_DIFFERENCE);
+
+ if (self->first)
+ gdk_paintable_snapshot (self->first, snapshot, width, height);
+ gtk_snapshot_pop (snapshot);
+
+ if (self->second)
+ gdk_paintable_snapshot (self->second, snapshot, width, height);
+ gtk_snapshot_pop (snapshot);
+
+ gtk_snapshot_pop (snapshot);
+}
+
+static int
+gtk_diff_paintable_paintable_get_intrinsic_width (GdkPaintable *paintable)
+{
+ GtkDiffPaintable *self = GTK_DIFF_PAINTABLE (paintable);
+ int result;
+
+ result = 0;
+
+ if (self->first)
+ result = MAX (result, gdk_paintable_get_intrinsic_width (self->first));
+ if (self->second)
+ result = MAX (result, gdk_paintable_get_intrinsic_width (self->second));
+
+ return result;
+}
+
+static int
+gtk_diff_paintable_paintable_get_intrinsic_height (GdkPaintable *paintable)
+{
+ GtkDiffPaintable *self = GTK_DIFF_PAINTABLE (paintable);
+ int result;
+
+ result = 0;
+
+ if (self->first)
+ result = MAX (result, gdk_paintable_get_intrinsic_height (self->first));
+ if (self->second)
+ result = MAX (result, gdk_paintable_get_intrinsic_height (self->second));
+
+ return result;
+}
+
+static void
+gtk_diff_paintable_paintable_init (GdkPaintableInterface *iface)
+{
+ iface->snapshot = gtk_diff_paintable_paintable_snapshot;
+ iface->get_intrinsic_width = gtk_diff_paintable_paintable_get_intrinsic_width;
+ iface->get_intrinsic_height = gtk_diff_paintable_paintable_get_intrinsic_height;
+}
+
+G_DEFINE_TYPE_EXTENDED (GtkDiffPaintable, gtk_diff_paintable, G_TYPE_OBJECT, 0,
+ G_IMPLEMENT_INTERFACE (GDK_TYPE_PAINTABLE,
+ gtk_diff_paintable_paintable_init))
+
+static void
+gtk_diff_paintable_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+
+{
+ GtkDiffPaintable *self = GTK_DIFF_PAINTABLE (object);
+
+ switch (prop_id)
+ {
+ case PROP_FIRST:
+ gtk_diff_paintable_set_first (self, g_value_get_object (value));
+ break;
+
+ case PROP_SECOND:
+ gtk_diff_paintable_set_second (self, g_value_get_object (value));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+gtk_diff_paintable_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GtkDiffPaintable *self = GTK_DIFF_PAINTABLE (object);
+
+ switch (prop_id)
+ {
+ case PROP_FIRST:
+ g_value_set_object (value, self->first);
+ break;
+
+ case PROP_SECOND:
+ g_value_set_object (value, self->second);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+gtk_diff_paintable_unset_paintable (GtkDiffPaintable *self,
+ GdkPaintable **paintable)
+{
+ guint flags;
+
+ if (*paintable == NULL)
+ return;
+
+ flags = gdk_paintable_get_flags (*paintable);
+
+ if ((flags & GDK_PAINTABLE_STATIC_CONTENTS) == 0)
+ g_signal_handlers_disconnect_by_func (*paintable,
+ gdk_paintable_invalidate_contents,
+ self);
+
+ if ((flags & GDK_PAINTABLE_STATIC_SIZE) == 0)
+ g_signal_handlers_disconnect_by_func (*paintable,
+ gdk_paintable_invalidate_size,
+ self);
+
+ g_clear_object (paintable);
+}
+
+static void
+gtk_diff_paintable_dispose (GObject *object)
+{
+ GtkDiffPaintable *self = GTK_DIFF_PAINTABLE (object);
+
+ gtk_diff_paintable_unset_paintable (self, &self->first);
+ gtk_diff_paintable_unset_paintable (self, &self->second);
+
+ G_OBJECT_CLASS (gtk_diff_paintable_parent_class)->dispose (object);
+}
+
+static void
+gtk_diff_paintable_class_init (GtkDiffPaintableClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+
+ gobject_class->get_property = gtk_diff_paintable_get_property;
+ gobject_class->set_property = gtk_diff_paintable_set_property;
+ gobject_class->dispose = gtk_diff_paintable_dispose;
+
+ properties[PROP_FIRST] =
+ g_param_spec_object ("first",
+ P_("First"),
+ P_("First paintable to diff"),
+ GDK_TYPE_PAINTABLE,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);
+
+ properties[PROP_SECOND] =
+ g_param_spec_object ("second",
+ P_("Second"),
+ P_("Second paintable to diff"),
+ GDK_TYPE_PAINTABLE,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);
+
+ g_object_class_install_properties (gobject_class, N_PROPS, properties);
+}
+
+static void
+gtk_diff_paintable_init (GtkDiffPaintable *self)
+{
+}
+
+GdkPaintable *
+gtk_diff_paintable_new (GdkPaintable *first,
+ GdkPaintable *second)
+{
+ g_return_val_if_fail (first == NULL || GDK_IS_PAINTABLE (first), NULL);
+ g_return_val_if_fail (second == NULL || GDK_IS_PAINTABLE (second), NULL);
+
+ return g_object_new (GTK_TYPE_DIFF_PAINTABLE,
+ "first", first,
+ "second", second,
+ NULL);
+}
+
+static gboolean
+gtk_diff_paintable_set_paintable (GtkDiffPaintable *self,
+ GdkPaintable **paintable,
+ GdkPaintable *new_paintable)
+{
+ if (*paintable == new_paintable)
+ return FALSE;
+
+ gtk_diff_paintable_unset_paintable (self, paintable);
+
+ if (new_paintable)
+ {
+ const guint flags = gdk_paintable_get_flags (new_paintable);
+
+ *paintable = g_object_ref (new_paintable);
+
+ if ((flags & GDK_PAINTABLE_STATIC_CONTENTS) == 0)
+ g_signal_connect_swapped (new_paintable,
+ "invalidate-contents",
+ G_CALLBACK (gdk_paintable_invalidate_contents),
+ self);
+ if ((flags & GDK_PAINTABLE_STATIC_SIZE) == 0)
+ g_signal_connect_swapped (new_paintable,
+ "invalidate-size",
+ G_CALLBACK (gdk_paintable_invalidate_size),
+ self);
+ }
+
+ gdk_paintable_invalidate_size (GDK_PAINTABLE (self));
+ gdk_paintable_invalidate_contents (GDK_PAINTABLE (self));
+
+ return TRUE;
+}
+
+void
+gtk_diff_paintable_set_first (GtkDiffPaintable *self,
+ GdkPaintable *paintable)
+{
+ g_return_if_fail (GTK_IS_DIFF_PAINTABLE (self));
+ g_return_if_fail (paintable == NULL || GDK_IS_PAINTABLE (paintable));
+
+ if (!gtk_diff_paintable_set_paintable (self, &self->first, paintable))
+ return;
+
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_FIRST]);
+}
+
+GdkPaintable *
+gtk_diff_paintable_get_first (GtkDiffPaintable *self)
+{
+ g_return_val_if_fail (GTK_IS_DIFF_PAINTABLE (self), NULL);
+
+ return self->first;
+}
+
+void
+gtk_diff_paintable_set_second (GtkDiffPaintable *self,
+ GdkPaintable *paintable)
+{
+ g_return_if_fail (GTK_IS_DIFF_PAINTABLE (self));
+ g_return_if_fail (paintable == NULL || GDK_IS_PAINTABLE (paintable));
+
+ if (!gtk_diff_paintable_set_paintable (self, &self->second, paintable))
+ return;
+
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SECOND]);
+}
+
+GdkPaintable *
+gtk_diff_paintable_get_second (GtkDiffPaintable *self)
+{
+ g_return_val_if_fail (GTK_IS_DIFF_PAINTABLE (self), NULL);
+
+ return self->second;
+}
+
diff --git a/gtk/gtkdiffpaintableprivate.h b/gtk/gtkdiffpaintableprivate.h
new file mode 100644
index 0000000000..9d3789fb20
--- /dev/null
+++ b/gtk/gtkdiffpaintableprivate.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright © 2019 Benjamin Otte
+ *
+ * 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_DIFF_PAINTABLE_H__
+#define __GTK_DIFF_PAINTABLE_H__
+
+#include <gsk/gsk.h>
+
+G_BEGIN_DECLS
+
+#define GTK_TYPE_DIFF_PAINTABLE (gtk_diff_paintable_get_type ())
+
+G_DECLARE_FINAL_TYPE (GtkDiffPaintable, gtk_diff_paintable, GTK, DIFF_PAINTABLE, GObject)
+
+GdkPaintable * gtk_diff_paintable_new (GdkPaintable *first,
+ GdkPaintable *second);
+
+void gtk_diff_paintable_set_first (GtkDiffPaintable *self,
+ GdkPaintable *first);
+GdkPaintable * gtk_diff_paintable_get_first (GtkDiffPaintable *self) G_GNUC_PURE;
+void gtk_diff_paintable_set_second (GtkDiffPaintable *self,
+ GdkPaintable *second);
+GdkPaintable * gtk_diff_paintable_get_second (GtkDiffPaintable *self) G_GNUC_PURE;
+
+G_END_DECLS
+
+#endif /* __GTK_DIFF_PAINTABLE_H__ */
diff --git a/gtk/gtkrendererpaintable.c b/gtk/gtkrendererpaintable.c
new file mode 100644
index 0000000000..8f5524e3d2
--- /dev/null
+++ b/gtk/gtkrendererpaintable.c
@@ -0,0 +1,321 @@
+/*
+ * Copyright © 2019 Benjamin Otte
+ *
+ * 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 "gtkrendererpaintableprivate.h"
+
+#include "gtkintl.h"
+#include "gtksnapshot.h"
+
+struct _GtkRendererPaintable
+{
+ GObject parent_instance;
+
+ GskRenderer *renderer;
+ GdkPaintable *paintable;
+};
+
+struct _GtkRendererPaintableClass
+{
+ GObjectClass parent_class;
+};
+
+enum {
+ PROP_0,
+ PROP_PAINTABLE,
+ PROP_RENDERER,
+ N_PROPS
+};
+
+static GParamSpec *properties[N_PROPS] = { NULL, };
+
+static void
+gtk_renderer_paintable_paintable_snapshot (GdkPaintable *paintable,
+ GdkSnapshot *snapshot,
+ double width,
+ double height)
+{
+ GtkRendererPaintable *self = GTK_RENDERER_PAINTABLE (paintable);
+ GtkSnapshot *node_snapshot;
+ GskRenderNode *node;
+ GdkTexture *texture;
+
+ if (self->paintable == NULL)
+ return;
+
+ if (self->renderer == NULL ||
+ !gsk_renderer_is_realized (self->renderer))
+ {
+ gdk_paintable_snapshot (self->paintable, snapshot, width, height);
+ return;
+ }
+
+ node_snapshot = gtk_snapshot_new ();
+ gdk_paintable_snapshot (self->paintable, node_snapshot, width, height);
+ node = gtk_snapshot_free_to_node (node_snapshot);
+
+ texture = gsk_renderer_render_texture (self->renderer,
+ node,
+ &GRAPHENE_RECT_INIT (0, 0, width, height));
+
+ gdk_paintable_snapshot (GDK_PAINTABLE (texture), snapshot, width, height);
+}
+
+static int
+gtk_renderer_paintable_paintable_get_intrinsic_width (GdkPaintable *paintable)
+{
+ GtkRendererPaintable *self = GTK_RENDERER_PAINTABLE (paintable);
+
+ if (self->paintable == NULL)
+ return 0;
+
+ return gdk_paintable_get_intrinsic_width (self->paintable);
+}
+
+static int
+gtk_renderer_paintable_paintable_get_intrinsic_height (GdkPaintable *paintable)
+{
+ GtkRendererPaintable *self = GTK_RENDERER_PAINTABLE (paintable);
+
+ if (self->paintable == NULL)
+ return 0;
+
+ return gdk_paintable_get_intrinsic_height (self->paintable);
+}
+
+static double
+gtk_renderer_paintable_paintable_get_intrinsic_aspect_ratio (GdkPaintable *paintable)
+{
+ GtkRendererPaintable *self = GTK_RENDERER_PAINTABLE (paintable);
+
+ if (self->paintable == NULL)
+ return 0.0;
+
+ return gdk_paintable_get_intrinsic_aspect_ratio (self->paintable);
+}
+
+static void
+gtk_renderer_paintable_paintable_init (GdkPaintableInterface *iface)
+{
+ iface->snapshot = gtk_renderer_paintable_paintable_snapshot;
+ iface->get_intrinsic_width = gtk_renderer_paintable_paintable_get_intrinsic_width;
+ iface->get_intrinsic_height = gtk_renderer_paintable_paintable_get_intrinsic_height;
+ iface->get_intrinsic_aspect_ratio = gtk_renderer_paintable_paintable_get_intrinsic_aspect_ratio;
+}
+
+G_DEFINE_TYPE_EXTENDED (GtkRendererPaintable, gtk_renderer_paintable, G_TYPE_OBJECT, 0,
+ G_IMPLEMENT_INTERFACE (GDK_TYPE_PAINTABLE,
+ gtk_renderer_paintable_paintable_init))
+
+static void
+gtk_renderer_paintable_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+
+{
+ GtkRendererPaintable *self = GTK_RENDERER_PAINTABLE (object);
+
+ switch (prop_id)
+ {
+ case PROP_PAINTABLE:
+ gtk_renderer_paintable_set_paintable (self, g_value_get_object (value));
+ break;
+
+ case PROP_RENDERER:
+ gtk_renderer_paintable_set_renderer (self, g_value_get_object (value));
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+gtk_renderer_paintable_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GtkRendererPaintable *self = GTK_RENDERER_PAINTABLE (object);
+
+ switch (prop_id)
+ {
+ case PROP_PAINTABLE:
+ g_value_set_object (value, self->paintable);
+ break;
+
+ case PROP_RENDERER:
+ g_value_set_object (value, self->renderer);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+}
+
+static void
+gtk_renderer_paintable_unset_paintable (GtkRendererPaintable *self)
+{
+ guint flags;
+
+ if (self->paintable == NULL)
+ return;
+
+ flags = gdk_paintable_get_flags (self->paintable);
+
+ if ((flags & GDK_PAINTABLE_STATIC_CONTENTS) == 0)
+ g_signal_handlers_disconnect_by_func (self->paintable,
+ gdk_paintable_invalidate_contents,
+ self);
+
+ if ((flags & GDK_PAINTABLE_STATIC_SIZE) == 0)
+ g_signal_handlers_disconnect_by_func (self->paintable,
+ gdk_paintable_invalidate_size,
+ self);
+
+ g_clear_object (&self->paintable);
+}
+
+static void
+gtk_renderer_paintable_dispose (GObject *object)
+{
+ GtkRendererPaintable *self = GTK_RENDERER_PAINTABLE (object);
+
+ g_clear_object (&self->renderer);
+ gtk_renderer_paintable_unset_paintable (self);
+
+ G_OBJECT_CLASS (gtk_renderer_paintable_parent_class)->dispose (object);
+}
+
+static void
+gtk_renderer_paintable_class_init (GtkRendererPaintableClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+
+ gobject_class->get_property = gtk_renderer_paintable_get_property;
+ gobject_class->set_property = gtk_renderer_paintable_set_property;
+ gobject_class->dispose = gtk_renderer_paintable_dispose;
+
+ properties[PROP_PAINTABLE] =
+ g_param_spec_object ("paintable",
+ P_("Paintable"),
+ P_("The paintable to be shown"),
+ GDK_TYPE_PAINTABLE,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);
+
+ properties[PROP_RENDERER] =
+ g_param_spec_object ("renderer",
+ P_("Renderer"),
+ P_("Renderer used to render the paintable"),
+ GSK_TYPE_RENDERER,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);
+
+ g_object_class_install_properties (gobject_class, N_PROPS, properties);
+}
+
+static void
+gtk_renderer_paintable_init (GtkRendererPaintable *self)
+{
+}
+
+GdkPaintable *
+gtk_renderer_paintable_new (GskRenderer *renderer,
+ GdkPaintable *paintable)
+{
+ g_return_val_if_fail (renderer == NULL || GSK_IS_RENDERER (renderer), NULL);
+ g_return_val_if_fail (paintable == NULL || GDK_IS_PAINTABLE (paintable), NULL);
+
+ return g_object_new (GTK_TYPE_RENDERER_PAINTABLE,
+ "renderer", renderer,
+ "paintable", paintable,
+ NULL);
+}
+
+void
+gtk_renderer_paintable_set_renderer (GtkRendererPaintable *self,
+ GskRenderer *renderer)
+{
+ g_return_if_fail (GTK_IS_RENDERER_PAINTABLE (self));
+ g_return_if_fail (renderer == NULL || GSK_IS_RENDERER (renderer));
+
+ if (!g_set_object (&self->renderer, renderer))
+ return;
+
+ if (self->paintable)
+ gdk_paintable_invalidate_contents (GDK_PAINTABLE (self));
+
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_RENDERER]);
+}
+
+GskRenderer *
+gtk_renderer_paintable_get_renderer (GtkRendererPaintable *self)
+{
+ g_return_val_if_fail (GTK_IS_RENDERER_PAINTABLE (self), NULL);
+
+ return self->renderer;
+}
+
+void
+gtk_renderer_paintable_set_paintable (GtkRendererPaintable *self,
+ GdkPaintable *paintable)
+{
+ g_return_if_fail (GTK_IS_RENDERER_PAINTABLE (self));
+ g_return_if_fail (paintable == NULL || GDK_IS_PAINTABLE (paintable));
+
+ if (self->paintable == paintable)
+ return;
+
+ gtk_renderer_paintable_unset_paintable (self);
+
+ if (paintable)
+ {
+ const guint flags = gdk_paintable_get_flags (paintable);
+
+ self->paintable = g_object_ref (paintable);
+
+ if ((flags & GDK_PAINTABLE_STATIC_CONTENTS) == 0)
+ g_signal_connect_swapped (paintable,
+ "invalidate-contents",
+ G_CALLBACK (gdk_paintable_invalidate_contents),
+ self);
+ if ((flags & GDK_PAINTABLE_STATIC_SIZE) == 0)
+ g_signal_connect_swapped (paintable,
+ "invalidate-size",
+ G_CALLBACK (gdk_paintable_invalidate_size),
+ self);
+ }
+
+ gdk_paintable_invalidate_size (GDK_PAINTABLE (self));
+ gdk_paintable_invalidate_contents (GDK_PAINTABLE (self));
+
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_PAINTABLE]);
+}
+
+GdkPaintable *
+gtk_renderer_paintable_get_paintable (GtkRendererPaintable *self)
+{
+ g_return_val_if_fail (GTK_IS_RENDERER_PAINTABLE (self), NULL);
+
+ return self->paintable;
+}
+
diff --git a/gtk/gtkrendererpaintableprivate.h b/gtk/gtkrendererpaintableprivate.h
new file mode 100644
index 0000000000..39b9f8e93b
--- /dev/null
+++ b/gtk/gtkrendererpaintableprivate.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright © 2019 Benjamin Otte
+ *
+ * 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_RENDERER_PAINTABLE_H__
+#define __GTK_RENDERER_PAINTABLE_H__
+
+#include <gsk/gsk.h>
+
+G_BEGIN_DECLS
+
+#define GTK_TYPE_RENDERER_PAINTABLE (gtk_renderer_paintable_get_type ())
+
+G_DECLARE_FINAL_TYPE (GtkRendererPaintable, gtk_renderer_paintable, GTK, RENDERER_PAINTABLE, GObject)
+
+GdkPaintable * gtk_renderer_paintable_new (GskRenderer *renderer,
+ GdkPaintable *paintable);
+
+void gtk_renderer_paintable_set_renderer (GtkRendererPaintable *self,
+ GskRenderer *renderer);
+GskRenderer * gtk_renderer_paintable_get_renderer (GtkRendererPaintable *self) G_GNUC_PURE;
+void gtk_renderer_paintable_set_paintable (GtkRendererPaintable *self,
+ GdkPaintable *paintable);
+GdkPaintable * gtk_renderer_paintable_get_paintable (GtkRendererPaintable *self) G_GNUC_PURE;
+
+G_END_DECLS
+
+#endif /* __GTK_RENDERER_PAINTABLE_H__ */
diff --git a/gtk/inspector/magnifier.c b/gtk/inspector/magnifier.c
index 4e826135a4..36810743b1 100644
--- a/gtk/inspector/magnifier.c
+++ b/gtk/inspector/magnifier.c
@@ -24,6 +24,7 @@
#include "gtkadjustment.h"
#include "gtkstack.h"
+#include "gtkdiffpaintableprivate.h"
#include "gtklabel.h"
#include "gtklistbox.h"
#include "gtkpicture.h"
@@ -134,19 +135,30 @@ static GtkWidget *
gtk_inspector_magnifier_create_renderer_widget (gpointer item,
gpointer user_data)
{
+ GtkInspectorMagnifier *self = user_data;
+ GtkInspectorMagnifierPrivate *priv = gtk_inspector_magnifier_get_instance_private (self);
GdkPaintable *paintable = item;
- GtkWidget *box, *label, *picture;
+ GdkPaintable *diff;
+ GtkWidget *vbox, *hbox, *label, *picture;
- box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
- gtk_widget_set_size_request (box, 160, 120);
+ vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
+ gtk_widget_set_size_request (vbox, 160, 60);
label = gtk_label_new (g_object_get_data (G_OBJECT (paintable), "description"));
- gtk_container_add (GTK_CONTAINER (box), label);
+ gtk_container_add (GTK_CONTAINER (vbox), label);
+
+ hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);
+ gtk_container_add (GTK_CONTAINER (vbox), hbox);
picture = gtk_picture_new_for_paintable (paintable);
- gtk_container_add (GTK_CONTAINER (box), picture);
+ gtk_container_add (GTK_CONTAINER (hbox), picture);
+
+ diff = gtk_diff_paintable_new (paintable, priv->paintable);
+ picture = gtk_picture_new_for_paintable (diff);
+ gtk_container_add (GTK_CONTAINER (hbox), picture);
+ g_object_unref (diff);
- return box;
+ return vbox;
}
static void
diff --git a/gtk/meson.build b/gtk/meson.build
index 59f5749551..2033a1a909 100644
--- a/gtk/meson.build
+++ b/gtk/meson.build
@@ -202,6 +202,7 @@ gtk_public_sources = files([
'gtkcontainer.c',
'gtkcssprovider.c',
'gtkdialog.c',
+ 'gtkdiffpaintable.c',
'gtkdnd.c',
'gtkdragdest.c',
'gtkdragsource.c',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]