/** * gtk_render_background_get_clip: * @context: a #GtkStyleContext * @x: X origin of the rectangle * @y: Y origin of the rectangle * @width: rectangle width * @height: rectangle height * @out_clip: (out): return location for the clip * * Returns the area that will be affected (i.e. drawn to) when * calling gtk_render_background() for the given @context and * rectangle. * * Since: 3.20 */ void gtk_render_background_get_clip (GtkStyleContext *context, gdouble x, gdouble y, gdouble width, gdouble height, GdkRectangle *out_clip) { GtkBorder shadow; _gtk_css_shadows_value_get_extents (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BOX_SHADOW), &shadow); out_clip->x = floor (x) - shadow.left; out_clip->y = floor (y) - shadow.top; out_clip->width = ceil (width) + shadow.left + shadow.right; out_clip->height = ceil (height) + shadow.top + shadow.bottom; }
/** * gtk_snapshot_render_layout: * @snapshot: a #GtkSnapshot * @context: the #GtkStyleContext to use * @x: X origin of the rectangle * @y: Y origin of the rectangle * @layout: the #PangoLayout to render * * Creates a render node for rendering @layout according to the style * information in @context, and appends it to the current node of @snapshot, * without changing the current node. * * Since: 3.90 */ void gtk_snapshot_render_layout (GtkSnapshot *snapshot, GtkStyleContext *context, gdouble x, gdouble y, PangoLayout *layout) { const GdkRGBA *fg_color; graphene_rect_t bounds; GtkBorder shadow_extents; PangoRectangle ink_rect; GtkCssValue *shadow; cairo_t *cr; g_return_if_fail (snapshot != NULL); g_return_if_fail (GTK_IS_STYLE_CONTEXT (context)); g_return_if_fail (PANGO_IS_LAYOUT (layout)); fg_color = _gtk_css_rgba_value_get_rgba (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_COLOR)); shadow = _gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_TEXT_SHADOW); pango_layout_get_pixel_extents (layout, &ink_rect, NULL); _gtk_css_shadows_value_get_extents (shadow, &shadow_extents); graphene_rect_init (&bounds, ink_rect.x - shadow_extents.left, ink_rect.y - shadow_extents.top, ink_rect.width + shadow_extents.left + shadow_extents.right, ink_rect.height + shadow_extents.top + shadow_extents.bottom); gtk_snapshot_translate_2d (snapshot, x, y); cr = gtk_snapshot_append_cairo_node (snapshot, &bounds, "Text<%dchars>", pango_layout_get_character_count (layout)); _gtk_css_shadows_value_paint_layout (shadow, cr, layout); gdk_cairo_set_source_rgba (cr, fg_color); pango_cairo_show_layout (cr, layout); cairo_destroy (cr); gtk_snapshot_translate_2d (snapshot, -x, -y); }
void gtk_css_style_render_icon_get_extents (GtkCssStyle *style, GdkRectangle *extents, gint x, gint y, gint width, gint height) { cairo_matrix_t transform_matrix, matrix; GtkBorder border; GdkRectangle rect; g_return_if_fail (GTK_IS_CSS_STYLE (style)); g_return_if_fail (extents != NULL); extents->x = x; extents->y = y; extents->width = width; extents->height = height; if (!_gtk_css_transform_value_get_matrix (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_ICON_TRANSFORM), &transform_matrix)) return; cairo_matrix_init_translate (&matrix, x + width / 2.0, y + height / 2.0); cairo_matrix_multiply (&matrix, &transform_matrix, &matrix); /* need to round to full pixels */ rect.x = - (width + 1) / 2; rect.y = - (height + 1) / 2; rect.width = (width + 1) & ~1; rect.height = (height + 1) & ~1; gtk_cairo_rectangle_transform (extents, &rect, &matrix); _gtk_css_shadows_value_get_extents (gtk_css_style_get_value (style, GTK_CSS_PROPERTY_ICON_SHADOW), &border); extents->x -= border.left; extents->y -= border.top; extents->width += border.left + border.right; extents->height += border.top + border.bottom; }