Gsk.RenderReplay¶
Fields¶
None
Methods¶
class |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Details¶
- class Gsk.RenderReplay¶
A facility to replay a [class`Gsk`.RenderNode] and its children, potentially modifying them.
This is a utility tool to walk a rendernode tree. The most powerful way is to provide a function via [method`Gsk`.RenderReplay.set_node_filter] to filter each individual node and then run [method`Gsk`.RenderReplay.filter_node] on the nodes you want to filter.
If you want to just walk the node tree and extract information without any modifications, you can also use [method`Gsk`.RenderNode.get_children].
Here is a little example application that redacts text in a node file:
``` #include <gtk/gtk.h>
static
Gsk.RenderNode* redact_nodes (Gsk.RenderReplay*replay,Gsk.RenderNode*node,objectuser_data) {Gsk.RenderNode*result;if (
Gsk.RenderNode.get_node_type(node) ==Gsk.RenderNodeType.TEXT_NODE) {Graphene.Rectbounds; constGdk.RGBA*color;Gsk.RenderNode.get_bounds(node, &bounds); color =Gsk.TextNode.get_color(node);result =
Gsk.ColorNode.new(color, &bounds); } else { result =Gsk.RenderReplay.default(replay, node); }return result; }
int main (int argc,
str*argv[]) {Gio.File*file;GLib.Bytes*bytes;Gsk.RenderNode*result, *node;Gsk.RenderReplay*replay;gtk_init ();
if (argc != 3) { g_print (“usage: %s INFILE OUTFILE\n”, argv[0]); return 0; }
file =
Gio.File.new_for_commandline_arg(argv[1]); bytes =Gio.File.load_bytes(file,None,None,None);GObject.Object.unref(file); if (bytes ==None) return 1;node =
Gsk.RenderNode.deserialize(bytes,None,None);GLib.Bytes.unref(bytes); if (node ==None) return 1;replay =
Gsk.RenderReplay.new();Gsk.RenderReplay.set_node_filter(replay, redact_nodes,None,None); result =Gsk.RenderReplay.filter_node(replay, node);Gsk.RenderReplay.free(replay);if (!:obj:Gsk.RenderNode.write_to_file (result, argv[2],
None)) return 1;Gsk.RenderNode.unref(result);Gsk.RenderNode.unref(node);return 0; } ```
New in version 4.22.
- classmethod new()¶
- Returns:
A new replay object to replay nodes
- Return type:
Creates a new replay object to replay nodes.
New in version 4.22.
- default(node)¶
- Parameters:
node (
Gsk.RenderNode) – the node to replay- Returns:
The replayed node
- Return type:
Replays the node using the default method.
The default method calls [method`Gsk`.RenderReplay.filter_node] on all its child nodes and the filter functions for all its properties. If none of them are changed, it returns the passed in node. Otherwise it constructs a new node with the changed children and properties.
It may not be possible to construct a new node when any of the callbacks return
None. In that case, this function will returnNone, too.New in version 4.22.
- filter_font(font)¶
- Parameters:
font (
Pango.Font) – The font to filter- Returns:
the filtered font
- Return type:
Filters a font using the current filter function.
New in version 4.22.
- filter_node(node)¶
- Parameters:
node (
Gsk.RenderNode) – the node to replay- Returns:
The replayed node
- Return type:
Replays a node using the replay’s filter function.
After the replay the node may be unchanged, or it may be removed, which will result in
Nonebeing returned.If no filter node is set, [method`Gsk`.RenderReplay.default] is called instead.
New in version 4.22.
- filter_texture(texture)¶
- Parameters:
texture (
Gdk.Texture) – The texture to filter- Returns:
the filtered texture
- Return type:
Filters a texture using the current filter function.
New in version 4.22.
- free()¶
Frees a
GskRenderReplay.New in version 4.22.
- set_font_filter(filter, *user_data)¶
- Parameters:
filter (
Gsk.RenderReplayFontFilterorNone) – the font filter function
Sets a filter function to be called by [method`Gsk`.RenderReplay.default] for nodes that contain fonts.
You can call [method`GskRenderReplay`.filter_font] to filter a font yourself.
New in version 4.22.
- set_node_filter(filter, *user_data)¶
- Parameters:
filter (
Gsk.RenderReplayNodeFilterorNone) – the function to call to replay nodes
Sets the function to use as a node filter.
This is the most complex function to use for replaying nodes. It can either:
keep the node and just return it unchanged
create a replacement node and return that
discard the node by returning
NULLcall [method`Gsk`.RenderReplay.default] to have the default handler run for this node, which calls your function on its children
New in version 4.22.
- set_texture_filter(filter, *user_data)¶
- Parameters:
filter (
Gsk.RenderReplayTextureFilterorNone) – the texture filter function
Sets a filter function to be called by [method`Gsk`.RenderReplay.default] for nodes that contain textures.
You can call [method`GskRenderReplay`.filter_texture] to filter a texture yourself.
New in version 4.22.