mirror of
https://github.com/brl/mutter.git
synced 2024-12-22 11:02:05 +00:00
bezier spline behaviours
This commit is contained in:
parent
0085b75610
commit
43593ab81f
23
ChangeLog
23
ChangeLog
@ -1,3 +1,26 @@
|
||||
2007-04-12 Tomas Frydrych <tf@openedhand.com>
|
||||
|
||||
* clutter/clutter-behaviour.h:
|
||||
* clutter/clutter-behaviour.c:
|
||||
* clutter/clutter-behaviour-path.h:
|
||||
* clutter/clutter-behaviour-path.c:
|
||||
Moved declaration of ClutterKnot from clutter-behaviour path
|
||||
into clutter-behaviour.
|
||||
|
||||
* clutter/clutter-fixed.h
|
||||
* clutter/clutter-fixed.c
|
||||
Added myself as an author.
|
||||
|
||||
* clutter/Makefile.am:
|
||||
* clutter/clutter.h:
|
||||
* clutter/clutter-behaviour-bspline.h:
|
||||
* clutter/clutter-behaviour-bspline.c:
|
||||
Added new bezier spline behaviour.
|
||||
|
||||
* examples/bspline.c:
|
||||
* examples/Makefile.am:
|
||||
An example of using bspline path.
|
||||
|
||||
2007-03-29 Tomas Frydrych <tf@openedhand.com>
|
||||
|
||||
* clutter/clutter-stage.c:
|
||||
|
@ -40,6 +40,7 @@ source_h = \
|
||||
$(srcdir)/clutter-behaviour.h \
|
||||
$(srcdir)/clutter-behaviour-opacity.h \
|
||||
$(srcdir)/clutter-behaviour-path.h \
|
||||
$(srcdir)/clutter-behaviour-bspline.h \
|
||||
$(srcdir)/clutter-behaviour-scale.h \
|
||||
$(srcdir)/clutter-clone-texture.h \
|
||||
$(srcdir)/clutter-color.h \
|
||||
@ -123,6 +124,7 @@ source_c = \
|
||||
clutter-behaviour.c \
|
||||
clutter-behaviour-opacity.c \
|
||||
clutter-behaviour-path.c \
|
||||
clutter-behaviour-bspline.c \
|
||||
clutter-behaviour-scale.c \
|
||||
clutter-color.c \
|
||||
clutter-clone-texture.c \
|
||||
|
1098
clutter/clutter-behaviour-bspline.c
Normal file
1098
clutter/clutter-behaviour-bspline.c
Normal file
File diff suppressed because it is too large
Load Diff
116
clutter/clutter-behaviour-bspline.h
Normal file
116
clutter/clutter-behaviour-bspline.h
Normal file
@ -0,0 +1,116 @@
|
||||
/*
|
||||
* Clutter.
|
||||
*
|
||||
* An OpenGL based 'interactive canvas' library.
|
||||
*
|
||||
* Authored By Tomas Frydrych <tf@openedhand.com>
|
||||
*
|
||||
* Copyright (C) 2006, 2007 OpenedHand
|
||||
*
|
||||
* 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, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef __CLUTTER_BEHAVIOUR_BSPLINE_H__
|
||||
#define __CLUTTER_BEHAVIOUR_BSPLINE_H__
|
||||
|
||||
#include <clutter/clutter-alpha.h>
|
||||
#include <clutter/clutter-actor.h>
|
||||
#include <clutter/clutter-behaviour.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define CLUTTER_TYPE_BEHAVIOUR_BSPLINE (clutter_behaviour_bspline_get_type ())
|
||||
|
||||
#define CLUTTER_BEHAVIOUR_BSPLINE(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST ((obj), \
|
||||
CLUTTER_TYPE_BEHAVIOUR_BSPLINE, ClutterBehaviourBspline))
|
||||
|
||||
#define CLUTTER_BEHAVIOUR_BSPLINE_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_CAST ((klass), \
|
||||
CLUTTER_TYPE_BEHAVIOUR_BSPLINE, ClutterBehaviourBsplineClass))
|
||||
|
||||
#define CLUTTER_IS_BEHAVIOUR_BSPLINE(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
|
||||
CLUTTER_TYPE_BEHAVIOUR_BSPLINE))
|
||||
|
||||
#define CLUTTER_IS_BEHAVIOUR_BSPLINE_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_TYPE ((klass), \
|
||||
CLUTTER_TYPE_BEHAVIOUR_BSPLINE))
|
||||
|
||||
#define CLUTTER_BEHAVIOUR_BSPLINE_GET_CLASS(obj) \
|
||||
(G_TYPE_INSTANCE_GET_CLASS ((obj), \
|
||||
CLUTTER_TYPE_BEHAVIOUR_BSPLINE, ClutterBehaviourBsplineClass))
|
||||
|
||||
typedef struct _ClutterBehaviourBspline ClutterBehaviourBspline;
|
||||
typedef struct _ClutterBehaviourBsplinePrivate ClutterBehaviourBsplinePrivate;
|
||||
typedef struct _ClutterBehaviourBsplineClass ClutterBehaviourBsplineClass;
|
||||
|
||||
struct _ClutterBehaviourBspline
|
||||
{
|
||||
ClutterBehaviour parent;
|
||||
ClutterBehaviourBsplinePrivate *priv;
|
||||
};
|
||||
|
||||
struct _ClutterBehaviourBsplineClass
|
||||
{
|
||||
ClutterBehaviourClass parent_class;
|
||||
|
||||
void (*knot_reached) (ClutterBehaviourBspline * bsplineb,
|
||||
const ClutterKnot * knot);
|
||||
|
||||
void (*_clutter_bspline_1) (void);
|
||||
void (*_clutter_bspline_2) (void);
|
||||
void (*_clutter_bspline_3) (void);
|
||||
void (*_clutter_bspline_4) (void);
|
||||
};
|
||||
|
||||
GType clutter_behaviour_bspline_get_type (void) G_GNUC_CONST;
|
||||
|
||||
ClutterBehaviour * clutter_behaviour_bspline_new (ClutterAlpha * alpha,
|
||||
const ClutterKnot * points,
|
||||
guint n_points);
|
||||
|
||||
void clutter_behaviour_bspline_append_knot (ClutterBehaviourBspline * bs,
|
||||
const ClutterKnot * knot);
|
||||
|
||||
void clutter_behaviour_bspline_append (ClutterBehaviourBspline * bs,
|
||||
const ClutterKnot * first_knot,
|
||||
...) G_GNUC_NULL_TERMINATED;
|
||||
|
||||
void clutter_behaviour_bspline_truncate (ClutterBehaviourBspline *bs,
|
||||
guint offset);
|
||||
|
||||
void clutter_behaviour_bspline_join (ClutterBehaviourBspline * bs1,
|
||||
ClutterBehaviourBspline * bs2);
|
||||
|
||||
ClutterBehaviourBspline * clutter_behaviour_bspline_split (ClutterBehaviourBspline * bs,
|
||||
guint offset);
|
||||
|
||||
void clutter_behaviour_bspline_clear (ClutterBehaviourBspline * bs);
|
||||
|
||||
void clutter_behaviour_bspline_adjust (ClutterBehaviourBspline * bs,
|
||||
guint offset,
|
||||
ClutterKnot * knot);
|
||||
|
||||
void clutter_behaviour_bspline_set_origin (ClutterBehaviourBspline * bs,
|
||||
ClutterKnot * knot);
|
||||
|
||||
void clutter_behaviour_bspline_get_origin (ClutterBehaviourBspline * bs,
|
||||
ClutterKnot * knot);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __CLUTTER_BEHAVIOUR_BSPLINE_H__ */
|
@ -55,86 +55,6 @@
|
||||
|
||||
#include <math.h>
|
||||
|
||||
/**
|
||||
* clutter_knot_copy:
|
||||
* @knot: a #ClutterKnot
|
||||
*
|
||||
* Makes an allocated copy of a knot.
|
||||
*
|
||||
* Return value: the copied knot.
|
||||
*
|
||||
* Since: 0.2
|
||||
*/
|
||||
ClutterKnot *
|
||||
clutter_knot_copy (const ClutterKnot *knot)
|
||||
{
|
||||
ClutterKnot *copy;
|
||||
|
||||
copy = g_slice_new0 (ClutterKnot);
|
||||
|
||||
*copy = *knot;
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
/**
|
||||
* clutter_knot_free:
|
||||
* @knot: a #ClutterKnot
|
||||
*
|
||||
* Frees the memory of an allocated knot.
|
||||
*
|
||||
* Since: 0.2
|
||||
*/
|
||||
void
|
||||
clutter_knot_free (ClutterKnot *knot)
|
||||
{
|
||||
if (G_LIKELY (knot))
|
||||
{
|
||||
g_slice_free (ClutterKnot, knot);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* clutter_knot_equal:
|
||||
* @knot_a: First knot
|
||||
* @knot_b: Second knot
|
||||
*
|
||||
* Compares to knot and checks if the point to the same location.
|
||||
*
|
||||
* Return value: %TRUE if the knots point to the same location.
|
||||
*
|
||||
* Since: 0.2
|
||||
*/
|
||||
gboolean
|
||||
clutter_knot_equal (const ClutterKnot *knot_a,
|
||||
const ClutterKnot *knot_b)
|
||||
{
|
||||
g_return_val_if_fail (knot_a != NULL, FALSE);
|
||||
g_return_val_if_fail (knot_b != NULL, FALSE);
|
||||
|
||||
if (knot_a == knot_b)
|
||||
return TRUE;
|
||||
|
||||
return knot_a->x == knot_b->x && knot_a->y == knot_b->y;
|
||||
}
|
||||
|
||||
GType
|
||||
clutter_knot_get_type (void)
|
||||
{
|
||||
static GType our_type = 0;
|
||||
|
||||
if (G_UNLIKELY (!our_type))
|
||||
{
|
||||
our_type =
|
||||
g_boxed_type_register_static ("ClutterKnot",
|
||||
(GBoxedCopyFunc) clutter_knot_copy,
|
||||
(GBoxedFreeFunc) clutter_knot_free);
|
||||
}
|
||||
|
||||
return our_type;
|
||||
}
|
||||
|
||||
|
||||
G_DEFINE_TYPE (ClutterBehaviourPath,
|
||||
clutter_behaviour_path,
|
||||
CLUTTER_TYPE_BEHAVIOUR);
|
||||
|
@ -33,22 +33,6 @@
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define CLUTTER_TYPE_KNOT (clutter_knot_get_type ())
|
||||
|
||||
typedef struct _ClutterKnot ClutterKnot;
|
||||
|
||||
struct _ClutterKnot
|
||||
{
|
||||
gint x,y;
|
||||
/* FIXME: optionally include bezier control points also ? */
|
||||
};
|
||||
|
||||
GType clutter_knot_get_type (void) G_GNUC_CONST;
|
||||
ClutterKnot *clutter_knot_copy (const ClutterKnot *knot);
|
||||
void clutter_knot_free (ClutterKnot *knot);
|
||||
gboolean clutter_knot_equal (const ClutterKnot *knot_a,
|
||||
const ClutterKnot *knot_b);
|
||||
|
||||
#define CLUTTER_TYPE_BEHAVIOUR_PATH (clutter_behaviour_path_get_type ())
|
||||
|
||||
#define CLUTTER_BEHAVIOUR_PATH(obj) \
|
||||
|
@ -59,6 +59,85 @@
|
||||
#include "clutter-debug.h"
|
||||
#include "clutter-private.h"
|
||||
|
||||
/**
|
||||
* clutter_knot_copy:
|
||||
* @knot: a #ClutterKnot
|
||||
*
|
||||
* Makes an allocated copy of a knot.
|
||||
*
|
||||
* Return value: the copied knot.
|
||||
*
|
||||
* Since: 0.2
|
||||
*/
|
||||
ClutterKnot *
|
||||
clutter_knot_copy (const ClutterKnot *knot)
|
||||
{
|
||||
ClutterKnot *copy;
|
||||
|
||||
copy = g_slice_new0 (ClutterKnot);
|
||||
|
||||
*copy = *knot;
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
/**
|
||||
* clutter_knot_free:
|
||||
* @knot: a #ClutterKnot
|
||||
*
|
||||
* Frees the memory of an allocated knot.
|
||||
*
|
||||
* Since: 0.2
|
||||
*/
|
||||
void
|
||||
clutter_knot_free (ClutterKnot *knot)
|
||||
{
|
||||
if (G_LIKELY (knot))
|
||||
{
|
||||
g_slice_free (ClutterKnot, knot);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* clutter_knot_equal:
|
||||
* @knot_a: First knot
|
||||
* @knot_b: Second knot
|
||||
*
|
||||
* Compares to knot and checks if the point to the same location.
|
||||
*
|
||||
* Return value: %TRUE if the knots point to the same location.
|
||||
*
|
||||
* Since: 0.2
|
||||
*/
|
||||
gboolean
|
||||
clutter_knot_equal (const ClutterKnot *knot_a,
|
||||
const ClutterKnot *knot_b)
|
||||
{
|
||||
g_return_val_if_fail (knot_a != NULL, FALSE);
|
||||
g_return_val_if_fail (knot_b != NULL, FALSE);
|
||||
|
||||
if (knot_a == knot_b)
|
||||
return TRUE;
|
||||
|
||||
return knot_a->x == knot_b->x && knot_a->y == knot_b->y;
|
||||
}
|
||||
|
||||
GType
|
||||
clutter_knot_get_type (void)
|
||||
{
|
||||
static GType our_type = 0;
|
||||
|
||||
if (G_UNLIKELY (!our_type))
|
||||
{
|
||||
our_type =
|
||||
g_boxed_type_register_static ("ClutterKnot",
|
||||
(GBoxedCopyFunc) clutter_knot_copy,
|
||||
(GBoxedFreeFunc) clutter_knot_free);
|
||||
}
|
||||
|
||||
return our_type;
|
||||
}
|
||||
|
||||
G_DEFINE_ABSTRACT_TYPE (ClutterBehaviour,
|
||||
clutter_behaviour,
|
||||
G_TYPE_OBJECT);
|
||||
|
@ -33,6 +33,21 @@
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define CLUTTER_TYPE_KNOT (clutter_knot_get_type ())
|
||||
|
||||
typedef struct _ClutterKnot ClutterKnot;
|
||||
|
||||
struct _ClutterKnot
|
||||
{
|
||||
gint x,y;
|
||||
};
|
||||
|
||||
GType clutter_knot_get_type (void) G_GNUC_CONST;
|
||||
ClutterKnot *clutter_knot_copy (const ClutterKnot *knot);
|
||||
void clutter_knot_free (ClutterKnot *knot);
|
||||
gboolean clutter_knot_equal (const ClutterKnot *knot_a,
|
||||
const ClutterKnot *knot_b);
|
||||
|
||||
#define CLUTTER_TYPE_BEHAVIOUR clutter_behaviour_get_type()
|
||||
|
||||
#define CLUTTER_BEHAVIOUR(obj) \
|
||||
|
@ -3,9 +3,9 @@
|
||||
*
|
||||
* An OpenGL based 'interactive canvas' library.
|
||||
*
|
||||
* Authored By Matthew Allum <mallum@openedhand.com>
|
||||
* Authored By Tomas Frydrych <tf@openedhand.com>
|
||||
*
|
||||
* Copyright (C) 2006 OpenedHand
|
||||
* Copyright (C) 2006, 2007 OpenedHand
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
|
@ -4,6 +4,7 @@
|
||||
* An OpenGL based 'interactive canvas' library.
|
||||
*
|
||||
* Authored By Matthew Allum <mallum@openedhand.com>
|
||||
* Tomas Frydrych <tf@openedhand.com>
|
||||
*
|
||||
* Copyright (C) 2006 OpenedHand
|
||||
*
|
||||
|
@ -35,6 +35,7 @@
|
||||
#include "clutter-behaviour.h"
|
||||
#include "clutter-behaviour-opacity.h"
|
||||
#include "clutter-behaviour-path.h"
|
||||
#include "clutter-behaviour-bspline.h"
|
||||
#include "clutter-behaviour-scale.h"
|
||||
#include "clutter-stage.h"
|
||||
#include "clutter-actor.h"
|
||||
|
@ -1,4 +1,4 @@
|
||||
noinst_PROGRAMS = test super-oh behave
|
||||
noinst_PROGRAMS = test super-oh behave test-text bspline
|
||||
|
||||
INCLUDES = -I$(top_srcdir)/
|
||||
LDADD = $(top_builddir)/clutter/libclutter-@CLUTTER_FLAVOUR@-@CLUTTER_MAJORMINOR@.la
|
||||
@ -21,6 +21,17 @@ behave_LDFLAGS = \
|
||||
$(CLUTTER_LIBS) \
|
||||
$(GCONF_LIBS)
|
||||
|
||||
test_text_SOURCES = test-text.c
|
||||
test_text_CFLAGS = $(CLUTTER_CFLAGS) $(GCONF_CFLAGS)
|
||||
test_text_LDFLAGS = \
|
||||
$(CLUTTER_LIBS) \
|
||||
$(GCONF_LIBS)
|
||||
|
||||
bspline_SOURCES = bspline.c
|
||||
bspline_CFLAGS = $(CLUTTER_CFLAGS) $(GCONF_CFLAGS)
|
||||
bspline_LDFLAGS = \
|
||||
$(CLUTTER_LIBS) \
|
||||
$(GCONF_LIBS)
|
||||
|
||||
EXTRA_DIST = redhand.png \
|
||||
clutter-logo-800x600.png \
|
||||
|
97
examples/bspline.c
Normal file
97
examples/bspline.c
Normal file
@ -0,0 +1,97 @@
|
||||
#include <clutter/clutter.h>
|
||||
|
||||
#define MAGIC 0.551784
|
||||
#define RADIUS 200
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
ClutterTimeline *timeline;
|
||||
ClutterAlpha *alpha;
|
||||
ClutterBehaviour *p_behave;
|
||||
ClutterActor *stage;
|
||||
ClutterActor *hand;
|
||||
ClutterColor stage_color = { 0xcc, 0xcc, 0xcc, 0xff };
|
||||
GdkPixbuf *pixbuf;
|
||||
guint i;
|
||||
|
||||
#if 1
|
||||
/* Circular path defined using a spline consisting of 4 bezier curves */
|
||||
ClutterKnot knots[] = {{ -RADIUS, 0 },
|
||||
{ -RADIUS, RADIUS*MAGIC },
|
||||
{ -RADIUS*MAGIC, RADIUS },
|
||||
{ 0, RADIUS },
|
||||
{ RADIUS*MAGIC, RADIUS },
|
||||
{ RADIUS, RADIUS*MAGIC },
|
||||
{ RADIUS, 0 },
|
||||
{ RADIUS, -RADIUS*MAGIC },
|
||||
{ RADIUS*MAGIC, -RADIUS },
|
||||
{ 0, -RADIUS },
|
||||
{ -RADIUS*MAGIC, -RADIUS },
|
||||
{ -RADIUS, -RADIUS*MAGIC },
|
||||
{ -RADIUS, 0}};
|
||||
|
||||
ClutterKnot origin = { 0, RADIUS };
|
||||
#else
|
||||
/* Approximation of a sine wave over <0,pi> */
|
||||
ClutterKnot knots[] = {{ 0, 0 },
|
||||
{ 2*RADIUS/3, 2*RADIUS*1.299 },
|
||||
{ 4*RADIUS/3, 2*RADIUS*1.299 },
|
||||
{ 2*RADIUS, 0 }};
|
||||
|
||||
ClutterKnot origin = { 0, 0};
|
||||
#endif
|
||||
|
||||
clutter_init (&argc, &argv);
|
||||
|
||||
stage = clutter_stage_get_default ();
|
||||
clutter_stage_hide_cursor (CLUTTER_STAGE (stage));
|
||||
|
||||
g_signal_connect (stage, "key-press-event",
|
||||
G_CALLBACK (clutter_main_quit),
|
||||
NULL);
|
||||
|
||||
pixbuf = gdk_pixbuf_new_from_file ("redhand.png", NULL);
|
||||
|
||||
if (!pixbuf)
|
||||
g_error("pixbuf load failed");
|
||||
|
||||
clutter_stage_set_color (CLUTTER_STAGE (stage),
|
||||
&stage_color);
|
||||
|
||||
/* Make a hand */
|
||||
hand = clutter_texture_new_from_pixbuf (pixbuf);
|
||||
clutter_actor_set_position (hand, 0, RADIUS);
|
||||
clutter_actor_show (hand);
|
||||
clutter_group_add (CLUTTER_GROUP (stage), hand);
|
||||
|
||||
/* Make a timeline */
|
||||
timeline = clutter_timeline_new (100, 26); /* num frames, fps */
|
||||
g_object_set (timeline, "loop", TRUE, 0);
|
||||
|
||||
/* Set an alpha func to power behaviour - ramp_inc is constant rise */
|
||||
alpha = clutter_alpha_new_full (timeline,
|
||||
CLUTTER_ALPHA_RAMP_INC,
|
||||
NULL, NULL);
|
||||
|
||||
/* Make a path behaviour and apply that too */
|
||||
p_behave =
|
||||
clutter_behaviour_bspline_new (alpha, knots,
|
||||
sizeof (knots)/sizeof(ClutterKnot));
|
||||
|
||||
clutter_behaviour_bspline_set_origin (CLUTTER_BEHAVIOUR_BSPLINE (p_behave),
|
||||
&origin);
|
||||
|
||||
clutter_behaviour_apply (p_behave, hand);
|
||||
|
||||
/* start the timeline and thus the animations */
|
||||
clutter_timeline_start (timeline);
|
||||
|
||||
clutter_actor_show_all (stage);
|
||||
|
||||
clutter_main();
|
||||
|
||||
g_object_unref (p_behave);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user