Merge branch 'wip/state-machine'

* wip/state-machine:
  Do not use wildcards in test-state
  script: Implement State deserialization
  state: added a "target-state" property
  state: documented data structures
  Add State interactive tests to the ignore file
  state: Documentation and introspection annotation fixes
  state: Minor coding style fixes
  state: Clean up the header's documentation
  state: Constify StateKey accessors
  Do not include clutter.h from a Clutter header file
  state-machine: made clutter_state_change take a boolean animate argument
  state-machine: use clutter_timeline_get_progress
  state-machine: add completed signal
  state machine: added state machine

Conflicts:
	.gitignore
This commit is contained in:
Emmanuele Bassi 2010-05-24 10:42:03 +01:00
commit 382bd394b9
13 changed files with 2268 additions and 0 deletions

3
.gitignore vendored
View File

@ -151,6 +151,8 @@ TAGS
/tests/interactive/test-stage-sizing
/tests/interactive/test-drag
/tests/interactive/test-constraints
/tests/interactive/test-state
/tests/interactive/test-state-animator
/tests/conform/stamp-test-conformance
/tests/conform/test-anchors
/tests/conform/test-cogl-backface-culling
@ -258,6 +260,7 @@ TAGS
/tests/conform/test-cogl-path
/tests/conform/test-cogl-wrap-modes
/tests/conform/test-clutter-cairo-texture
/tests/conform/test-state-base
/tests/conform/wrappers
/tests/micro-bench/test-text-perf
/tests/micro-bench/test-text

View File

@ -121,6 +121,7 @@ source_h = \
$(srcdir)/clutter-stage.h \
$(srcdir)/clutter-stage-manager.h \
$(srcdir)/clutter-stage-window.h \
$(srcdir)/clutter-state.h \
$(srcdir)/clutter-texture.h \
$(srcdir)/clutter-text.h \
$(srcdir)/clutter-timeline.h \
@ -203,6 +204,7 @@ source_c = \
$(srcdir)/clutter-stage.c \
$(srcdir)/clutter-stage-manager.c \
$(srcdir)/clutter-stage-window.c \
$(srcdir)/clutter-state.c \
$(srcdir)/clutter-texture.c \
$(srcdir)/clutter-text.c \
$(srcdir)/clutter-timeline.c \

1769
clutter/clutter-state.c Normal file

File diff suppressed because it is too large Load Diff

158
clutter/clutter-state.h Normal file
View File

@ -0,0 +1,158 @@
/*
* Clutter.
*
* An OpenGL based 'interactive canvas' library.
*
* Authored By Øyvind Kolås <pippin@linux.intel.com>
*
* Copyright (C) 2009 Intel Corporation
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __CLUTTER_STATE_H__
#define __CLUTTER_STATE_H__
#include <clutter/clutter-types.h>
#include <clutter/clutter-timeline.h>
G_BEGIN_DECLS
#define CLUTTER_TYPE_STATE (clutter_state_get_type ())
#define CLUTTER_STATE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CLUTTER_TYPE_STATE, ClutterState))
#define CLUTTER_STATE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CLUTTER_TYPE_STATE, ClutterStateClass))
#define CLUTTER_IS_STATE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CLUTTER_TYPE_STATE))
#define CLUTTER_IS_STATE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CLUTTER_TYPE_STATE))
#define CLUTTER_STATE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CLUTTER_TYPE_STATE, ClutterStateClass))
typedef struct _ClutterState ClutterState;
typedef struct _ClutterStatePrivate ClutterStatePrivate;
typedef struct _ClutterStateClass ClutterStateClass;
/**
* ClutterStateKey:
*
* <structname>ClutterStateKey</structname> is an opaque structure whose
* members cannot be accessed directly
*
* Since: 1.4
*/
typedef struct _ClutterStateKey ClutterStateKey;
/**
* ClutterState:
*
* The <structname>ClutterState</structname> structure contains only
* private data and should be accessed using the provided API
*
* Since: 1.4
*/
struct _ClutterState
{
/*< private >*/
GObject parent;
ClutterStatePrivate *priv;
};
/**
* ClutterStateClass:
* @completed: class handler for the #ClutterState::completed signal
*
* The <structname>ClutterStateClass</structname> structure contains
* only private data
*
* Since: 1.4
*/
struct _ClutterStateClass
{
/*< private >*/
GObjectClass parent_class;
/*< public >*/
void (* completed) (ClutterState *state);
/*< private >*/
/* padding for future expansion */
gpointer _padding_dummy[8];
};
GType clutter_state_get_type (void) G_GNUC_CONST;
ClutterState *clutter_state_new (void);
ClutterTimeline * clutter_state_change (ClutterState *state,
const gchar *target_transition_name,
gboolean animate);
ClutterState * clutter_state_set_key (ClutterState *state,
const gchar *source_transition_name,
const gchar *target_transition_name,
GObject *object,
const gchar *property_name,
guint mode,
const GValue *value,
gdouble pre_delay,
gdouble post_delay);
void clutter_state_set_duration (ClutterState *state,
const gchar *source_transition_name,
const gchar *target_transition_name,
guint duration);
guint clutter_state_get_duration (ClutterState *state,
const gchar *source_transition_name,
const gchar *target_transition_name);
void clutter_state_set (ClutterState *state,
const gchar *source_transition_name,
const gchar *target_transition_name,
gpointer first_object,
const gchar *first_property_name,
gulong first_mode,
...);
GList * clutter_state_get_states (ClutterState *state);
GList * clutter_state_get_keys (ClutterState *state,
const gchar *source_transition_name,
const gchar *target_transition_name,
GObject *object,
const gchar *property_name);
void clutter_state_remove_key (ClutterState *state,
const gchar *source_transition_name,
const gchar *target_transition_name,
GObject *object,
const gchar *property_name);
ClutterTimeline * clutter_state_get_timeline (ClutterState *state);
void clutter_state_set_animator (ClutterState *state,
const gchar *source_transition_name,
const gchar *target_transition_name,
ClutterAnimator *animator);
ClutterAnimator * clutter_state_get_animator (ClutterState *state,
const gchar *source_transition_name,
const gchar *target_transition_name);
G_CONST_RETURN gchar *clutter_state_get_target_state (ClutterState *state);
/*
* ClutterStateKey
*/
GType clutter_state_key_get_type (void) G_GNUC_CONST;
gdouble clutter_state_key_get_pre_delay (const ClutterStateKey *state_key);
gdouble clutter_state_key_get_post_delay (const ClutterStateKey *state_key);
gulong clutter_state_key_get_mode (const ClutterStateKey *state_key);
void clutter_state_key_get_value (const ClutterStateKey *state_key,
GValue *value);
GObject * clutter_state_key_get_object (const ClutterStateKey *state_key);
G_CONST_RETURN gchar *clutter_state_key_get_property_name (const ClutterStateKey *state_key);
G_CONST_RETURN gchar *clutter_state_key_get_source_state_name (const ClutterStateKey *state_key);
G_CONST_RETURN gchar *clutter_state_key_get_target_state_name (const ClutterStateKey *state_key);
G_END_DECLS
#endif /* __CLUTTER_STATE_H__ */

View File

@ -84,6 +84,7 @@
#include "clutter-stage.h"
#include "clutter-stage-manager.h"
#include "clutter-stage-window.h"
#include "clutter-state.h"
#include "clutter-texture.h"
#include "clutter-text.h"
#include "clutter-timeline.h"

View File

@ -51,6 +51,7 @@ test_conformance_SOURCES = \
test-actor-destroy.c \
test-behaviours.c \
test-animator.c \
test-state.c \
$(NULL)
# For convenience, this provides a way to easily run individual unit tests:

View File

@ -184,6 +184,7 @@ main (int argc, char **argv)
TEST_CONFORM_SIMPLE ("/script", test_animator_base);
TEST_CONFORM_SIMPLE ("/script", test_animator_properties);
TEST_CONFORM_SIMPLE ("/script", test_animator_multi_properties);
TEST_CONFORM_SIMPLE ("/script", test_state_base);
TEST_CONFORM_SIMPLE ("/behaviours", test_behaviours);

View File

@ -0,0 +1,59 @@
#include <clutter/clutter.h>
#include "test-conform-common.h"
void
test_state_base (TestConformSimpleFixture *fixture G_GNUC_UNUSED,
gconstpointer dummy G_GNUC_UNUSED)
{
ClutterScript *script = clutter_script_new ();
GObject *state = NULL;
GError *error = NULL;
gchar *test_file;
GList *states, *keys;
ClutterStateKey *state_key;
guint duration;
test_file = clutter_test_get_data_file ("test-state-1.json");
clutter_script_load_from_file (script, test_file, &error);
if (g_test_verbose () && error)
g_print ("Error: %s\n", error->message);
g_free (test_file);
#if GLIB_CHECK_VERSION (2, 20, 0)
g_assert_no_error (error);
#else
g_assert (error == NULL);
#endif
state = clutter_script_get_object (script, "state");
g_assert (CLUTTER_IS_STATE (state));
states = clutter_state_get_states (CLUTTER_STATE (state));
g_assert (states != NULL);
g_assert (g_list_find (states, g_intern_static_string ("clicked")));
g_list_free (states);
duration = clutter_state_get_duration (CLUTTER_STATE (state), "base", "clicked");
g_assert_cmpint (duration, ==, 250);
duration = clutter_state_get_duration (CLUTTER_STATE (state), "clicked", "base");
g_assert_cmpint (duration, ==, 150);
keys = clutter_state_get_keys (CLUTTER_STATE (state), "base", "clicked",
clutter_script_get_object (script, "rect"),
"opacity");
g_assert (keys != NULL);
g_assert_cmpint (g_list_length (keys), ==, 1);
state_key = keys->data;
g_assert (clutter_state_key_get_object (state_key) == clutter_script_get_object (script, "rect"));
g_assert (clutter_state_key_get_mode (state_key) == CLUTTER_LINEAR);
g_assert_cmpstr (clutter_state_key_get_property_name (state_key), ==, "opacity");
g_list_free (keys);
g_object_unref (script);
}

View File

@ -12,6 +12,7 @@ json_files = \
test-animator-1.json \
test-animator-2.json \
test-animator-3.json \
test-state-1.json \
$(NULL)
png_files = \

View File

@ -0,0 +1,33 @@
[
{
"type" : "ClutterRectangle",
"id" : "rect",
"width" : 100,
"height" : 100
},
{
"type" : "ClutterState",
"id" : "state",
"transitions" : [
{
"source" : "base",
"target" : "clicked",
"duration" : 250,
"keys" : [
[ "rect", "opacity", "linear", 128 ]
]
},
{
"source" : "clicked",
"target" : "base",
"duration" : 150,
"keys" : [
[ "rect", "opacity", "linear", 255 ]
]
}
]
}
]

View File

@ -20,6 +20,8 @@ UNIT_TESTS = \
test-fullscreen.c \
test-shader.c \
test-animator.c \
test-state.c \
test-state-animator.c \
test-unproject.c \
test-viewport.c \
test-fbo.c \

View File

@ -0,0 +1,134 @@
#include <stdlib.h>
#include <math.h>
#include <gmodule.h>
#include <clutter/clutter.h>
static ClutterState *state;
static ClutterAnimator *animator;
static gboolean press_event (ClutterActor *actor,
ClutterEvent *event,
gpointer user_data)
{
clutter_grab_pointer (actor);
clutter_state_change (state, "end", TRUE);
return TRUE;
}
static gboolean release_event (ClutterActor *actor,
ClutterEvent *event,
gpointer user_data)
{
clutter_state_change (state, "start", TRUE);
clutter_ungrab_pointer ();
return TRUE;
}
static ClutterActor *new_rect (gint r,
gint g,
gint b,
gint a)
{
GError *error = NULL;
ClutterColor *color = clutter_color_new (r, g, b, a);
ClutterActor *rectangle = clutter_rectangle_new_with_color (color);
gchar *file = g_build_filename (TESTS_DATADIR, "redhand.png", NULL);
rectangle = clutter_texture_new_from_file (file, &error);
if (rectangle == NULL)
g_error ("image load failed: %s", error->message);
g_free (file);
clutter_actor_set_size (rectangle, 128, 128);
clutter_color_free (color);
return rectangle;
}
G_MODULE_EXPORT gint
test_state_animator_main (gint argc,
gchar **argv)
{
ClutterActor *stage;
ClutterActor *rects[40];
gint i;
clutter_init (&argc, &argv);
stage = clutter_stage_get_default ();
for (i=0; i<2; i++)
{
rects[i]=new_rect (255 *(i * 1.0/40), 50, 160, 255);
clutter_container_add_actor (CLUTTER_CONTAINER (stage), rects[i]);
clutter_actor_set_anchor_point (rects[i], 64, 64);
clutter_actor_set_position (rects[i], 320.0, 240.0);
clutter_actor_set_opacity (rects[i], 0x70);
clutter_actor_set_reactive (rects[i], TRUE);
g_signal_connect (rects[i], "button-press-event", G_CALLBACK (press_event), NULL);
g_signal_connect (rects[i], "button-release-event", G_CALLBACK (release_event), NULL);
}
state = clutter_state_new ();
clutter_state_set (state, NULL, "start",
rects[0], "depth", CLUTTER_LINEAR, 0.0,
rects[0], "x", CLUTTER_LINEAR, 100.0,
rects[0], "y", CLUTTER_LINEAR, 300.0,
rects[1], "opacity", CLUTTER_LINEAR, 0x20,
rects[1], "scale-x", CLUTTER_LINEAR, 1.0,
rects[1], "scale-y", CLUTTER_LINEAR, 1.0,
NULL);
clutter_state_set (state, NULL, "end",
rects[0], "depth", CLUTTER_LINEAR, 200.0,
rects[0], "x", CLUTTER_LINEAR, 320.0,
rects[0], "y", CLUTTER_LINEAR, 240.0,
rects[1], "opacity", CLUTTER_LINEAR, 0xff,
rects[1], "scale-x", CLUTTER_LINEAR, 2.0,
rects[1], "scale-y", CLUTTER_LINEAR, 2.0,
NULL);
animator = clutter_animator_new ();
clutter_animator_set (animator,
rects[0], "depth", -1, 0.0, 0.0,
rects[0], "depth", CLUTTER_LINEAR, 1.0, 275.0,
rects[0], "x", -1, 0.0, 0.0,
rects[0], "x", CLUTTER_LINEAR, 0.5, 200.0,
rects[0], "x", CLUTTER_LINEAR, 1.0, 320.0,
rects[0], "y", -1, 0.0, 0.0,
rects[0], "y", CLUTTER_LINEAR, 0.3, 100.0,
rects[0], "y", CLUTTER_LINEAR, 1.0, 240.0,
rects[1], "opacity", -1, 0.0, 0x20,
rects[1], "opacity", CLUTTER_LINEAR, 1.0, 0xff,
rects[1], "scale-x", -1, 0.0, 1.0,
rects[1], "scale-x", CLUTTER_LINEAR, 0.5, 2.0,
rects[1], "scale-x", CLUTTER_LINEAR, 1.0, 2.0,
rects[1], "scale-y", -1, 0.0, 1.0,
rects[1], "scale-y", CLUTTER_LINEAR, 0.5, 2.0,
rects[1], "scale-y", CLUTTER_LINEAR, 1.0, 2.0,
NULL);
clutter_animator_property_set_ease_in (animator, G_OBJECT (rects[0]), "depth", TRUE);
clutter_animator_property_set_ease_in (animator, G_OBJECT (rects[0]), "x", TRUE);
clutter_animator_property_set_ease_in (animator, G_OBJECT (rects[0]), "y", TRUE);
clutter_animator_property_set_ease_in (animator, G_OBJECT (rects[1]), "opacity", TRUE);
clutter_animator_property_set_ease_in (animator, G_OBJECT (rects[1]), "scale-x", TRUE);
clutter_animator_property_set_ease_in (animator, G_OBJECT (rects[1]), "scale-y", TRUE);
clutter_animator_property_set_interpolation (animator, G_OBJECT (rects[0]), "x",
CLUTTER_INTERPOLATION_CUBIC);
clutter_animator_property_set_interpolation (animator, G_OBJECT (rects[0]), "y",
CLUTTER_INTERPOLATION_CUBIC);
clutter_state_set_animator (state, "start", "end", animator);
g_object_unref (animator);
clutter_actor_show (stage);
clutter_state_change (state, "start", TRUE);
clutter_main ();
g_object_unref (state);
return EXIT_SUCCESS;
}

View File

@ -0,0 +1,104 @@
#include <stdlib.h>
#include <math.h>
#include <gmodule.h>
#include <clutter/clutter.h>
static ClutterState *state;
static gboolean press_event (ClutterActor *actor,
ClutterEvent *event,
gpointer user_data)
{
clutter_grab_pointer (actor);
clutter_state_change (state, "end", TRUE);
return TRUE;
}
static gboolean release_event (ClutterActor *actor,
ClutterEvent *event,
gpointer user_data)
{
clutter_state_change (state, "start", TRUE);
clutter_ungrab_pointer ();
return TRUE;
}
static void completed (ClutterState *sstate,
gpointer data)
{
g_print ("Completed transitioning to state: %s\n",
clutter_state_get_target_state (sstate));
}
static ClutterActor *new_rect (gint r,
gint g,
gint b,
gint a)
{
GError *error = NULL;
ClutterColor *color = clutter_color_new (r, g, b, a);
ClutterActor *rectangle = clutter_rectangle_new_with_color (color);
gchar *file = g_build_filename (TESTS_DATADIR, "redhand.png", NULL);
rectangle = clutter_texture_new_from_file (file, &error);
if (rectangle == NULL)
g_error ("image load failed: %s", error->message);
g_free (file);
clutter_actor_set_size (rectangle, 128, 128);
clutter_color_free (color);
return rectangle;
}
G_MODULE_EXPORT gint
test_state_main (gint argc,
gchar **argv)
{
ClutterActor *stage;
ClutterActor *rects[40];
gint i;
clutter_init (&argc, &argv);
stage = clutter_stage_get_default ();
for (i=0; i<2; i++)
{
rects[i]=new_rect (255 *(i * 1.0/40), 50, 160, 255);
clutter_container_add_actor (CLUTTER_CONTAINER (stage), rects[i]);
clutter_actor_set_anchor_point (rects[i], 64, 64);
clutter_actor_set_position (rects[i], 320.0, 240.0);
clutter_actor_set_opacity (rects[i], 0x70);
clutter_actor_set_reactive (rects[i], TRUE);
g_signal_connect (rects[i], "button-press-event", G_CALLBACK (press_event), NULL);
g_signal_connect (rects[i], "button-release-event", G_CALLBACK (release_event), NULL);
}
state = clutter_state_new ();
clutter_state_set (state, NULL, "start",
rects[0], "depth", CLUTTER_LINEAR, 0.0,
rects[0], "x", CLUTTER_LINEAR, 100.0,
rects[0], "y", CLUTTER_LINEAR, 300.0,
rects[1], "opacity", CLUTTER_LINEAR, 0x20,
rects[1], "scale-x", CLUTTER_LINEAR, 1.0,
rects[1], "scale-y", CLUTTER_LINEAR, 1.0,
NULL);
clutter_state_set (state, NULL, "end",
rects[0], "depth", CLUTTER_LINEAR, 200.0,
rects[0], "x", CLUTTER_LINEAR, 320.0,
rects[0], "y", CLUTTER_LINEAR, 240.0,
rects[1], "opacity", CLUTTER_LINEAR, 0xff,
rects[1], "scale-x", CLUTTER_LINEAR, 2.0,
rects[1], "scale-y", CLUTTER_LINEAR, 2.0,
NULL);
clutter_state_set_duration (state, "start", "end", 5000);
g_signal_connect (state, "completed", G_CALLBACK (completed), NULL);
clutter_actor_show (stage);
clutter_state_change (state, "start", TRUE);
clutter_main ();
g_object_unref (state);
return EXIT_SUCCESS;
}