diff options
author | Matthias Clasen <mclasen@redhat.com> | 2023-04-03 22:32:31 -0400 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2023-04-03 22:33:34 -0400 |
commit | 6182f4a3326a9365d1e9ab18ad1b6522cf914f35 (patch) | |
tree | bf7a3c22db8851ab31ae14c81135525453807a78 | |
parent | 9ccde8b913f2e538185008d1ac38a4877538de6f (diff) | |
download | gtk+-6182f4a3326a9365d1e9ab18ad1b6522cf914f35.tar.gz |
node-editor: Improve the scaling
We only want to scale the main rendering, not whats
shown in the sidebar. Also, make the scale logarithmic.
-rw-r--r-- | demos/node-editor/node-editor-window.c | 31 | ||||
-rw-r--r-- | demos/node-editor/node-editor-window.ui | 6 |
2 files changed, 27 insertions, 10 deletions
diff --git a/demos/node-editor/node-editor-window.c b/demos/node-editor/node-editor-window.c index 5c38140162..5678b6869d 100644 --- a/demos/node-editor/node-editor-window.c +++ b/demos/node-editor/node-editor-window.c @@ -174,6 +174,7 @@ text_changed (GtkTextBuffer *buffer, GtkTextIter iter; GtkTextIter start, end; float scale; + GskRenderNode *big_node; g_array_remove_range (self->errors, 0, self->errors->len); text = get_current_text (self->text_buffer); @@ -186,13 +187,18 @@ text_changed (GtkTextBuffer *buffer, 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) + if (self->node && scale != 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; + scale = pow (2., scale); + big_node = gsk_transform_node_new (self->node, gsk_transform_scale (NULL, scale, scale)); + } + else if (self->node) + { + big_node = gsk_render_node_ref (self->node); + } + else + { + big_node = NULL; } g_bytes_unref (bytes); @@ -205,17 +211,26 @@ text_changed (GtkTextBuffer *buffer, guint i; snapshot = gtk_snapshot_new (); + gsk_render_node_get_bounds (big_node, &bounds); + gtk_snapshot_translate (snapshot, &GRAPHENE_POINT_INIT (- bounds.origin.x, - bounds.origin.y)); + gtk_snapshot_append_node (snapshot, big_node); + paintable = gtk_snapshot_free_to_paintable (snapshot, &bounds.size); + gtk_picture_set_paintable (GTK_PICTURE (self->picture), paintable); + g_clear_object (&paintable); + + snapshot = gtk_snapshot_new (); gsk_render_node_get_bounds (self->node, &bounds); gtk_snapshot_translate (snapshot, &GRAPHENE_POINT_INIT (- bounds.origin.x, - bounds.origin.y)); gtk_snapshot_append_node (snapshot, self->node); paintable = gtk_snapshot_free_to_paintable (snapshot, &bounds.size); - gtk_picture_set_paintable (GTK_PICTURE (self->picture), paintable); + for (i = 0; i < g_list_model_get_n_items (G_LIST_MODEL (self->renderers)); i++) { gpointer item = g_list_model_get_item (G_LIST_MODEL (self->renderers), i); gtk_renderer_paintable_set_paintable (item, paintable); g_object_unref (item); } + g_clear_object (&paintable); } else @@ -223,6 +238,8 @@ text_changed (GtkTextBuffer *buffer, gtk_picture_set_paintable (GTK_PICTURE (self->picture), NULL); } + g_clear_pointer (&big_node, gsk_render_node_unref); + gtk_text_buffer_get_start_iter (self->text_buffer, &iter); while (!gtk_text_iter_is_end (&iter)) diff --git a/demos/node-editor/node-editor-window.ui b/demos/node-editor/node-editor-window.ui index 34d4452a4a..45a37cd952 100644 --- a/demos/node-editor/node-editor-window.ui +++ b/demos/node-editor/node-editor-window.ui @@ -163,9 +163,9 @@ <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="lower">-4</property> + <property name="value">0</property> + <property name="upper">4</property> <property name="step-increment">0.1</property> <property name="page-increment">0.5</property> </object> |