snapshot: Add gtk_snapshot_push_fill()
This commit is contained in:
@@ -105,6 +105,10 @@ struct _GtkSnapshotState {
|
||||
struct {
|
||||
GskRoundedRect bounds;
|
||||
} rounded_clip;
|
||||
struct {
|
||||
GskPath *path;
|
||||
GskFillRule fill_rule;
|
||||
} fill;
|
||||
struct {
|
||||
gsize n_shadows;
|
||||
GskShadow *shadows;
|
||||
@@ -1096,6 +1100,71 @@ gtk_snapshot_push_rounded_clip (GtkSnapshot *snapshot,
|
||||
gsk_rounded_rect_scale_affine (&state->data.rounded_clip.bounds, bounds, scale_x, scale_y, dx, dy);
|
||||
}
|
||||
|
||||
static GskRenderNode *
|
||||
gtk_snapshot_collect_fill (GtkSnapshot *snapshot,
|
||||
GtkSnapshotState *state,
|
||||
GskRenderNode **nodes,
|
||||
guint n_nodes)
|
||||
{
|
||||
GskRenderNode *node, *fill_node;
|
||||
|
||||
node = gtk_snapshot_collect_default (snapshot, state, nodes, n_nodes);
|
||||
if (node == NULL)
|
||||
return NULL;
|
||||
|
||||
fill_node = gsk_fill_node_new (node,
|
||||
state->data.fill.path,
|
||||
state->data.fill.fill_rule);
|
||||
|
||||
if (fill_node->bounds.size.width == 0 ||
|
||||
fill_node->bounds.size.height == 0)
|
||||
{
|
||||
gsk_render_node_unref (node);
|
||||
gsk_render_node_unref (fill_node);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gsk_render_node_unref (node);
|
||||
|
||||
return fill_node;
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_snapshot_clear_fill (GtkSnapshotState *state)
|
||||
{
|
||||
gsk_path_unref (state->data.fill.path);
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_snapshot_push_fill:
|
||||
* @snapshot: a #GtkSnapshot
|
||||
* @path: The path describing the area to fill
|
||||
* @fill_rule: The fill rule to use
|
||||
*
|
||||
* 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 gtk_snapshot_pop().
|
||||
*/
|
||||
void
|
||||
gtk_snapshot_push_fill (GtkSnapshot *snapshot,
|
||||
GskPath *path,
|
||||
GskFillRule fill_rule)
|
||||
{
|
||||
GtkSnapshotState *state;
|
||||
|
||||
/* FIXME: Is it worth calling ensure_affine() and transforming the path here? */
|
||||
gtk_snapshot_ensure_identity (snapshot);
|
||||
|
||||
state = gtk_snapshot_push_state (snapshot,
|
||||
gtk_snapshot_get_current_state (snapshot)->transform,
|
||||
gtk_snapshot_collect_fill,
|
||||
gtk_snapshot_clear_fill);
|
||||
|
||||
state->data.fill.path = gsk_path_ref (path);
|
||||
state->data.fill.fill_rule = fill_rule;
|
||||
}
|
||||
|
||||
static GskRenderNode *
|
||||
gtk_snapshot_collect_shadow (GtkSnapshot *snapshot,
|
||||
GtkSnapshotState *state,
|
||||
|
||||
@@ -88,6 +88,10 @@ GDK_AVAILABLE_IN_ALL
|
||||
void gtk_snapshot_push_rounded_clip (GtkSnapshot *snapshot,
|
||||
const GskRoundedRect *bounds);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_snapshot_push_fill (GtkSnapshot *snapshot,
|
||||
GskPath *path,
|
||||
GskFillRule fill_rule);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_snapshot_push_shadow (GtkSnapshot *snapshot,
|
||||
const GskShadow *shadow,
|
||||
gsize n_shadows);
|
||||
|
||||
Reference in New Issue
Block a user