Class Snapshot

All Implemented Interfaces:
PointerInterface

public class Snapshot extends Snapshot
`GtkSnapshot` 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].

https://docs.gtk.org/gtk4/class.Snapshot.html

  • Constructor Details

    • Snapshot

      public Snapshot(PointerContainer pointer)
    • Snapshot

      public Snapshot()
      Creates a new `GtkSnapshot`.
  • Method Details

    • getClassHandler

      public static ClassHandler getClassHandler()
    • appendCairo

      public Context appendCairo(@Nonnull Rect bounds)
      Creates a new [class@Gsk.CairoNode] and appends it to the current
      render node of @snapshot, without changing the current node.
      Parameters:
      bounds - the bounds for the new node
      Returns:
      a `cairo_t` suitable for drawing the contents of the newly created render node
    • appendColor

      public void appendColor(@Nonnull RGBA color, @Nonnull Rect 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.
      Parameters:
      color - the color to draw
      bounds - the bounds for the new node
    • appendInsetShadow

      public void appendInsetShadow(@Nonnull RoundedRect outline, @Nonnull RGBA color, float dx, float dy, float spread, float blur_radius)
      Appends an inset shadow into the box given by @outline.
      Parameters:
      outline - outline of the region surrounded by shadow
      color - color of the shadow
      dx - horizontal offset of shadow
      dy - vertical offset of shadow
      spread - how far the shadow spreads towards the inside
      blur_radius - how much blur to apply to the shadow
    • appendLayout

      public void appendLayout(@Nonnull Layout layout, @Nonnull RGBA color)
      Parameters:
      layout -
      color -
    • appendNode

      public void appendNode(@Nonnull RenderNode 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.
      Parameters:
      node - a `GskRenderNode`
    • appendOutsetShadow

      public void appendOutsetShadow(@Nonnull RoundedRect outline, @Nonnull RGBA color, float dx, float dy, float spread, float blur_radius)
      Appends an outset shadow node around the box given by @outline.
      Parameters:
      outline - outline of the region surrounded by shadow
      color - color of the shadow
      dx - horizontal offset of shadow
      dy - vertical offset of shadow
      spread - how far the shadow spreads towards the outside
      blur_radius - how much blur to apply to the shadow
    • appendTexture

      public void appendTexture(@Nonnull Texture texture, @Nonnull Rect bounds)
      Creates a new render node drawing the @texture
      into the given @bounds and appends it to the
      current render node of @snapshot.
      Parameters:
      texture - the texture to render
      bounds - the bounds for the new node
    • freeToNode

      public RenderNode freeToNode()
      Returns the node that was constructed by @snapshot
      and frees @snapshot.
      Returns:
      a newly-created [class@Gsk.RenderNode]
    • freeToPaintable

      public Paintable freeToPaintable(@Nullable Size size)
      Returns a paintable for the node that was
      constructed by @snapshot and frees @snapshot.
      Parameters:
      size - The size of the resulting paintable or %NULL to use the bounds of the snapshot
      Returns:
      a newly-created [iface@Gdk.Paintable]
    • glShaderPopTexture

      public void glShaderPopTexture()
      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].
    • perspective

      public void perspective(float depth)
      Applies a perspective projection transform.

      See [method@Gsk.Transform.perspective] for a discussion on the details.
      Parameters:
      depth - distance of the z=0 plane
    • pop

      public void pop()
      Removes the top element from the stack of render nodes,
      and appends it to the node underneath it.
    • pushBlend

      public void pushBlend(int 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].
      Parameters:
      blend_mode - blend mode to use
    • pushBlur

      public void pushBlur(double radius)
      Blurs an image.

      The image is recorded until the next call to [method@Gtk.Snapshot.pop].
      Parameters:
      radius - the blur radius to use. Must be positive
    • pushClip

      public void pushClip(@Nonnull Rect bounds)
      Clips an image to a rectangle.

      The image is recorded until the next call to [method@Gtk.Snapshot.pop].
      Parameters:
      bounds - the rectangle to clip to
    • pushColorMatrix

      public void pushColorMatrix(@Nonnull Matrix color_matrix, @Nonnull Vec4 color_offset)
      Modifies the colors of an image by applying an affine transformation
      in RGB space.

      The image is recorded until the next call to [method@Gtk.Snapshot.pop].
      Parameters:
      color_matrix - the color matrix to use
      color_offset - the color offset to use
    • pushCrossFade

      public void pushCrossFade(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].
      Parameters:
      progress - progress between 0.0 and 1.0
    • pushDebug

      public void pushDebug(@Nonnull Str message, Object... _elipse)
      Inserts a debug node with a message.

      Debug nodes don't affect the rendering at all, but can be
      helpful in identifying parts of a render node tree dump,
      for example in the GTK inspector.
      Parameters:
      message - a printf-style format string
      _elipse - arguments for @message
    • pushDebug

      public void pushDebug(String message, Object... _elipse)
      Inserts a debug node with a message.

      Debug nodes don't affect the rendering at all, but can be
      helpful in identifying parts of a render node tree dump,
      for example in the GTK inspector.
      Parameters:
      message - a printf-style format string
      _elipse - arguments for @message
    • pushGlShader

      public void pushGlShader(@Nonnull GLShader shader, @Nonnull Rect bounds, @Nonnull Bytes 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].
      Parameters:
      shader - The code to run
      bounds - the rectangle to render into
      take_args - Data block with arguments for the shader.
    • pushOpacity

      public void pushOpacity(double opacity)
      Modifies the opacity of an image.

      The image is recorded until the next call to [method@Gtk.Snapshot.pop].
      Parameters:
      opacity - the opacity to use
    • pushRepeat

      public void pushRepeat(@Nonnull Rect bounds, @Nullable Rect child_bounds)
      Creates a node that repeats the child node.

      The child is recorded until the next call to [method@Gtk.Snapshot.pop].
      Parameters:
      bounds - the bounds within which to repeat
      child_bounds - the bounds of the child or %NULL to use the full size of the collected child node
    • pushRoundedClip

      public void pushRoundedClip(@Nonnull RoundedRect bounds)
      Clips an image to a rounded rectangle.

      The image is recorded until the next call to [method@Gtk.Snapshot.pop].
      Parameters:
      bounds - the rounded rectangle to clip to
    • renderBackground

      public void renderBackground(@Nonnull StyleContext 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.
      Parameters:
      context - the style context that defines the background
      x - X origin of the rectangle
      y - Y origin of the rectangle
      width - rectangle width
      height - rectangle height
    • renderFocus

      public void renderFocus(@Nonnull StyleContext 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.
      Parameters:
      context - the style context that defines the focus ring
      x - X origin of the rectangle
      y - Y origin of the rectangle
      width - rectangle width
      height - rectangle height
    • renderFrame

      public void renderFrame(@Nonnull StyleContext 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.
      Parameters:
      context - the style context that defines the frame
      x - X origin of the rectangle
      y - Y origin of the rectangle
      width - rectangle width
      height - rectangle height
    • renderInsertionCursor

      public void renderInsertionCursor(@Nonnull StyleContext context, double x, double y, @Nonnull Layout layout, int index, int direction)
      Draws a text caret using @snapshot at the specified index of @layout.
      Parameters:
      context - a `GtkStyleContext`
      x - X origin
      y - Y origin
      layout - the `PangoLayout` of the text
      index - the index in the `PangoLayout`
      direction - the `PangoDirection` of the text
    • renderLayout

      public void renderLayout(@Nonnull StyleContext context, double x, double y, @Nonnull Layout 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.
      Parameters:
      context - the style context that defines the text
      x - X origin of the rectangle
      y - Y origin of the rectangle
      layout - the `PangoLayout` to render
    • restore

      public void 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.
    • rotate

      public void rotate(float angle)
      Rotates @@snapshot's coordinate system by @angle degrees in 2D space -
      or in 3D speak, rotates around the Z axis.

      To rotate around other axes, use [method@Gsk.Transform.rotate_3d].
      Parameters:
      angle - the rotation angle, in degrees (clockwise)
    • rotate3d

      public void rotate3d(float angle, @Nonnull Vec3 axis)
      Rotates @snapshot's coordinate system by @angle degrees around @axis.

      For a rotation in 2D space, use [method@Gsk.Transform.rotate].
      Parameters:
      angle - the rotation angle, in degrees (clockwise)
      axis - The rotation axis
    • save

      public void 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@Snapshot.save] and [class@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()`.
    • scale

      public void scale(float factor_x, float 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.
      Parameters:
      factor_x - scaling factor on the X axis
      factor_y - scaling factor on the Y axis
    • scale3d

      public void scale3d(float factor_x, float factor_y, float factor_z)
      Scales @snapshot's coordinate system by the given factors.
      Parameters:
      factor_x - scaling factor on the X axis
      factor_y - scaling factor on the Y axis
      factor_z - scaling factor on the Z axis
    • toNode

      public RenderNode toNode()
      Returns 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].
      Returns:
      the constructed `GskRenderNode`
    • toPaintable

      public Paintable toPaintable(@Nullable Size 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].
      Parameters:
      size - The size of the resulting paintable or %NULL to use the bounds of the snapshot
      Returns:
      a new `GdkPaintable`
    • transform

      public void transform(@Nullable Transform transform)
      Transforms @snapshot's coordinate system with the given @transform.
      Parameters:
      transform - the transform to apply
    • transformMatrix

      public void transformMatrix(@Nonnull Matrix matrix)
      Transforms @snapshot's coordinate system with the given @matrix.
      Parameters:
      matrix - the matrix to multiply the transform with
    • translate

      public void translate(@Nonnull Point point)
      Translates @snapshot's coordinate system by @point in 2-dimensional space.
      Parameters:
      point - the point to translate the snapshot by
    • translate3d

      public void translate3d(@Nonnull Point3D point)
      Translates @snapshot's coordinate system by @point.
      Parameters:
      point - the point to translate the snapshot by
    • getTypeID

      public static long getTypeID()
    • getParentTypeID

      public static long getParentTypeID()
    • getTypeSize

      public static TypeSystem.TypeSize getTypeSize()
    • getParentTypeSize

      public static TypeSystem.TypeSize getParentTypeSize()
    • getInstanceSize

      public static int getInstanceSize()