mirror of
https://github.com/brl/mutter.git
synced 2024-11-26 10:00:45 -05:00
state machine: added state machine
This commit is contained in:
parent
5b2311aed7
commit
fcdc3a8989
@ -115,6 +115,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 \
|
||||
@ -191,6 +192,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 \
|
||||
|
1310
clutter/clutter-state.c
Normal file
1310
clutter/clutter-state.c
Normal file
File diff suppressed because it is too large
Load Diff
156
clutter/clutter-state.h
Normal file
156
clutter/clutter-state.h
Normal file
@ -0,0 +1,156 @@
|
||||
/*
|
||||
* 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.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;
|
||||
typedef struct _ClutterStateKey ClutterStateKey;
|
||||
|
||||
/**
|
||||
* ClutterState:
|
||||
*
|
||||
* The #ClutterState structure contains only private data and
|
||||
* should be accessed using the provided API
|
||||
*
|
||||
* Since: 1.4
|
||||
*/
|
||||
struct _ClutterState
|
||||
{
|
||||
/*< private >*/
|
||||
GObject parent;
|
||||
ClutterStatePrivate *priv;
|
||||
};
|
||||
|
||||
/**
|
||||
* ClutterStateClass:
|
||||
*
|
||||
* The #ClutterStateClass structure contains only private data
|
||||
*
|
||||
* Since: 1.4
|
||||
*/
|
||||
struct _ClutterStateClass
|
||||
{
|
||||
/*< private >*/
|
||||
GObjectClass parent_class;
|
||||
|
||||
/* padding for future expansion */
|
||||
gpointer _padding_dummy[16];
|
||||
};
|
||||
|
||||
GType clutter_state_get_type (void) G_GNUC_CONST;
|
||||
ClutterState *clutter_state_new (void);
|
||||
|
||||
|
||||
/* XXX: clutter_state_run?
|
||||
* the current (target?) transition should be a property of ClutterState
|
||||
*/
|
||||
ClutterTimeline * clutter_state_change (ClutterState *state,
|
||||
const gchar *target_transition_name);
|
||||
ClutterTimeline * clutter_state_change_noanim (ClutterState *state,
|
||||
const gchar *target_transition_name);
|
||||
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);
|
||||
|
||||
GType clutter_state_key_get_type (void) G_GNUC_CONST;
|
||||
gdouble clutter_state_key_get_pre_delay (ClutterStateKey *state_key);
|
||||
gdouble clutter_state_key_get_post_delay (ClutterStateKey *state_key);
|
||||
gulong clutter_state_key_get_mode (ClutterStateKey *state_key);
|
||||
void clutter_state_key_get_value (ClutterStateKey *state_key,
|
||||
GValue *value);
|
||||
GObject * clutter_state_key_get_object (ClutterStateKey *state_key);
|
||||
const gchar * clutter_state_key_get_property_name (ClutterStateKey *state_key);
|
||||
const gchar * clutter_state_key_get_source_state_name (ClutterStateKey *state_key);
|
||||
const gchar * clutter_state_key_get_target_state_name (ClutterStateKey *state_key);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __CLUTTER_STATE_H__ */
|
@ -78,6 +78,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"
|
||||
|
@ -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 \
|
||||
|
134
tests/interactive/test-state-animator.c
Normal file
134
tests/interactive/test-state-animator.c
Normal 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");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean release_event (ClutterActor *actor,
|
||||
ClutterEvent *event,
|
||||
gpointer user_data)
|
||||
{
|
||||
clutter_state_change (state, "start");
|
||||
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");
|
||||
|
||||
clutter_main ();
|
||||
g_object_unref (state);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
97
tests/interactive/test-state.c
Normal file
97
tests/interactive/test-state.c
Normal file
@ -0,0 +1,97 @@
|
||||
#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");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean release_event (ClutterActor *actor,
|
||||
ClutterEvent *event,
|
||||
gpointer user_data)
|
||||
{
|
||||
clutter_state_change (state, "start");
|
||||
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_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);
|
||||
|
||||
clutter_actor_show (stage);
|
||||
clutter_state_change (state, "start");
|
||||
|
||||
clutter_main ();
|
||||
g_object_unref (state);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
Loading…
Reference in New Issue
Block a user