2016-05-05 14:21:51 +00:00
|
|
|
#include "clutter-build-config.h"
|
2010-10-11 14:57:22 +00:00
|
|
|
|
2010-10-21 11:16:05 +00:00
|
|
|
#include <math.h>
|
|
|
|
|
2010-10-11 14:57:22 +00:00
|
|
|
#include "clutter-types.h"
|
|
|
|
#include "clutter-interval.h"
|
|
|
|
#include "clutter-private.h"
|
2018-05-24 09:51:22 +00:00
|
|
|
#include "clutter-actor-box-private.h"
|
2010-10-11 14:57:22 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_actor_box_new:
|
|
|
|
* @x_1: X coordinate of the top left point
|
|
|
|
* @y_1: Y coordinate of the top left point
|
|
|
|
* @x_2: X coordinate of the bottom right point
|
|
|
|
* @y_2: Y coordinate of the bottom right point
|
|
|
|
*
|
2022-05-25 16:41:48 +00:00
|
|
|
* Allocates a new [struct@ActorBox] using the passed coordinates
|
2012-04-18 16:31:28 +00:00
|
|
|
* for the top left and bottom right points.
|
2010-10-11 14:57:22 +00:00
|
|
|
*
|
2012-04-18 16:31:28 +00:00
|
|
|
* This function is the logical equivalent of:
|
|
|
|
*
|
2022-05-25 16:41:48 +00:00
|
|
|
* ```c
|
2012-04-18 16:31:28 +00:00
|
|
|
* clutter_actor_box_init (clutter_actor_box_alloc (),
|
|
|
|
* x_1, y_1,
|
|
|
|
* x_2, y_2);
|
2022-05-25 16:41:48 +00:00
|
|
|
* ```
|
2012-04-18 16:31:28 +00:00
|
|
|
*
|
|
|
|
* Return value: (transfer full): the newly allocated #ClutterActorBox.
|
2022-05-25 16:41:48 +00:00
|
|
|
* Use [method@ActorBox.free] to free the resources
|
2010-10-11 14:57:22 +00:00
|
|
|
*/
|
|
|
|
ClutterActorBox *
|
|
|
|
clutter_actor_box_new (gfloat x_1,
|
|
|
|
gfloat y_1,
|
|
|
|
gfloat x_2,
|
|
|
|
gfloat y_2)
|
|
|
|
{
|
2012-04-18 16:31:28 +00:00
|
|
|
return clutter_actor_box_init (clutter_actor_box_alloc (),
|
|
|
|
x_1, y_1,
|
|
|
|
x_2, y_2);
|
|
|
|
}
|
2012-03-17 15:27:26 +00:00
|
|
|
|
2012-04-18 16:31:28 +00:00
|
|
|
/**
|
|
|
|
* clutter_actor_box_alloc:
|
|
|
|
*
|
2022-05-25 16:41:48 +00:00
|
|
|
* Allocates a new [struct@ActorBox].
|
2012-04-18 16:31:28 +00:00
|
|
|
*
|
|
|
|
* Return value: (transfer full): the newly allocated #ClutterActorBox.
|
2022-05-25 16:41:48 +00:00
|
|
|
* Use [method@ActorBox.free] to free its resources
|
2012-04-18 16:31:28 +00:00
|
|
|
*/
|
|
|
|
ClutterActorBox *
|
|
|
|
clutter_actor_box_alloc (void)
|
|
|
|
{
|
2020-10-19 17:57:45 +00:00
|
|
|
return g_new0 (ClutterActorBox, 1);
|
2012-03-17 15:27:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_actor_box_init:
|
|
|
|
* @box: a #ClutterActorBox
|
|
|
|
* @x_1: X coordinate of the top left point
|
|
|
|
* @y_1: Y coordinate of the top left point
|
|
|
|
* @x_2: X coordinate of the bottom right point
|
|
|
|
* @y_2: Y coordinate of the bottom right point
|
|
|
|
*
|
|
|
|
* Initializes @box with the given coordinates.
|
|
|
|
*
|
2012-04-18 16:31:28 +00:00
|
|
|
* Return value: (transfer none): the initialized #ClutterActorBox
|
2012-03-17 15:27:26 +00:00
|
|
|
*/
|
2012-04-18 16:31:28 +00:00
|
|
|
ClutterActorBox *
|
2012-03-17 15:27:26 +00:00
|
|
|
clutter_actor_box_init (ClutterActorBox *box,
|
|
|
|
gfloat x_1,
|
|
|
|
gfloat y_1,
|
|
|
|
gfloat x_2,
|
|
|
|
gfloat y_2)
|
|
|
|
{
|
2012-04-18 16:31:28 +00:00
|
|
|
g_return_val_if_fail (box != NULL, NULL);
|
2012-03-17 15:27:26 +00:00
|
|
|
|
2010-10-11 14:57:22 +00:00
|
|
|
box->x1 = x_1;
|
|
|
|
box->y1 = y_1;
|
|
|
|
box->x2 = x_2;
|
|
|
|
box->y2 = y_2;
|
2012-04-18 16:31:28 +00:00
|
|
|
|
|
|
|
return box;
|
2012-03-17 15:27:26 +00:00
|
|
|
}
|
2010-10-11 14:57:22 +00:00
|
|
|
|
2012-03-17 15:27:26 +00:00
|
|
|
/**
|
|
|
|
* clutter_actor_box_init_rect:
|
|
|
|
* @box: a #ClutterActorBox
|
|
|
|
* @x: X coordinate of the origin
|
|
|
|
* @y: Y coordinate of the origin
|
|
|
|
* @width: width of the box
|
|
|
|
* @height: height of the box
|
|
|
|
*
|
|
|
|
* Initializes @box with the given origin and size.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
clutter_actor_box_init_rect (ClutterActorBox *box,
|
|
|
|
gfloat x,
|
|
|
|
gfloat y,
|
|
|
|
gfloat width,
|
|
|
|
gfloat height)
|
|
|
|
{
|
|
|
|
g_return_if_fail (box != NULL);
|
|
|
|
|
|
|
|
box->x1 = x;
|
|
|
|
box->y1 = y;
|
|
|
|
box->x2 = box->x1 + width;
|
|
|
|
box->y2 = box->y1 + height;
|
2010-10-11 14:57:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_actor_box_copy:
|
|
|
|
* @box: a #ClutterActorBox
|
|
|
|
*
|
|
|
|
* Copies @box
|
|
|
|
*
|
|
|
|
* Return value: a newly allocated copy of #ClutterActorBox. Use
|
2022-05-25 16:41:48 +00:00
|
|
|
* [method@ActorBox.free] to free the allocated resources
|
2010-10-11 14:57:22 +00:00
|
|
|
*/
|
|
|
|
ClutterActorBox *
|
|
|
|
clutter_actor_box_copy (const ClutterActorBox *box)
|
|
|
|
{
|
|
|
|
if (G_LIKELY (box != NULL))
|
2020-10-19 17:57:45 +00:00
|
|
|
return g_memdup2 (box, sizeof (ClutterActorBox));
|
2010-10-11 14:57:22 +00:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_actor_box_free:
|
|
|
|
* @box: a #ClutterActorBox
|
|
|
|
*
|
2022-05-25 16:41:48 +00:00
|
|
|
* Frees a #ClutterActorBox allocated using [ctor@ActorBox.new]
|
|
|
|
* or [method@ActorBox.copy].
|
2010-10-11 14:57:22 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
clutter_actor_box_free (ClutterActorBox *box)
|
|
|
|
{
|
|
|
|
if (G_LIKELY (box != NULL))
|
2020-10-19 17:57:45 +00:00
|
|
|
g_free (box);
|
2010-10-11 14:57:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_actor_box_equal:
|
|
|
|
* @box_a: a #ClutterActorBox
|
|
|
|
* @box_b: a #ClutterActorBox
|
|
|
|
*
|
|
|
|
* Checks @box_a and @box_b for equality
|
|
|
|
*
|
|
|
|
* Return value: %TRUE if the passed #ClutterActorBox are equal
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
clutter_actor_box_equal (const ClutterActorBox *box_a,
|
|
|
|
const ClutterActorBox *box_b)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (box_a != NULL && box_b != NULL, FALSE);
|
|
|
|
|
|
|
|
if (box_a == box_b)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
return box_a->x1 == box_b->x1 && box_a->y1 == box_b->y1 &&
|
|
|
|
box_a->x2 == box_b->x2 && box_a->y2 == box_b->y2;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_actor_box_get_x:
|
|
|
|
* @box: a #ClutterActorBox
|
|
|
|
*
|
|
|
|
* Retrieves the X coordinate of the origin of @box
|
|
|
|
*
|
|
|
|
* Return value: the X coordinate of the origin
|
|
|
|
*/
|
|
|
|
gfloat
|
|
|
|
clutter_actor_box_get_x (const ClutterActorBox *box)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (box != NULL, 0.);
|
|
|
|
|
|
|
|
return box->x1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_actor_box_get_y:
|
|
|
|
* @box: a #ClutterActorBox
|
|
|
|
*
|
|
|
|
* Retrieves the Y coordinate of the origin of @box
|
|
|
|
*
|
|
|
|
* Return value: the Y coordinate of the origin
|
|
|
|
*/
|
|
|
|
gfloat
|
|
|
|
clutter_actor_box_get_y (const ClutterActorBox *box)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (box != NULL, 0.);
|
|
|
|
|
|
|
|
return box->y1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_actor_box_get_width:
|
|
|
|
* @box: a #ClutterActorBox
|
|
|
|
*
|
|
|
|
* Retrieves the width of the @box
|
|
|
|
*
|
|
|
|
* Return value: the width of the box
|
|
|
|
*/
|
|
|
|
gfloat
|
|
|
|
clutter_actor_box_get_width (const ClutterActorBox *box)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (box != NULL, 0.);
|
|
|
|
|
|
|
|
return box->x2 - box->x1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_actor_box_get_height:
|
|
|
|
* @box: a #ClutterActorBox
|
|
|
|
*
|
|
|
|
* Retrieves the height of the @box
|
|
|
|
*
|
|
|
|
* Return value: the height of the box
|
|
|
|
*/
|
|
|
|
gfloat
|
|
|
|
clutter_actor_box_get_height (const ClutterActorBox *box)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (box != NULL, 0.);
|
|
|
|
|
|
|
|
return box->y2 - box->y1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_actor_box_get_origin:
|
|
|
|
* @box: a #ClutterActorBox
|
|
|
|
* @x: (out) (allow-none): return location for the X coordinate, or %NULL
|
|
|
|
* @y: (out) (allow-none): return location for the Y coordinate, or %NULL
|
|
|
|
*
|
|
|
|
* Retrieves the origin of @box
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
clutter_actor_box_get_origin (const ClutterActorBox *box,
|
|
|
|
gfloat *x,
|
|
|
|
gfloat *y)
|
|
|
|
{
|
|
|
|
g_return_if_fail (box != NULL);
|
|
|
|
|
|
|
|
if (x)
|
|
|
|
*x = box->x1;
|
|
|
|
|
|
|
|
if (y)
|
|
|
|
*y = box->y1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_actor_box_get_size:
|
|
|
|
* @box: a #ClutterActorBox
|
|
|
|
* @width: (out) (allow-none): return location for the width, or %NULL
|
|
|
|
* @height: (out) (allow-none): return location for the height, or %NULL
|
|
|
|
*
|
|
|
|
* Retrieves the size of @box
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
clutter_actor_box_get_size (const ClutterActorBox *box,
|
|
|
|
gfloat *width,
|
|
|
|
gfloat *height)
|
|
|
|
{
|
|
|
|
g_return_if_fail (box != NULL);
|
|
|
|
|
|
|
|
if (width)
|
|
|
|
*width = box->x2 - box->x1;
|
|
|
|
|
|
|
|
if (height)
|
|
|
|
*height = box->y2 - box->y1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_actor_box_get_area:
|
|
|
|
* @box: a #ClutterActorBox
|
|
|
|
*
|
|
|
|
* Retrieves the area of @box
|
|
|
|
*
|
|
|
|
* Return value: the area of a #ClutterActorBox, in pixels
|
|
|
|
*/
|
|
|
|
gfloat
|
|
|
|
clutter_actor_box_get_area (const ClutterActorBox *box)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (box != NULL, 0.);
|
|
|
|
|
|
|
|
return (box->x2 - box->x1) * (box->y2 - box->y1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_actor_box_contains:
|
|
|
|
* @box: a #ClutterActorBox
|
|
|
|
* @x: X coordinate of the point
|
|
|
|
* @y: Y coordinate of the point
|
|
|
|
*
|
|
|
|
* Checks whether a point with @x, @y coordinates is contained
|
2020-08-26 09:49:50 +00:00
|
|
|
* within @box
|
2010-10-11 14:57:22 +00:00
|
|
|
*
|
|
|
|
* Return value: %TRUE if the point is contained by the #ClutterActorBox
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
clutter_actor_box_contains (const ClutterActorBox *box,
|
|
|
|
gfloat x,
|
|
|
|
gfloat y)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (box != NULL, FALSE);
|
|
|
|
|
|
|
|
return (x > box->x1 && x < box->x2) &&
|
|
|
|
(y > box->y1 && y < box->y2);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_actor_box_from_vertices:
|
|
|
|
* @box: a #ClutterActorBox
|
2019-02-20 13:18:48 +00:00
|
|
|
* @verts: (array fixed-size=4): array of four #graphene_point3d_t
|
2010-10-11 14:57:22 +00:00
|
|
|
*
|
|
|
|
* Calculates the bounding box represented by the four vertices; for details
|
2022-05-25 16:41:48 +00:00
|
|
|
* of the vertex array see [method@Actor.get_abs_allocation_vertices].
|
2010-10-11 14:57:22 +00:00
|
|
|
*/
|
|
|
|
void
|
2019-02-20 13:18:48 +00:00
|
|
|
clutter_actor_box_from_vertices (ClutterActorBox *box,
|
|
|
|
const graphene_point3d_t verts[])
|
2010-10-11 14:57:22 +00:00
|
|
|
{
|
|
|
|
gfloat x_1, x_2, y_1, y_2;
|
|
|
|
|
|
|
|
g_return_if_fail (box != NULL);
|
|
|
|
g_return_if_fail (verts != NULL);
|
|
|
|
|
|
|
|
/* 4-way min/max */
|
|
|
|
x_1 = verts[0].x;
|
|
|
|
y_1 = verts[0].y;
|
|
|
|
|
|
|
|
if (verts[1].x < x_1)
|
|
|
|
x_1 = verts[1].x;
|
|
|
|
|
|
|
|
if (verts[2].x < x_1)
|
|
|
|
x_1 = verts[2].x;
|
|
|
|
|
|
|
|
if (verts[3].x < x_1)
|
|
|
|
x_1 = verts[3].x;
|
|
|
|
|
|
|
|
if (verts[1].y < y_1)
|
|
|
|
y_1 = verts[1].y;
|
|
|
|
|
|
|
|
if (verts[2].y < y_1)
|
|
|
|
y_1 = verts[2].y;
|
|
|
|
|
|
|
|
if (verts[3].y < y_1)
|
|
|
|
y_1 = verts[3].y;
|
|
|
|
|
|
|
|
x_2 = verts[0].x;
|
|
|
|
y_2 = verts[0].y;
|
|
|
|
|
|
|
|
if (verts[1].x > x_2)
|
|
|
|
x_2 = verts[1].x;
|
|
|
|
|
|
|
|
if (verts[2].x > x_2)
|
|
|
|
x_2 = verts[2].x;
|
|
|
|
|
|
|
|
if (verts[3].x > x_2)
|
|
|
|
x_2 = verts[3].x;
|
|
|
|
|
|
|
|
if (verts[1].y > y_2)
|
|
|
|
y_2 = verts[1].y;
|
|
|
|
|
|
|
|
if (verts[2].y > y_2)
|
|
|
|
y_2 = verts[2].y;
|
|
|
|
|
|
|
|
if (verts[3].y > y_2)
|
|
|
|
y_2 = verts[3].y;
|
|
|
|
|
|
|
|
box->x1 = x_1;
|
|
|
|
box->x2 = x_2;
|
|
|
|
box->y1 = y_1;
|
|
|
|
box->y2 = y_2;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_actor_box_interpolate:
|
|
|
|
* @initial: the initial #ClutterActorBox
|
|
|
|
* @final: the final #ClutterActorBox
|
|
|
|
* @progress: the interpolation progress
|
|
|
|
* @result: (out): return location for the interpolation
|
|
|
|
*
|
2022-05-25 16:41:48 +00:00
|
|
|
* Interpolates between @initial and @final `ClutterActorBox`es
|
2010-10-11 14:57:22 +00:00
|
|
|
* using @progress
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
clutter_actor_box_interpolate (const ClutterActorBox *initial,
|
|
|
|
const ClutterActorBox *final,
|
|
|
|
gdouble progress,
|
|
|
|
ClutterActorBox *result)
|
|
|
|
{
|
|
|
|
g_return_if_fail (initial != NULL);
|
|
|
|
g_return_if_fail (final != NULL);
|
|
|
|
g_return_if_fail (result != NULL);
|
|
|
|
|
|
|
|
result->x1 = initial->x1 + (final->x1 - initial->x1) * progress;
|
|
|
|
result->y1 = initial->y1 + (final->y1 - initial->y1) * progress;
|
|
|
|
result->x2 = initial->x2 + (final->x2 - initial->x2) * progress;
|
|
|
|
result->y2 = initial->y2 + (final->y2 - initial->y2) * progress;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_actor_box_clamp_to_pixel:
|
|
|
|
* @box: (inout): the #ClutterActorBox to clamp
|
|
|
|
*
|
|
|
|
* Clamps the components of @box to the nearest integer
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
clutter_actor_box_clamp_to_pixel (ClutterActorBox *box)
|
|
|
|
{
|
|
|
|
g_return_if_fail (box != NULL);
|
|
|
|
|
|
|
|
box->x1 = floorf (box->x1);
|
|
|
|
box->y1 = floorf (box->y1);
|
|
|
|
box->x2 = ceilf (box->x2);
|
|
|
|
box->y2 = ceilf (box->y2);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_actor_box_union:
|
2013-12-04 16:09:09 +00:00
|
|
|
* @a: (in): the first #ClutterActorBox
|
2010-10-11 14:57:22 +00:00
|
|
|
* @b: (in): the second #ClutterActorBox
|
|
|
|
* @result: (out): the #ClutterActorBox representing a union
|
|
|
|
* of @a and @b
|
|
|
|
*
|
|
|
|
* Unions the two boxes @a and @b and stores the result in @result.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
clutter_actor_box_union (const ClutterActorBox *a,
|
|
|
|
const ClutterActorBox *b,
|
|
|
|
ClutterActorBox *result)
|
|
|
|
{
|
|
|
|
g_return_if_fail (a != NULL);
|
|
|
|
g_return_if_fail (b != NULL);
|
|
|
|
g_return_if_fail (result != NULL);
|
|
|
|
|
|
|
|
result->x1 = MIN (a->x1, b->x1);
|
|
|
|
result->y1 = MIN (a->y1, b->y1);
|
|
|
|
|
|
|
|
result->x2 = MAX (a->x2, b->x2);
|
|
|
|
result->y2 = MAX (a->y2, b->y2);
|
|
|
|
}
|
2010-10-08 14:21:57 +00:00
|
|
|
|
|
|
|
static gboolean
|
|
|
|
clutter_actor_box_progress (const GValue *a,
|
|
|
|
const GValue *b,
|
|
|
|
gdouble factor,
|
|
|
|
GValue *retval)
|
|
|
|
{
|
|
|
|
ClutterActorBox res = { 0, };
|
|
|
|
|
|
|
|
clutter_actor_box_interpolate (g_value_get_boxed (a),
|
|
|
|
g_value_get_boxed (b),
|
|
|
|
factor,
|
|
|
|
&res);
|
|
|
|
|
|
|
|
g_value_set_boxed (retval, &res);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2010-10-25 14:45:35 +00:00
|
|
|
/**
|
|
|
|
* clutter_actor_box_set_origin:
|
|
|
|
* @box: a #ClutterActorBox
|
|
|
|
* @x: the X coordinate of the new origin
|
|
|
|
* @y: the Y coordinate of the new origin
|
|
|
|
*
|
|
|
|
* Changes the origin of @box, maintaining the size of the #ClutterActorBox.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
clutter_actor_box_set_origin (ClutterActorBox *box,
|
|
|
|
gfloat x,
|
|
|
|
gfloat y)
|
|
|
|
{
|
|
|
|
gfloat width, height;
|
|
|
|
|
|
|
|
g_return_if_fail (box != NULL);
|
|
|
|
|
|
|
|
width = box->x2 - box->x1;
|
|
|
|
height = box->y2 - box->y1;
|
|
|
|
|
2012-03-17 15:27:26 +00:00
|
|
|
clutter_actor_box_init_rect (box, x, y, width, height);
|
2010-10-25 14:45:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* clutter_actor_box_set_size:
|
|
|
|
* @box: a #ClutterActorBox
|
|
|
|
* @width: the new width
|
|
|
|
* @height: the new height
|
|
|
|
*
|
|
|
|
* Sets the size of @box, maintaining the origin of the #ClutterActorBox.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
clutter_actor_box_set_size (ClutterActorBox *box,
|
|
|
|
gfloat width,
|
|
|
|
gfloat height)
|
|
|
|
{
|
|
|
|
g_return_if_fail (box != NULL);
|
|
|
|
|
|
|
|
box->x2 = box->x1 + width;
|
|
|
|
box->y2 = box->y1 + height;
|
|
|
|
}
|
|
|
|
|
2018-05-24 09:51:22 +00:00
|
|
|
void
|
|
|
|
_clutter_actor_box_enlarge_for_effects (ClutterActorBox *box)
|
|
|
|
{
|
|
|
|
float width, height;
|
|
|
|
|
|
|
|
/* The aim here is that for a given rectangle defined with floating point
|
|
|
|
* coordinates we want to determine a stable quantized size in pixels
|
|
|
|
* that doesn't vary due to the original box's sub-pixel position.
|
|
|
|
*
|
|
|
|
* The reason this is important is because effects will use this
|
|
|
|
* API to determine the size of offscreen framebuffers and so for
|
2020-08-26 09:49:50 +00:00
|
|
|
* a fixed-size object that may be animated across the screen we
|
2018-05-24 09:51:22 +00:00
|
|
|
* want to make sure that the stage paint-box has an equally stable
|
|
|
|
* size so that effects aren't made to continuously re-allocate
|
|
|
|
* a corresponding fbo.
|
|
|
|
*
|
|
|
|
* The other thing we consider is that the calculation of this box is
|
|
|
|
* subject to floating point precision issues that might be slightly
|
|
|
|
* different to the precision issues involved with actually painting the
|
|
|
|
* actor, which might result in painting slightly leaking outside the
|
|
|
|
* user's calculated paint-volume. For this we simply aim to pad out the
|
|
|
|
* paint-volume by at least half a pixel all the way around.
|
|
|
|
*/
|
|
|
|
width = box->x2 - box->x1;
|
|
|
|
height = box->y2 - box->y1;
|
|
|
|
width = CLUTTER_NEARBYINT (width);
|
|
|
|
height = CLUTTER_NEARBYINT (height);
|
|
|
|
/* XXX: NB the width/height may now be up to 0.5px too small so we
|
|
|
|
* must also pad by 0.25px all around to account for this. In total we
|
|
|
|
* must padd by at least 0.75px around all sides. */
|
|
|
|
|
|
|
|
/* XXX: The furthest that we can overshoot the bottom right corner by
|
|
|
|
* here is 1.75px in total if you consider that the 0.75 padding could
|
|
|
|
* just cross an integer boundary and so ceil will effectively add 1.
|
|
|
|
*/
|
|
|
|
box->x2 = ceilf (box->x2 + 0.75);
|
|
|
|
box->y2 = ceilf (box->y2 + 0.75);
|
|
|
|
|
|
|
|
/* Now we redefine the top-left relative to the bottom right based on the
|
|
|
|
* rounded width/height determined above + a constant so that the overall
|
2020-08-26 09:49:50 +00:00
|
|
|
* size of the box will be stable and not dependent on the box's
|
2018-05-24 09:51:22 +00:00
|
|
|
* position.
|
|
|
|
*
|
|
|
|
* Adding 3px to the width/height will ensure we cover the maximum of
|
|
|
|
* 1.75px padding on the bottom/right and still ensure we have > 0.75px
|
|
|
|
* padding on the top/left.
|
|
|
|
*/
|
|
|
|
box->x1 = box->x2 - width - 3;
|
|
|
|
box->y1 = box->y2 - height - 3;
|
|
|
|
}
|
|
|
|
|
2017-09-01 01:18:52 +00:00
|
|
|
/**
|
|
|
|
* clutter_actor_box_scale:
|
|
|
|
* @box: a #ClutterActorBox
|
|
|
|
* @scale: scale factor for resizing this box
|
|
|
|
*
|
|
|
|
* Rescale the @box by provided @scale factor.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
clutter_actor_box_scale (ClutterActorBox *box,
|
|
|
|
gfloat scale)
|
|
|
|
{
|
|
|
|
g_return_if_fail (box != NULL);
|
|
|
|
|
|
|
|
box->x1 *= scale;
|
|
|
|
box->x2 *= scale;
|
|
|
|
box->y1 *= scale;
|
|
|
|
box->y2 *= scale;
|
|
|
|
}
|
|
|
|
|
2020-06-06 10:55:07 +00:00
|
|
|
/**
|
|
|
|
* clutter_actor_box_is_initialized:
|
|
|
|
* @box: a #ClutterActorBox
|
|
|
|
*
|
|
|
|
* Checks if @box has been initialized, a #ClutterActorBox is uninitialized
|
|
|
|
* if it has a size of -1 at an origin of 0, 0.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE if the box is uninitialized, %FALSE if it isn't
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
clutter_actor_box_is_initialized (ClutterActorBox *box)
|
|
|
|
{
|
|
|
|
gboolean x1_uninitialized, x2_uninitialized;
|
|
|
|
gboolean y1_uninitialized, y2_uninitialized;
|
|
|
|
|
|
|
|
g_return_val_if_fail (box != NULL, TRUE);
|
|
|
|
|
|
|
|
x1_uninitialized = isinf (box->x1);
|
|
|
|
x2_uninitialized = isinf (box->x2) && signbit (box->x2);
|
|
|
|
y1_uninitialized = isinf (box->y1);
|
|
|
|
y2_uninitialized = isinf (box->y2) && signbit (box->y2);
|
|
|
|
|
|
|
|
return !x1_uninitialized || !x2_uninitialized ||
|
|
|
|
!y1_uninitialized || !y2_uninitialized;
|
|
|
|
}
|
|
|
|
|
2010-10-08 14:21:57 +00:00
|
|
|
G_DEFINE_BOXED_TYPE_WITH_CODE (ClutterActorBox, clutter_actor_box,
|
|
|
|
clutter_actor_box_copy,
|
|
|
|
clutter_actor_box_free,
|
|
|
|
CLUTTER_REGISTER_INTERVAL_PROGRESS (clutter_actor_box_progress));
|