[gtk/wip/baedert/nodeeditor: 58/73] inspector: Show alternative renderings
- From: Timm Bäder <baedert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/baedert/nodeeditor: 58/73] inspector: Show alternative renderings
- Date: Mon, 22 Apr 2019 10:12:26 +0000 (UTC)
commit 3f572f9d45a64aaacf8e870b33edd42f7b3538b6
Author: Timm Bäder <mail baedert org>
Date: Tue Apr 16 06:11:45 2019 +0200
inspector: Show alternative renderings
gtk/inspector/magnifier.c | 163 +++++++++++++++++++++++++++++++++++++++++----
gtk/inspector/magnifier.ui | 16 ++++-
gtk/meson.build | 1 +
3 files changed, 164 insertions(+), 16 deletions(-)
---
diff --git a/gtk/inspector/magnifier.c b/gtk/inspector/magnifier.c
index 34cf33fa19..4e826135a4 100644
--- a/gtk/inspector/magnifier.c
+++ b/gtk/inspector/magnifier.c
@@ -22,9 +22,22 @@
#include "gtkmagnifierprivate.h"
-#include "gtklabel.h"
#include "gtkadjustment.h"
#include "gtkstack.h"
+#include "gtklabel.h"
+#include "gtklistbox.h"
+#include "gtkpicture.h"
+#include "gtkrendererpaintableprivate.h"
+#include "gtkwidgetpaintable.h"
+
+#ifdef GDK_WINDOWING_BROADWAY
+#include "gsk/gskbroadwayrendererprivate.h"
+#endif
+#include "gsk/gskcairorendererprivate.h"
+#include "gsk/gl/gskglrendererprivate.h"
+#ifdef GDK_RENDERING_VULKAN
+#include "gsk/vulkan/gskvulkanrendererprivate.h"
+#endif
enum
{
@@ -36,43 +49,149 @@ struct _GtkInspectorMagnifierPrivate
{
GtkWidget *object;
GtkWidget *magnifier;
+ GtkWidget *renderer_listbox;
GtkAdjustment *adjustment;
+ GListStore *renderers;
+ GdkPaintable *paintable;
};
G_DEFINE_TYPE_WITH_PRIVATE (GtkInspectorMagnifier, gtk_inspector_magnifier, GTK_TYPE_BOX)
static void
-gtk_inspector_magnifier_init (GtkInspectorMagnifier *sl)
+gtk_inspector_magnifier_add_renderer (GtkInspectorMagnifier *self,
+ GType renderer_type,
+ const char *description)
+{
+ GtkInspectorMagnifierPrivate *priv = gtk_inspector_magnifier_get_instance_private (self);
+ GskRenderer *renderer;
+ GdkSurface *surface;
+ GdkPaintable *paintable;
+
+ surface = gtk_widget_get_surface (GTK_WIDGET (self));
+ g_assert (surface != NULL);
+
+ if (renderer_type == G_TYPE_NONE)
+ renderer = NULL;
+ else
+ {
+ renderer = g_object_new (renderer_type, NULL);
+
+ if (!gsk_renderer_realize (renderer, surface, NULL))
+ {
+ g_object_unref (renderer);
+ return;
+ }
+ }
+
+ paintable = gtk_renderer_paintable_new (renderer, priv->paintable);
+ g_object_set_data_full (G_OBJECT (paintable), "description", g_strdup (description), g_free);
+ g_object_unref (renderer);
+
+ g_list_store_append (priv->renderers, paintable);
+ g_object_unref (paintable);
+}
+
+static void
+gtk_inspector_magnifier_realize (GtkWidget *widget)
+{
+ GtkInspectorMagnifier *self = GTK_INSPECTOR_MAGNIFIER (widget);
+
+ GTK_WIDGET_CLASS (gtk_inspector_magnifier_parent_class)->realize (widget);
+
+ gtk_inspector_magnifier_add_renderer (self,
+ G_TYPE_NONE,
+ "Default");
+ gtk_inspector_magnifier_add_renderer (self,
+ GSK_TYPE_GL_RENDERER,
+ "OpenGL");
+#ifdef GDK_RENDERING_VULKAN
+ gtk_inspector_magnifier_add_renderer (self,
+ GSK_TYPE_VULKAN_RENDERER,
+ "Vulkan");
+#endif
+#ifdef GDK_WINDOWING_BROADWAY
+ gtk_inspector_magnifier_add_renderer (self,
+ GSK_TYPE_BROADWAY_RENDERER,
+ "Broadway");
+#endif
+ gtk_inspector_magnifier_add_renderer (self,
+ GSK_TYPE_CAIRO_RENDERER,
+ "Cairo");
+}
+
+static void
+gtk_inspector_magnifier_unrealize (GtkWidget *widget)
+{
+ GtkInspectorMagnifier *self = GTK_INSPECTOR_MAGNIFIER (widget);
+ GtkInspectorMagnifierPrivate *priv = gtk_inspector_magnifier_get_instance_private (self);
+
+ g_list_store_remove_all (priv->renderers);
+
+ GTK_WIDGET_CLASS (gtk_inspector_magnifier_parent_class)->unrealize (widget);
+}
+
+static GtkWidget *
+gtk_inspector_magnifier_create_renderer_widget (gpointer item,
+ gpointer user_data)
+{
+ GdkPaintable *paintable = item;
+ GtkWidget *box, *label, *picture;
+
+ box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
+ gtk_widget_set_size_request (box, 160, 120);
+
+ label = gtk_label_new (g_object_get_data (G_OBJECT (paintable), "description"));
+ gtk_container_add (GTK_CONTAINER (box), label);
+
+ picture = gtk_picture_new_for_paintable (paintable);
+ gtk_container_add (GTK_CONTAINER (box), picture);
+
+ return box;
+}
+
+static void
+gtk_inspector_magnifier_init (GtkInspectorMagnifier *self)
{
- sl->priv = gtk_inspector_magnifier_get_instance_private (sl);
- gtk_widget_init_template (GTK_WIDGET (sl));
+ self->priv = gtk_inspector_magnifier_get_instance_private (self);
+ gtk_widget_init_template (GTK_WIDGET (self));
+
+ self->priv->renderers = g_list_store_new (GDK_TYPE_PAINTABLE);
+ gtk_list_box_bind_model (GTK_LIST_BOX (self->priv->renderer_listbox),
+ G_LIST_MODEL (self->priv->renderers),
+ gtk_inspector_magnifier_create_renderer_widget,
+ self,
+ NULL);
+ self->priv->paintable = gtk_widget_paintable_new (NULL);
}
void
-gtk_inspector_magnifier_set_object (GtkInspectorMagnifier *sl,
- GObject *object)
+gtk_inspector_magnifier_set_object (GtkInspectorMagnifier *self,
+ GObject *object)
{
+ GtkInspectorMagnifierPrivate *priv = gtk_inspector_magnifier_get_instance_private (self);
GtkWidget *stack;
GtkStackPage *page;
- stack = gtk_widget_get_parent (GTK_WIDGET (sl));
- page = gtk_stack_get_page (GTK_STACK (stack), GTK_WIDGET (sl));
+ stack = gtk_widget_get_parent (GTK_WIDGET (self));
+ page = gtk_stack_get_page (GTK_STACK (stack), GTK_WIDGET (self));
- sl->priv->object = NULL;
+ priv->object = NULL;
if (!GTK_IS_WIDGET (object) || !gtk_widget_is_visible (GTK_WIDGET (object)))
{
g_object_set (page, "visible", FALSE, NULL);
- _gtk_magnifier_set_inspected (GTK_MAGNIFIER (sl->priv->magnifier), NULL);
+ _gtk_magnifier_set_inspected (GTK_MAGNIFIER (priv->magnifier), NULL);
+ gtk_widget_paintable_set_widget (GTK_WIDGET_PAINTABLE (priv->paintable), NULL);
return;
}
g_object_set (page, "visible", TRUE, NULL);
- sl->priv->object = GTK_WIDGET (object);
+ priv->object = GTK_WIDGET (object);
- _gtk_magnifier_set_inspected (GTK_MAGNIFIER (sl->priv->magnifier), GTK_WIDGET (object));
- _gtk_magnifier_set_coords (GTK_MAGNIFIER (sl->priv->magnifier), 0, 0);
+ _gtk_magnifier_set_inspected (GTK_MAGNIFIER (priv->magnifier), GTK_WIDGET (object));
+ gtk_widget_paintable_set_widget (GTK_WIDGET_PAINTABLE (priv->paintable), GTK_WIDGET (object));
+ _gtk_magnifier_set_coords (GTK_MAGNIFIER (priv->magnifier), 0, 0);
}
static void
@@ -115,6 +234,17 @@ set_property (GObject *object,
}
}
+static void
+gtk_inspector_magnifier_dispose (GObject *object)
+{
+ GtkInspectorMagnifier *self = GTK_INSPECTOR_MAGNIFIER (object);
+ GtkInspectorMagnifierPrivate *priv = gtk_inspector_magnifier_get_instance_private (self);
+
+ g_clear_object (&priv->renderers);
+
+ G_OBJECT_CLASS (gtk_inspector_magnifier_parent_class)->dispose (object);
+}
+
static void
constructed (GObject *object)
{
@@ -123,6 +253,8 @@ constructed (GObject *object)
g_object_bind_property (sl->priv->adjustment, "value",
sl->priv->magnifier, "magnification",
G_BINDING_SYNC_CREATE);
+
+ G_OBJECT_CLASS (gtk_inspector_magnifier_parent_class)->constructed (object);
}
static void
@@ -133,14 +265,19 @@ gtk_inspector_magnifier_class_init (GtkInspectorMagnifierClass *klass)
object_class->get_property = get_property;
object_class->set_property = set_property;
+ object_class->dispose = gtk_inspector_magnifier_dispose;
object_class->constructed = constructed;
g_object_class_install_property (object_class, PROP_ADJUSTMENT,
g_param_spec_object ("adjustment", NULL, NULL,
GTK_TYPE_ADJUSTMENT, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+ widget_class->realize = gtk_inspector_magnifier_realize;
+ widget_class->unrealize = gtk_inspector_magnifier_unrealize;
+
gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/libgtk/inspector/magnifier.ui");
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorMagnifier, magnifier);
+ gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorMagnifier, renderer_listbox);
}
// vim: set et sw=2 ts=2:
diff --git a/gtk/inspector/magnifier.ui b/gtk/inspector/magnifier.ui
index 27d72e9ba1..f8bb2ff25f 100644
--- a/gtk/inspector/magnifier.ui
+++ b/gtk/inspector/magnifier.ui
@@ -5,9 +5,19 @@
<object class="GtkScrolledWindow">
<property name="expand">1</property>
<child>
- <object class="GtkMagnifier" id="magnifier">
- <property name="visible">True</property>
- <property name="resize">True</property>
+ <object class="GtkBox">
+ <child>
+ <object class="GtkMagnifier" id="magnifier">
+ <property name="hexpand">True</property>
+ <property name="vexpand">True</property>
+ <property name="resize">True</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkListBox" id="renderer_listbox">
+ <property name="width-request">240</property>
+ </object>
+ </child>
</object>
</child>
</object>
diff --git a/gtk/meson.build b/gtk/meson.build
index 76fef838f5..59f5749551 100644
--- a/gtk/meson.build
+++ b/gtk/meson.build
@@ -313,6 +313,7 @@ gtk_public_sources = files([
'gtkrenderbackground.c',
'gtkrenderborder.c',
'gtkrendericon.c',
+ 'gtkrendererpaintable.c',
'gtkrendernodepaintable.c',
'gtkrevealer.c',
'gtkroot.c',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]