Gtk.Snapshot¶
class — extends Gdk.Snapshot
Assists in creating Gsk.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
Snapshot.pop to change the current node.
The typical way to obtain a GtkSnapshot object is as an argument to
the Widget.snapshot vfunc. If you need to create your own
GtkSnapshot, use 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.
Constructors¶
new¶
Creates a new GtkSnapshot.
Methods¶
append_border¶
def append_border(self, outline: Gsk.RoundedRect, border_width: list[float], border_color: list[Gdk.RGBA]) -> None
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 borderborder_width— the stroke width of the border on the top, right, bottom and left side respectively.border_color— the color used on the top, right, bottom and left side.
append_cairo¶
Creates a new 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
append_color¶
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 drawbounds— the bounds for the new node
append_conic_gradient¶
def append_conic_gradient(self, bounds: Graphene.Rect, center: Graphene.Point, rotation: float, stops: list[Gsk.ColorStop]) -> None
Appends a conic gradient node with the given stops to 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
append_fill¶
A convenience method to fill a path with a color.
See Snapshot.push_fill if you need
to fill a path with more complex content than
a color.
Parameters:
path— The path describing the area to fillfill_rule— The fill rule to usecolor— the color to fill the path with
append_inset_shadow¶
def append_inset_shadow(self, outline: Gsk.RoundedRect, color: Gdk.RGBA, dx: float, dy: float, spread: float, blur_radius: float) -> None
Appends an inset shadow into the box given by outline.
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 insideblur_radius— how much blur to apply to the shadow
append_layout¶
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 Widget.get_color.
Note that if the layout does not produce any visible output, then nodes
may not be added to the snapshot.
Parameters:
layout— thePangoLayoutto rendercolor— the foreground color to render the layout in
append_linear_gradient¶
def append_linear_gradient(self, bounds: Graphene.Rect, start_point: Graphene.Point, end_point: Graphene.Point, stops: list[Gsk.ColorStop]) -> None
Appends a linear gradient node with the given stops to snapshot.
Parameters:
bounds— the rectangle to render the linear gradient intostart_point— the point at which the linear gradient will beginend_point— the point at which the linear gradient will finishstops— the color stops defining the gradient
append_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— aGskRenderNode
append_outset_shadow¶
def append_outset_shadow(self, outline: Gsk.RoundedRect, color: Gdk.RGBA, dx: float, dy: float, spread: float, blur_radius: float) -> None
Appends an outset shadow node around the box given by outline.
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 outsideblur_radius— how much blur to apply to the shadow
append_paste¶
Creates a new render node that pastes the contents
copied by a previous call to Snapshot.push_copy
Parameters:
bounds— the bounds for the new nodenth— the index of the copy, with 0 being the latest copy, 1 being the copy before that, and so on.
append_radial_gradient¶
def append_radial_gradient(self, bounds: Graphene.Rect, center: Graphene.Point, hradius: float, vradius: float, start: float, end: float, stops: list[Gsk.ColorStop]) -> None
Appends a radial gradient node with the given stops to 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
append_repeating_linear_gradient¶
def append_repeating_linear_gradient(self, bounds: Graphene.Rect, start_point: Graphene.Point, end_point: Graphene.Point, stops: list[Gsk.ColorStop]) -> None
Appends a repeating linear gradient node with the given stops to snapshot.
Parameters:
bounds— the rectangle to render the linear gradient intostart_point— the point at which the linear gradient will beginend_point— the point at which the linear gradient will finishstops— the color stops defining the gradient
append_repeating_radial_gradient¶
def append_repeating_radial_gradient(self, bounds: Graphene.Rect, center: Graphene.Point, hradius: float, vradius: float, start: float, end: float, stops: list[Gsk.ColorStop]) -> None
Appends a repeating radial gradient node with the given stops to 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
append_scaled_texture¶
def append_scaled_texture(self, texture: Gdk.Texture, filter: Gsk.ScalingFilter | int, bounds: Graphene.Rect) -> None
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 Snapshot.append_texture,
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
append_stroke¶
A convenience method to stroke a path with a color.
See Snapshot.push_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
append_texture¶
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 Snapshot.append_scaled_texture
if you need other filtering, such as nearest-neighbour.
Parameters:
texture— the texture to renderbounds— the bounds for the new node
gl_shader_pop_texture¶
:::warning Deprecated since 4.16 This API is deprecated. :::
Removes the top element from the stack of render nodes and
adds it to the nearest Gsk.GLShaderNode below it.
This must be called the same number of times as the number
of textures is needed for the shader in
Snapshot.push_gl_shader.
perspective¶
Applies a perspective projection transform.
See Gsk.Transform.perspective for a discussion on the details.
Parameters:
depth— distance of the z=0 plane
pop¶
Removes the top element from the stack of render nodes, and appends it to the node underneath it.
push_blend¶
Blends together two images with the given blend mode.
Until the first call to 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 Snapshot.pop.
Calling this function requires two subsequent calls
to Snapshot.pop.
Parameters:
blend_mode— blend mode to use
push_blur¶
Blurs an image.
The image is recorded until the next call to Snapshot.pop.
Parameters:
radius— the blur radius to use. Must be positive
push_clip¶
Clips an image to a rectangle.
The image is recorded until the next call to Snapshot.pop.
Parameters:
bounds— the rectangle to clip to
push_color_matrix¶
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 Snapshot.pop.
Parameters:
color_matrix— the color matrix to usecolor_offset— the color offset to use
push_component_transfer¶
def push_component_transfer(self, red: Gsk.ComponentTransfer, green: Gsk.ComponentTransfer, blue: Gsk.ComponentTransfer, alpha: Gsk.ComponentTransfer) -> None
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 Snapshot.pop.
Parameters:
red— the transfer for the red componentgreen— the transfer for the green componentblue— the transfer for the blue componentalpha— the transfer for the alpha component
push_composite¶
Until the first call to 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 Snapshot.pop.
Calling this function requires 2 subsequent calls to Snapshot.pop.
Parameters:
op— The Porter/Duff compositing operator to use
push_copy¶
Stores the current rendering state for later pasting via
Snapshot.append_paste.
Pasting is possible until the matching call to Snapshot.pop.
push_cross_fade¶
Snapshots a cross-fade operation between two images with the
given progress.
Until the first call to Snapshot.pop, the start image
will be snapshot. After that call, the end image will be recorded
until the second call to Snapshot.pop.
Calling this function requires two subsequent calls
to Snapshot.pop.
Parameters:
progress— progress between 0.0 and 1.0
push_fill¶
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 Snapshot.pop.
If you want to fill the path with a color, Snapshot.append_fill
than rendering new ones, use Snapshot.append_fill
may be more convenient.
Parameters:
path— The path describing the area to fillfill_rule— The fill rule to use
push_gl_shader¶
:::warning Deprecated since 4.16 This API is deprecated. :::
Push a Gsk.GLShaderNode.
The node uses the given Gsk.GLShader and uniform values
Additionally this takes a list of n_children other nodes
which will be passed to the 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 Gsk.GLShader.format_args
or 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 Gsk.GLShader.compile to ensure the shader
will work for the renderer before using it.
If the shader requires textures (see Gsk.GLShader.get_n_textures),
then it is expected that you call 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
Snapshot.pop.
If you want to use pre-existing textures as input to the shader rather
than rendering new ones, use 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 Gsk.GLShader.
Parameters:
shader— The code to runbounds— the rectangle to render intotake_args— Data block with arguments for the shader.
push_isolation¶
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 Snapshot.pop.
Parameters:
features— features that are isolated
push_mask¶
Until the first call to 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 Snapshot.pop.
Calling this function requires 2 subsequent calls to Snapshot.pop.
Parameters:
mask_mode— mask mode to use
push_opacity¶
Modifies the opacity of an image.
The image is recorded until the next call to Snapshot.pop.
Parameters:
opacity— the opacity to use
push_repeat¶
Creates a node that repeats the child node.
The child is recorded until the next call to Snapshot.pop.
Parameters:
bounds— the bounds within which to repeatchild_bounds— the bounds of the child orNoneto use the full size of the collected child node
push_rounded_clip¶
Clips an image to a rounded rectangle.
The image is recorded until the next call to Snapshot.pop.
Parameters:
bounds— the rounded rectangle to clip to
push_shadow¶
Applies a shadow to an image.
The image is recorded until the next call to Snapshot.pop.
Parameters:
shadow— the first shadow specification
push_stroke¶
Strokes the given path with the attributes given by stroke and
an image.
The image is recorded until the next call to 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, Snapshot.append_stroke
may be more convenient.
Parameters:
path— The path to strokestroke— The stroke attributes
render_background¶
def render_background(self, context: StyleContext, x: float, y: float, width: float, height: float) -> None
:::warning Deprecated since 4.10 This API is 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 backgroundx— X origin of the rectangley— Y origin of the rectanglewidth— rectangle widthheight— rectangle height
render_focus¶
def render_focus(self, context: StyleContext, x: float, y: float, width: float, height: float) -> None
:::warning Deprecated since 4.10 This API is 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 ringx— X origin of the rectangley— Y origin of the rectanglewidth— rectangle widthheight— rectangle height
render_frame¶
def render_frame(self, context: StyleContext, x: float, y: float, width: float, height: float) -> None
:::warning Deprecated since 4.10 This API is 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 framex— X origin of the rectangley— Y origin of the rectanglewidth— rectangle widthheight— rectangle height
render_insertion_cursor¶
def render_insertion_cursor(self, context: StyleContext, x: float, y: float, layout: Pango.Layout, index: int, direction: Pango.Direction | int) -> None
:::warning Deprecated since 4.10 This API is deprecated. :::
Draws a text caret using snapshot at the specified index of layout.
Parameters:
context— aGtkStyleContextx— X originy— Y originlayout— thePangoLayoutof the textindex— the index in thePangoLayoutdirection— thePangoDirectionof the text
render_layout¶
:::warning Deprecated since 4.10 This API is 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 textx— X origin of the rectangley— Y origin of the rectanglelayout— thePangoLayoutto render
restore¶
Restores snapshot to the state saved by a preceding call to
Snapshot.save and removes that state from the stack of
saved states.
rotate¶
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 Gsk.Transform.rotate_3d.
Parameters:
angle— the rotation angle, in degrees (clockwise)
rotate_3d¶
Rotates snapshot's coordinate system by angle degrees around axis.
For a rotation in 2D space, use Gsk.Transform.rotate.
Parameters:
angle— the rotation angle, in degrees (clockwise)axis— The rotation axis
save¶
Makes a copy of the current state of snapshot and saves it
on an internal stack.
When Snapshot.restore is called, snapshot will
be restored to the saved state.
Multiple calls to Snapshot.save and 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¶
Scales snapshot's coordinate system in 2-dimensional space by
the given factors.
Use Snapshot.scale_3d to scale in all 3 dimensions.
Parameters:
factor_x— scaling factor on the X axisfactor_y— scaling factor on the Y axis
scale_3d¶
Scales snapshot's coordinate system by the given factors.
Parameters:
factor_x— scaling factor on the X axisfactor_y— scaling factor on the Y axisfactor_z— scaling factor on the Z axis
to_node¶
Returns the render node that was constructed
by snapshot.
Note that this function may return None 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.Object.unref.
to_paintable¶
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.Object.unref.
Parameters:
size— The size of the resulting paintable orNoneto use the bounds of the snapshot
transform¶
Transforms snapshot's coordinate system with the given transform.
Parameters:
transform— the transform to apply
transform_matrix¶
Transforms snapshot's coordinate system with the given matrix.
Parameters:
matrix— the matrix to multiply the transform with
translate¶
Translates snapshot's coordinate system by point in 2-dimensional space.
Parameters:
point— the point to translate the snapshot by
translate_3d¶
Translates snapshot's coordinate system by point.
Parameters:
point— the point to translate the snapshot by