Class Snapshot

All Implemented Interfaces:
Proxy

@Generated("org.javagi.JavaGI") public class Snapshot extends Snapshot

Assists in creating RenderNodes 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 pop() to change the current node.

The typical way to obtain a GtkSnapshot object is as an argument to the Widget.snapshot(Snapshot) vfunc. If you need to create your own GtkSnapshot, use Snapshot().

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.

  • Constructor Details

    • Snapshot

      public Snapshot(MemorySegment address)
      Create a Snapshot instance for the provided memory address.
      Parameters:
      address - the memory address of the native object
    • Snapshot

      public Snapshot()
      Create a new Snapshot.
  • Method Details

    • getType

      public static @Nullable Type getType()
      Get the GType of the Snapshot class.
      Returns:
      the GType
    • getMemoryLayout

      public static MemoryLayout getMemoryLayout()
      The memory layout of the native struct.
      Returns:
      the memory layout
    • asParent

      protected Snapshot asParent()
      Return this instance as if it were its parent type. Comparable to the Java super keyword, but ensures the parent typeclass is also used in native code.
      Overrides:
      asParent in class Snapshot
      Returns:
      the instance as if it were its parent type
    • appendBorder

      public void appendBorder(RoundedRect outline, @Nullable float @Nullable [] borderWidth, @Nullable RGBA @Nullable [] borderColor)

      Appends a stroked border rectangle inside the given outline.

      The four sides of the border can have different widths and colors.

      Parameters:
      outline - the outline of the border
      borderWidth - the stroke width of the border on the top, right, bottom and left side respectively.
      borderColor - the color used on the top, right, bottom and left side.
      Throws:
      IllegalArgumentException - when length of borderWidth is less than 4
      IllegalArgumentException - when length of borderColor is less than 4
    • appendCairo

      public org.freedesktop.cairo.Context appendCairo(Rect bounds)
      Creates a new 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(RGBA color, 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
    • appendConicGradient

      public void appendConicGradient(Rect bounds, Point center, float rotation, @Nullable ColorStop @Nullable [] stops)
      Appends a conic gradient node with the given stops to snapshot.
      Parameters:
      bounds - the rectangle to render the gradient into
      center - the center point of the conic gradient
      rotation - the clockwise rotation in degrees of the starting angle. 0 means the starting angle is the top.
      stops - the color stops defining the gradient
    • appendFill

      public void appendFill(Path path, FillRule fillRule, RGBA color)

      A convenience method to fill a path with a color.

      See pushFill(Path, FillRule) if you need to fill a path with more complex content than a color.

      Parameters:
      path - The path describing the area to fill
      fillRule - The fill rule to use
      color - the color to fill the path with
      Since:
      4.14
    • appendInsetShadow

      public void appendInsetShadow(RoundedRect outline, RGBA color, float dx, float dy, float spread, float blurRadius)
      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
      blurRadius - how much blur to apply to the shadow
    • appendLayout

      public void appendLayout(Layout layout, RGBA color)

      Creates render nodes for rendering layout in the given foregound color and appends them to the current node of this Snapshot without changing the current node. The current theme's foreground color for a widget can be obtained with Widget.getColor(RGBA).

      Note that if the layout does not produce any visible output, then nodes may not be added to the snapshot.

      Parameters:
      layout - the PangoLayout to render
      color - the foreground color to render the layout in
    • appendLinearGradient

      public void appendLinearGradient(Rect bounds, Point startPoint, Point endPoint, @Nullable ColorStop @Nullable [] stops)
      Appends a linear gradient node with the given stops to snapshot.
      Parameters:
      bounds - the rectangle to render the linear gradient into
      startPoint - the point at which the linear gradient will begin
      endPoint - the point at which the linear gradient will finish
      stops - the color stops defining the gradient
    • appendNode

      public void appendNode(RenderNode node)

      Appends node to the current render node of snapshot, without changing the current node.

      If this Snapshot does not have a current node yet, node will become the initial node.

      Parameters:
      node - a GskRenderNode
    • appendOutsetShadow

      public void appendOutsetShadow(RoundedRect outline, RGBA color, float dx, float dy, float spread, float blurRadius)
      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
      blurRadius - how much blur to apply to the shadow
    • appendPaste

      public void appendPaste(Rect bounds, long nth)
      Creates a new render node that pastes the contents copied by a previous call to pushCopy()
      Parameters:
      bounds - the bounds for the new node
      nth - the index of the copy, with 0 being the latest copy, 1 being the copy before that, and so on.
      Since:
      4.22
    • appendRadialGradient

      public void appendRadialGradient(Rect bounds, Point center, float hradius, float vradius, float start, float end, @Nullable ColorStop @Nullable [] stops)
      Appends a radial gradient node with the given stops to snapshot.
      Parameters:
      bounds - the rectangle to render the readial gradient into
      center - the center point for the radial gradient
      hradius - the horizontal radius
      vradius - the vertical radius
      start - the start position (on the horizontal axis)
      end - the end position (on the horizontal axis)
      stops - the color stops defining the gradient
    • appendRepeatingLinearGradient

      public void appendRepeatingLinearGradient(Rect bounds, Point startPoint, Point endPoint, @Nullable ColorStop @Nullable [] stops)
      Appends a repeating linear gradient node with the given stops to snapshot.
      Parameters:
      bounds - the rectangle to render the linear gradient into
      startPoint - the point at which the linear gradient will begin
      endPoint - the point at which the linear gradient will finish
      stops - the color stops defining the gradient
    • appendRepeatingRadialGradient

      public void appendRepeatingRadialGradient(Rect bounds, Point center, float hradius, float vradius, float start, float end, @Nullable ColorStop @Nullable [] stops)
      Appends a repeating radial gradient node with the given stops to snapshot.
      Parameters:
      bounds - the rectangle to render the readial gradient into
      center - the center point for the radial gradient
      hradius - the horizontal radius
      vradius - the vertical radius
      start - the start position (on the horizontal axis)
      end - the end position (on the horizontal axis)
      stops - the color stops defining the gradient
    • appendScaledTexture

      public void appendScaledTexture(Texture texture, ScalingFilter filter, Rect 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 appendTexture(Texture, Rect), this function provides control about how the filter that is used when scaling.

      Parameters:
      texture - the texture to render
      filter - the filter to use
      bounds - the bounds for the new node
      Since:
      4.10
    • appendStroke

      public void appendStroke(Path path, Stroke stroke, RGBA color)

      A convenience method to stroke a path with a color.

      See pushStroke(Path, Stroke) if you need to stroke a path with more complex content than a color.

      Parameters:
      path - The path describing the area to fill
      stroke - The stroke attributes
      color - the color to fill the path with
      Since:
      4.14
    • appendTexture

      public void appendTexture(Texture texture, Rect 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 appendScaledTexture(Texture, ScalingFilter, Rect) if you need other filtering, such as nearest-neighbour.

      Parameters:
      texture - the texture to render
      bounds - the bounds for the new node
    • freeToNode

      public @Nullable RenderNode freeToNode()

      Returns the node that was constructed by this Snapshot and frees snapshot.

      See also toNode().

      Returns:
      a newly-created RenderNode
    • freeToPaintable

      public @Nullable Paintable freeToPaintable(@Nullable Size size)
      Returns a paintable for the node that was constructed by this 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 Paintable
    • glShaderPopTexture

      @Deprecated public void glShaderPopTexture()
      Deprecated.
      GTK's new Vulkan-focused rendering does not support this feature. Use GLArea for OpenGL rendering.

      Removes the top element from the stack of render nodes and adds it to the nearest GLShaderNode below it.

      This must be called the same number of times as the number of textures is needed for the shader in pushGlShader(GLShader, Rect, byte[]).

    • perspective

      public void perspective(float depth)

      Applies a perspective projection transform.

      See 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(BlendMode blendMode)

      Blends together two images with the given blend mode.

      Until the first call to 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 pop().

      Calling this function requires two subsequent calls to pop().

      Parameters:
      blendMode - blend mode to use
    • pushBlur

      public void pushBlur(double radius)

      Blurs an image.

      The image is recorded until the next call to pop().

      Parameters:
      radius - the blur radius to use. Must be positive
    • pushClip

      public void pushClip(Rect bounds)

      Clips an image to a rectangle.

      The image is recorded until the next call to pop().

      Parameters:
      bounds - the rectangle to clip to
    • pushColorMatrix

      public void pushColorMatrix(Matrix colorMatrix, Vec4 colorOffset)

      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 pop().

      Parameters:
      colorMatrix - the color matrix to use
      colorOffset - the color offset to use
    • pushComponentTransfer

      public void pushComponentTransfer(ComponentTransfer red, ComponentTransfer green, ComponentTransfer blue, ComponentTransfer 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 pop().

      Parameters:
      red - the transfer for the red component
      green - the transfer for the green component
      blue - the transfer for the blue component
      alpha - the transfer for the alpha component
      Since:
      4.20
    • pushComposite

      public void pushComposite(PorterDuff op)

      Until the first call to 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 pop().

      Calling this function requires 2 subsequent calls to gtk_snapshot_pop().

      Parameters:
      op - The Porter/Duff compositing operator to use
      Since:
      4.22
    • pushCopy

      public void pushCopy()

      Stores the current rendering state for later pasting via appendPaste(Rect, long).

      Pasting is possible until the matching call to pop().

      Since:
      4.22
    • pushCrossFade

      public void pushCrossFade(double progress)

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

      Until the first call to pop(), the start image will be snapshot. After that call, the end image will be recorded until the second call to pop().

      Calling this function requires two subsequent calls to pop().

      Parameters:
      progress - progress between 0.0 and 1.0
    • pushDebug

      public void pushDebug(String message, Object... varargs)

      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
      varargs - arguments for message
    • pushFill

      public void pushFill(Path path, FillRule fillRule)

      Fills the area given by path and fillRule with an image and discards everything outside of it.

      The image is recorded until the next call to pop().

      If you want to fill the path with a color, appendFill(Path, FillRule, RGBA) than rendering new ones, use appendFill(Path, FillRule, RGBA) may be more convenient.

      Parameters:
      path - The path describing the area to fill
      fillRule - The fill rule to use
      Since:
      4.14
    • pushGlShader

      @Deprecated public void pushGlShader(GLShader shader, Rect bounds, byte[] takeArgs)
      Deprecated.
      GTK's new Vulkan-focused rendering does not support this feature. Use GLArea for OpenGL rendering.

      Push a GLShaderNode.

      The node uses the given GLShader and uniform values Additionally this takes a list of nChildren other nodes which will be passed to the GLShaderNode.

      The takeArgs 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 GLShader#formatArgs or Gsk.ShaderArgsBuilder.

      The snapshotter takes ownership of takeArgs, 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 GLShader#compile to ensure the shader will work for the renderer before using it.

      If the shader requires textures (see GLShader#getNTextures), then it is expected that you call glShaderPopTexture() 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 pop().

      If you want to use pre-existing textures as input to the shader rather than rendering new ones, use appendTexture(Texture, Rect) to push a texture node. These will be used directly rather than being re-rendered.

      For details on how to write shaders, see GLShader.

      Parameters:
      shader - The code to run
      bounds - the rectangle to render into
      takeArgs - Data block with arguments for the shader.
    • pushIsolation

      public void pushIsolation(Set<Isolation> 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 Gsk.Isolation.

      Content is isolated until the next call to pop().

      Parameters:
      features - features that are isolated
      Since:
      4.22
    • pushIsolation

      public void pushIsolation(Isolation... 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 Gsk.Isolation.

      Content is isolated until the next call to pop().

      Parameters:
      features - features that are isolated
      Since:
      4.22
    • pushMask

      public void pushMask(MaskMode maskMode)

      Until the first call to 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 pop().

      Calling this function requires 2 subsequent calls to gtk_snapshot_pop().

      Parameters:
      maskMode - mask mode to use
      Since:
      4.10
    • pushOpacity

      public void pushOpacity(double opacity)

      Modifies the opacity of an image.

      The image is recorded until the next call to pop().

      Parameters:
      opacity - the opacity to use
    • pushRepeat

      public void pushRepeat(Rect bounds, @Nullable Rect childBounds)

      Creates a node that repeats the child node.

      The child is recorded until the next call to pop().

      Parameters:
      bounds - the bounds within which to repeat
      childBounds - the bounds of the child or null to use the full size of the collected child node
    • pushRoundedClip

      public void pushRoundedClip(RoundedRect bounds)

      Clips an image to a rounded rectangle.

      The image is recorded until the next call to pop().

      Parameters:
      bounds - the rounded rectangle to clip to
    • pushShadow

      public void pushShadow(@Nullable Shadow @Nullable [] shadow)

      Applies a shadow to an image.

      The image is recorded until the next call to pop().

      Parameters:
      shadow - the first shadow specification
    • pushStroke

      public void pushStroke(Path path, Stroke stroke)

      Strokes the given path with the attributes given by stroke and an image.

      The image is recorded until the next call to 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, appendStroke(Path, Stroke, RGBA) may be more convenient.

      Parameters:
      path - The path to stroke
      stroke - The stroke attributes
      Since:
      4.14
    • renderBackground

      @Deprecated public void renderBackground(StyleContext context, double x, double y, double width, double height)
      Deprecated.
      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

      @Deprecated public void renderFocus(StyleContext context, double x, double y, double width, double height)
      Deprecated.
      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

      @Deprecated public void renderFrame(StyleContext context, double x, double y, double width, double height)
      Deprecated.
      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

      @Deprecated public void renderInsertionCursor(StyleContext context, double x, double y, Layout layout, int index, Direction direction)
      Deprecated.
      Draws a text caret using this 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

      @Deprecated public void renderLayout(StyleContext context, double x, double y, Layout layout)
      Deprecated.
      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 this Snapshot to the state saved by a preceding call to 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. 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 Transform#rotate3d.

      Parameters:
      angle - the rotation angle, in degrees (clockwise)
    • rotate3d

      public void rotate3d(float angle, Vec3 axis)

      Rotates snapshot's coordinate system by angle degrees around axis.

      For a rotation in 2D space, use 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 this Snapshot and saves it on an internal stack.

      When restore() is called, this Snapshot will be restored to the saved state.

      Multiple calls to save() and 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 factorX, float factorY)

      Scales snapshot's coordinate system in 2-dimensional space by the given factors.

      Use scale3d(float, float, float) to scale in all 3 dimensions.

      Parameters:
      factorX - scaling factor on the X axis
      factorY - scaling factor on the Y axis
    • scale3d

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

      public @Nullable RenderNode toNode()

      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 GObject#unref.

      Returns:
      the constructed GskRenderNode or null if there are no nodes to render.
    • toPaintable

      public @Nullable 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 GObject#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(Matrix matrix)
      Transforms snapshot's coordinate system with the given matrix.
      Parameters:
      matrix - the matrix to multiply the transform with
    • translate

      public void translate(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(Point3D point)
      Translates snapshot's coordinate system by point.
      Parameters:
      point - the point to translate the snapshot by
    • builder

      public static Snapshot.Builder<? extends Snapshot.Builder> builder()
      A Snapshot.Builder object constructs a Snapshot with the specified properties. Use the various set...() methods to set properties, and finish construction with Snapshot.Builder.build().
      Returns:
      the builder object