/** * gtk_render_icon: * @context: a #GtkStyleContext * @cr: a #cairo_t * @pixbuf: a #GdkPixbuf containing the icon to draw * @x: X position for the @pixbuf * @y: Y position for the @pixbuf * * Renders the icon in @pixbuf at the specified @x and @y coordinates. * * This function will render the icon in @pixbuf at exactly its size, * regardless of scaling factors, which may not be appropriate when * drawing on displays with high pixel densities. * * You probably want to use gtk_render_icon_surface() instead, if you * already have a Cairo surface. * * Since: 3.2 **/ void gtk_render_icon (GtkStyleContext *context, cairo_t *cr, GdkPixbuf *pixbuf, gdouble x, gdouble y) { cairo_surface_t *surface; g_return_if_fail (GTK_IS_STYLE_CONTEXT (context)); g_return_if_fail (cr != NULL); cairo_save (cr); cairo_new_path (cr); surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, 1, NULL); gtk_css_style_render_icon_surface (gtk_style_context_lookup_style (context), cr, surface, x, y); cairo_surface_destroy (surface); cairo_restore (cr); }
/** * gtk_render_frame: * @context: a #GtkStyleContext * @cr: a #cairo_t * @x: X origin of the rectangle * @y: Y origin of the rectangle * @width: rectangle width * @height: rectangle height * * Renders a frame around the rectangle defined by @x, @y, @width, @height. * * Examples of frame rendering, showing the effect of `border-image`, * `border-color`, `border-width`, `border-radius` and junctions: * * ![](frames.png) * * Since: 3.0 **/ void gtk_render_frame (GtkStyleContext *context, cairo_t *cr, gdouble x, gdouble y, gdouble width, gdouble height) { g_return_if_fail (GTK_IS_STYLE_CONTEXT (context)); g_return_if_fail (cr != NULL); if (width <= 0 || height <= 0) return; cairo_save (cr); cairo_new_path (cr); gtk_css_style_render_border (gtk_style_context_lookup_style (context), cr, x, y, width, height, 0, gtk_style_context_get_junction_sides (context)); cairo_restore (cr); }
static void gtk_do_render_slider (GtkStyleContext *context, cairo_t *cr, gdouble x, gdouble y, gdouble width, gdouble height, GtkOrientation orientation) { GtkCssStyle *style; GtkJunctionSides junction; style = gtk_style_context_lookup_style (context); junction = gtk_style_context_get_junction_sides (context); gtk_css_style_render_background (style, cr, x, y, width, height, junction); gtk_css_style_render_border (style, cr, x, y, width, height, 0, junction); }
/** * gtk_render_frame_gap: * @context: a #GtkStyleContext * @cr: a #cairo_t * @x: X origin of the rectangle * @y: Y origin of the rectangle * @width: rectangle width * @height: rectangle height * @gap_side: side where the gap is * @xy0_gap: initial coordinate (X or Y depending on @gap_side) for the gap * @xy1_gap: end coordinate (X or Y depending on @gap_side) for the gap * * Renders a frame around the rectangle defined by (@x, @y, @width, @height), * leaving a gap on one side. @xy0_gap and @xy1_gap will mean X coordinates * for %GTK_POS_TOP and %GTK_POS_BOTTOM gap sides, and Y coordinates for * %GTK_POS_LEFT and %GTK_POS_RIGHT. * * Typical rendering of a frame with a gap: * * ![](frame-gap.png) * * Since: 3.0 **/ void gtk_render_frame_gap (GtkStyleContext *context, cairo_t *cr, gdouble x, gdouble y, gdouble width, gdouble height, GtkPositionType gap_side, gdouble xy0_gap, gdouble xy1_gap) { g_return_if_fail (GTK_IS_STYLE_CONTEXT (context)); g_return_if_fail (cr != NULL); g_return_if_fail (xy0_gap <= xy1_gap); g_return_if_fail (xy0_gap >= 0); if (width <= 0 || height <= 0) return; if (gap_side == GTK_POS_LEFT || gap_side == GTK_POS_RIGHT) g_return_if_fail (xy1_gap <= height); else g_return_if_fail (xy1_gap <= width); gtk_css_style_render_frame_gap (gtk_style_context_lookup_style (context), cr, x, y, width, height, gap_side, xy0_gap, xy1_gap); }
/** * gtk_render_extension: * @context: a #GtkStyleContext * @cr: a #cairo_t * @x: X origin of the rectangle * @y: Y origin of the rectangle * @width: rectangle width * @height: rectangle height * @gap_side: side where the gap is * * Renders a extension (as in a #GtkNotebook tab) in the rectangle * defined by @x, @y, @width, @height. The side where the extension * connects to is defined by @gap_side. * * Typical extension rendering: * * ![](extensions.png) * * Since: 3.0 **/ void gtk_render_extension (GtkStyleContext *context, cairo_t *cr, gdouble x, gdouble y, gdouble width, gdouble height, GtkPositionType gap_side) { g_return_if_fail (GTK_IS_STYLE_CONTEXT (context)); g_return_if_fail (cr != NULL); if (width <= 0 || height <= 0) return; cairo_save (cr); cairo_new_path (cr); gtk_css_style_render_extension (gtk_style_context_lookup_style (context), cr, x, y, width, height, gap_side); cairo_restore (cr); }
static void gtk_do_render_arrow (GtkStyleContext *context, cairo_t *cr, gdouble angle, gdouble x, gdouble y, gdouble size) { GtkCssImageBuiltinType image_type; /* map [0, 2 * pi) to [0, 4) */ angle = round (2 * angle / G_PI); switch (((int) angle) & 3) { case 0: image_type = GTK_CSS_IMAGE_BUILTIN_ARROW_UP; break; case 1: image_type = GTK_CSS_IMAGE_BUILTIN_ARROW_RIGHT; break; case 2: image_type = GTK_CSS_IMAGE_BUILTIN_ARROW_DOWN; break; case 3: image_type = GTK_CSS_IMAGE_BUILTIN_ARROW_LEFT; break; default: g_assert_not_reached (); image_type = GTK_CSS_IMAGE_BUILTIN_ARROW_UP; break; } gtk_css_style_render_icon (gtk_style_context_lookup_style (context), cr, x, y, size, size, image_type); }
/* * gtk_render_content_path: * @context: style context to get style information from * @cr: cairo context to add path to * @x: x coordinate of CSS box * @y: y coordinate of CSS box * @width: width of CSS box * @height: height of CSS box * * Adds the path of the content box to @cr for a given border box. * This function respects rounded corners. * * This is useful if you are drawing content that is supposed to * fill the whole content area, like the color buttons in * #GtkColorChooserDialog. **/ void gtk_render_content_path (GtkStyleContext *context, cairo_t *cr, double x, double y, double width, double height) { GtkRoundedBox box; g_return_if_fail (GTK_IS_STYLE_CONTEXT (context)); g_return_if_fail (cr != NULL); _gtk_rounded_box_init_rect (&box, x, y, width, height); _gtk_rounded_box_apply_border_radius_for_style (&box, gtk_style_context_lookup_style (context), 0); _gtk_rounded_box_shrink (&box, _gtk_css_number_value_get (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BORDER_TOP_WIDTH), 100) + _gtk_css_number_value_get (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_PADDING_TOP), 100), _gtk_css_number_value_get (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BORDER_RIGHT_WIDTH), 100) + _gtk_css_number_value_get (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_PADDING_RIGHT), 100), _gtk_css_number_value_get (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BORDER_BOTTOM_WIDTH), 100) + _gtk_css_number_value_get (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_PADDING_BOTTOM), 100), _gtk_css_number_value_get (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BORDER_LEFT_WIDTH), 100) + _gtk_css_number_value_get (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_PADDING_LEFT), 100)); _gtk_rounded_box_path (&box, cr); }
/** * gtk_render_icon_surface: * @context: a #GtkStyleContext * @cr: a #cairo_t * @surface: a #cairo_surface_t containing the icon to draw * @x: X position for the @icon * @y: Y position for the @incon * * Renders the icon in @surface at the specified @x and @y coordinates. * * Since: 3.10 **/ void gtk_render_icon_surface (GtkStyleContext *context, cairo_t *cr, cairo_surface_t *surface, gdouble x, gdouble y) { g_return_if_fail (GTK_IS_STYLE_CONTEXT (context)); g_return_if_fail (cr != NULL); gtk_css_style_render_icon_surface (gtk_style_context_lookup_style (context), cr, surface, x, y); }
static void gtk_do_render_handle (GtkStyleContext *context, cairo_t *cr, gdouble x, gdouble y, gdouble width, gdouble height) { GtkCssImageBuiltinType type; gtk_render_background (context, cr, x, y, width, height); gtk_render_frame (context, cr, x, y, width, height); if (gtk_style_context_has_class (context, GTK_STYLE_CLASS_GRIP)) { GtkJunctionSides sides = gtk_style_context_get_junction_sides (context); /* order is important here for when too many (or too few) sides are set */ if ((sides & GTK_JUNCTION_CORNER_BOTTOMRIGHT) == GTK_JUNCTION_CORNER_BOTTOMRIGHT) type = GTK_CSS_IMAGE_BUILTIN_GRIP_BOTTOMRIGHT; else if ((sides & GTK_JUNCTION_CORNER_TOPRIGHT) == GTK_JUNCTION_CORNER_TOPRIGHT) type = GTK_CSS_IMAGE_BUILTIN_GRIP_TOPRIGHT; else if ((sides & GTK_JUNCTION_CORNER_BOTTOMLEFT) == GTK_JUNCTION_CORNER_BOTTOMLEFT) type = GTK_CSS_IMAGE_BUILTIN_GRIP_BOTTOMLEFT; else if ((sides & GTK_JUNCTION_CORNER_TOPLEFT) == GTK_JUNCTION_CORNER_TOPLEFT) type = GTK_CSS_IMAGE_BUILTIN_GRIP_TOPLEFT; else if (sides & GTK_JUNCTION_RIGHT) type = GTK_CSS_IMAGE_BUILTIN_GRIP_RIGHT; else if (sides & GTK_JUNCTION_BOTTOM) type = GTK_CSS_IMAGE_BUILTIN_GRIP_BOTTOM; else if (sides & GTK_JUNCTION_TOP) type = GTK_CSS_IMAGE_BUILTIN_GRIP_TOP; else if (sides & GTK_JUNCTION_LEFT) type = GTK_CSS_IMAGE_BUILTIN_GRIP_LEFT; else type = GTK_CSS_IMAGE_BUILTIN_GRIP_BOTTOMRIGHT; } else if (gtk_style_context_has_class (context, GTK_STYLE_CLASS_PANE_SEPARATOR)) { type = GTK_CSS_IMAGE_BUILTIN_PANE_SEPARATOR; } else { type = GTK_CSS_IMAGE_BUILTIN_HANDLE; } gtk_css_style_render_icon (gtk_style_context_lookup_style (context), cr, x, y, width, height, type); }
/** * gtk_render_activity: * @context: a #GtkStyleContext * @cr: a #cairo_t * @x: X origin of the rectangle * @y: Y origin of the rectangle * @width: rectangle width * @height: rectangle height * * Renders an activity indicator (such as in #GtkSpinner). * The state %GTK_STATE_FLAG_CHECKED determines whether there is * activity going on. * * Since: 3.0 **/ void gtk_render_activity (GtkStyleContext *context, cairo_t *cr, gdouble x, gdouble y, gdouble width, gdouble height) { g_return_if_fail (GTK_IS_STYLE_CONTEXT (context)); g_return_if_fail (cr != NULL); if (width <= 0 || height <= 0) return; gtk_css_style_render_icon (gtk_style_context_lookup_style (context), cr, x, y, width, height, GTK_CSS_IMAGE_BUILTIN_SPINNER); }
/** * gtk_render_background: * @context: a #GtkStyleContext * @cr: a #cairo_t * @x: X origin of the rectangle * @y: Y origin of the rectangle * @width: rectangle width * @height: rectangle height * * Renders the background of an element. * * Typical background rendering, showing the effect of * `background-image`, `border-width` and `border-radius`: * * ![](background.png) * * Since: 3.0. **/ void gtk_render_background (GtkStyleContext *context, cairo_t *cr, gdouble x, gdouble y, gdouble width, gdouble height) { g_return_if_fail (GTK_IS_STYLE_CONTEXT (context)); g_return_if_fail (cr != NULL); if (width <= 0 || height <= 0) return; gtk_css_style_render_background (gtk_style_context_lookup_style (context), cr, x, y, width, height); }
/** * gtk_snapshot_render_focus: * @snapshot: a #GtkSnapshot * @context: the #GtkStyleContext to use * @x: X origin of the rectangle * @y: Y origin of the rectangle * @width: rectangle width * @height: rectangle height * * Creates a render node for the focus outline according to @context, * and appends it to the current node of @snapshot, without changing * the current node. * * Since: 3.90 */ void gtk_snapshot_render_focus (GtkSnapshot *snapshot, GtkStyleContext *context, gdouble x, gdouble y, gdouble width, gdouble height) { g_return_if_fail (snapshot != NULL); g_return_if_fail (GTK_IS_STYLE_CONTEXT (context)); gtk_snapshot_translate_2d (snapshot, x, y); gtk_css_style_snapshot_outline (gtk_style_context_lookup_style (context), snapshot, width, height); gtk_snapshot_translate_2d (snapshot, -x, -y); }
/** * gtk_snapshot_render_icon: * @snapshot: a #GtkSnapshot * @context: the #GtkStyleContext to use * @pixbuf: the #GdkPixbuf to render * @x: X origin of the rectangle * @y: Y origin of the rectangle * * Creates a render node for rendering @pixbuf 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_icon (GtkSnapshot *snapshot, GtkStyleContext *context, GdkPixbuf *pixbuf, gdouble x, gdouble y) { GskTexture *texture; texture = gsk_texture_new_for_pixbuf (pixbuf); gtk_snapshot_translate_2d (snapshot, x, y); gtk_css_style_snapshot_icon_texture (gtk_style_context_lookup_style (context), snapshot, texture, 1); gtk_snapshot_translate_2d (snapshot, -x, -y); gsk_texture_unref (texture); }
static void gtk_do_render_check (GtkStyleContext *context, cairo_t *cr, gdouble x, gdouble y, gdouble width, gdouble height) { GtkStateFlags state; GtkCssImageBuiltinType image_type; state = gtk_style_context_get_state (context); if (state & GTK_STATE_FLAG_INCONSISTENT) image_type = GTK_CSS_IMAGE_BUILTIN_CHECK_INCONSISTENT; else if (state & GTK_STATE_FLAG_CHECKED) image_type = GTK_CSS_IMAGE_BUILTIN_CHECK_CHECKED; else image_type = GTK_CSS_IMAGE_BUILTIN_CHECK; gtk_css_style_render_icon (gtk_style_context_lookup_style (context), cr, x, y, width, height, image_type); }
/** * gtk_render_focus: * @context: a #GtkStyleContext * @cr: a #cairo_t * @x: X origin of the rectangle * @y: Y origin of the rectangle * @width: rectangle width * @height: rectangle height * * Renders a focus indicator on the rectangle determined by @x, @y, @width, @height. * * Typical focus rendering: * * ![](focus.png) * * Since: 3.0 **/ void gtk_render_focus (GtkStyleContext *context, cairo_t *cr, gdouble x, gdouble y, gdouble width, gdouble height) { g_return_if_fail (GTK_IS_STYLE_CONTEXT (context)); g_return_if_fail (cr != NULL); if (width <= 0 || height <= 0) return; cairo_save (cr); cairo_new_path (cr); gtk_css_style_render_outline (gtk_style_context_lookup_style (context), cr, x, y, width, height); cairo_restore (cr); }
static void gtk_do_render_expander (GtkStyleContext *context, cairo_t *cr, gdouble x, gdouble y, gdouble width, gdouble height) { GtkCssImageBuiltinType image_type; GtkStateFlags state; state = gtk_style_context_get_state (context); if (gtk_style_context_has_class (context, "horizontal")) { if (state & GTK_STATE_FLAG_DIR_RTL) image_type = (state & GTK_STATE_FLAG_CHECKED) ? GTK_CSS_IMAGE_BUILTIN_EXPANDER_HORIZONTAL_RIGHT_EXPANDED : GTK_CSS_IMAGE_BUILTIN_EXPANDER_HORIZONTAL_RIGHT; else image_type = (state & GTK_STATE_FLAG_CHECKED) ? GTK_CSS_IMAGE_BUILTIN_EXPANDER_HORIZONTAL_LEFT_EXPANDED : GTK_CSS_IMAGE_BUILTIN_EXPANDER_HORIZONTAL_LEFT; } else { if (state & GTK_STATE_FLAG_DIR_RTL) image_type = (state & GTK_STATE_FLAG_CHECKED) ? GTK_CSS_IMAGE_BUILTIN_EXPANDER_VERTICAL_RIGHT_EXPANDED : GTK_CSS_IMAGE_BUILTIN_EXPANDER_VERTICAL_RIGHT; else image_type = (state & GTK_STATE_FLAG_CHECKED) ? GTK_CSS_IMAGE_BUILTIN_EXPANDER_VERTICAL_LEFT_EXPANDED : GTK_CSS_IMAGE_BUILTIN_EXPANDER_VERTICAL_LEFT; } gtk_css_style_render_icon (gtk_style_context_lookup_style (context), cr, x, y, width, height, image_type); }
static void gtk_do_render_handle (GtkStyleContext *context, cairo_t *cr, gdouble x, gdouble y, gdouble width, gdouble height) { GtkCssImageBuiltinType type; gtk_render_background (context, cr, x, y, width, height); gtk_render_frame (context, cr, x, y, width, height); if (gtk_style_context_has_class (context, GTK_STYLE_CLASS_PANE_SEPARATOR)) { type = GTK_CSS_IMAGE_BUILTIN_PANE_SEPARATOR; } else { type = GTK_CSS_IMAGE_BUILTIN_HANDLE; } gtk_css_style_render_icon (gtk_style_context_lookup_style (context), cr, x, y, width, height, type); }