gi-gsk-4.0.9: Gsk bindings
CopyrightWill Thompson and Iñaki García Etxebarria
LicenseLGPL-2.1
MaintainerIñaki García Etxebarria
Safe HaskellNone
LanguageHaskell2010

GI.Gsk.Structs.RenderReplay

Description

A facility to replay a 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 renderReplaySetNodeFilter to filter each individual node and then run renderReplayFilterNode on the nodes you want to filter.

An easier method exists to just walk the node tree and extract information without any modifications. If you want to do that, the functions renderReplaySetNodeForeach exists. You can also call renderReplayForeachNode to run that function. Note that the previously mentioned complex functionality will still be invoked if you have set up a function for it, but its result will not be returned.

Here is an example that combines both approaches to print the whole tree:

c code

#include <gtk/gtk.h>

static GskRenderNode *
print_nodes (GskRenderReplay *replay,
             GskRenderNode   *node,
             gpointer         user_data)
{
  int *depth = user_data;
  GskRenderNode *result;

  g_print ("%*s%s\n", 2 * *depth, "", g_type_name_from_instance ((GTypeInstance *) node));
  
  *depth += 1;
  result = gsk_render_replay_default (replay, node);
  *depth -= 1;

  return result;
}

int
main (int argc, char *argv[])
{
  GFile *file;
  GBytes *bytes;
  GskRenderNode *node;
  GskRenderReplay *replay;
  int depth = 0;

  gtk_init ();

  if (argc < 2)
    {
      g_print ("usage: %s NODEFILE\n", argv[0]);
      return 0;
    }

  file = g_file_new_for_commandline_arg (argv[1]);
  bytes = g_file_load_bytes (file, NULL, NULL, NULL);
  g_object_unref (file);
  if (bytes == NULL)
    return 1;

  node = gsk_render_node_deserialize (bytes, NULL, NULL);
  g_bytes_unref (bytes);
  if (node == NULL)
    return 1;

  replay = gsk_render_replay_new ();
  gsk_render_replay_set_node_filter (replay, print_nodes, &depth, NULL);
  gsk_render_node_foreach_node (replay, node);
  gsk_render_node_unref (node);

  return 0;
}

Since: 4.22

Synopsis

Exported types

Methods

Click to display all available methods, including inherited ones

Expand

Methods

default, filterFont, filterNode, filterTexture, foreachNode, free.

Getters

None.

Setters

setFontFilter, setNodeFilter, setNodeForeach, setTextureFilter.

default

renderReplayDefault Source #

Arguments

:: (HasCallStack, MonadIO m, IsRenderNode a) 
=> RenderReplay

self: the replay

-> a

node: the node to replay

-> m (Maybe RenderNode)

Returns: The replayed node

Replays the node using the default method.

The default method calls renderReplayFilterNode 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 NULL. In that case, this function will return NULL, too.

Since: 4.22

filterFont

renderReplayFilterFont Source #

Arguments

:: (HasCallStack, MonadIO m, IsFont a) 
=> RenderReplay

self: the replay

-> a

font: The font to filter

-> m Font

Returns: the filtered font

Filters a font using the current filter function.

Since: 4.22

filterNode

renderReplayFilterNode Source #

Arguments

:: (HasCallStack, MonadIO m, IsRenderNode a) 
=> RenderReplay

self: the replay

-> a

node: the node to replay

-> m (Maybe RenderNode)

Returns: The replayed node

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 Nothing being returned.

This function calls the registered callback in the following order:

  1. If a foreach function is set, it is called first. If it returns false, this function immediately exits and returns the passed in node.
  2. If a node filter is set, it is called and its result is returned.
  3. renderReplayDefault is called and its result is returned.

Since: 4.22

filterTexture

renderReplayFilterTexture Source #

Arguments

:: (HasCallStack, MonadIO m, IsTexture a) 
=> RenderReplay

self: the replay

-> a

texture: The texture to filter

-> m Texture

Returns: the filtered texture

Filters a texture using the current filter function.

Since: 4.22

foreachNode

renderReplayForeachNode Source #

Arguments

:: (HasCallStack, MonadIO m, IsRenderNode a) 
=> RenderReplay

self: the replay

-> a

node: the node to replay

-> m () 

Calls the filter and foreach functions for each node.

This function calls renderReplayFilterNode internally, but discards the result assuming no changes were made.

Since: 4.22

free

renderReplayFree Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> RenderReplay

self: the replay object to free

-> m () 

Frees a GskRenderReplay.

Since: 4.22

new

renderReplayNew Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> m RenderReplay

Returns: A new replay object to replay nodes

Creates a new replay object to replay nodes.

Since: 4.22

setFontFilter

renderReplaySetFontFilter Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> RenderReplay

self: the replay

-> Maybe RenderReplayFontFilter

filter: the font filter function

-> m () 

Sets a filter function to be called by renderReplayDefault for nodes that contain fonts.

You can call [methodgskRenderReplay.filter_font] to filter a font yourself.

Since: 4.22

setNodeFilter

renderReplaySetNodeFilter Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> RenderReplay 
-> Maybe RenderReplayNodeFilter

filter: the function to call to replay nodes

-> m () 

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 NULL
  • call renderReplayDefault to have the default handler run for this node, which calls your function on its children

Since: 4.22

setNodeForeach

renderReplaySetNodeForeach Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> RenderReplay

self: the replay

-> Maybe RenderReplayNodeForeach

foreach: the function to call for all nodes

-> m () 

Sets the function to call for every node.

This function is called before the node filter, so if it returns false, the node filter will never be called.

Since: 4.22

setTextureFilter

renderReplaySetTextureFilter Source #

Arguments

:: (HasCallStack, MonadIO m) 
=> RenderReplay

self: the replay

-> Maybe RenderReplayTextureFilter

filter: the texture filter function

-> m () 

Sets a filter function to be called by renderReplayDefault for nodes that contain textures.

You can call [methodgskRenderReplay.filter_texture] to filter a texture yourself.

Since: 4.22