2016-11-07 18:10:49 +00:00
|
|
|
/* GTK - The GIMP Toolkit
|
|
|
|
* Copyright (C) 2016 Benjamin Otte <otte@gnome.org>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "gtksnapshot.h"
|
|
|
|
#include "gtksnapshotprivate.h"
|
|
|
|
|
2016-11-13 22:54:30 +00:00
|
|
|
#include "gtkcssrgbavalueprivate.h"
|
|
|
|
#include "gtkcssshadowsvalueprivate.h"
|
2016-11-13 15:16:39 +00:00
|
|
|
#include "gtkrenderbackgroundprivate.h"
|
|
|
|
#include "gtkrenderborderprivate.h"
|
2016-11-15 05:19:16 +00:00
|
|
|
#include "gtkrendericonprivate.h"
|
2016-11-13 15:16:39 +00:00
|
|
|
#include "gtkstylecontextprivate.h"
|
|
|
|
|
2016-11-11 23:37:54 +00:00
|
|
|
#include "gsk/gskrendernodeprivate.h"
|
|
|
|
|
2016-11-18 11:53:57 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:gtksnapshot
|
|
|
|
* @Short_description: Auxiliary object for snapshots
|
|
|
|
* @Title: GtkSnapshot
|
|
|
|
*
|
|
|
|
* GtkSnapshot is an auxiliary object that assists in creating #GskRenderNodes
|
|
|
|
* in the #GtkWidget::snapshot vfunc. 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 the one that gtk_snapshot_append_node()
|
|
|
|
* operates on. Use the gtk_snapshot_push_() and gtk_snapshot_pop() functions to
|
|
|
|
* change the current node.
|
|
|
|
*
|
|
|
|
* The only way to obtain a #GtkSnapshot object is as an argument to
|
|
|
|
* the #GtkWidget::snapshot vfunc.
|
|
|
|
*/
|
|
|
|
|
2016-11-17 00:55:26 +00:00
|
|
|
static GtkSnapshotState *
|
|
|
|
gtk_snapshot_state_new (GtkSnapshotState *parent,
|
|
|
|
GskRenderNode *node)
|
|
|
|
{
|
|
|
|
GtkSnapshotState *state;
|
|
|
|
|
|
|
|
state = g_slice_new0 (GtkSnapshotState);
|
|
|
|
|
|
|
|
state->node = node;
|
|
|
|
state->parent = parent;
|
|
|
|
graphene_matrix_init_identity (&state->transform);
|
|
|
|
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_snapshot_state_free (GtkSnapshotState *state)
|
|
|
|
{
|
|
|
|
g_slice_free (GtkSnapshotState, state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_snapshot_state_set_transform (GtkSnapshotState *state,
|
|
|
|
const graphene_matrix_t *transform)
|
|
|
|
{
|
|
|
|
graphene_matrix_init_from_matrix (&state->transform, transform);
|
2016-11-17 02:31:15 +00:00
|
|
|
|
|
|
|
state->world_is_valid = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const graphene_matrix_t *
|
|
|
|
gtk_snapshot_state_get_world_transform (GtkSnapshotState *state)
|
|
|
|
{
|
|
|
|
if (!state->world_is_valid)
|
|
|
|
{
|
|
|
|
if (state->parent)
|
|
|
|
graphene_matrix_multiply (gtk_snapshot_state_get_world_transform (state->parent),
|
|
|
|
&state->transform,
|
|
|
|
&state->world_transform);
|
|
|
|
else
|
|
|
|
graphene_matrix_init_from_matrix (&state->world_transform, &state->transform);
|
|
|
|
|
|
|
|
state->world_is_valid = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return &state->world_transform;
|
2016-11-17 00:55:26 +00:00
|
|
|
}
|
|
|
|
|
2016-11-07 18:10:49 +00:00
|
|
|
void
|
2016-11-17 01:14:10 +00:00
|
|
|
gtk_snapshot_init (GtkSnapshot *snapshot,
|
|
|
|
GskRenderer *renderer,
|
2016-12-09 20:33:38 +00:00
|
|
|
const cairo_region_t *clip,
|
|
|
|
const char *name,
|
|
|
|
...)
|
2016-11-07 18:10:49 +00:00
|
|
|
{
|
2016-12-09 20:33:38 +00:00
|
|
|
cairo_rectangle_int_t extents;
|
|
|
|
|
|
|
|
cairo_region_get_extents (clip, &extents);
|
|
|
|
|
2016-11-17 01:14:10 +00:00
|
|
|
snapshot->state = NULL;
|
|
|
|
snapshot->renderer = renderer;
|
|
|
|
snapshot->clip_region = clip;
|
2016-12-09 20:33:38 +00:00
|
|
|
snapshot->root = gsk_renderer_create_render_node (renderer);
|
|
|
|
gsk_render_node_set_bounds (snapshot->root, &GRAPHENE_RECT_INIT (extents.x, extents.y, extents.width, extents.height));
|
|
|
|
|
|
|
|
if (name)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
char *str;
|
|
|
|
|
|
|
|
va_start (args, name);
|
|
|
|
str = g_strdup_vprintf (name, args);
|
|
|
|
va_end (args);
|
|
|
|
|
|
|
|
gsk_render_node_set_name (snapshot->root, str);
|
|
|
|
|
|
|
|
g_free (str);
|
|
|
|
}
|
|
|
|
|
|
|
|
snapshot->state = gtk_snapshot_state_new (NULL, snapshot->root);
|
2016-11-07 18:10:49 +00:00
|
|
|
}
|
|
|
|
|
2016-11-11 23:37:54 +00:00
|
|
|
GskRenderNode *
|
2016-11-17 00:55:26 +00:00
|
|
|
gtk_snapshot_finish (GtkSnapshot *snapshot)
|
2016-11-08 00:42:06 +00:00
|
|
|
{
|
2016-12-09 20:33:38 +00:00
|
|
|
gtk_snapshot_pop (snapshot);
|
|
|
|
|
2016-11-17 00:55:26 +00:00
|
|
|
if (snapshot->state != NULL)
|
2016-11-11 23:37:54 +00:00
|
|
|
{
|
|
|
|
g_warning ("Too many gtk_snapshot_push() calls.");
|
|
|
|
}
|
2016-11-08 00:42:06 +00:00
|
|
|
|
2016-11-17 00:55:26 +00:00
|
|
|
return snapshot->root;
|
2016-11-08 00:42:06 +00:00
|
|
|
}
|
|
|
|
|
2016-11-18 11:53:57 +00:00
|
|
|
/**
|
|
|
|
* gtk_snapshot_push_node:
|
|
|
|
* @snapshot: a #GtkSnapshot
|
|
|
|
* @node: the render node to push
|
|
|
|
*
|
|
|
|
* Appends @node to the current render node of @snapshot,
|
|
|
|
* and makes @node the new current render node.
|
|
|
|
*
|
|
|
|
* Since: 3.90
|
|
|
|
*/
|
2016-11-07 18:10:49 +00:00
|
|
|
void
|
2016-11-17 00:55:26 +00:00
|
|
|
gtk_snapshot_push_node (GtkSnapshot *snapshot,
|
2016-11-13 15:16:39 +00:00
|
|
|
GskRenderNode *node)
|
2016-11-07 18:10:49 +00:00
|
|
|
{
|
2016-11-17 00:55:26 +00:00
|
|
|
gtk_snapshot_append_node (snapshot, node);
|
2016-11-07 18:10:49 +00:00
|
|
|
|
2016-11-17 00:55:26 +00:00
|
|
|
snapshot->state = gtk_snapshot_state_new (snapshot->state, node);
|
2016-11-07 18:10:49 +00:00
|
|
|
}
|
|
|
|
|
2016-11-18 11:53:57 +00:00
|
|
|
/**
|
|
|
|
* gtk_snapshot_push:
|
|
|
|
* @snapshot: a #GtkSnapshot
|
|
|
|
* @bounds: the bounds for the new node
|
2016-12-01 09:19:24 +00:00
|
|
|
* @name: (transfer none): a printf() style format string for the name for the new node
|
2016-11-18 11:53:57 +00:00
|
|
|
* @...: arguments to insert into the format string
|
|
|
|
*
|
|
|
|
* Creates a new render node, appends it to the current render
|
|
|
|
* node of @snapshot, and makes it the new current render node.
|
|
|
|
*
|
|
|
|
* Since: 3.90
|
|
|
|
*/
|
2016-11-13 15:16:39 +00:00
|
|
|
void
|
2016-11-18 12:57:10 +00:00
|
|
|
gtk_snapshot_push (GtkSnapshot *snapshot,
|
2016-11-13 15:16:39 +00:00
|
|
|
const graphene_rect_t *bounds,
|
|
|
|
const char *name,
|
|
|
|
...)
|
|
|
|
{
|
|
|
|
GskRenderNode *node;
|
|
|
|
|
2016-11-18 12:57:10 +00:00
|
|
|
node = gsk_renderer_create_render_node (snapshot->renderer);
|
2016-11-13 15:16:39 +00:00
|
|
|
gsk_render_node_set_bounds (node, bounds);
|
|
|
|
|
|
|
|
if (name)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
char *str;
|
|
|
|
|
|
|
|
va_start (args, name);
|
|
|
|
str = g_strdup_vprintf (name, args);
|
|
|
|
va_end (args);
|
|
|
|
|
|
|
|
gsk_render_node_set_name (node, str);
|
|
|
|
|
|
|
|
g_free (str);
|
|
|
|
}
|
|
|
|
|
2016-11-18 12:57:10 +00:00
|
|
|
gtk_snapshot_push_node (snapshot, node);
|
2016-11-13 15:16:39 +00:00
|
|
|
gsk_render_node_unref (node);
|
|
|
|
}
|
|
|
|
|
2016-11-18 11:53:57 +00:00
|
|
|
/**
|
|
|
|
* gtk_snapshot_pop:
|
|
|
|
* @snapshot: a #GtkSnapshot
|
|
|
|
*
|
|
|
|
* Removes the top element from the stack of render nodes,
|
|
|
|
* making the node underneath the current node again.
|
|
|
|
*
|
|
|
|
* Since: 3.90
|
|
|
|
*/
|
2016-11-07 18:10:49 +00:00
|
|
|
void
|
2016-11-17 00:55:26 +00:00
|
|
|
gtk_snapshot_pop (GtkSnapshot *snapshot)
|
2016-11-07 18:10:49 +00:00
|
|
|
{
|
2016-11-17 00:55:26 +00:00
|
|
|
GtkSnapshotState *state;
|
|
|
|
|
|
|
|
if (snapshot->state == NULL)
|
2016-11-11 23:37:54 +00:00
|
|
|
{
|
|
|
|
g_warning ("Too many gtk_snapshot_pop() calls.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-11-17 00:55:26 +00:00
|
|
|
state = snapshot->state;
|
|
|
|
snapshot->state = state->parent;
|
2016-11-11 23:37:54 +00:00
|
|
|
|
2016-11-17 00:55:26 +00:00
|
|
|
gtk_snapshot_state_free (state);
|
2016-11-07 18:10:49 +00:00
|
|
|
}
|
|
|
|
|
2016-11-18 11:53:57 +00:00
|
|
|
/**
|
|
|
|
* gtk_snapshot_get_renderer:
|
|
|
|
* @snapshot: a #GtkSnapshot
|
|
|
|
*
|
|
|
|
* Obtains the #GskRenderer that this snapshot will be
|
|
|
|
* rendered with.
|
|
|
|
*
|
2016-12-01 09:19:24 +00:00
|
|
|
* Returns: (transfer none): the #GskRenderer
|
2016-11-18 11:53:57 +00:00
|
|
|
*
|
|
|
|
* Since: 3.90
|
|
|
|
*/
|
2016-11-07 18:10:49 +00:00
|
|
|
GskRenderer *
|
2016-11-18 12:57:10 +00:00
|
|
|
gtk_snapshot_get_renderer (const GtkSnapshot *snapshot)
|
2016-11-07 18:10:49 +00:00
|
|
|
{
|
2016-11-18 12:57:10 +00:00
|
|
|
return snapshot->renderer;
|
2016-11-07 18:10:49 +00:00
|
|
|
}
|
|
|
|
|
2016-11-18 11:53:57 +00:00
|
|
|
/**
|
|
|
|
* gtk_snapshot_set_transform:
|
|
|
|
* @snapshot: a #GtkSnapshot
|
|
|
|
* @transform: a transformation matrix
|
|
|
|
*
|
|
|
|
* Replaces the current transformation with the given @transform.
|
|
|
|
*
|
|
|
|
* Since: 3.90
|
|
|
|
*/
|
2016-11-11 23:37:54 +00:00
|
|
|
void
|
2016-11-17 00:55:26 +00:00
|
|
|
gtk_snapshot_set_transform (GtkSnapshot *snapshot,
|
2016-11-11 23:37:54 +00:00
|
|
|
const graphene_matrix_t *transform)
|
|
|
|
{
|
2016-11-17 00:55:26 +00:00
|
|
|
g_return_if_fail (snapshot->state != NULL);
|
|
|
|
|
|
|
|
gtk_snapshot_state_set_transform (snapshot->state, transform);
|
2016-11-11 23:37:54 +00:00
|
|
|
}
|
|
|
|
|
2016-11-18 11:53:57 +00:00
|
|
|
/**
|
|
|
|
* gtk_snapshot_transform:
|
|
|
|
* @snapshot: a #GtkSnapshot
|
|
|
|
* @transform: a transformation matrix
|
|
|
|
*
|
|
|
|
* Appends @transform to the current transformation.
|
|
|
|
*
|
|
|
|
* Since: 3.90
|
|
|
|
*/
|
2016-11-11 23:37:54 +00:00
|
|
|
void
|
2016-11-17 00:55:26 +00:00
|
|
|
gtk_snapshot_transform (GtkSnapshot *snapshot,
|
2016-11-11 23:37:54 +00:00
|
|
|
const graphene_matrix_t *transform)
|
|
|
|
{
|
|
|
|
graphene_matrix_t result;
|
|
|
|
|
2016-11-17 00:55:26 +00:00
|
|
|
g_return_if_fail (snapshot->state != NULL);
|
|
|
|
|
|
|
|
graphene_matrix_multiply (transform, &snapshot->state->transform, &result);
|
|
|
|
gtk_snapshot_state_set_transform (snapshot->state, &result);
|
2016-11-11 23:37:54 +00:00
|
|
|
}
|
|
|
|
|
2016-11-18 11:53:57 +00:00
|
|
|
/**
|
|
|
|
* gtk_snapshot_translate_2d:
|
2016-11-18 12:57:10 +00:00
|
|
|
* @snapshot: a $GtkSnapshot
|
2016-11-18 11:53:57 +00:00
|
|
|
* @x: horizontal translation
|
|
|
|
* @y: vertical translation
|
|
|
|
*
|
|
|
|
* Appends a translation by (@x, @y) to the current transformation.
|
|
|
|
*
|
|
|
|
* Since: 3.90
|
|
|
|
*/
|
2016-11-11 23:37:54 +00:00
|
|
|
void
|
2016-11-18 12:57:10 +00:00
|
|
|
gtk_snapshot_translate_2d (GtkSnapshot *snapshot,
|
2016-11-11 23:37:54 +00:00
|
|
|
int x,
|
|
|
|
int y)
|
|
|
|
{
|
|
|
|
graphene_matrix_t transform;
|
|
|
|
graphene_point3d_t point;
|
|
|
|
|
|
|
|
graphene_point3d_init (&point, x, y, 0);
|
|
|
|
graphene_matrix_init_translate (&transform, &point);
|
2016-11-18 12:57:10 +00:00
|
|
|
gtk_snapshot_transform (snapshot, &transform);
|
2016-11-11 23:37:54 +00:00
|
|
|
}
|
|
|
|
|
2016-11-18 11:53:57 +00:00
|
|
|
/**
|
|
|
|
* gtk_snapshot_append_node:
|
|
|
|
* @snapshot: a #GtkSnapshot
|
|
|
|
* @node: a #GskRenderNode
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2016-11-11 23:37:54 +00:00
|
|
|
void
|
2016-11-17 00:55:26 +00:00
|
|
|
gtk_snapshot_append_node (GtkSnapshot *snapshot,
|
2016-11-11 23:37:54 +00:00
|
|
|
GskRenderNode *node)
|
|
|
|
{
|
2016-11-17 00:55:26 +00:00
|
|
|
g_return_if_fail (snapshot != NULL);
|
2016-11-11 23:37:54 +00:00
|
|
|
g_return_if_fail (GSK_IS_RENDER_NODE (node));
|
|
|
|
|
2016-11-17 00:55:26 +00:00
|
|
|
if (snapshot->state)
|
|
|
|
{
|
|
|
|
gsk_render_node_append_child (snapshot->state->node, node);
|
|
|
|
gsk_render_node_set_transform (node, &snapshot->state->transform);
|
|
|
|
}
|
2016-11-11 23:37:54 +00:00
|
|
|
else
|
|
|
|
{
|
2016-11-15 21:39:05 +00:00
|
|
|
g_critical ("Tried appending a node to an already finished snapshot.");
|
2016-11-11 23:37:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-18 11:53:57 +00:00
|
|
|
/**
|
|
|
|
* gtk_snapshot_append:
|
|
|
|
* @snapshot: a #GtkSnapshot
|
|
|
|
* @bounds: the bounds for the new node
|
2016-12-01 09:19:24 +00:00
|
|
|
* @name: (transfer none): a printf() style format string for the name for the new node
|
2016-11-18 11:53:57 +00:00
|
|
|
* @...: arguments to insert into the format string
|
|
|
|
*
|
|
|
|
* Creates a new render node and appends it to the current render
|
|
|
|
* node of @snapshot, without changing the current node.
|
|
|
|
*
|
|
|
|
* Since: 3.90
|
|
|
|
*
|
2016-12-01 09:19:24 +00:00
|
|
|
* Returns: (transfer full): the newly created #GskRenderNode
|
2016-11-18 11:53:57 +00:00
|
|
|
*/
|
2016-11-15 05:19:16 +00:00
|
|
|
GskRenderNode *
|
2016-11-18 12:57:10 +00:00
|
|
|
gtk_snapshot_append (GtkSnapshot *snapshot,
|
2016-11-15 05:19:16 +00:00
|
|
|
const graphene_rect_t *bounds,
|
|
|
|
const char *name,
|
|
|
|
...)
|
|
|
|
{
|
|
|
|
GskRenderNode *node;
|
|
|
|
|
2016-11-18 12:57:10 +00:00
|
|
|
g_return_val_if_fail (snapshot != NULL, NULL);
|
2016-11-15 05:19:16 +00:00
|
|
|
g_return_val_if_fail (bounds != NULL, NULL);
|
|
|
|
|
2016-11-18 12:57:10 +00:00
|
|
|
node = gsk_renderer_create_render_node (snapshot->renderer);
|
2016-11-15 05:19:16 +00:00
|
|
|
gsk_render_node_set_bounds (node, bounds);
|
|
|
|
|
|
|
|
if (name)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
char *str;
|
|
|
|
|
|
|
|
va_start (args, name);
|
|
|
|
str = g_strdup_vprintf (name, args);
|
|
|
|
va_end (args);
|
|
|
|
|
|
|
|
gsk_render_node_set_name (node, str);
|
|
|
|
|
|
|
|
g_free (str);
|
|
|
|
}
|
|
|
|
|
2016-11-18 12:57:10 +00:00
|
|
|
gtk_snapshot_append_node (snapshot, node);
|
2016-11-15 05:19:16 +00:00
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2016-11-18 11:53:57 +00:00
|
|
|
/**
|
|
|
|
* gtk_snapshot_append_cairo_node:
|
2016-11-18 12:57:10 +00:00
|
|
|
* @snapshot: a #GtkSnapshot
|
2016-11-18 11:53:57 +00:00
|
|
|
* @bounds: the bounds for the new node
|
2016-12-01 09:19:24 +00:00
|
|
|
* @name: (transfer none): a printf() style format string for the name for the new node
|
2016-11-18 11:53:57 +00:00
|
|
|
* @...: arguments to insert into the format string
|
|
|
|
*
|
|
|
|
* Creates a new render node and appends it to the current render
|
|
|
|
* node of @snapshot, without changing the current node.
|
|
|
|
*
|
|
|
|
* Returns: a cairo_t suitable for drawing the contents of the newly
|
|
|
|
* created render node
|
|
|
|
*
|
|
|
|
* Since: 3.90
|
|
|
|
*/
|
2016-11-11 23:37:54 +00:00
|
|
|
cairo_t *
|
2016-11-18 12:57:10 +00:00
|
|
|
gtk_snapshot_append_cairo_node (GtkSnapshot *snapshot,
|
2016-11-11 23:37:54 +00:00
|
|
|
const graphene_rect_t *bounds,
|
|
|
|
const char *name,
|
|
|
|
...)
|
|
|
|
{
|
|
|
|
GskRenderNode *node;
|
|
|
|
|
2016-11-18 12:57:10 +00:00
|
|
|
g_return_val_if_fail (snapshot != NULL, NULL);
|
2016-11-11 23:37:54 +00:00
|
|
|
g_return_val_if_fail (bounds != NULL, NULL);
|
|
|
|
|
2016-12-11 00:23:02 +00:00
|
|
|
node = gsk_cairo_node_new (bounds);
|
2016-11-11 23:37:54 +00:00
|
|
|
|
|
|
|
if (name)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
char *str;
|
|
|
|
|
|
|
|
va_start (args, name);
|
|
|
|
str = g_strdup_vprintf (name, args);
|
|
|
|
va_end (args);
|
|
|
|
|
|
|
|
gsk_render_node_set_name (node, str);
|
|
|
|
|
|
|
|
g_free (str);
|
|
|
|
}
|
|
|
|
|
2016-11-18 12:57:10 +00:00
|
|
|
gtk_snapshot_append_node (snapshot, node);
|
2016-11-11 23:37:54 +00:00
|
|
|
gsk_render_node_unref (node);
|
|
|
|
|
2016-12-11 00:23:02 +00:00
|
|
|
return gsk_cairo_node_get_draw_context (node, snapshot->renderer);
|
2016-11-11 23:37:54 +00:00
|
|
|
}
|
|
|
|
|
2016-11-17 02:31:15 +00:00
|
|
|
static void
|
|
|
|
rectangle_init_from_graphene (cairo_rectangle_int_t *cairo,
|
|
|
|
const graphene_rect_t *graphene)
|
|
|
|
{
|
|
|
|
cairo->x = floorf (graphene->origin.x);
|
|
|
|
cairo->y = floorf (graphene->origin.y);
|
|
|
|
cairo->width = ceilf (graphene->origin.x + graphene->size.width) - cairo->x;
|
|
|
|
cairo->height = ceilf (graphene->origin.y + graphene->size.height) - cairo->y;
|
|
|
|
}
|
|
|
|
|
2016-11-18 11:53:57 +00:00
|
|
|
/**
|
|
|
|
* gtk_snapshot_clips_rect:
|
|
|
|
* @snapshot: a #GtkSnapshot
|
|
|
|
* @bounds: a rectangle
|
|
|
|
*
|
|
|
|
* Tests whether the rectangle is entirely outside the clip region of @snapshot.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE is @bounds is entirely outside the clip region
|
|
|
|
*
|
|
|
|
* Since: 3.90
|
|
|
|
*/
|
2016-11-13 19:47:34 +00:00
|
|
|
gboolean
|
|
|
|
gtk_snapshot_clips_rect (GtkSnapshot *snapshot,
|
|
|
|
const graphene_rect_t *bounds)
|
|
|
|
{
|
2016-11-17 02:31:15 +00:00
|
|
|
cairo_rectangle_int_t rect;
|
|
|
|
|
|
|
|
if (snapshot->state)
|
|
|
|
{
|
|
|
|
const graphene_matrix_t *world;
|
|
|
|
graphene_rect_t transformed;
|
|
|
|
|
|
|
|
world = gtk_snapshot_state_get_world_transform (snapshot->state);
|
|
|
|
|
|
|
|
graphene_matrix_transform_bounds (world, bounds, &transformed);
|
|
|
|
rectangle_init_from_graphene (&rect, &transformed);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rectangle_init_from_graphene (&rect, bounds);
|
|
|
|
}
|
|
|
|
|
|
|
|
return cairo_region_contains_rectangle (snapshot->clip_region, &rect) == CAIRO_REGION_OVERLAP_OUT;
|
2016-11-13 19:47:34 +00:00
|
|
|
}
|
|
|
|
|
2016-11-18 11:53:57 +00:00
|
|
|
/**
|
|
|
|
* gtk_snapshot_render_background:
|
2016-11-18 12:57:10 +00:00
|
|
|
* @snapshot: a #GtkSnapshot
|
2016-11-18 11:53:57 +00:00
|
|
|
* @context: the #GtkStyleContext to use
|
|
|
|
* @x: X origin of the rectangle
|
|
|
|
* @y: Y origin of the rectangle
|
|
|
|
* @width: rectangle width
|
|
|
|
* @height: rectangle height
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* Since: 3.90
|
|
|
|
*/
|
2016-11-13 15:16:39 +00:00
|
|
|
void
|
2016-11-18 12:57:10 +00:00
|
|
|
gtk_snapshot_render_background (GtkSnapshot *snapshot,
|
2016-11-13 15:16:39 +00:00
|
|
|
GtkStyleContext *context,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
gdouble width,
|
|
|
|
gdouble height)
|
|
|
|
{
|
2016-11-18 12:57:10 +00:00
|
|
|
g_return_if_fail (snapshot != NULL);
|
2016-11-13 15:16:39 +00:00
|
|
|
g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
|
|
|
|
|
2016-11-18 12:57:10 +00:00
|
|
|
gtk_snapshot_translate_2d (snapshot, x, y);
|
2016-11-13 15:16:39 +00:00
|
|
|
gtk_css_style_snapshot_background (gtk_style_context_lookup_style (context),
|
2016-11-18 12:57:10 +00:00
|
|
|
snapshot,
|
2016-11-13 15:16:39 +00:00
|
|
|
width, height,
|
|
|
|
gtk_style_context_get_junction_sides (context));
|
2016-11-18 12:57:10 +00:00
|
|
|
gtk_snapshot_translate_2d (snapshot, -x, -y);
|
2016-11-13 15:16:39 +00:00
|
|
|
}
|
|
|
|
|
2016-11-18 12:57:10 +00:00
|
|
|
/**
|
|
|
|
* gtk_snapshot_render_frame:
|
|
|
|
* @snapshot: a #GtkSnapshot
|
|
|
|
* @context: the #GtkStyleContext to use
|
|
|
|
* @x: X origin of the rectangle
|
|
|
|
* @y: Y origin of the rectangle
|
|
|
|
* @width: rectangle width
|
|
|
|
* @height: rectangle height
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* Since: 3.90
|
|
|
|
*/
|
2016-11-13 15:16:39 +00:00
|
|
|
void
|
2016-11-18 12:57:10 +00:00
|
|
|
gtk_snapshot_render_frame (GtkSnapshot *snapshot,
|
2016-11-13 15:16:39 +00:00
|
|
|
GtkStyleContext *context,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
gdouble width,
|
|
|
|
gdouble height)
|
|
|
|
{
|
2016-11-18 12:57:10 +00:00
|
|
|
g_return_if_fail (snapshot != NULL);
|
2016-11-13 15:16:39 +00:00
|
|
|
g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
|
|
|
|
|
2016-11-18 12:57:10 +00:00
|
|
|
gtk_snapshot_translate_2d (snapshot, x, y);
|
2016-11-13 15:16:39 +00:00
|
|
|
gtk_css_style_snapshot_border (gtk_style_context_lookup_style (context),
|
2016-11-18 12:57:10 +00:00
|
|
|
snapshot,
|
2016-11-13 15:16:39 +00:00
|
|
|
width, height,
|
|
|
|
gtk_style_context_get_junction_sides (context));
|
2016-11-18 12:57:10 +00:00
|
|
|
gtk_snapshot_translate_2d (snapshot, -x, -y);
|
2016-11-13 15:16:39 +00:00
|
|
|
}
|
2016-11-13 22:54:30 +00:00
|
|
|
|
2016-11-18 11:53:57 +00:00
|
|
|
/**
|
|
|
|
* gtk_snapshot_render_focus:
|
2016-11-18 12:57:10 +00:00
|
|
|
* @snapshot: a #GtkSnapshot
|
2016-11-18 11:53:57 +00:00
|
|
|
* @context: the #GtkStyleContext to use
|
|
|
|
* @x: X origin of the rectangle
|
|
|
|
* @y: Y origin of the rectangle
|
|
|
|
* @width: rectangle width
|
|
|
|
* @height: rectangle height
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* Since: 3.90
|
|
|
|
*/
|
2016-11-14 21:58:58 +00:00
|
|
|
void
|
2016-11-18 12:57:10 +00:00
|
|
|
gtk_snapshot_render_focus (GtkSnapshot *snapshot,
|
2016-11-14 21:58:58 +00:00
|
|
|
GtkStyleContext *context,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
gdouble width,
|
|
|
|
gdouble height)
|
|
|
|
{
|
2016-11-18 12:57:10 +00:00
|
|
|
g_return_if_fail (snapshot != NULL);
|
2016-11-14 21:58:58 +00:00
|
|
|
g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
|
|
|
|
|
2016-11-18 12:57:10 +00:00
|
|
|
gtk_snapshot_translate_2d (snapshot, x, y);
|
2016-11-14 21:58:58 +00:00
|
|
|
gtk_css_style_snapshot_outline (gtk_style_context_lookup_style (context),
|
2016-11-18 12:57:10 +00:00
|
|
|
snapshot,
|
2016-11-14 21:58:58 +00:00
|
|
|
width, height);
|
2016-11-18 12:57:10 +00:00
|
|
|
gtk_snapshot_translate_2d (snapshot, -x, -y);
|
2016-11-14 21:58:58 +00:00
|
|
|
}
|
|
|
|
|
2016-11-18 11:53:57 +00:00
|
|
|
/**
|
|
|
|
* gtk_snapshot_render_layout:
|
2016-11-18 12:57:10 +00:00
|
|
|
* @snapshot: a #GtkSnapshot
|
2016-11-18 11:53:57 +00:00
|
|
|
* @context: the #GtkStyleContext to use
|
|
|
|
* @x: X origin of the rectangle
|
|
|
|
* @y: Y origin of the rectangle
|
|
|
|
* @layout: the #PangoLayout to render
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* Since: 3.90
|
|
|
|
*/
|
2016-11-13 22:54:30 +00:00
|
|
|
void
|
2016-11-18 12:57:10 +00:00
|
|
|
gtk_snapshot_render_layout (GtkSnapshot *snapshot,
|
2016-11-13 22:54:30 +00:00
|
|
|
GtkStyleContext *context,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y,
|
|
|
|
PangoLayout *layout)
|
|
|
|
{
|
|
|
|
const GdkRGBA *fg_color;
|
|
|
|
graphene_rect_t bounds;
|
|
|
|
GtkBorder shadow_extents;
|
|
|
|
PangoRectangle ink_rect;
|
|
|
|
GtkCssValue *shadow;
|
|
|
|
cairo_t *cr;
|
|
|
|
|
2016-11-18 12:57:10 +00:00
|
|
|
g_return_if_fail (snapshot != NULL);
|
2016-11-13 22:54:30 +00:00
|
|
|
g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
|
|
|
|
g_return_if_fail (PANGO_IS_LAYOUT (layout));
|
|
|
|
|
|
|
|
fg_color = _gtk_css_rgba_value_get_rgba (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_COLOR));
|
|
|
|
shadow = _gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_TEXT_SHADOW);
|
|
|
|
pango_layout_get_pixel_extents (layout, &ink_rect, NULL);
|
|
|
|
_gtk_css_shadows_value_get_extents (shadow, &shadow_extents);
|
|
|
|
graphene_rect_init (&bounds,
|
|
|
|
ink_rect.x - shadow_extents.left,
|
|
|
|
ink_rect.y - shadow_extents.top,
|
|
|
|
ink_rect.width + shadow_extents.left + shadow_extents.right,
|
|
|
|
ink_rect.height + shadow_extents.top + shadow_extents.bottom);
|
|
|
|
|
2016-11-18 12:57:10 +00:00
|
|
|
gtk_snapshot_translate_2d (snapshot, x, y);
|
2016-11-13 22:54:30 +00:00
|
|
|
|
2016-11-18 12:57:10 +00:00
|
|
|
cr = gtk_snapshot_append_cairo_node (snapshot, &bounds, "Text<%dchars>", pango_layout_get_character_count (layout));
|
2016-11-13 22:54:30 +00:00
|
|
|
|
|
|
|
_gtk_css_shadows_value_paint_layout (shadow, cr, layout);
|
|
|
|
|
|
|
|
gdk_cairo_set_source_rgba (cr, fg_color);
|
|
|
|
pango_cairo_show_layout (cr, layout);
|
|
|
|
|
|
|
|
cairo_destroy (cr);
|
2016-11-18 12:57:10 +00:00
|
|
|
gtk_snapshot_translate_2d (snapshot, -x, -y);
|
2016-11-13 22:54:30 +00:00
|
|
|
}
|
|
|
|
|
2016-11-18 11:53:57 +00:00
|
|
|
/**
|
|
|
|
* gtk_snapshot_render_icon:
|
|
|
|
* @snapshot: a #GtkSnapshot
|
|
|
|
* @context: the #GtkStyleContext to use
|
|
|
|
* @pixbuf: the #GdkPixbuf to render
|
|
|
|
* @x: X origin of the rectangle
|
|
|
|
* @y: Y origin of the rectangle
|
|
|
|
*
|
|
|
|
* Creates a render node for rendering @pixbuf according to the style
|
|
|
|
* information in @context, and appends it to the current node of @snapshot,
|
|
|
|
* without changing the current node.
|
|
|
|
*
|
|
|
|
* Since: 3.90
|
|
|
|
*/
|
2016-11-15 05:19:16 +00:00
|
|
|
void
|
|
|
|
gtk_snapshot_render_icon (GtkSnapshot *snapshot,
|
|
|
|
GtkStyleContext *context,
|
|
|
|
GdkPixbuf *pixbuf,
|
|
|
|
gdouble x,
|
|
|
|
gdouble y)
|
|
|
|
{
|
|
|
|
GskTexture *texture;
|
|
|
|
|
2016-11-16 03:14:32 +00:00
|
|
|
texture = gsk_texture_new_for_pixbuf (pixbuf);
|
2016-11-15 05:19:16 +00:00
|
|
|
gtk_snapshot_translate_2d (snapshot, x, y);
|
2016-11-16 19:51:53 +00:00
|
|
|
gtk_css_style_snapshot_icon_texture (gtk_style_context_lookup_style (context),
|
|
|
|
snapshot,
|
2016-11-26 10:51:30 +00:00
|
|
|
texture,
|
|
|
|
1);
|
2016-11-15 05:19:16 +00:00
|
|
|
gtk_snapshot_translate_2d (snapshot, -x, -y);
|
|
|
|
gsk_texture_unref (texture);
|
|
|
|
}
|
|
|
|
|