diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt index 191363ae5d..4882717c79 100644 --- a/docs/reference/gtk/gtk4-sections.txt +++ b/docs/reference/gtk/gtk4-sections.txt @@ -4462,6 +4462,8 @@ gtk_snapshot_transform gtk_snapshot_translate_2d gtk_snapshot_append_node gtk_snapshot_append_cairo_node +gtk_snapshot_append_texture_node +gtk_snapshot_append_color_node gtk_snapshot_clips_rect gtk_snapshot_render_background gtk_snapshot_render_frame diff --git a/gtk/gtkrendericon.c b/gtk/gtkrendericon.c index 082f87d7d2..9be7201e83 100644 --- a/gtk/gtkrendericon.c +++ b/gtk/gtkrendericon.c @@ -297,17 +297,11 @@ gtk_css_style_snapshot_icon_texture (GtkCssStyle *style, if (graphene_matrix_is_identity (&transform_matrix)) { - double offset_x, offset_y; - - gtk_snapshot_get_offset (snapshot, &offset_x, &offset_y); graphene_rect_init (&bounds, - offset_x, offset_y, + 0, 0, gsk_texture_get_width (texture) / texture_scale, gsk_texture_get_height (texture) / texture_scale); - icon_node = gsk_texture_node_new (texture, &bounds); - gsk_render_node_set_name (icon_node, "Icon"); - - gtk_snapshot_append_node (snapshot, icon_node); + gtk_snapshot_append_texture_node (snapshot, texture, &bounds, "Icon"); } else { diff --git a/gtk/gtksnapshot.c b/gtk/gtksnapshot.c index ff0eda2dd7..9ba07a5c4c 100644 --- a/gtk/gtksnapshot.c +++ b/gtk/gtksnapshot.c @@ -374,6 +374,100 @@ gtk_snapshot_append_cairo_node (GtkSnapshot *snapshot, return cr; } +/** + * gtk_snapshot_append_texture_node: + * @snapshot: a #GtkSnapshot + * @texture: the #GskTexture to render + * @bounds: the bounds for the new node + * @name: (transfer none): a printf() style format string for the name for the new node + * @...: arguments to insert into the format string + * + * Creates a new render node drawing the @texture into the given @bounds and appends it + * to the current render node of @snapshot. + **/ +void +gtk_snapshot_append_texture_node (GtkSnapshot *snapshot, + GskTexture *texture, + const graphene_rect_t *bounds, + const char *name, + ...) +{ + GskRenderNode *node; + graphene_rect_t real_bounds; + + g_return_if_fail (snapshot != NULL); + g_return_if_fail (GSK_IS_TEXTURE (texture)); + g_return_if_fail (bounds != NULL); + + graphene_rect_offset_r (bounds, snapshot->state->translate_x, snapshot->state->translate_y, &real_bounds); + node = gsk_texture_node_new (texture, &real_bounds); + + if (name) + { + va_list args; + char *str; + + va_start (args, name); + str = g_strdup_vprintf (name, args); + va_end (args); + + gsk_render_node_set_name (node, str); + + g_free (str); + } + + gtk_snapshot_append_node (snapshot, node); + gsk_render_node_unref (node); +} + +/** + * gtk_snapshot_append_color_node: + * @snapshot: a #GtkSnapshot + * @color: the #GdkRGBA to draw + * @bounds: the bounds for the new node + * @name: (transfer none): a printf() style format string for the name for the new node + * @...: arguments to insert into the format string + * + * Creates a new render node drawing the @color into the given @bounds and appends it + * to the current render node of @snapshot. + * + * You should try to avoid calling this function if @color is transparent. + **/ +void +gtk_snapshot_append_color_node (GtkSnapshot *snapshot, + const GdkRGBA *color, + const graphene_rect_t *bounds, + const char *name, + ...) +{ + GskRenderNode *node; + graphene_rect_t real_bounds; + + g_return_if_fail (snapshot != NULL); + g_return_if_fail (color != NULL); + g_return_if_fail (bounds != NULL); + + graphene_rect_offset_r (bounds, snapshot->state->translate_x, snapshot->state->translate_y, &real_bounds); + node = gsk_color_node_new (color, &real_bounds); + + if (name) + { + va_list args; + char *str; + + va_start (args, name); + str = g_strdup_vprintf (name, args); + va_end (args); + + gsk_render_node_set_name (node, str); + + g_free (str); + } + + gtk_snapshot_append_node (snapshot, node); + gsk_render_node_unref (node); +} + static void rectangle_init_from_graphene (cairo_rectangle_int_t *cairo, const graphene_rect_t *graphene) diff --git a/gtk/gtksnapshot.h b/gtk/gtksnapshot.h index 2c62533400..8a2cc4ac1e 100644 --- a/gtk/gtksnapshot.h +++ b/gtk/gtksnapshot.h @@ -64,6 +64,18 @@ cairo_t * gtk_snapshot_append_cairo_node (GtkSnapshot const graphene_rect_t *bounds, const char *name, ...) G_GNUC_PRINTF(3, 4); +GDK_AVAILABLE_IN_3_90 +void gtk_snapshot_append_texture_node (GtkSnapshot *snapshot, + GskTexture *texture, + const graphene_rect_t *bounds, + const char *name, + ...) G_GNUC_PRINTF (4, 5); +GDK_AVAILABLE_IN_3_90 +void gtk_snapshot_append_color_node (GtkSnapshot *snapshot, + const GdkRGBA *color, + const graphene_rect_t *bounds, + const char *name, + ...) G_GNUC_PRINTF (4, 5); GDK_AVAILABLE_IN_3_90 gboolean gtk_snapshot_clips_rect (GtkSnapshot *snapshot,