5 #include "clutter-types.h"
6 #include "clutter-interval.h"
7 #include "clutter-private.h"
10 * clutter_actor_box_new:
11 * @x_1: X coordinate of the top left point
12 * @y_1: Y coordinate of the top left point
13 * @x_2: X coordinate of the bottom right point
14 * @y_2: Y coordinate of the bottom right point
16 * Allocates a new #ClutterActorBox using the passed coordinates
17 * for the top left and bottom right points
19 * Return value: the newly allocated #ClutterActorBox. Use
20 * clutter_actor_box_free() to free the resources
25 clutter_actor_box_new (gfloat x_1,
32 box = g_slice_new (ClutterActorBox);
42 * clutter_actor_box_copy:
43 * @box: a #ClutterActorBox
47 * Return value: a newly allocated copy of #ClutterActorBox. Use
48 * clutter_actor_box_free() to free the allocated resources
53 clutter_actor_box_copy (const ClutterActorBox *box)
55 if (G_LIKELY (box != NULL))
56 return g_slice_dup (ClutterActorBox, box);
62 * clutter_actor_box_free:
63 * @box: a #ClutterActorBox
65 * Frees a #ClutterActorBox allocated using clutter_actor_box_new()
66 * or clutter_actor_box_copy()
71 clutter_actor_box_free (ClutterActorBox *box)
73 if (G_LIKELY (box != NULL))
74 g_slice_free (ClutterActorBox, box);
78 clutter_actor_box_progress (const GValue *a,
83 ClutterActorBox res = { 0, };
85 clutter_actor_box_interpolate (g_value_get_boxed (a),
86 g_value_get_boxed (b),
90 g_value_set_boxed (retval, &res);
96 clutter_actor_box_get_type (void)
98 static GType our_type = 0;
100 if (G_UNLIKELY (our_type == 0))
103 g_boxed_type_register_static (I_("ClutterActorBox"),
104 (GBoxedCopyFunc) clutter_actor_box_copy,
105 (GBoxedFreeFunc) clutter_actor_box_free);
107 clutter_interval_register_progress_func (our_type,
108 clutter_actor_box_progress);
115 * clutter_actor_box_equal:
116 * @box_a: a #ClutterActorBox
117 * @box_b: a #ClutterActorBox
119 * Checks @box_a and @box_b for equality
121 * Return value: %TRUE if the passed #ClutterActorBox are equal
126 clutter_actor_box_equal (const ClutterActorBox *box_a,
127 const ClutterActorBox *box_b)
129 g_return_val_if_fail (box_a != NULL && box_b != NULL, FALSE);
134 return box_a->x1 == box_b->x1 && box_a->y1 == box_b->y1 &&
135 box_a->x2 == box_b->x2 && box_a->y2 == box_b->y2;
139 * clutter_actor_box_get_x:
140 * @box: a #ClutterActorBox
142 * Retrieves the X coordinate of the origin of @box
144 * Return value: the X coordinate of the origin
149 clutter_actor_box_get_x (const ClutterActorBox *box)
151 g_return_val_if_fail (box != NULL, 0.);
157 * clutter_actor_box_get_y:
158 * @box: a #ClutterActorBox
160 * Retrieves the Y coordinate of the origin of @box
162 * Return value: the Y coordinate of the origin
167 clutter_actor_box_get_y (const ClutterActorBox *box)
169 g_return_val_if_fail (box != NULL, 0.);
175 * clutter_actor_box_get_width:
176 * @box: a #ClutterActorBox
178 * Retrieves the width of the @box
180 * Return value: the width of the box
185 clutter_actor_box_get_width (const ClutterActorBox *box)
187 g_return_val_if_fail (box != NULL, 0.);
189 return box->x2 - box->x1;
193 * clutter_actor_box_get_height:
194 * @box: a #ClutterActorBox
196 * Retrieves the height of the @box
198 * Return value: the height of the box
203 clutter_actor_box_get_height (const ClutterActorBox *box)
205 g_return_val_if_fail (box != NULL, 0.);
207 return box->y2 - box->y1;
211 * clutter_actor_box_get_origin:
212 * @box: a #ClutterActorBox
213 * @x: (out) (allow-none): return location for the X coordinate, or %NULL
214 * @y: (out) (allow-none): return location for the Y coordinate, or %NULL
216 * Retrieves the origin of @box
221 clutter_actor_box_get_origin (const ClutterActorBox *box,
225 g_return_if_fail (box != NULL);
235 * clutter_actor_box_get_size:
236 * @box: a #ClutterActorBox
237 * @width: (out) (allow-none): return location for the width, or %NULL
238 * @height: (out) (allow-none): return location for the height, or %NULL
240 * Retrieves the size of @box
245 clutter_actor_box_get_size (const ClutterActorBox *box,
249 g_return_if_fail (box != NULL);
252 *width = box->x2 - box->x1;
255 *height = box->y2 - box->y1;
259 * clutter_actor_box_get_area:
260 * @box: a #ClutterActorBox
262 * Retrieves the area of @box
264 * Return value: the area of a #ClutterActorBox, in pixels
269 clutter_actor_box_get_area (const ClutterActorBox *box)
271 g_return_val_if_fail (box != NULL, 0.);
273 return (box->x2 - box->x1) * (box->y2 - box->y1);
277 * clutter_actor_box_contains:
278 * @box: a #ClutterActorBox
279 * @x: X coordinate of the point
280 * @y: Y coordinate of the point
282 * Checks whether a point with @x, @y coordinates is contained
285 * Return value: %TRUE if the point is contained by the #ClutterActorBox
290 clutter_actor_box_contains (const ClutterActorBox *box,
294 g_return_val_if_fail (box != NULL, FALSE);
296 return (x > box->x1 && x < box->x2) &&
297 (y > box->y1 && y < box->y2);
301 * clutter_actor_box_from_vertices:
302 * @box: a #ClutterActorBox
303 * @verts: (array fixed-size=4): array of four #ClutterVertex
305 * Calculates the bounding box represented by the four vertices; for details
306 * of the vertex array see clutter_actor_get_abs_allocation_vertices().
311 clutter_actor_box_from_vertices (ClutterActorBox *box,
312 const ClutterVertex verts[])
314 gfloat x_1, x_2, y_1, y_2;
316 g_return_if_fail (box != NULL);
317 g_return_if_fail (verts != NULL);
323 if (verts[1].x < x_1)
326 if (verts[2].x < x_1)
329 if (verts[3].x < x_1)
332 if (verts[1].y < y_1)
335 if (verts[2].y < y_1)
338 if (verts[3].y < y_1)
344 if (verts[1].x > x_2)
347 if (verts[2].x > x_2)
350 if (verts[3].x > x_2)
353 if (verts[1].y > y_2)
356 if (verts[2].y > y_2)
359 if (verts[3].y > y_2)
369 * clutter_actor_box_interpolate:
370 * @initial: the initial #ClutterActorBox
371 * @final: the final #ClutterActorBox
372 * @progress: the interpolation progress
373 * @result: (out): return location for the interpolation
375 * Interpolates between @initial and @final #ClutterActorBox<!-- -->es
381 clutter_actor_box_interpolate (const ClutterActorBox *initial,
382 const ClutterActorBox *final,
384 ClutterActorBox *result)
386 g_return_if_fail (initial != NULL);
387 g_return_if_fail (final != NULL);
388 g_return_if_fail (result != NULL);
390 result->x1 = initial->x1 + (final->x1 - initial->x1) * progress;
391 result->y1 = initial->y1 + (final->y1 - initial->y1) * progress;
392 result->x2 = initial->x2 + (final->x2 - initial->x2) * progress;
393 result->y2 = initial->y2 + (final->y2 - initial->y2) * progress;
397 * clutter_actor_box_clamp_to_pixel:
398 * @box: (inout): the #ClutterActorBox to clamp
400 * Clamps the components of @box to the nearest integer
405 clutter_actor_box_clamp_to_pixel (ClutterActorBox *box)
407 g_return_if_fail (box != NULL);
409 box->x1 = floorf (box->x1);
410 box->y1 = floorf (box->y1);
411 box->x2 = ceilf (box->x2);
412 box->y2 = ceilf (box->y2);
416 * clutter_actor_box_union:
417 * @a: (in) the first #ClutterActorBox
418 * @b: (in): the second #ClutterActorBox
419 * @result: (out): the #ClutterActorBox representing a union
422 * Unions the two boxes @a and @b and stores the result in @result.
427 clutter_actor_box_union (const ClutterActorBox *a,
428 const ClutterActorBox *b,
429 ClutterActorBox *result)
431 g_return_if_fail (a != NULL);
432 g_return_if_fail (b != NULL);
433 g_return_if_fail (result != NULL);
435 result->x1 = MIN (a->x1, b->x1);
436 result->y1 = MIN (a->y1, b->y1);
438 result->x2 = MAX (a->x2, b->x2);
439 result->y2 = MAX (a->y2, b->y2);