diff --git a/clutter/clutter-actor.c b/clutter/clutter-actor.c index e1219e06b..f0a870ab9 100644 --- a/clutter/clutter-actor.c +++ b/clutter/clutter-actor.c @@ -7743,19 +7743,95 @@ clutter_geometry_get_type (void) * ClutterVertices */ -static ClutterVertex * -clutter_vertex_copy (const ClutterVertex *vertex) +/** + * clutter_vertex_new: + * @x: X coordinate + * @y: Y coordinate + * @z: Z coordinate + * + * Creates a new #ClutterVertex for the point in 3D space + * identified by the 3 coordinates @x, @y, @z + * + * Return value: the newly allocate #ClutterVertex. Use + * clutter_vertex_free() to free the resources + * + * Since: 1.0 + */ +ClutterVertex * +clutter_vertex_new (gfloat x, + gfloat y, + gfloat z) { - return g_slice_dup (ClutterVertex, vertex); + ClutterVertex *vertex; + + vertex = g_slice_new (ClutterVertex); + vertex->x = x; + vertex->y = y; + vertex->z = z; + + return vertex; } -static void +/** + * clutter_vertex_copy: + * @vertex: a #ClutterVertex + * + * Copies @vertex + * + * Return value: a newly allocated copy of #ClutterVertex. Use + * clutter_vertex_free() to free the allocated resources + * + * Since: 1.0 + */ +ClutterVertex * +clutter_vertex_copy (const ClutterVertex *vertex) +{ + if (G_LIKELY (vertex != NULL)) + return g_slice_dup (ClutterVertex, vertex); + + return NULL; +} + +/** + * clutter_vertext_free: + * @vertex: a #ClutterVertex + * + * Frees a #ClutterVertex allocated using clutter_vertex_copy() + * + * Since: 1.0 + */ +void clutter_vertex_free (ClutterVertex *vertex) { if (G_UNLIKELY (vertex != NULL)) g_slice_free (ClutterVertex, vertex); } +/** + * clutter_vertex_equal: + * @vertex_a: a #ClutterVertex + * @vertex_b: a #ClutterVertex + * + * Compares @vertex_a and @vertex_b for equality + * + * Return value: %TRUE if the passed #ClutterVertex are equal + * + * Since: 1.0 + */ +gboolean +clutter_vertex_equal (const ClutterVertex *vertex_a, + const ClutterVertex *vertex_b) +{ + g_return_val_if_fail (vertex_a != NULL && vertex_b != NULL, FALSE); + + if (vertex_a == vertex_b) + return TRUE; + + return vertex_a->x == vertex_b->x && + vertex_a->y == vertex_b->y && + vertex_a->z == vertex_b->z; +} + GType clutter_vertex_get_type (void) { @@ -7773,13 +7849,69 @@ clutter_vertex_get_type (void) /* * ClutterActorBox */ -static ClutterActorBox * -clutter_actor_box_copy (const ClutterActorBox *box) + +/** + * 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 + * + * Allocates a new #ClutterActorBox using the passed coordinates + * for the top left and bottom right points + * + * Return value: the newly allocated #ClutterActorBox. Use + * clutter_actor_box_free() to free the resources + * + * Since: 1.0 + */ +ClutterActorBox * +clutter_actor_box_new (gfloat x_1, + gfloat y_1, + gfloat x_2, + gfloat y_2) { - return g_slice_dup (ClutterActorBox, box); + ClutterActorBox *box; + + box = g_slice_new (ClutterActorBox); + box->x1 = x_1; + box->y1 = y_1; + box->x2 = x_2; + box->y2 = y_2; + + return box; } -static void +/** + * clutter_actor_box_copy: + * @box: a #ClutterActorBox + * + * Copies @box + * + * Return value: a newly allocated copy of #ClutterActorBox. Use + * clutter_actor_box_free() to free the allocated resources + * + * Since: 1.0 + */ +ClutterActorBox * +clutter_actor_box_copy (const ClutterActorBox *box) +{ + if (G_LIKELY (box != NULL)) + return g_slice_dup (ClutterActorBox, box); + + return NULL; +} + +/** + * clutter_actor_box_free: + * @box: a #ClutterActorBox + * + * Frees a #ClutterActorBox allocated using clutter_actor_box_new() + * or clutter_actor_box_copy() + * + * Since: 1.0 + */ +void clutter_actor_box_free (ClutterActorBox *box) { if (G_LIKELY (box != NULL)) @@ -7799,6 +7931,188 @@ clutter_actor_box_get_type (void) return our_type; } +/** + * 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 + * + * Since: 1.0 + */ +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_origin: + * @box: a #ClutterActorBox + * @x: (out): return location for the X coordinate, or %NULL + * @y: (out): return location for the Y coordinate, or %NULL + * + * Retrieves the origin of @box + * + * Since: 1.0 + */ +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): return location for the width, or %NULL + * @height: (out): return location for the height, or %NULL + * + * Retrieves the size of @box + * + * Since: 1.0 + */ +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 + * + * Since: 1.0 + */ +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 + * withing @box + * + * Return value: %TRUE if the point is contained by the #ClutterActorBox + * + * Since: 1.0 + */ +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 + * @verts: (array fixed-size=4): array of four #ClutterVertex + * + * Calculates the bounding box represented by the four vertices; for details + * of the vertex array see clutter_actor_get_abs_allocation_vertices(). + * + * Since: 1.0 + */ +void +clutter_actor_box_from_vertices (ClutterActorBox *box, + const ClutterVertex verts[]) +{ + 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; +} + /******************************************************************************/ struct _ShaderData @@ -8147,71 +8461,6 @@ clutter_actor_is_scaled (ClutterActor *self) return FALSE; } -/** - * clutter_actor_box_get_from_vertices: - * @vtx: array of four #ClutterVertex - * @box: (out): return location for a #ClutterActorBox - * - * Calculates the bounding box represented by the four vertices; for details - * of the vertex array see clutter_actor_get_abs_allocation_vertices(). - * - * Since: 0.6 - */ -void -clutter_actor_get_box_from_vertices (ClutterVertex vtx[4], - ClutterActorBox *box) -{ - gfloat x_1, x_2, y_1, y_2; - - /* 4-way min/max */ - x_1 = vtx[0].x; - y_1 = vtx[0].y; - - if (vtx[1].x < x_1) - x_1 = vtx[1].x; - - if (vtx[2].x < x_1) - x_1 = vtx[2].x; - - if (vtx[3].x < x_1) - x_1 = vtx[3].x; - - if (vtx[1].y < y_1) - y_1 = vtx[1].y; - - if (vtx[2].y < y_1) - y_1 = vtx[2].y; - - if (vtx[3].y < y_1) - y_1 = vtx[3].y; - - x_2 = vtx[0].x; - y_2 = vtx[0].y; - - if (vtx[1].x > x_2) - x_2 = vtx[1].x; - - if (vtx[2].x > x_2) - x_2 = vtx[2].x; - - if (vtx[3].x > x_2) - x_2 = vtx[3].x; - - if (vtx[1].y > y_2) - y_2 = vtx[1].y; - - if (vtx[2].y > y_2) - y_2 = vtx[2].y; - - if (vtx[3].y > y_2) - y_2 = vtx[3].y; - - box->x1 = x_1; - box->x2 = x_2; - box->y1 = y_1; - box->y2 = y_2; -} - /** * clutter_actor_get_stage: * @actor: a #ClutterActor diff --git a/clutter/clutter-actor.h b/clutter/clutter-actor.h index 9c7b9cd9b..88d77a83b 100644 --- a/clutter/clutter-actor.h +++ b/clutter/clutter-actor.h @@ -34,27 +34,18 @@ #include #include -#include #include -#include #include #include G_BEGIN_DECLS -#define CLUTTER_TYPE_ACTOR_BOX (clutter_actor_box_get_type ()) -#define CLUTTER_TYPE_ACTOR (clutter_actor_get_type ()) - -#define CLUTTER_ACTOR(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), CLUTTER_TYPE_ACTOR, ClutterActor)) -#define CLUTTER_ACTOR_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), CLUTTER_TYPE_ACTOR, ClutterActorClass)) -#define CLUTTER_IS_ACTOR(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CLUTTER_TYPE_ACTOR)) -#define CLUTTER_IS_ACTOR_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), CLUTTER_TYPE_ACTOR)) -#define CLUTTER_ACTOR_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), CLUTTER_TYPE_ACTOR, ClutterActorClass)) +#define CLUTTER_TYPE_ACTOR (clutter_actor_get_type ()) +#define CLUTTER_ACTOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CLUTTER_TYPE_ACTOR, ClutterActor)) +#define CLUTTER_ACTOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CLUTTER_TYPE_ACTOR, ClutterActorClass)) +#define CLUTTER_IS_ACTOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CLUTTER_TYPE_ACTOR)) +#define CLUTTER_IS_ACTOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CLUTTER_TYPE_ACTOR)) +#define CLUTTER_ACTOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CLUTTER_TYPE_ACTOR, ClutterActorClass)) /** * CLUTTER_ACTOR_SET_FLAGS: @@ -80,7 +71,6 @@ G_BEGIN_DECLS #define CLUTTER_ACTOR_IS_REACTIVE(a) ((((ClutterActor*)(a))->flags & CLUTTER_ACTOR_REACTIVE) != FALSE) typedef struct _ClutterActorClass ClutterActorClass; -typedef struct _ClutterActorBox ClutterActorBox; typedef struct _ClutterActorPrivate ClutterActorPrivate; /** @@ -138,28 +128,6 @@ typedef enum CLUTTER_ABSOLUTE_ORIGIN_CHANGED = 1 << 1 } ClutterAllocationFlags; -/** - * ClutterActorBox: - * @x1: X coordinate of the top left corner - * @y1: Y coordinate of the top left corner - * @x2: X coordinate of the bottom right corner - * @y2: Y coordinate of the bottom right corner - * - * Bounding box of an actor. The coordinates of the top left and right bottom - * corners of an actor. The coordinates of the two points are expressed in - * pixels with sub-pixel precision - */ -struct _ClutterActorBox -{ - gfloat x1; - gfloat y1; - - gfloat x2; - gfloat y2; -}; - -GType clutter_actor_box_get_type (void) G_GNUC_CONST; - /** * ClutterActor: * @flags: #ClutterActorFlags @@ -530,9 +498,6 @@ gboolean clutter_actor_is_rotated (ClutterActor *self); gboolean clutter_actor_is_scaled (ClutterActor *self); gboolean clutter_actor_should_pick_paint (ClutterActor *self); -void clutter_actor_box_get_from_vertices (ClutterVertex vtx[4], - ClutterActorBox *box); - void clutter_actor_get_abs_allocation_vertices (ClutterActor *self, ClutterVertex verts[4]); diff --git a/clutter/clutter-deprecated.h b/clutter/clutter-deprecated.h index 3f79c9044..f27b81536 100644 --- a/clutter/clutter-deprecated.h +++ b/clutter/clutter-deprecated.h @@ -176,4 +176,6 @@ #define clutter_stage_fullscreen clutter_stage_fullscreen_REPLACED_BY_clutter_stage_set_fullscreen #define clutter_stage_unfullscreen clutter_stage_unfullscreen_REPLACED_BY_clutter_stage_set_fullscreen +#define clutter_actor_get_box_from_vertices clutter_actor_get_box_from_vertices_REPLACED_BY_clutter_actor_box_from_vertices + #endif /* CLUTTER_DEPRECATED_H */ diff --git a/clutter/clutter-types.h b/clutter/clutter-types.h index 88921ad95..dd09d62d1 100644 --- a/clutter/clutter-types.h +++ b/clutter/clutter-types.h @@ -33,6 +33,7 @@ G_BEGIN_DECLS +#define CLUTTER_TYPE_ACTOR_BOX (clutter_actor_box_get_type ()) #define CLUTTER_TYPE_GEOMETRY (clutter_geometry_get_type ()) #define CLUTTER_TYPE_KNOT (clutter_knot_get_type ()) #define CLUTTER_TYPE_VERTEX (clutter_vertex_get_type ()) @@ -75,10 +76,79 @@ typedef enum { /*< prefix=CLUTTER_GRAVITY >*/ CLUTTER_GRAVITY_CENTER } ClutterGravity; +typedef struct _ClutterActorBox ClutterActorBox; typedef struct _ClutterGeometry ClutterGeometry; typedef struct _ClutterKnot ClutterKnot; typedef struct _ClutterVertex ClutterVertex; +/** + * ClutterVertex: + * @x: X coordinate of the vertex + * @y: Y coordinate of the vertex + * @z: Z coordinate of the vertex + * + * Vertex of an actor in 3D space, expressed in pixels + * + * Since: 0.4 + */ +struct _ClutterVertex +{ + gfloat x; + gfloat y; + gfloat z; +}; + +GType clutter_vertex_get_type (void) G_GNUC_CONST; +ClutterVertex *clutter_vertex_new (gfloat x, + gfloat y, + gfloat z); +ClutterVertex *clutter_vertex_copy (const ClutterVertex *vertex); +void clutter_vertex_free (ClutterVertex *vertex); +gboolean clutter_vertex_equal (const ClutterVertex *vertex_a, + const ClutterVertex *vertex_b); + +/** + * ClutterActorBox: + * @x1: X coordinate of the top left corner + * @y1: Y coordinate of the top left corner + * @x2: X coordinate of the bottom right corner + * @y2: Y coordinate of the bottom right corner + * + * Bounding box of an actor. The coordinates of the top left and right bottom + * corners of an actor. The coordinates of the two points are expressed in + * pixels with sub-pixel precision + */ +struct _ClutterActorBox +{ + gfloat x1; + gfloat y1; + + gfloat x2; + gfloat y2; +}; + +GType clutter_actor_box_get_type (void) G_GNUC_CONST; +ClutterActorBox *clutter_actor_box_new (gfloat x_1, + gfloat y_1, + gfloat x_2, + gfloat y_2); +ClutterActorBox *clutter_actor_box_copy (const ClutterActorBox *box); +void clutter_actor_box_free (ClutterActorBox *box); +gboolean clutter_actor_box_equal (const ClutterActorBox *box_a, + const ClutterActorBox *box_b); +void clutter_actor_box_get_origin (const ClutterActorBox *box, + gfloat *x, + gfloat *y); +void clutter_actor_box_get_size (const ClutterActorBox *box, + gfloat *width, + gfloat *height); +gfloat clutter_actor_box_get_area (const ClutterActorBox *box); +gboolean clutter_actor_box_contains (const ClutterActorBox *box, + gfloat x, + gfloat y); +void clutter_actor_box_from_vertices (ClutterActorBox *box, + const ClutterVertex verts[]); + /** * ClutterGeometry: * @x: X coordinate of the top left corner of an actor @@ -99,26 +169,6 @@ struct _ClutterGeometry GType clutter_geometry_get_type (void) G_GNUC_CONST; - -/** - * ClutterVertex: - * @x: X coordinate of the vertex - * @y: Y coordinate of the vertex - * @z: Z coordinate of the vertex - * - * Vertex of an actor in 3D space, expressed in pixels - * - * Since: 0.4 - */ -struct _ClutterVertex -{ - gfloat x; - gfloat y; - gfloat z; -}; - -GType clutter_vertex_get_type (void) G_GNUC_CONST; - /** * ClutterKnot: * @x: X coordinate of the knot diff --git a/doc/reference/clutter/clutter-sections.txt b/doc/reference/clutter/clutter-sections.txt index c16577e48..0441653ab 100644 --- a/doc/reference/clutter/clutter-sections.txt +++ b/doc/reference/clutter/clutter-sections.txt @@ -259,7 +259,6 @@ CLUTTER_ACTOR_IS_VISIBLE CLUTTER_ACTOR_IS_REACTIVE -ClutterActorBox ClutterActorFlags ClutterRequestMode ClutterGeometry @@ -366,10 +365,6 @@ clutter_actor_get_paint_opacity clutter_actor_get_paint_visibility clutter_actor_get_abs_allocation_vertices - -ClutterVertex -clutter_actor_box_get_from_vertices - clutter_actor_set_anchor_point clutter_actor_get_anchor_point @@ -393,6 +388,25 @@ clutter_actor_get_pango_context clutter_actor_create_pango_context clutter_actor_create_pango_layout + +ClutterActorBox +clutter_actor_box_new +clutter_actor_box_copy +clutter_actor_box_free +clutter_actor_box_equal +clutter_actor_box_get_origin +clutter_actor_box_get_size +clutter_actor_box_get_area +clutter_actor_box_contains +clutter_actor_box_from_vertices + + +ClutterVertex +clutter_vertex_new +clutter_vertex_copy +clutter_vertex_free +clutter_vertex_equal + CLUTTER_TYPE_GEOMETRY CLUTTER_TYPE_ACTOR_BOX