Basics

Guides

API Reference

Menu

Basics

Guides

API Reference

class: Snapshot

[23:7] extends: object

Assists in creating [class@Gsk.RenderNode]s for widgets. It functions in a similar way to a cairo context, and maintains a stack of render nodes and their associated transformations. The node at the top of the stack is the one that gtk_snapshot_append_…() functions operate on. Use the gtk_snapshot_push_…() functions and [method@Snapshot.pop] to change the current node. The typical way to obtain a GtkSnapshot object is as an argument to the [vfunc@Gtk.Widget.snapshot] vfunc. If you need to create your own GtkSnapshot, use [ctor@Gtk.Snapshot.new]. Note that GtkSnapshot applies some optimizations, so the node it produces may not match the API calls 1:1. For example, it will omit clip nodes if the child node is entirely contained within the clip rectangle.

Members

  • handleObj
  • lib
  • retainedCallbacks
  • signalHandlerNames
  • signalSetterHandlers

Methods

  • Snapshot ()

    Creates a new GtkSnapshot.

  • toNativeHandle (Source)

    Normalizes a constructor argument into a raw pointer carrier. Accepts a raw NativeHandle, a raw NativeBuffer returned from fn.call(...), another generated wrapper exposing handle(), or null. Returns null when the argument carries no pointer.

    • @p Source is the raw handle, raw buffer, wrapper, or null.
    • @r A raw pointer carrier or null when no pointer is present.
  • getLib ()

    Returns the opened native library for this generated wrapper.

    • @r The opened native library.
  • handle ()

    Returns the wrapped NativeHandle.

    • @r The wrapped NativeHandle.
  • isNull ()

    Returns true when the wrapped handle is null.

    • @r A bool.
  • describe ()

    Returns a small string for debugging generated wrappers.

    • @r A string.
  • asSnapshot ()

    Wraps this handle as Snapshot.

    • @r A Snapshot object.
  • append_cairo (object bounds)

    Creates a new [class@Gsk.CairoNode] and appends it to the current render node of @snapshot, without changing the current node.

    • @p bounds is the bounds for the new node.
  • append_color (color, object bounds)

    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.

    • @p color is the color to draw.
    • @p bounds is the bounds for the new node.
    • @r None.
  • append_fill (object path, string fill_rule, color)

    A convenience method to fill a path with a color. See [method@Gtk.Snapshot.push_fill] if you need to fill a path with more complex content than a color.

    • @p path is The path describing the area to fill.
    • @p fill_rule is The fill rule to use.
    • @p color is the color to fill the path with.
    • @r None.
  • append_inset_shadow (object outline, color, double dx, double dy, double spread, double blur_radius)

    Appends an inset shadow into the box given by @outline.

    • @p outline is outline of the region surrounded by shadow.
    • @p color is color of the shadow.
    • @p dx is horizontal offset of shadow.
    • @p dy is vertical offset of shadow.
    • @p spread is how far the shadow spreads towards the inside.
    • @p blur_radius is how much blur to apply to the shadow.
    • @r None.
  • append_layout (object layout, color)

    Creates render nodes for rendering @layout in the given foregound @color and appends them to the current node of @snapshot without changing the current node. The current theme's foreground color for a widget can be obtained with [method@Gtk.Widget.get_color]. Note that if the layout does not produce any visible output, then nodes may not be added to the

    • @snapshot. ``
    • @p layout is the PangoLayout to render.
    • @p color is the foreground color to render the layout in.
    • @r None.
  • append_node (object node)

    Appends @node to the current render node of @snapshot, without changing the current node. If @snapshot does not have a current node yet, @node will become the initial node.

    • @p node is a GskRenderNode.
    • @r None.
  • append_outset_shadow (object outline, color, double dx, double dy, double spread, double blur_radius)

    Appends an outset shadow node around the box given by @outline.

    • @p outline is outline of the region surrounded by shadow.
    • @p color is color of the shadow.
    • @p dx is horizontal offset of shadow.
    • @p dy is vertical offset of shadow.
    • @p spread is how far the shadow spreads towards the outside.
    • @p blur_radius is how much blur to apply to the shadow.
    • @r None.
  • append_paste (object bounds, int nth)

    Creates a new render node that pastes the contents copied by a previous call to [method@Gtk.Snapshot.push_copy]

    • @p bounds is the bounds for the new node.
    • @p nth is the index of the copy, with 0 being the latest copy, 1 being the copy before that, and so on..
    • @r None.
  • append_scaled_texture (object texture, string filter, object bounds)

    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.

    • @p texture is the texture to render.
    • @p filter is the filter to use.
    • @p bounds is the bounds for the new node.
    • @r None.
  • append_stroke (object path, object stroke, color)

    A convenience method to stroke a path with a color. See [method@Gtk.Snapshot.push_stroke] if you need to stroke a path with more complex content than a color.

    • @p path is The path describing the area to fill.
    • @p stroke is The stroke attributes.
    • @p color is the color to fill the path with.
    • @r None.
  • append_texture (object texture, object bounds)

    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.

    • @p texture is the texture to render.
    • @p bounds is the bounds for the new node.
    • @r None.
  • free_to_node ()

    Returns the node that was constructed by @snapshot and frees @snapshot. See also [method@Gtk.Snapshot.to_node].

  • free_to_paintable (size)

    Returns a paintable for the node that was constructed by @snapshot and frees @snapshot.

    • @p size is The size of the resulting paintable or %NULL to use the bounds of the snapshot.
  • gl_shader_pop_texture ()

    Removes the top element from the stack of render nodes and adds it to the nearest [class@Gsk.GLShaderNode] below it. This must be called the same number of times as the number of textures is needed for the shader in [method@Gtk.Snapshot.push_gl_shader].

    • @r None.
  • perspective (double depth)

    Applies a perspective projection transform. See [method@Gsk.Transform.perspective] for a discussion on the details.

    • @p depth is distance of the z=0 plane.
    • @r None.
  • pop ()

    Removes the top element from the stack of render nodes, and appends it to the node underneath it.

    • @r None.
  • push_blend (string blend_mode)

    Blends together two images with the given blend mode. Until the first call to [method@Gtk.Snapshot.pop], the bottom image for the blend operation will be recorded. After that call, the top image to be blended will be recorded until the second call to [method@Gtk.Snapshot.pop]. Calling this function requires two subsequent calls to [method@Gtk.Snapshot.pop].

    • @p blend_mode is blend mode to use.
    • @r None.
  • push_blur (double radius)

    Blurs an image. The image is recorded until the next call to [method@Gtk.Snapshot.pop].

    • @p radius is the blur radius to use. Must be positive.
    • @r None.
  • push_clip (object bounds)

    Clips an image to a rectangle. The image is recorded until the next call to [method@Gtk.Snapshot.pop].

    • @p bounds is the rectangle to clip to.
    • @r None.
  • push_color_matrix (object color_matrix, object color_offset)

    Modifies the colors of an image by applying an affine transformation in RGB space. In particular, the colors will be transformed by applying pixel = transpose(color_matrix) * pixel + color_offset for every pixel. The transformation operates on unpremultiplied colors, with color components ordered R, G, B, A. The image is recorded until the next call to [method@Gtk.Snapshot.pop].

    • @p color_matrix is the color matrix to use.
    • @p color_offset is the color offset to use.
    • @r None.
  • push_component_transfer (object red, object green, object blue, object alpha)

    Modifies the colors of an image by applying a transfer function for each component. The transfer functions operate on unpremultiplied colors. The image is recorded until the next call to [method@Gtk.Snapshot.pop].

    • @p red is the transfer for the red component.
    • @p green is the transfer for the green component.
    • @p blue is the transfer for the blue component.
    • @p alpha is the transfer for the alpha component.
    • @r None.
  • push_composite (string op)

    Until the first call to [method@Gtk.Snapshot.pop], the mask image for the mask operation will be recorded. After that call, the child image will be recorded until the second call to [method@Gtk.Snapshot.pop]. Calling this function requires 2 subsequent calls to gtk_snapshot_pop().

    • @p op is The Porter/Duff compositing operator to use.
    • @r None.
  • push_copy ()

    Stores the current rendering state for later pasting via [method@Gtk.Snapshot.append_paste]. Pasting is possible until the matching call to [method@Gtk.Snapshot.pop].

    • @r None.
  • push_cross_fade (double progress)

    Snapshots a cross-fade operation between two images with the given

    • @progress. Until the first call to [method@Gtk.Snapshot.pop], the start image will be snapshot. After that call, the end image will be recorded until the second call to [method@Gtk.Snapshot.pop]. Calling this function requires two subsequent calls to [method@Gtk.Snapshot.pop].
    • @p progress is progress between 0.0 and 1.0.
    • @r None.
  • push_fill (object path, string fill_rule)

    Fills the area given by @path and @fill_rule with an image and discards everything outside of it. The image is recorded until the next call to [method@Gtk.Snapshot.pop]. If you want to fill the path with a color, [method@Gtk.Snapshot.append_fill] than rendering new ones, use [method@Gtk.Snapshot.append_fill] may be more convenient.

    • @p path is The path describing the area to fill.
    • @p fill_rule is The fill rule to use.
    • @r None.
  • push_gl_shader (object shader, object bounds, object take_args)

    Push a [class@Gsk.GLShaderNode]. The node uses the given [class@Gsk.GLShader] and uniform values Additionally this takes a list of

    • @n_children other nodes which will be passed to the [class@Gsk.GLShaderNode]. The @take_args argument is a block of data to use for uniform arguments, as per types and offsets defined by the
    • @shader. Normally this is generated by [method@Gsk.GLShader.format_args] or [struct@Gsk.ShaderArgsBuilder]. The snapshotter takes ownership of
    • @take_args, so the caller should not free it after this. If the renderer doesn't support GL shaders, or if there is any problem when compiling the shader, then the node will draw pink. You should use [method@Gsk.GLShader.compile] to ensure the @shader will work for the renderer before using it. If the shader requires textures (see [method@Gsk.GLShader.get_n_textures]), then it is expected that you call [method@Gtk.Snapshot.gl_shader_pop_texture] the number of times that are required. Each of these calls will generate a node that is added as a child to the GskGLShaderNode, which in turn will render these offscreen and pass as a texture to the shader. Once all textures (if any) are pop:ed, you must call the regular [method@Gtk.Snapshot.pop]. If you want to use pre-existing textures as input to the shader rather than rendering new ones, use [method@Gtk.Snapshot.append_texture] to push a texture node. These will be used directly rather than being re-rendered. For details on how to write shaders, see [class@Gsk.GLShader].
    • @p shader is The code to run.
    • @p bounds is the rectangle to render into.
    • @p take_args is Data block with arguments for the shader..
    • @r None.
  • push_isolation (string features)

    Isolates the following drawing operations from previous ones. You can express "everything but these flags" in a forward compatible way by using bit math: GSK_ISOLATION_ALL & ~(GSK_ISOLATION_BACKGROUND | GSK_ISOLATION_COPY_PASTE) will isolate everything but background and copy/paste. For what isolation features exist, see [flags@Gsk.Isolation]. Content is isolated until the next call to [method@Gtk.Snapshot.pop].

    • @p features is features that are isolated.
    • @r None.
  • push_mask (string mask_mode)

    Until the first call to [method@Gtk.Snapshot.pop], the mask image for the mask operation will be recorded. After that call, the source image will be recorded until the second call to [method@Gtk.Snapshot.pop]. Calling this function requires 2 subsequent calls to gtk_snapshot_pop().

    • @p mask_mode is mask mode to use.
    • @r None.
  • push_opacity (double opacity)

    Modifies the opacity of an image. The image is recorded until the next call to [method@Gtk.Snapshot.pop].

    • @p opacity is the opacity to use.
    • @r None.
  • push_repeat (object bounds, object child_bounds)

    Creates a node that repeats the child node. The child is recorded until the next call to [method@Gtk.Snapshot.pop].

    • @p bounds is the bounds within which to repeat.
    • @p child_bounds is the bounds of the child or %NULL to use the full size of the collected child node.
    • @r None.
  • push_rounded_clip (object bounds)

    Clips an image to a rounded rectangle. The image is recorded until the next call to [method@Gtk.Snapshot.pop].

    • @p bounds is the rounded rectangle to clip to.
    • @r None.
  • push_stroke (object path, object stroke)

    Strokes the given @path with the attributes given by @stroke and an image. The image is recorded until the next call to [method@Gtk.Snapshot.pop]. Note that the strokes are subject to the same transformation as everything else, so uneven scaling will cause horizontal and vertical strokes to have different widths. If you want to stroke the path with a color, [method@Gtk.Snapshot.append_stroke] may be more convenient.

    • @p path is The path to stroke.
    • @p stroke is The stroke attributes.
    • @r None.
  • render_background (object context, double x, double y, double width, double height)

    Creates a render node for the CSS background according to @context, and appends it to the current node of @snapshot, without changing the current node.

    • @p context is the style context that defines the background.
    • @p x is X origin of the rectangle.
    • @p y is Y origin of the rectangle.
    • @p width is rectangle width.
    • @p height is rectangle height.
    • @r None.
  • render_focus (object context, double x, double y, double width, double 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.

    • @p context is the style context that defines the focus ring.
    • @p x is X origin of the rectangle.
    • @p y is Y origin of the rectangle.
    • @p width is rectangle width.
    • @p height is rectangle height.
    • @r None.
  • render_frame (object context, double x, double y, double width, double height)

    Creates a render node for the CSS border according to @context, and appends it to the current node of @snapshot, without changing the current node.

    • @p context is the style context that defines the frame.
    • @p x is X origin of the rectangle.
    • @p y is Y origin of the rectangle.
    • @p width is rectangle width.
    • @p height is rectangle height.
    • @r None.
  • render_insertion_cursor (object context, double x, double y, object layout, int index, string direction)

    Draws a text caret using @snapshot at the specified index of @layout.

    • @p context is a GtkStyleContext.
    • @p x is X origin.
    • @p y is Y origin.
    • @p layout is the PangoLayout of the text.
    • @p index is the index in the PangoLayout.
    • @p direction is the PangoDirection of the text.
    • @r None.
  • render_layout (object context, double x, double y, object layout)

    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.

    • @p context is the style context that defines the text.
    • @p x is X origin of the rectangle.
    • @p y is Y origin of the rectangle.
    • @p layout is the PangoLayout to render.
    • @r None.
  • restore ()

    Restores @snapshot to the state saved by a preceding call to [method@Snapshot.save] and removes that state from the stack of saved states.

    • @r None.
  • rotate (double angle)

    Rotates @@snapshot's coordinate system by @angle degrees in 2D space - or in 3D speak, rotates around the Z axis. The rotation happens around the origin point of (0, 0) in the @snapshot's current coordinate system. To rotate around axes other than the Z axis, use [method@Gsk.Transform.rotate_3d].

    • @p angle is the rotation angle, in degrees (clockwise).
    • @r None.
  • rotate_3d (double angle, object axis)

    Rotates @snapshot's coordinate system by @angle degrees around @axis. For a rotation in 2D space, use [method@Gsk.Transform.rotate].

    • @p angle is the rotation angle, in degrees (clockwise).
    • @p axis is The rotation axis.
    • @r None.
  • save ()

    Makes a copy of the current state of @snapshot and saves it on an internal stack. When [method@Gtk.Snapshot.restore] is called, @snapshot will be restored to the saved state. Multiple calls to [method@Gtk.Snapshot.save] and [method@Gtk.Snapshot.restore] can be nested; each call to gtk_snapshot_restore() restores the state from the matching paired gtk_snapshot_save(). It is necessary to clear all saved states with corresponding calls to gtk_snapshot_restore().

    • @r None.
  • scale (double factor_x, double factor_y)

    Scales @snapshot's coordinate system in 2-dimensional space by the given factors. Use [method@Gtk.Snapshot.scale_3d] to scale in all 3 dimensions.

    • @p factor_x is scaling factor on the X axis.
    • @p factor_y is scaling factor on the Y axis.
    • @r None.
  • scale_3d (double factor_x, double factor_y, double factor_z)

    Scales @snapshot's coordinate system by the given factors.

    • @p factor_x is scaling factor on the X axis.
    • @p factor_y is scaling factor on the Y axis.
    • @p factor_z is scaling factor on the Z axis.
    • @r None.
  • to_node ()

    Returns the render node that was constructed by @snapshot. Note that this function may return %NULL if nothing has been added to the snapshot or if its content does not produce pixels to be rendered. After calling this function, it is no longer possible to add more nodes to @snapshot. The only function that should be called after this is [method@GObject.Object.unref].

  • to_paintable (size)

    Returns a paintable encapsulating the render node that was constructed by

    • @snapshot. After calling this function, it is no longer possible to add more nodes to @snapshot. The only function that should be called after this is [method@GObject.Object.unref].
    • @p size is The size of the resulting paintable or %NULL to use the bounds of the snapshot.
  • transform (object transform)

    Transforms @snapshot's coordinate system with the given @transform.

    • @p transform is the transform to apply.
    • @r None.
  • transform_matrix (object matrix)

    Transforms @snapshot's coordinate system with the given @matrix.

    • @p matrix is the matrix to multiply the transform with.
    • @r None.
  • translate (point)

    Translates @snapshot's coordinate system by @point in 2-dimensional space.

    • @p point is the point to translate the snapshot by.
    • @r None.
  • translate_3d (point)

    Translates @snapshot's coordinate system by @point.

    • @p point is the point to translate the snapshot by.
    • @r None.