Add gtk_snapshot_append_scaled_texture

This is the snapshot api corresponding to
gsk_texture_scale_node_new.
This commit is contained in:
Matthias Clasen
2023-02-11 14:20:23 -05:00
parent 238e7ec351
commit 67c53e46f9
2 changed files with 47 additions and 0 deletions

View File

@@ -1918,6 +1918,10 @@ gtk_snapshot_append_cairo (GtkSnapshot *snapshot,
* Creates a new render node drawing the @texture
* into the given @bounds and appends it to the
* current render node of @snapshot.
*
* If the texture needs to be scaled to fill @bounds,
* linear filtering is used. See [method@Gtk.Snapshot.append_scaled_texture]
* if you need other filtering, such as nearest-neighbour.
*/
void
gtk_snapshot_append_texture (GtkSnapshot *snapshot,
@@ -1939,6 +1943,44 @@ gtk_snapshot_append_texture (GtkSnapshot *snapshot,
gtk_snapshot_append_node_internal (snapshot, node);
}
/**
* gtk_snapshot_append_scaled_texture:
* @snapshot: a `GtkSnapshot`
* @texture: the texture to render
* @filter: the filter to use
* @bounds: the bounds for the new node
*
* Creates a new render node drawing the @texture
* into the given @bounds and appends it to the
* current render node of @snapshot.
*
* In contrast to [method@Gtk.Snapshot.append_texture],
* this function provides control about how the filter
* that is used when scaling.
*
* Since: 4.10
*/
void
gtk_snapshot_append_scaled_texture (GtkSnapshot *snapshot,
GdkTexture *texture,
GskScalingFilter filter,
const graphene_rect_t *bounds)
{
GskRenderNode *node;
graphene_rect_t real_bounds;
float scale_x, scale_y, dx, dy;
g_return_if_fail (snapshot != NULL);
g_return_if_fail (GDK_IS_TEXTURE (texture));
g_return_if_fail (bounds != NULL);
gtk_snapshot_ensure_affine (snapshot, &scale_x, &scale_y, &dx, &dy);
gtk_graphene_rect_scale_affine (bounds, scale_x, scale_y, dx, dy, &real_bounds);
node = gsk_texture_scale_node_new (texture, &real_bounds, filter);
gtk_snapshot_append_node_internal (snapshot, node);
}
/**
* gtk_snapshot_append_color:
* @snapshot: a `GtkSnapshot`

View File

@@ -152,6 +152,11 @@ GDK_AVAILABLE_IN_ALL
void gtk_snapshot_append_texture (GtkSnapshot *snapshot,
GdkTexture *texture,
const graphene_rect_t *bounds);
GDK_AVAILABLE_IN_4_10
void gtk_snapshot_append_scaled_texture (GtkSnapshot *snapshot,
GdkTexture *texture,
GskScalingFilter filter,
const graphene_rect_t *bounds);
GDK_AVAILABLE_IN_ALL
void gtk_snapshot_append_color (GtkSnapshot *snapshot,
const GdkRGBA *color,