[gtk/wip/baedert/transforms6] add GtkTransformer
- From: Timm Bäder <baedert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/baedert/transforms6] add GtkTransformer
- Date: Wed, 13 Feb 2019 14:25:50 +0000 (UTC)
commit 041849cf2263db24145ce2fa49e52e9b9ff3911e
Author: Timm Bäder <mail baedert org>
Date: Wed Feb 13 15:24:09 2019 +0100
add GtkTransformer
a widget
demos/widget-factory/widget-factory.c | 8 ++
demos/widget-factory/widget-factory.ui | 8 +-
gtk/gtk.h | 1 +
gtk/gtktransformer.c | 141 +++++++++++++++++++++++++++++++++
gtk/gtktransformer.h | 46 +++++++++++
gtk/meson.build | 2 +
6 files changed, 204 insertions(+), 2 deletions(-)
---
diff --git a/demos/widget-factory/widget-factory.c b/demos/widget-factory/widget-factory.c
index f19ae57d83..36bc52f7ad 100644
--- a/demos/widget-factory/widget-factory.c
+++ b/demos/widget-factory/widget-factory.c
@@ -1653,6 +1653,7 @@ activate (GApplication *app)
gint i;
GPermission *permission;
GAction *action;
+ graphene_matrix_t matrix;
g_type_ensure (my_text_view_get_type ());
@@ -1895,6 +1896,13 @@ activate (GApplication *app)
g_signal_connect (adj, "value-changed", G_CALLBACK (adjustment3_value_changed), widget);
g_signal_connect (adj, "value-changed", G_CALLBACK (adjustment3_value_changed), widget2);
+ widget = (GtkWidget *)gtk_builder_get_object (builder, "switch_transformer");
+ graphene_matrix_init_translate (&matrix,
+ &GRAPHENE_POINT3D_INIT (-450, -485, 0));
+ gtk_transformer_set_transform (GTK_TRANSFORMER (widget),
+ &matrix);
+
+
gtk_widget_show (GTK_WIDGET (window));
g_object_unref (builder);
diff --git a/demos/widget-factory/widget-factory.ui b/demos/widget-factory/widget-factory.ui
index 419f1493d8..a1df912d7c 100644
--- a/demos/widget-factory/widget-factory.ui
+++ b/demos/widget-factory/widget-factory.ui
@@ -872,8 +872,12 @@ Suspendisse feugiat quam quis dolor accumsan cursus.</property>
</object>
</child>
<child>
- <object class="GtkSwitch" id="switch1">
- <property name="halign">center</property>
+ <object class="GtkTransformer" id="switch_transformer">
+ <child>
+ <object class="GtkSwitch" id="switch1">
+ <property name="halign">center</property>
+ </object>
+ </child>
</object>
</child>
<child>
diff --git a/gtk/gtk.h b/gtk/gtk.h
index c79f1a9dfb..3e29a07f99 100644
--- a/gtk/gtk.h
+++ b/gtk/gtk.h
@@ -225,6 +225,7 @@
#include <gtk/gtktoolshell.h>
#include <gtk/gtktooltip.h>
#include <gtk/gtktestutils.h>
+#include <gtk/gtktransformer.h>
#include <gtk/gtktreednd.h>
#include <gtk/gtktreelistmodel.h>
#include <gtk/gtktreemodel.h>
diff --git a/gtk/gtktransformer.c b/gtk/gtktransformer.c
new file mode 100644
index 0000000000..38905c2844
--- /dev/null
+++ b/gtk/gtktransformer.c
@@ -0,0 +1,141 @@
+/*
+ * Copyright © 2019 Timm Bäder
+ *
+ * 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 "gtktransformer.h"
+
+
+/**
+ * ──────────▄▄▄▄▄▄▄▄▄──────────
+ * ───────▄█████████████▄───────
+ *▐███▌─█████████████████─▐███▌
+ *─████▄─▀███▄─────▄███▀─▄████─
+ *─▐█████▄─▀███▄─▄███▀─▄█████▌─
+ *──██▄▀███▄─▀█████▀─▄███▀▄██──
+ *──▐█▀█▄▀███─▄─▀─▄─███▀▄█▀█▌──
+ *───██▄▀█▄██─██▄██─██▄█▀▄██───
+ *────▀██▄▀██─█████─██▀▄██▀────
+ *───▄──▀████─█████─████▀──▄───
+ *───██────────███────────██───
+ *───██▄────▄█─███─█▄────▄██───
+ *───████─▄███─███─███▄─████───
+ *───████─████─███─████─████───
+ *───████─████─███─████─████───
+ *───████─████▄▄▄▄▄████─████───
+ *───▀███─█████████████─███▀───
+ *─────▀█─███─▄▄▄▄▄─███─█▀─────
+ *────────▀█▌▐█████▌▐█▀────────
+ *───────────███████───────────
+ */
+struct _GtkTransformer
+{
+ GtkWidget parent_instance;
+
+ graphene_matrix_t child_transform;
+};
+
+G_DEFINE_TYPE (GtkTransformer, gtk_transformer, GTK_TYPE_WIDGET);
+
+static void
+gtk_transformer_measure (GtkWidget *widget,
+ GtkOrientation orientation,
+ int for_size,
+ int *minimum,
+ int *natural,
+ int *minimum_baseline,
+ int *natural_baseline)
+{
+ GtkWidget *child = gtk_widget_get_first_child (widget);
+
+ if (child)
+ gtk_widget_measure (child,
+ orientation,
+ for_size,
+ minimum, natural,
+ minimum_baseline, natural_baseline);
+}
+
+static void
+gtk_transformer_size_allocate (GtkWidget *widget,
+ int width,
+ int height,
+ int baseline)
+{
+ GtkTransformer *self = GTK_TRANSFORMER (widget);
+ GtkWidget *child = gtk_widget_get_first_child (widget);
+
+ if (child)
+ gtk_widget_size_allocate_transformed (child,
+ width,
+ height,
+ baseline,
+ &self->child_transform);
+}
+
+static void
+gtk_transformer_dispose (GObject *object)
+{
+ GtkWidget *child = gtk_widget_get_first_child (GTK_WIDGET (object));
+
+ g_clear_pointer (&child, gtk_widget_unparent);
+
+ G_OBJECT_CLASS (gtk_transformer_parent_class)->dispose (object);
+}
+
+static void
+gtk_transformer_class_init (GtkTransformerClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
+ object_class->dispose = gtk_transformer_dispose;
+
+ widget_class->measure = gtk_transformer_measure;
+ widget_class->size_allocate = gtk_transformer_size_allocate;
+}
+
+static void
+gtk_transformer_init (GtkTransformer *self)
+{
+ gtk_widget_set_has_surface (GTK_WIDGET (self), FALSE);
+
+ graphene_matrix_init_identity (&self->child_transform);
+}
+
+GtkWidget *
+gtk_transformer_new (GtkWidget *child)
+{
+ GtkTransformer *self = GTK_TRANSFORMER (g_object_new (GTK_TYPE_TRANSFORMER, NULL));
+
+ gtk_widget_set_parent (child, GTK_WIDGET (self));
+
+ return GTK_WIDGET (self);
+}
+
+void
+gtk_transformer_set_transform (GtkTransformer *self,
+ const graphene_matrix_t *transform)
+{
+ g_return_if_fail (GTK_IS_TRANSFORMER (self));
+
+ graphene_matrix_init_from_matrix (&self->child_transform, transform);
+
+ gtk_widget_queue_allocate (GTK_WIDGET (self));
+}
diff --git a/gtk/gtktransformer.h b/gtk/gtktransformer.h
new file mode 100644
index 0000000000..0ff0931a5a
--- /dev/null
+++ b/gtk/gtktransformer.h
@@ -0,0 +1,46 @@
+/*
+ * Copyright © 2019 Timm Bäder
+ *
+ * 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_TRANSFORMER_H__
+#define __GTK_TRANSFORMER_H__
+
+#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
+#error "Only <gtk/gtk.h> can be included directly."
+#endif
+
+#include <gtk/gtkwidget.h>
+
+G_BEGIN_DECLS
+
+#define GTK_TYPE_TRANSFORMER (gtk_transformer_get_type ())
+
+GDK_AVAILABLE_IN_ALL
+G_DECLARE_FINAL_TYPE (GtkTransformer, gtk_transformer, GTK, TRANSFORMER, GtkWidget);
+
+GDK_AVAILABLE_IN_ALL
+GtkWidget * gtk_transformer_new (GtkWidget *child);
+
+GDK_AVAILABLE_IN_ALL
+void gtk_transformer_set_transform (GtkTransformer *self,
+ const graphene_matrix_t *transform);
+
+
+G_END_DECLS
+
+#endif /* __GTK_TRANSFORMER_H__ */
diff --git a/gtk/meson.build b/gtk/meson.build
index 3ebb1b5867..c529ff6c80 100644
--- a/gtk/meson.build
+++ b/gtk/meson.build
@@ -306,6 +306,7 @@ gtk_public_sources = files([
'gtkradiomenuitem.c',
'gtkradiotoolbutton.c',
'gtkrange.c',
+ 'gtktransformer.c',
'gtktreerbtree.c',
'gtkrecentmanager.c',
'gtkrender.c',
@@ -600,6 +601,7 @@ gtk_public_headers = files([
'gtktoolitem.h',
'gtktoolshell.h',
'gtktooltip.h',
+ 'gtktransformer.h',
'gtktreednd.h',
'gtktreelistmodel.h',
'gtktreemodel.h',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]