base-types: Add zero point and rect

A constant ClutterPoint for (0, 0) and a constant degenerate ClutterRect
can be useful as guards for pointers, freeing the NULL value to mean
"unset".
This commit is contained in:
Emmanuele Bassi 2012-06-09 10:35:56 +01:00
parent 24495918bb
commit 17539bca95
4 changed files with 96 additions and 46 deletions

View File

@ -377,6 +377,26 @@ G_DEFINE_BOXED_TYPE (ClutterMargin, clutter_margin,
* ClutterPoint * ClutterPoint
*/ */
static const ClutterPoint _clutter_point_zero = CLUTTER_POINT_INIT_ZERO;
/**
* clutter_point_zero:
*
* A point centered at (0, 0).
*
* The returned value can be used as a guard.
*
* Return value: a point centered in (0, 0); the returned #ClutterPoint
* is owned by Clutter and it should not be modified or freed.
*
* Since: 1.12
*/
const ClutterPoint *
clutter_point_zero (void)
{
return &_clutter_point_zero;
}
/** /**
* clutter_point_alloc: * clutter_point_alloc:
* *
@ -672,6 +692,8 @@ G_DEFINE_BOXED_TYPE_WITH_CODE (ClutterSize, clutter_size,
* ClutterRect * ClutterRect
*/ */
static const ClutterRect _clutter_rect_zero = CLUTTER_RECT_INIT_ZERO;
static gboolean clutter_rect_progress (const GValue *a, static gboolean clutter_rect_progress (const GValue *a,
const GValue *b, const GValue *b,
gdouble progress, gdouble progress,
@ -705,6 +727,26 @@ clutter_rect_normalize_internal (ClutterRect *rect)
} }
} }
/**
* clutter_rect_zero:
*
* A #ClutterRect with #ClutterRect.origin set at (0, 0) and a size
* of 0.
*
* The returned value can be used as a guard.
*
* Return value: a rectangle with origin in (0, 0) and a size of 0.
* The returned #ClutterRect is owned by Clutter and it should not
* be modified or freed.
*
* Since: 1.12
*/
const ClutterRect *
clutter_rect_zero (void)
{
return &_clutter_rect_zero;
}
/** /**
* clutter_rect_alloc: * clutter_rect_alloc:
* *

View File

@ -161,6 +161,8 @@ struct _ClutterPoint
CLUTTER_AVAILABLE_IN_1_12 CLUTTER_AVAILABLE_IN_1_12
GType clutter_point_get_type (void) G_GNUC_CONST; GType clutter_point_get_type (void) G_GNUC_CONST;
CLUTTER_AVAILABLE_IN_1_12
const ClutterPoint * clutter_point_zero (void);
CLUTTER_AVAILABLE_IN_1_12 CLUTTER_AVAILABLE_IN_1_12
ClutterPoint * clutter_point_alloc (void); ClutterPoint * clutter_point_alloc (void);
CLUTTER_AVAILABLE_IN_1_12 CLUTTER_AVAILABLE_IN_1_12
@ -294,6 +296,8 @@ struct _ClutterRect
CLUTTER_AVAILABLE_IN_1_12 CLUTTER_AVAILABLE_IN_1_12
GType clutter_rect_get_type (void) G_GNUC_CONST; GType clutter_rect_get_type (void) G_GNUC_CONST;
CLUTTER_AVAILABLE_IN_1_12
const ClutterRect * clutter_rect_zero (void);
CLUTTER_AVAILABLE_IN_1_12 CLUTTER_AVAILABLE_IN_1_12
ClutterRect * clutter_rect_alloc (void); ClutterRect * clutter_rect_alloc (void);
CLUTTER_AVAILABLE_IN_1_12 CLUTTER_AVAILABLE_IN_1_12

View File

@ -1044,6 +1044,7 @@ clutter_point_equals
clutter_point_free clutter_point_free
clutter_point_get_type clutter_point_get_type
clutter_point_init clutter_point_init
clutter_point_zero
clutter_profile_flags DATA clutter_profile_flags DATA
clutter_property_transition_get_property_name clutter_property_transition_get_property_name
clutter_property_transition_get_type clutter_property_transition_get_type
@ -1068,6 +1069,7 @@ clutter_rect_intersection
clutter_rect_normalize clutter_rect_normalize
clutter_rect_offset clutter_rect_offset
clutter_rect_union clutter_rect_union
clutter_rect_zero
clutter_rectangle_get_border_color clutter_rectangle_get_border_color
clutter_rectangle_get_border_width clutter_rectangle_get_border_width
clutter_rectangle_get_color clutter_rectangle_get_color

View File

@ -3187,6 +3187,7 @@ ClutterPaintVolume
<SUBSECTION> <SUBSECTION>
CLUTTER_POINT_INIT CLUTTER_POINT_INIT
CLUTTER_POINT_INIT_ZERO CLUTTER_POINT_INIT_ZERO
clutter_point_zero
clutter_point_alloc clutter_point_alloc
clutter_point_init clutter_point_init
clutter_point_copy clutter_point_copy
@ -3206,6 +3207,7 @@ clutter_size_equals
<SUBSECTION> <SUBSECTION>
CLUTTER_RECT_INIT CLUTTER_RECT_INIT
CLUTTER_RECT_INIT_ZERO CLUTTER_RECT_INIT_ZERO
clutter_rect_zero
clutter_rect_alloc clutter_rect_alloc
clutter_rect_init clutter_rect_init
clutter_rect_copy clutter_rect_copy