mutter/tests/interactive/test-animation.c
Emmanuele Bassi d6d208da7d Remove Units from the public API
With the recent change to internal floating point values, ClutterUnit
has become a redundant type, defined to be a float. All integer entry
points are being internally converted to floating point values to be
passed to the GL pipeline with the least amount of conversion.

ClutterUnit is thus exposed as just a "pixel with fractionary bits",
and not -- as users might think -- as generic, resolution and device
independent units. not that it was the case, but a definitive amount
of people was convinced it did provide this "feature", and was flummoxed
about the mere existence of this type.

So, having ClutterUnit exposed in the public API doubles the entry
points and has the following disadvantages:

  - we have to maintain twice the amount of entry points in ClutterActor
  - we still do an integer-to-float implicit conversion
  - we introduce a weird impedance between pixels and "pixels with
    fractionary bits"
  - language bindings will have to choose what to bind, and resort
    to manually overriding the API
    + *except* for language bindings based on GObject-Introspection, as
      they cannot do manual overrides, thus will replicate the entire
      set of entry points

For these reason, we should coalesces every Actor entry point for
pixels and for ClutterUnit into a single entry point taking a float,
like:

  void clutter_actor_set_x (ClutterActor *self,
                            gfloat        x);
  void clutter_actor_get_size (ClutterActor *self,
                               gfloat       *width,
                               gfloat       *height);
  gfloat clutter_actor_get_height (ClutterActor *self);

etc.

The issues I have identified are:

  - we'll have a two cases of compiler warnings:
    - printf() format of the return values from %d to %f
    - clutter_actor_get_size() taking floats instead of unsigned ints
  - we'll have a problem with varargs when passing an integer instead
    of a floating point value, except on 64bit platforms where the
    size of a float is the same as the size of an int

To be clear: the *intent* of the API should not change -- we still use
pixels everywhere -- but:

  - we remove ambiguity in the API with regard to pixels and units
  - we remove entry points we get to maintain for the whole 1.0
    version of the API
  - we make things simpler to bind for both manual language bindings
    and automatic (gobject-introspection based) ones
  - we have the simplest API possible while still exposing the
    capabilities of the underlying GL implementation
2009-05-06 16:44:47 +01:00

115 lines
3.2 KiB
C

#include <stdlib.h>
#include <gmodule.h>
#include <clutter/clutter.h>
static gboolean is_expanded = FALSE;
static void
on_animation_complete (ClutterAnimation *animation,
ClutterActor *actor)
{
is_expanded = !is_expanded;
g_print ("Animation complete\n");
clutter_actor_set_reactive (actor, TRUE);
}
static gboolean
on_button_press (ClutterActor *actor,
ClutterButtonEvent *event,
gpointer dummy)
{
ClutterAnimation *animation;
gfloat old_x, old_y, new_x, new_y;
gfloat old_width, old_height, new_width, new_height;
gdouble new_angle;
ClutterVertex vertex = { 0, };
ClutterColor new_color = { 0, };
clutter_actor_get_position (actor, &old_x, &old_y);
clutter_actor_get_size (actor, &old_width, &old_height);
/* determine the final state of the animation depending on
* the state of the actor
*/
if (!is_expanded)
{
new_x = old_x - 100;
new_y = old_y - 100;
new_width = old_width + 200;
new_height = old_height + 200;
new_angle = 360.0;
new_color.red = 0xdd;
new_color.green = 0x44;
new_color.blue = 0xdd;
new_color.alpha = 0xff;
}
else
{
new_x = old_x + 100;
new_y = old_y + 100;
new_width = old_width - 200;
new_height = old_height - 200;
new_angle = 0.0;
new_color.red = 0x44;
new_color.green = 0xdd;
new_color.blue = 0x44;
new_color.alpha = 0x88;
}
vertex.x = CLUTTER_UNITS_FROM_FLOAT ((float) new_width / 2);
vertex.y = CLUTTER_UNITS_FROM_FLOAT ((float) new_height / 2);
animation =
clutter_actor_animate (actor, CLUTTER_EASE_IN_EXPO, 2000,
"x", (int) new_x,
"y", (int) new_y,
"width", (int) new_width,
"height", (int) new_height,
"color", &new_color,
"rotation-angle-z", new_angle,
"fixed::rotation-center-z", &vertex,
"fixed::reactive", FALSE,
NULL);
g_signal_connect (animation,
"completed", G_CALLBACK (on_animation_complete),
actor);
return TRUE;
}
G_MODULE_EXPORT int
test_animation_main (int argc, char *argv[])
{
ClutterActor *stage, *rect;
ClutterColor stage_color = { 0x66, 0x66, 0xdd, 0xff };
ClutterColor rect_color = { 0x44, 0xdd, 0x44, 0xff };
clutter_init (&argc, &argv);
stage = clutter_stage_get_default ();
clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color);
rect = clutter_rectangle_new_with_color (&rect_color);
clutter_container_add_actor (CLUTTER_CONTAINER (stage), rect);
clutter_actor_set_size (rect, 50, 50);
clutter_actor_set_anchor_point (rect, 25, 25);
clutter_actor_set_position (rect,
clutter_actor_get_width (stage) / 2,
clutter_actor_get_height (stage) / 2);
clutter_actor_set_opacity (rect, 0x88);
clutter_actor_set_reactive (rect, TRUE);
g_signal_connect (rect,
"button-press-event", G_CALLBACK (on_button_press),
NULL);
clutter_actor_show (stage);
clutter_main ();
return EXIT_SUCCESS;
}