diff options
author | Emmanuele Bassi <ebassi@linux.intel.com> | 2009-03-09 17:35:08 +0000 |
---|---|---|
committer | Emmanuele Bassi <ebassi@linux.intel.com> | 2009-03-10 12:38:04 +0000 |
commit | d1f3190f5b9b93b6da32c0afa8c2544b5c1c8415 (patch) | |
tree | 60790b637aab02867cfa80da8bc6742aba6b9b40 | |
parent | 6bee140e7458e92e3cf3b884cc06f2dc4c4a99a5 (diff) | |
download | clutter-d1f3190f5b9b93b6da32c0afa8c2544b5c1c8415.tar.gz |
[units] Add more conversion functions
A GValue containing a ClutterUnit should be transformable into a
GValue holding an integer, a floating point value or a fixed point
value.
This means adding more transformation functions when registering
the ClutterUnit GType.
-rw-r--r-- | clutter/clutter-units.c | 73 | ||||
-rw-r--r-- | clutter/clutter-units.h | 23 |
2 files changed, 85 insertions, 11 deletions
diff --git a/clutter/clutter-units.c b/clutter/clutter-units.c index 9ea6d78a0..e51d2e379 100644 --- a/clutter/clutter-units.c +++ b/clutter/clutter-units.c @@ -160,7 +160,7 @@ clutter_units_pt (gdouble pt) * @em: em to convert * * Converts a value in em to #ClutterUnit<!-- -->s at the - * current DPI. + * current DPI * * Return value: the value in units * @@ -176,6 +176,42 @@ clutter_units_em (gdouble em) return em * _clutter_backend_get_units_per_em (backend); } +/** + * clutter_units_pixels: + * @px: pixels to convert + * + * Converts a value in pixels to #ClutterUnit<!-- -->s + * + * Return value: the value in units + * + * Since: 1.0 + */ +ClutterUnit +clutter_units_pixels (gint px) +{ + return CLUTTER_UNITS_FROM_INT (px); +} + +/** + * clutter_units_to_pixels: + * @units: units to convert + * + * Converts a value in #ClutterUnit<!-- -->s to pixels + * + * Return value: the value in pixels + * + * Since: 1.0 + */ +gint +clutter_units_to_pixels (ClutterUnit units) +{ + return CLUTTER_UNITS_TO_INT (units); +} + +/* + * GValue and GParamSpec integration + */ + static GTypeInfo _info = { 0, NULL, @@ -246,6 +282,36 @@ clutter_value_transform_int_unit (const GValue *src, dest->data[0].v_float = CLUTTER_UNITS_FROM_INT (src->data[0].v_int); } +static void +clutter_value_transform_unit_float (const GValue *src, + GValue *dest) +{ + dest->data[0].v_float = CLUTTER_UNITS_TO_FLOAT (src->data[0].v_float); +} + +static void +clutter_value_transform_float_unit (const GValue *src, + GValue *dest) +{ + dest->data[0].v_float = CLUTTER_UNITS_FROM_FLOAT (src->data[0].v_float); +} + +#if 0 +static void +clutter_value_transform_unit_fixed (const GValue *src, + GValue *dest) +{ + dest->data[0].v_int = CLUTTER_UNITS_TO_FIXED (src->data[0].v_float); +} + +static void +clutter_value_transform_fixed_unit (const GValue *src, + GValue *dest) +{ + dest->data[0].v_float = CLUTTER_UNITS_FROM_FIXED (src->data[0].v_int); +} +#endif + static const GTypeValueTable _clutter_unit_value_table = { clutter_value_init_unit, NULL, @@ -274,6 +340,11 @@ clutter_unit_get_type (void) clutter_value_transform_unit_int); g_value_register_transform_func (G_TYPE_INT, _clutter_unit_type, clutter_value_transform_int_unit); + + g_value_register_transform_func (_clutter_unit_type, G_TYPE_FLOAT, + clutter_value_transform_unit_float); + g_value_register_transform_func (G_TYPE_FLOAT, _clutter_unit_type, + clutter_value_transform_float_unit); } return _clutter_unit_type; diff --git a/clutter/clutter-units.h b/clutter/clutter-units.h index efc622e1b..00a1e0dc2 100644 --- a/clutter/clutter-units.h +++ b/clutter/clutter-units.h @@ -39,8 +39,8 @@ G_BEGIN_DECLS /** * ClutterUnit: * - * Device independent unit used by Clutter. The value held can be transformed - * into other units, likes pixels. + * Device independent unit used by Clutter. The value held can be + * transformed into other units, likes pixels. * * Since: 0.4 */ @@ -52,8 +52,8 @@ typedef float ClutterUnit; #define CLUTTER_UNITS_FROM_FLOAT(x) (x) #define CLUTTER_UNITS_TO_FLOAT(x) (x) -#define CLUTTER_UNITS_FROM_FIXED(x) (x) -#define CLUTTER_UNITS_TO_FIXED(x) (x) +#define CLUTTER_UNITS_FROM_FIXED(x) (COGL_FIXED_TO_FLOAT (x)) +#define CLUTTER_UNITS_TO_FIXED(x) (COGL_FIXED_FROM_FLOAT (x)) /** * CLUTTER_UNITS_FORMAT: @@ -79,7 +79,7 @@ typedef float ClutterUnit; * * Since: 0.6 */ -#define CLUTTER_UNITS_FROM_DEVICE(x) CLUTTER_UNITS_FROM_INT ((x)) +#define CLUTTER_UNITS_FROM_DEVICE(x) (clutter_units_pixels ((x))) /** * CLUTTER_UNITS_TO_DEVICE: @@ -89,7 +89,7 @@ typedef float ClutterUnit; * * Since: 0.6 */ -#define CLUTTER_UNITS_TO_DEVICE(x) CLUTTER_UNITS_TO_INT ((x)) +#define CLUTTER_UNITS_TO_DEVICE(x) (clutter_units_to_pixels ((x))) /** * CLUTTER_UNITS_FROM_PANGO_UNIT: @@ -99,7 +99,7 @@ typedef float ClutterUnit; * * Since: 0.6 */ -#define CLUTTER_UNITS_FROM_PANGO_UNIT(x) ((float)((x) / 1024)) +#define CLUTTER_UNITS_FROM_PANGO_UNIT(x) ((float)((x) / 1024.0)) /** * CLUTTER_UNITS_TO_PANGO_UNIT: @@ -141,9 +141,12 @@ typedef float ClutterUnit; */ #define CLUTTER_UNITS_FROM_EM(x) (clutter_units_em (x)) -ClutterUnit clutter_units_mm (gdouble mm); -ClutterUnit clutter_units_pt (gdouble pt); -ClutterUnit clutter_units_em (gdouble em); +ClutterUnit clutter_units_mm (gdouble mm); +ClutterUnit clutter_units_pt (gdouble pt); +ClutterUnit clutter_units_em (gdouble em); +ClutterUnit clutter_units_pixels (gint px); + +gint clutter_units_to_pixels (ClutterUnit units); #define CLUTTER_TYPE_UNIT (clutter_unit_get_type ()) #define CLUTTER_TYPE_PARAM_UNIT (clutter_param_unit_get_type ()) |