Class Snapshot
- All Implemented Interfaces:
Proxy
GtkSnapshot
assists in creating 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
pop()
to change the current node.
The typical way to obtain a GtkSnapshot
object is as an argument to
the Widget.snapshot(org.gnome.gtk.Snapshot)
vfunc. If you need to create your own
GtkSnapshot
, use Snapshot()
.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Snapshot.Builder<B extends Snapshot.Builder<B>>
Inner class implementing a builder pattern to construct a GObject with properties.static class
Nested classes/interfaces inherited from class org.gnome.gdk.Snapshot
Snapshot.SnapshotImpl
Nested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass
-
Constructor Summary
ConstructorDescriptionSnapshot()
Creates a newGtkSnapshot
.Snapshot
(MemorySegment address) Create a Snapshot proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionvoid
appendBorder
(RoundedRect outline, float[] borderWidth, RGBA[] borderColor) Appends a stroked border rectangle inside the givenoutline
.org.freedesktop.cairo.Context
appendCairo
(Rect bounds) Creates a newCairoNode
and appends it to the current render node of this Snapshot, without changing the current node.void
appendColor
(RGBA color, Rect bounds) Creates a new render node drawing thecolor
into the givenbounds
and appends it to the current render node of this Snapshot.void
appendConicGradient
(Rect bounds, Point center, float rotation, ColorStop[] stops) Appends a conic gradient node with the given stops to this Snapshot.void
appendFill
(Path path, FillRule fillRule, RGBA color) A convenience method to fill a path with a color.void
appendInsetShadow
(RoundedRect outline, RGBA color, float dx, float dy, float spread, float blurRadius) Appends an inset shadow into the box given byoutline
.void
appendLayout
(Layout layout, RGBA color) Creates render nodes for renderinglayout
in the given foregoundcolor
and appends them to the current node of this Snapshot without changing the current node.void
appendLinearGradient
(Rect bounds, Point startPoint, Point endPoint, ColorStop[] stops) Appends a linear gradient node with the given stops to this Snapshot.void
appendNode
(RenderNode node) Appendsnode
to the current render node of this Snapshot, without changing the current node.void
appendOutsetShadow
(RoundedRect outline, RGBA color, float dx, float dy, float spread, float blurRadius) Appends an outset shadow node around the box given byoutline
.void
appendRadialGradient
(Rect bounds, Point center, float hradius, float vradius, float start, float end, ColorStop[] stops) Appends a radial gradient node with the given stops to this Snapshot.void
appendRepeatingLinearGradient
(Rect bounds, Point startPoint, Point endPoint, ColorStop[] stops) Appends a repeating linear gradient node with the given stops to this Snapshot.void
appendRepeatingRadialGradient
(Rect bounds, Point center, float hradius, float vradius, float start, float end, ColorStop[] stops) Appends a repeating radial gradient node with the given stops to this Snapshot.void
appendScaledTexture
(Texture texture, ScalingFilter filter, Rect bounds) Creates a new render node drawing thetexture
into the givenbounds
and appends it to the current render node of this Snapshot.void
appendStroke
(Path path, Stroke stroke, RGBA color) A convenience method to stroke a path with a color.void
appendTexture
(Texture texture, Rect bounds) Creates a new render node drawing thetexture
into the givenbounds
and appends it to the current render node of this Snapshot.protected Snapshot
asParent()
Returns this instance as if it were its parent type.static Snapshot.Builder
<? extends Snapshot.Builder> builder()
ASnapshot.Builder
object constructs aSnapshot
with the specified properties.Returns the node that was constructed by this Snapshot and frees this Snapshot.freeToPaintable
(@Nullable Size size) Returns a paintable for the node that was constructed by this Snapshot and frees this Snapshot.static Type
getType()
Get the GType of the Snapshot classvoid
Deprecated.GTK's new Vulkan-focused rendering does not support this feature.void
perspective
(float depth) Applies a perspective projection transform.void
pop()
Removes the top element from the stack of render nodes, and appends it to the node underneath it.void
Blends together two images with the given blend mode.void
pushBlur
(double radius) Blurs an image.void
Clips an image to a rectangle.void
pushColorMatrix
(Matrix colorMatrix, Vec4 colorOffset) Modifies the colors of an image by applying an affine transformation in RGB space.void
pushCrossFade
(double progress) Snapshots a cross-fade operation between two images with the givenprogress
.void
Inserts a debug node with a message.void
Fills the area given bypath
andfillRule
with an image and discards everything outside of it.void
pushGlShader
(GLShader shader, Rect bounds, Bytes takeArgs) Deprecated.GTK's new Vulkan-focused rendering does not support this feature.void
Until the first call topop()
, the mask image for the mask operation will be recorded.void
pushOpacity
(double opacity) Modifies the opacity of an image.void
pushRepeat
(Rect bounds, @Nullable Rect childBounds) Creates a node that repeats the child node.void
pushRoundedClip
(RoundedRect bounds) Clips an image to a rounded rectangle.void
pushShadow
(Shadow[] shadow) Applies a shadow to an image.void
pushStroke
(Path path, Stroke stroke) Strokes the givenpath
with the attributes given bystroke
and an image.void
renderBackground
(StyleContext context, double x, double y, double width, double height) Deprecated.void
renderFocus
(StyleContext context, double x, double y, double width, double height) Deprecated.void
renderFrame
(StyleContext context, double x, double y, double width, double height) Deprecated.void
renderInsertionCursor
(StyleContext context, double x, double y, Layout layout, int index, Direction direction) Deprecated.void
renderLayout
(StyleContext context, double x, double y, Layout layout) Deprecated.void
restore()
Restores this Snapshot to the state saved by a preceding call tosave()
and removes that state from the stack of saved states.void
rotate
(float angle) Rotates this Snapshot's coordinate system byangle
degrees in 2D space - or in 3D speak, rotates around the Z axis.void
Rotates this Snapshot's coordinate system byangle
degrees aroundaxis
.void
save()
Makes a copy of the current state of this Snapshot and saves it on an internal stack.void
scale
(float factorX, float factorY) Scales this Snapshot's coordinate system in 2-dimensional space by the given factors.void
scale3d
(float factorX, float factorY, float factorZ) Scales this Snapshot's coordinate system by the given factors.toNode()
Returns the render node that was constructed by this Snapshot.toPaintable
(@Nullable Size size) Returns a paintable encapsulating the render node that was constructed by this Snapshot.void
Transforms this Snapshot's coordinate system with the giventransform
.void
transformMatrix
(Matrix matrix) Transforms this Snapshot's coordinate system with the givenmatrix
.void
Translates this Snapshot's coordinate system bypoint
in 2-dimensional space.void
translate3d
(Point3D point) Translates this Snapshot's coordinate system bypoint
.Methods inherited from class org.gnome.gobject.GObject
addToggleRef, addWeakPointer, bindProperty, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, connect, constructed, disconnect, dispatchPropertiesChanged, dispose, dupData, dupQdata, emit, emitNotify, finalize_, forceFloating, freezeNotify, get, getData, getMemoryLayout, getProperty, getProperty, getProperty, getQdata, getv, interfaceFindProperty, interfaceInstallProperty, interfaceListProperties, isFloating, newInstance, newInstance, newInstance, newInstance, newv, notify_, notify_, notifyByPspec, onNotify, ref, refSink, removeToggleRef, removeWeakPointer, replaceData, replaceQdata, runDispose, set, setData, setDataFull, setProperty, setProperty, setProperty, setQdata, setQdataFull, setv, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref, withProperties
Methods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, getPrivate, readGClass, writeGClass
Methods inherited from class io.github.jwharm.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
Snapshot
Create a Snapshot proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
Snapshot
public Snapshot()Creates a newGtkSnapshot
.
-
-
Method Details
-
getType
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuper
keyword, but will set the native typeclass function pointers to the parent type. When overriding a native virtual method in Java, "chaining up" withsuper.methodName()
doesn't work, because it invokes the overridden function pointer again. To chain up, callasParent().methodName()
. This will call the native function pointer of this virtual method in the typeclass of the parent type. -
appendBorder
Appends a stroked border rectangle inside the givenoutline
.The four sides of the border can have different widths and colors.
- Parameters:
outline
- the outline of the borderborderWidth
- 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.
-
appendCairo
Creates a newCairoNode
and appends it to the current render node of this 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
Creates a new render node drawing thecolor
into the givenbounds
and appends it to the current render node of this Snapshot.You should try to avoid calling this function if
color
is transparent.- Parameters:
color
- the color to drawbounds
- the bounds for the new node
-
appendConicGradient
Appends a conic gradient node with the given stops to this Snapshot.- Parameters:
bounds
- the rectangle to render the gradient intocenter
- the center point of the conic gradientrotation
- 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
A convenience method to fill a path with a color.See
pushFill(org.gnome.gsk.Path, org.gnome.gsk.FillRule)
if you need to fill a path with more complex content than a color.- Parameters:
path
- The path describing the area to fillfillRule
- The fill rule to usecolor
- the color to fill the path with
-
appendInsetShadow
public void appendInsetShadow(RoundedRect outline, RGBA color, float dx, float dy, float spread, float blurRadius) Appends an inset shadow into the box given byoutline
.- Parameters:
outline
- outline of the region surrounded by shadowcolor
- color of the shadowdx
- horizontal offset of shadowdy
- vertical offset of shadowspread
- how far the shadow spreads towards the insideblurRadius
- how much blur to apply to the shadow
-
appendLayout
Creates render nodes for renderinglayout
in the given foregoundcolor
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 withWidget.getColor(org.gnome.gdk.RGBA)
.Note that if the layout does not produce any visible output, then nodes may not be added to the this Snapshot.
- Parameters:
layout
- thePangoLayout
to rendercolor
- the foreground color to render the layout in
-
appendLinearGradient
Appends a linear gradient node with the given stops to this Snapshot.- Parameters:
bounds
- the rectangle to render the linear gradient intostartPoint
- the point at which the linear gradient will beginendPoint
- the point at which the linear gradient will finishstops
- the color stops defining the gradient
-
appendNode
Appendsnode
to the current render node of this Snapshot, without changing the current node.If this Snapshot does not have a current node yet,
node
will become the initial node.- Parameters:
node
- aGskRenderNode
-
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 byoutline
.- Parameters:
outline
- outline of the region surrounded by shadowcolor
- color of the shadowdx
- horizontal offset of shadowdy
- vertical offset of shadowspread
- how far the shadow spreads towards the outsideblurRadius
- how much blur to apply to the shadow
-
appendRadialGradient
public void appendRadialGradient(Rect bounds, Point center, float hradius, float vradius, float start, float end, ColorStop[] stops) Appends a radial gradient node with the given stops to this Snapshot.- Parameters:
bounds
- the rectangle to render the readial gradient intocenter
- the center point for the radial gradienthradius
- the horizontal radiusvradius
- the vertical radiusstart
- 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, ColorStop[] stops) Appends a repeating linear gradient node with the given stops to this Snapshot.- Parameters:
bounds
- the rectangle to render the linear gradient intostartPoint
- the point at which the linear gradient will beginendPoint
- the point at which the linear gradient will finishstops
- the color stops defining the gradient
-
appendRepeatingRadialGradient
public void appendRepeatingRadialGradient(Rect bounds, Point center, float hradius, float vradius, float start, float end, ColorStop[] stops) Appends a repeating radial gradient node with the given stops to this Snapshot.- Parameters:
bounds
- the rectangle to render the readial gradient intocenter
- the center point for the radial gradienthradius
- the horizontal radiusvradius
- the vertical radiusstart
- the start position (on the horizontal axis)end
- the end position (on the horizontal axis)stops
- the color stops defining the gradient
-
appendScaledTexture
Creates a new render node drawing thetexture
into the givenbounds
and appends it to the current render node of this Snapshot.In contrast to
appendTexture(org.gnome.gdk.Texture, org.gnome.graphene.Rect)
, this function provides control about how the filter that is used when scaling.- Parameters:
texture
- the texture to renderfilter
- the filter to usebounds
- the bounds for the new node
-
appendStroke
A convenience method to stroke a path with a color.See
pushStroke(org.gnome.gsk.Path, org.gnome.gsk.Stroke)
if you need to stroke a path with more complex content than a color.- Parameters:
path
- The path describing the area to fillstroke
- The stroke attributescolor
- the color to fill the path with
-
appendTexture
Creates a new render node drawing thetexture
into the givenbounds
and appends it to the current render node of this Snapshot.If the texture needs to be scaled to fill
bounds
, linear filtering is used. SeeappendScaledTexture(org.gnome.gdk.Texture, org.gnome.gsk.ScalingFilter, org.gnome.graphene.Rect)
if you need other filtering, such as nearest-neighbour.- Parameters:
texture
- the texture to renderbounds
- the bounds for the new node
-
freeToNode
Returns the node that was constructed by this Snapshot and frees this Snapshot.See also
toNode()
.- Returns:
- a newly-created
RenderNode
-
freeToPaintable
-
glShaderPopTexture
Deprecated.GTK's new Vulkan-focused rendering does not support this feature. UseGLArea
for OpenGL rendering.Removes the top element from the stack of render nodes and adds it to the nearestGLShaderNode
below it.This must be called the same number of times as the number of textures is needed for the shader in
pushGlShader(org.gnome.gsk.GLShader, org.gnome.graphene.Rect, org.gnome.glib.Bytes)
. -
perspective
public void perspective(float depth) Applies a perspective projection transform.See
Transform.perspective(float)
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
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 topop()
.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
-
pushColorMatrix
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 usecolorOffset
- the color offset to use
-
pushCrossFade
public void pushCrossFade(double progress) Snapshots a cross-fade operation between two images with the givenprogress
.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 topop()
.Calling this function requires two subsequent calls to
pop()
.- Parameters:
progress
- progress between 0.0 and 1.0
-
pushDebug
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 stringvarargs
- arguments formessage
-
pushFill
Fills the area given bypath
andfillRule
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(org.gnome.gsk.Path, org.gnome.gsk.FillRule, org.gnome.gdk.RGBA)
may be more convenient.- Parameters:
path
- The path describing the area to fillfillRule
- The fill rule to use
-
pushGlShader
Deprecated.GTK's new Vulkan-focused rendering does not support this feature. UseGLArea
for OpenGL rendering.Push aGLShaderNode
.The node uses the given
GLShader
and uniform values Additionally this takes a list ofnChildren
other nodes which will be passed to theGLShaderNode
.The
takeArgs
argument is a block of data to use for uniform arguments, as per types and offsets defined by theshader
. Normally this is generated byGLShader.formatArgs(java.lang.Object...)
orGsk.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(org.gnome.gsk.Renderer)
to ensure theshader
will work for the renderer before using it.If the shader requires textures (see
GLShader.getNTextures()
), then it is expected that you callglShaderPopTexture()
the number of times that are required. Each of these calls will generate a node that is added as a child to theGskGLShaderNode
, 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(org.gnome.gdk.Texture, org.gnome.graphene.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 runbounds
- the rectangle to render intotakeArgs
- Data block with arguments for the shader.
-
pushMask
-
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
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 repeatchildBounds
- the bounds of the child ornull
to use the full size of the collected child node
-
pushRoundedClip
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
-
pushStroke
Strokes the givenpath
with the attributes given bystroke
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(org.gnome.gsk.Path, org.gnome.gsk.Stroke, org.gnome.gdk.RGBA)
may be more convenient.- Parameters:
path
- The path to strokestroke
- The stroke attributes
-
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 tocontext
, and appends it to the current node of this Snapshot, without changing the current node.- Parameters:
context
- the style context that defines the backgroundx
- X origin of the rectangley
- Y origin of the rectanglewidth
- rectangle widthheight
- 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 tocontext
, and appends it to the current node of this Snapshot, without changing the current node.- Parameters:
context
- the style context that defines the focus ringx
- X origin of the rectangley
- Y origin of the rectanglewidth
- rectangle widthheight
- 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 tocontext
, and appends it to the current node of this Snapshot, without changing the current node.- Parameters:
context
- the style context that defines the framex
- X origin of the rectangley
- Y origin of the rectanglewidth
- rectangle widthheight
- 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 oflayout
.- Parameters:
context
- aGtkStyleContext
x
- X originy
- Y originlayout
- thePangoLayout
of the textindex
- the index in thePangoLayout
direction
- thePangoDirection
of the text
-
renderLayout
Deprecated.Creates a render node for renderinglayout
according to the style information incontext
, and appends it to the current node of this Snapshot, without changing the current node.- Parameters:
context
- the style context that defines the textx
- X origin of the rectangley
- Y origin of the rectanglelayout
- thePangoLayout
to render
-
restore
public void restore()Restores this Snapshot to the state saved by a preceding call tosave()
and removes that state from the stack of saved states. -
rotate
public void rotate(float angle) Rotates this Snapshot's coordinate system byangle
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 this Snapshot's current coordinate system.To rotate around axes other than the Z axis, use
Transform.rotate3d(float, org.gnome.graphene.Vec3)
.- Parameters:
angle
- the rotation angle, in degrees (clockwise)
-
rotate3d
Rotates this Snapshot's coordinate system byangle
degrees aroundaxis
.For a rotation in 2D space, use
Transform.rotate(float)
.- 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()
andrestore()
can be nested; each call togtk_snapshot_restore()
restores the state from the matching pairedgtk_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 this 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 axisfactorY
- scaling factor on the Y axis
-
scale3d
public void scale3d(float factorX, float factorY, float factorZ) Scales this Snapshot's coordinate system by the given factors.- Parameters:
factorX
- scaling factor on the X axisfactorY
- scaling factor on the Y axisfactorZ
- scaling factor on the Z axis
-
toNode
Returns the render node that was constructed by this 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 this Snapshot. The only function that should be called after this is
GObject.unref()
.- Returns:
- the constructed
GskRenderNode
ornull
if there are no nodes to render.
-
toPaintable
Returns a paintable encapsulating the render node that was constructed by this Snapshot.After calling this function, it is no longer possible to add more nodes to this Snapshot. The only function that should be called after this is
GObject.unref()
.- Parameters:
size
- The size of the resulting paintable ornull
to use the bounds of the snapshot- Returns:
- a new
GdkPaintable
-
transform
Transforms this Snapshot's coordinate system with the giventransform
.- Parameters:
transform
- the transform to apply
-
transformMatrix
Transforms this Snapshot's coordinate system with the givenmatrix
.- Parameters:
matrix
- the matrix to multiply the transform with
-
translate
Translates this Snapshot's coordinate system bypoint
in 2-dimensional space.- Parameters:
point
- the point to translate the snapshot by
-
translate3d
Translates this Snapshot's coordinate system bypoint
.- Parameters:
point
- the point to translate the snapshot by
-
builder
ASnapshot.Builder
object constructs aSnapshot
with the specified properties. Use the variousset...()
methods to set properties, and finish construction withSnapshot.Builder.build()
.
-