[gtk/node-editor-scale] node-editor: Add a zoom button




commit 27db4b5c2f1822581c22f146edbd9b46d5393e27
Author: Matthias Clasen <mclasen redhat com>
Date:   Tue Jun 7 13:39:22 2022 -0400

    node-editor: Add a zoom button
    
    This is a bit more convenient than manually
    adding a transform node in the text editor.

 demos/node-editor/node-editor-window.c  | 23 +++++++++++++++++++++++
 demos/node-editor/node-editor-window.ui | 17 +++++++++++++++++
 2 files changed, 40 insertions(+)
---
diff --git a/demos/node-editor/node-editor-window.c b/demos/node-editor/node-editor-window.c
index 84baae7809..68f261183a 100644
--- a/demos/node-editor/node-editor-window.c
+++ b/demos/node-editor/node-editor-window.c
@@ -57,6 +57,7 @@ struct _NodeEditorWindow
   GtkWidget *testcase_cairo_checkbutton;
   GtkWidget *testcase_name_entry;
   GtkWidget *testcase_save_button;
+  GtkWidget *scale_scale;
 
   GtkWidget *renderer_listbox;
   GListStore *renderers;
@@ -171,6 +172,7 @@ text_changed (GtkTextBuffer    *buffer,
   GBytes *bytes;
   GtkTextIter iter;
   GtkTextIter start, end;
+  float scale;
 
   g_array_remove_range (self->errors, 0, self->errors->len);
   text = get_current_text (self->text_buffer);
@@ -181,6 +183,17 @@ text_changed (GtkTextBuffer    *buffer,
 
   /* If this is too slow, go fix the parser performance */
   self->node = gsk_render_node_deserialize (bytes, deserialize_error_func, self);
+
+  scale = gtk_scale_button_get_value (GTK_SCALE_BUTTON (self->scale_scale));
+  if (self->node && scale != 1.0)
+    {
+      GskRenderNode *node;
+
+      node = gsk_transform_node_new (self->node, gsk_transform_scale (NULL, scale, scale));
+      gsk_render_node_unref (self->node);
+      self->node = node;
+    }
+
   g_bytes_unref (bytes);
   if (self->node)
     {
@@ -277,6 +290,14 @@ text_changed (GtkTextBuffer    *buffer,
                                      &start, &end);
 }
 
+static void
+scale_changed (GObject          *object,
+               GParamSpec       *pspec,
+               NodeEditorWindow *self)
+{
+  text_changed (self->text_buffer, self);
+}
+
 static gboolean
 text_view_query_tooltip_cb (GtkWidget        *widget,
                             int               x,
@@ -962,6 +983,7 @@ node_editor_window_class_init (NodeEditorWindowClass *class)
   gtk_widget_class_bind_template_child (widget_class, NodeEditorWindow, testcase_cairo_checkbutton);
   gtk_widget_class_bind_template_child (widget_class, NodeEditorWindow, testcase_name_entry);
   gtk_widget_class_bind_template_child (widget_class, NodeEditorWindow, testcase_save_button);
+  gtk_widget_class_bind_template_child (widget_class, NodeEditorWindow, scale_scale);
 
   gtk_widget_class_bind_template_callback (widget_class, text_view_query_tooltip_cb);
   gtk_widget_class_bind_template_callback (widget_class, open_cb);
@@ -1068,6 +1090,7 @@ node_editor_window_init (NodeEditorWindow *self)
 
   self->text_buffer = gtk_text_buffer_new (self->tag_table);
   g_signal_connect (self->text_buffer, "changed", G_CALLBACK (text_changed), self);
+  g_signal_connect (self->scale_scale, "notify::value", G_CALLBACK (scale_changed), self);
   gtk_text_view_set_buffer (GTK_TEXT_VIEW (self->text_view), self->text_buffer);
 
   /* Default */
diff --git a/demos/node-editor/node-editor-window.ui b/demos/node-editor/node-editor-window.ui
index 0ac7142a04..74c87ce8e7 100644
--- a/demos/node-editor/node-editor-window.ui
+++ b/demos/node-editor/node-editor-window.ui
@@ -157,6 +157,23 @@
             <signal name="notify::active" handler="dark_mode_cb" swapped="0"/>
           </object>
         </child>
+        <child type="end">
+          <object class="GtkScaleButton" id="scale_scale">
+            <property name="focus-on-click">0</property>
+            <property name="valign">center</property>
+            <property name="adjustment">
+              <object class="GtkAdjustment">
+                <property name="lower">1</property>
+                <property name="value">1</property>
+                <property name="upper">10</property>
+                <property name="step-increment">0.1</property>
+                <property name="page-increment">0.5</property>
+              </object>
+            </property>
+            <property name="icons">zoom-in-symbolic</property>
+            <property name="tooltip-text" translatable="yes">Scale the image</property>
+          </object>
+        </child>
       </object>
     </child>
     <child>


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