Merge branch 'node-editor-things' into 'main'

Revert "rendernodepaintable: Provide accurate aspect ratio"

See merge request GNOME/gtk!5788
This commit is contained in:
Matthias Clasen 2023-04-04 02:47:39 +00:00
commit a9a6371ceb
3 changed files with 29 additions and 24 deletions

View File

@ -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);
@ -204,18 +210,27 @@ text_changed (GtkTextBuffer *buffer,
graphene_rect_t bounds;
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))

View File

@ -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>

View File

@ -52,8 +52,8 @@ gtk_render_node_paintable_paintable_snapshot (GdkPaintable *paintable,
gtk_snapshot_save (snapshot);
gtk_snapshot_scale (snapshot,
width / (self->bounds.size.width),
height / (self->bounds.size.height));
width / ceilf (self->bounds.size.width),
height / ceilf (self->bounds.size.height));
gtk_snapshot_translate (snapshot, &GRAPHENE_POINT_INIT (-self->bounds.origin.x, -self->bounds.origin.y));
gtk_snapshot_push_clip (snapshot, &self->bounds);
@ -88,17 +88,6 @@ gtk_render_node_paintable_paintable_get_intrinsic_height (GdkPaintable *paintabl
return ceilf (self->bounds.size.height);
}
static double
gtk_render_node_paintable_paintable_get_intrinsic_aspect_ratio (GdkPaintable *paintable)
{
GtkRenderNodePaintable *self = GTK_RENDER_NODE_PAINTABLE (paintable);
if (self->bounds.size.height != 0)
return self->bounds.size.width / self->bounds.size.height;
return 0;
}
static void
gtk_render_node_paintable_paintable_init (GdkPaintableInterface *iface)
{
@ -106,7 +95,6 @@ gtk_render_node_paintable_paintable_init (GdkPaintableInterface *iface)
iface->get_flags = gtk_render_node_paintable_paintable_get_flags;
iface->get_intrinsic_width = gtk_render_node_paintable_paintable_get_intrinsic_width;
iface->get_intrinsic_height = gtk_render_node_paintable_paintable_get_intrinsic_height;
iface->get_intrinsic_aspect_ratio = gtk_render_node_paintable_paintable_get_intrinsic_aspect_ratio;
}
G_DEFINE_TYPE_EXTENDED (GtkRenderNodePaintable, gtk_render_node_paintable, G_TYPE_OBJECT, 0,