mirror of
https://github.com/brl/mutter.git
synced 2024-11-29 19:40:43 -05:00
2008-05-09 Emmanuele Bassi <ebassi@openedhand.com>
Bug #902 - Support transform from G_TYPE_INT to ClutterUnit * clutter/clutter-units.c: (clutter_value_transform_int_unit), (clutter_unit_get_type): Add GValue transformation function from integer values to ClutterUnit. (#902) (param_unit_validate): Fix validation for ClutterParamSpecUnit; this allows writable ClutterUnit properties. * clutter/clutter-fixed.c: (clutter_value_transform_int_fixed), (clutter_value_transform_double_fixed), (clutter_value_transform_float_fixed): Add GValue transformation functions from native types (int, double, float) to ClutterFixed. (clutter_fixed_get_type): Register the new transformation functions. (param_fixed_validate): Fix validation for ClutterParamSpecUnit; this allows writable ClutterFixed properties.
This commit is contained in:
parent
ef084cfa95
commit
1abccbad21
23
ChangeLog
23
ChangeLog
@ -1,3 +1,26 @@
|
|||||||
|
2008-05-09 Emmanuele Bassi <ebassi@openedhand.com>
|
||||||
|
|
||||||
|
Bug #902 - Support transform from G_TYPE_INT to ClutterUnit
|
||||||
|
|
||||||
|
* clutter/clutter-units.c:
|
||||||
|
(clutter_value_transform_int_unit),
|
||||||
|
(clutter_unit_get_type): Add GValue transformation function from
|
||||||
|
integer values to ClutterUnit. (#902)
|
||||||
|
|
||||||
|
(param_unit_validate): Fix validation for ClutterParamSpecUnit;
|
||||||
|
this allows writable ClutterUnit properties.
|
||||||
|
|
||||||
|
* clutter/clutter-fixed.c:
|
||||||
|
(clutter_value_transform_int_fixed),
|
||||||
|
(clutter_value_transform_double_fixed),
|
||||||
|
(clutter_value_transform_float_fixed): Add GValue transformation
|
||||||
|
functions from native types (int, double, float) to ClutterFixed.
|
||||||
|
|
||||||
|
(clutter_fixed_get_type): Register the new transformation functions.
|
||||||
|
|
||||||
|
(param_fixed_validate): Fix validation for ClutterParamSpecUnit;
|
||||||
|
this allows writable ClutterFixed properties.
|
||||||
|
|
||||||
2008-05-07 Ivan Leben <ivan@o-hand.com>
|
2008-05-07 Ivan Leben <ivan@o-hand.com>
|
||||||
|
|
||||||
* clutter/cogl/cogl.h.in:
|
* clutter/cogl/cogl.h.in:
|
||||||
|
@ -43,5 +43,6 @@
|
|||||||
#define clutter_shader_is_bound clutter_shader_is_bound_REPLACED_BY_clutter_shader_is_compiled
|
#define clutter_shader_is_bound clutter_shader_is_bound_REPLACED_BY_clutter_shader_is_compiled
|
||||||
|
|
||||||
#define clutter_texture_new_from_pixbuf clutter_texture_new_from_pixbuf_DEPRECATED_BY_clutter_texture_new_from_file_OR_clutter_texture_new_AND_clutter_texture_set_from_rgb_data
|
#define clutter_texture_new_from_pixbuf clutter_texture_new_from_pixbuf_DEPRECATED_BY_clutter_texture_new_from_file_OR_clutter_texture_new_AND_clutter_texture_set_from_rgb_data
|
||||||
|
#define clutter_texture_set_pixbuf clutter_texture_set_pixbuf+DEPRECATED_BY_clutter_texture_set_from_rgb_data
|
||||||
|
|
||||||
#endif /* CLUTTER_DEPRECATED_H */
|
#endif /* CLUTTER_DEPRECATED_H */
|
||||||
|
@ -1035,7 +1035,7 @@ static void
|
|||||||
clutter_value_transform_fixed_int (const GValue *src,
|
clutter_value_transform_fixed_int (const GValue *src,
|
||||||
GValue *dest)
|
GValue *dest)
|
||||||
{
|
{
|
||||||
dest->data[0].v_int = src->data[0].v_int;
|
dest->data[0].v_int = CLUTTER_FIXED_TO_INT (src->data[0].v_int);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -1052,6 +1052,28 @@ clutter_value_transform_fixed_float (const GValue *src,
|
|||||||
dest->data[0].v_float = CLUTTER_FIXED_TO_FLOAT (src->data[0].v_int);
|
dest->data[0].v_float = CLUTTER_FIXED_TO_FLOAT (src->data[0].v_int);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
clutter_value_transform_int_fixed (const GValue *src,
|
||||||
|
GValue *dest)
|
||||||
|
{
|
||||||
|
dest->data[0].v_int = CLUTTER_INT_TO_FIXED (src->data[0].v_int);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
clutter_value_transform_double_fixed (const GValue *src,
|
||||||
|
GValue *dest)
|
||||||
|
{
|
||||||
|
dest->data[0].v_int = CLUTTER_FLOAT_TO_FIXED (src->data[0].v_double);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
clutter_value_transform_float_fixed (const GValue *src,
|
||||||
|
GValue *dest)
|
||||||
|
{
|
||||||
|
dest->data[0].v_int = CLUTTER_FLOAT_TO_FIXED (src->data[0].v_float);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static const GTypeValueTable _clutter_fixed_value_table = {
|
static const GTypeValueTable _clutter_fixed_value_table = {
|
||||||
clutter_value_init_fixed,
|
clutter_value_init_fixed,
|
||||||
NULL,
|
NULL,
|
||||||
@ -1078,10 +1100,16 @@ clutter_fixed_get_type (void)
|
|||||||
|
|
||||||
g_value_register_transform_func (_clutter_fixed_type, G_TYPE_INT,
|
g_value_register_transform_func (_clutter_fixed_type, G_TYPE_INT,
|
||||||
clutter_value_transform_fixed_int);
|
clutter_value_transform_fixed_int);
|
||||||
|
g_value_register_transform_func (G_TYPE_INT, _clutter_fixed_type,
|
||||||
|
clutter_value_transform_int_fixed);
|
||||||
g_value_register_transform_func (_clutter_fixed_type, G_TYPE_FLOAT,
|
g_value_register_transform_func (_clutter_fixed_type, G_TYPE_FLOAT,
|
||||||
clutter_value_transform_fixed_float);
|
clutter_value_transform_fixed_float);
|
||||||
|
g_value_register_transform_func (G_TYPE_FLOAT, _clutter_fixed_type,
|
||||||
|
clutter_value_transform_float_fixed);
|
||||||
g_value_register_transform_func (_clutter_fixed_type, G_TYPE_DOUBLE,
|
g_value_register_transform_func (_clutter_fixed_type, G_TYPE_DOUBLE,
|
||||||
clutter_value_transform_fixed_double);
|
clutter_value_transform_fixed_double);
|
||||||
|
g_value_register_transform_func (G_TYPE_DOUBLE, _clutter_fixed_type,
|
||||||
|
clutter_value_transform_double_fixed);
|
||||||
}
|
}
|
||||||
|
|
||||||
return _clutter_fixed_type;
|
return _clutter_fixed_type;
|
||||||
@ -1145,13 +1173,27 @@ param_fixed_validate (GParamSpec *pspec,
|
|||||||
GValue *value)
|
GValue *value)
|
||||||
{
|
{
|
||||||
ClutterParamSpecFixed *fspec = CLUTTER_PARAM_SPEC_FIXED (pspec);
|
ClutterParamSpecFixed *fspec = CLUTTER_PARAM_SPEC_FIXED (pspec);
|
||||||
gint oval = value->data[0].v_int;
|
gint oval = CLUTTER_FIXED_TO_INT (value->data[0].v_int);
|
||||||
|
gint min, max, val;
|
||||||
|
|
||||||
value->data[0].v_int = CLAMP (value->data[0].v_int,
|
g_assert (CLUTTER_IS_PARAM_SPEC_FIXED (pspec));
|
||||||
fspec->minimum,
|
|
||||||
fspec->maximum);
|
|
||||||
|
|
||||||
return value->data[0].v_int != oval;
|
/* we compare the integer part of the value because the minimum
|
||||||
|
* and maximum values cover just that part of the representation
|
||||||
|
*/
|
||||||
|
|
||||||
|
min = fspec->minimum;
|
||||||
|
max = fspec->maximum;
|
||||||
|
val = CLUTTER_FIXED_TO_INT (value->data[0].v_int);
|
||||||
|
|
||||||
|
val = CLAMP (val, min, max);
|
||||||
|
if (val != oval)
|
||||||
|
{
|
||||||
|
value->data[0].v_int = val;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gint
|
static gint
|
||||||
|
@ -4,7 +4,8 @@
|
|||||||
*
|
*
|
||||||
* An OpenGL based 'interactive canvas' library.
|
* An OpenGL based 'interactive canvas' library.
|
||||||
*
|
*
|
||||||
* Authored By Tomas Frydrych <tf@openedhand.com>
|
* Authored By: Tomas Frydrych <tf@openedhand.com>
|
||||||
|
* Emmanuele Bassi <ebassi@openedhand.com>
|
||||||
*
|
*
|
||||||
* Copyright (C) 2007 OpenedHand
|
* Copyright (C) 2007 OpenedHand
|
||||||
*
|
*
|
||||||
@ -29,19 +30,65 @@
|
|||||||
* @short_description: A logical distance unit.
|
* @short_description: A logical distance unit.
|
||||||
*
|
*
|
||||||
* Clutter units are logical units with granularity greater than that of the
|
* Clutter units are logical units with granularity greater than that of the
|
||||||
* device units; they are used by #ClutterActorBox and the _units() family of
|
* device units; they are used by #ClutterActorBox and the units-based family
|
||||||
* ClutterActor functions. To convert between clutter units and device units,
|
* of #ClutterActor functions. To convert between Clutter units and device
|
||||||
* use #CLUTTER_UNITS_FROM_DEVICE and #CLUTTER_UNITS_TO_DEVICE macros.
|
* units, use %CLUTTER_UNITS_FROM_DEVICE and %CLUTTER_UNITS_TO_DEVICE macros.
|
||||||
*
|
*
|
||||||
* Note: It is expected that as of version 0.6 all dimensions in the public
|
* #ClutterUnit<!-- -->s can be converted from other units like millimeters,
|
||||||
* Clutter API will be given in clutter units. In order to ease the transition,
|
* typographic points (at the current resolution) and percentages. It is
|
||||||
* two extra macros have been provided, #CLUTTER_UNITS_TMP_TO_DEVICE and
|
* also possible to convert fixed point values to and from #ClutterUnit
|
||||||
* #CLUTTER_UNITS_TMP_FROM_DEVICE. In version 0.4 these are identity macros,
|
* values.
|
||||||
* but when the API transition happens will map to #CLUTTER_UNITS_TO_DEVICE and
|
|
||||||
* #CLUTTER_UNITS_FROM_DEVICE respectively. You can use these in newly written
|
|
||||||
* code as place holders.
|
|
||||||
*
|
*
|
||||||
* Since: 0.4
|
* In order to register a #ClutterUnit property, the #ClutterParamSpecUnit
|
||||||
|
* #GParamSpec sub-class should be used:
|
||||||
|
*
|
||||||
|
* |[
|
||||||
|
* GParamSpec *pspec;
|
||||||
|
*
|
||||||
|
* pspec = clutter_param_spec_unit ("width",
|
||||||
|
* "Width",
|
||||||
|
* "Width of the actor, in units",
|
||||||
|
* 0, CLUTTER_MAXUNIT,
|
||||||
|
* 0,
|
||||||
|
* G_PARAM_READWRITE);
|
||||||
|
* g_object_class_install_property (gobject_class, PROP_WIDTH, pspec);
|
||||||
|
* ]|
|
||||||
|
*
|
||||||
|
* A #GValue holding units can be manipulated using clutter_value_set_unit()
|
||||||
|
* and clutter_value_get_unit(). #GValue<!-- -->s containing a #ClutterUnit
|
||||||
|
* value can also be transformed to #GValue<!-- -->s containing integer
|
||||||
|
* values - with a loss of precision:
|
||||||
|
*
|
||||||
|
* |[
|
||||||
|
* static gboolean
|
||||||
|
* units_to_int (const GValue *src,
|
||||||
|
* GValue *dest)
|
||||||
|
* {
|
||||||
|
* g_return_val_if_fail (CLUTTER_VALUE_HOLDS_UNIT (src), FALSE);
|
||||||
|
*
|
||||||
|
* g_value_init (dest, G_TYPE_INT);
|
||||||
|
* return g_value_transform (src, &dest);
|
||||||
|
* }
|
||||||
|
* ]|
|
||||||
|
*
|
||||||
|
* The code above is equivalent to:
|
||||||
|
*
|
||||||
|
* |[
|
||||||
|
* static gboolean
|
||||||
|
* units_to_int (const GValue *src,
|
||||||
|
* GValue *dest)
|
||||||
|
* {
|
||||||
|
* g_return_val_if_fail (CLUTTER_VALUE_HOLDS_UNIT (src), FALSE);
|
||||||
|
*
|
||||||
|
* g_value_init (dest, G_TYPE_INT);
|
||||||
|
* g_value_set_int (dest,
|
||||||
|
* CLUTTER_UNITS_TO_INT (clutter_value_get_unit (src)));
|
||||||
|
*
|
||||||
|
* return TRUE;
|
||||||
|
* }
|
||||||
|
* ]|
|
||||||
|
*
|
||||||
|
* #ClutterUnit is available since Clutter 0.4
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
@ -114,7 +161,14 @@ static void
|
|||||||
clutter_value_transform_unit_int (const GValue *src,
|
clutter_value_transform_unit_int (const GValue *src,
|
||||||
GValue *dest)
|
GValue *dest)
|
||||||
{
|
{
|
||||||
dest->data[0].v_int = src->data[0].v_int;
|
dest->data[0].v_int = CLUTTER_UNITS_TO_INT (src->data[0].v_int);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
clutter_value_transform_int_unit (const GValue *src,
|
||||||
|
GValue *dest)
|
||||||
|
{
|
||||||
|
dest->data[0].v_int = CLUTTER_UNITS_FROM_INT (src->data[0].v_int);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const GTypeValueTable _clutter_unit_value_table = {
|
static const GTypeValueTable _clutter_unit_value_table = {
|
||||||
@ -143,6 +197,8 @@ clutter_unit_get_type (void)
|
|||||||
|
|
||||||
g_value_register_transform_func (_clutter_unit_type, G_TYPE_INT,
|
g_value_register_transform_func (_clutter_unit_type, G_TYPE_INT,
|
||||||
clutter_value_transform_unit_int);
|
clutter_value_transform_unit_int);
|
||||||
|
g_value_register_transform_func (G_TYPE_INT, _clutter_unit_type,
|
||||||
|
clutter_value_transform_int_unit);
|
||||||
}
|
}
|
||||||
|
|
||||||
return _clutter_unit_type;
|
return _clutter_unit_type;
|
||||||
@ -206,13 +262,26 @@ param_unit_validate (GParamSpec *pspec,
|
|||||||
GValue *value)
|
GValue *value)
|
||||||
{
|
{
|
||||||
ClutterParamSpecUnit *uspec = CLUTTER_PARAM_SPEC_UNIT (pspec);
|
ClutterParamSpecUnit *uspec = CLUTTER_PARAM_SPEC_UNIT (pspec);
|
||||||
gint oval = value->data[0].v_int;
|
gint oval = CLUTTER_UNITS_TO_INT (value->data[0].v_int);
|
||||||
|
gint min, max, val;
|
||||||
|
|
||||||
value->data[0].v_int = CLAMP (value->data[0].v_int,
|
g_assert (CLUTTER_IS_PARAM_SPEC_UNIT (pspec));
|
||||||
uspec->minimum,
|
|
||||||
uspec->maximum);
|
|
||||||
|
|
||||||
return value->data[0].v_int != oval;
|
/* we compare the integer part of the value because the minimum
|
||||||
|
* and maximum values cover just that part of the representation
|
||||||
|
*/
|
||||||
|
min = uspec->minimum;
|
||||||
|
max = uspec->maximum;
|
||||||
|
val = CLUTTER_UNITS_TO_INT (value->data[0].v_int);
|
||||||
|
|
||||||
|
val = CLAMP (val, min, max);
|
||||||
|
if (val != oval)
|
||||||
|
{
|
||||||
|
value->data[0].v_int = val;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gint
|
static gint
|
||||||
|
@ -31,6 +31,8 @@ gboolean idle (gpointer data)
|
|||||||
|
|
||||||
clutter_actor_paint (stage);
|
clutter_actor_paint (stage);
|
||||||
++fps;
|
++fps;
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
Loading…
Reference in New Issue
Block a user