+2006-08-15 Matthew Allum <mallum@openedhand.com>
+
+ * clutter/clutter-behaviour.c:
+ * clutter/clutter-behaviour.h:
+ * clutter/clutter-behaviours.c:
+ * clutter/clutter-timeline.c:
+ * clutter/clutter-timeline.h:
+ * clutter/clutter.h:
+ Make basic behaviour infrastructure actually work.
+
+ * examples/Makefile.am:
+ * examples/behave.c:
+ Add a simple behaviour demo/test
+
+ * clutter/clutter-media.c: (clutter_media_set_volume):
+ Actuall set volume rather than position.. (Fixes #141)
+
2006-08-14 Matthew Allum <mallum@openedhand.com>
* clutter/Makefile.am:
#include "config.h"
-#include "clutter-behaviour.h"
-#include "clutter-enum-types.h"
-#include "clutter-private.h" /* for DBG */
#include "clutter-timeline.h"
+#include "clutter-actor.h"
+#include "clutter-behaviour.h"
G_DEFINE_TYPE (ClutterBehaviour, clutter_behaviour, G_TYPE_OBJECT);
#include <glib-object.h>
-#include "clutter.h"
-
G_BEGIN_DECLS
#define CLUTTER_TYPE_BEHAVIOUR clutter_behaviour_get_type()
#include "config.h"
+#include "clutter-timeline.h"
+#include "clutter-actor.h"
+#include "clutter-behaviour.h"
#include "clutter-behaviours.h"
#include "clutter-enum-types.h"
-#include "clutter-private.h" /* for DBG */
-#include "clutter-timeline.h"
+#include "clutter-main.h"
G_DEFINE_TYPE (ClutterBehaviourPath, \
clutter_behaviour_path, \
self->priv = priv = CLUTTER_BEHAVIOUR_PATH_GET_PRIVATE (self);
}
+/*
+
+function line(x0, x1, y0, y1)
+ boolean steep := abs(y1 - y0) > abs(x1 - x0)
+ if steep then
+ swap(x0, y0)
+ swap(x1, y1)
+ if x0 > x1 then
+ swap(x0, x1)
+ swap(y0, y1)
+ int deltax := x1 - x0
+ int deltay := abs(y1 - y0)
+ int error := 0
+ int ystep
+ int y := y0
+ if y0 < y1 then ystep := 1 else ystep := -1
+ for x from x0 to x1
+ if steep then plot(y,x) else plot(x,y)
+ error := error + deltay
+ if 2
+
+ */
+
ClutterBehaviour*
clutter_behaviour_path_new (ClutterTimeline *timeline,
gint x1,
opacity += priv->opacity_start;
+ CLUTTER_DBG("alpha %i opacity %i\n", alpha, opacity);
+
clutter_actor_set_opacity (actor, opacity);
}
clutter_behaviour_actors_foreach
(CLUTTER_BEHAVIOUR(behave),
(GFunc)clutter_behaviour_opacity_frame_foreach,
- GINT_TO_POINTER(frame_num));
+ behave);
}
ClutterBehaviour*
{
g_return_if_fail (CLUTTER_IS_MEDIA(media));
- CLUTTER_MEDIA_GET_INTERFACE (media)->set_position (media, volume);
+ CLUTTER_MEDIA_GET_INTERFACE (media)->set_volume (media, volume);
}
/**
#include <pango/pangoft2.h>
+
G_BEGIN_DECLS
typedef struct _ClutterMainContext ClutterMainContext;
glEnable(GL_BLEND);
glEnable(texture->priv->target_type);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
opacity = clutter_actor_get_opacity(self);
/ timeline->priv->nframes;
}
+guint32
+clutter_timeline_alpha_ramp_dec_func (ClutterTimeline *timeline)
+{
+ return ((timeline->priv->nframes - timeline->priv->current_frame_num)
+ * CLUTTER_TIMELINE_MAX_ALPHA)
+ / timeline->priv->nframes;
+}
+
+guint32
+clutter_timeline_alpha_ramp_func (ClutterTimeline *timeline)
+{
+
+ if (timeline->priv->current_frame_num > (timeline->priv->nframes/2))
+ {
+ return (((timeline->priv->nframes) - timeline->priv->current_frame_num)
+ * CLUTTER_TIMELINE_MAX_ALPHA)
+ / (timeline->priv->nframes/2);
+ }
+ else
+ {
+ return (timeline->priv->current_frame_num * CLUTTER_TIMELINE_MAX_ALPHA)
+ / (timeline->priv->nframes/2);
+ }
+}
+
+
/* Object */
static void
self->priv = G_TYPE_INSTANCE_GET_PRIVATE(self,
CLUTTER_TYPE_TIMELINE,
ClutterTimelinePrivate);
+
+ self->priv->alpha_func = CLUTTER_ALPHA_RAMP_INC;
}
static gboolean
priv->last_frame_msecs = msecs;
- /* Advance frames */
- priv->current_frame_num += nframes;;
-
/* Update alpha value */
if (priv->alpha_func)
priv->alpha = priv->alpha_func(timeline);
+ /* Advance frames */
+ priv->current_frame_num += nframes;;
+
/* Handle loop or stop */
if (priv->current_frame_num > priv->nframes)
{
priv->current_frame_num = priv->nframes;
if (nframes > 1)
- g_signal_emit (timeline, timeline_signals[SIGNAL_NEW_FRAME],
- 0, priv->current_frame_num);
+ {
+ g_signal_emit (timeline, timeline_signals[SIGNAL_NEW_FRAME],
+ 0, priv->current_frame_num);
+ }
if (priv->loop)
clutter_timeline_rewind (timeline);
}
/**
+ * clutter_timeline_set_alpha_func:
+ * @timeline: A #ClutterTimeline
+ * @func: A #ClutterTimelineAlphaFunc
+ *
+ */
+void
+clutter_timeline_set_alpha_func (ClutterTimeline *timeline,
+ ClutterTimelineAlphaFunc func)
+{
+ timeline->priv->alpha_func = func;
+}
+
+/**
* clutter_timeline_new:
* @nframes: #ClutterTimeline number of frames
* @fps: #ClutterTimeline frames per second
gint32
clutter_timeline_get_alpha (ClutterTimeline *timeline);
+void
+clutter_timeline_set_alpha_func (ClutterTimeline *timeline,
+ ClutterTimelineAlphaFunc func);
+
guint32
clutter_timeline_alpha_ramp_inc_func (ClutterTimeline *timeline);
+guint32
+clutter_timeline_alpha_ramp_dec_func (ClutterTimeline *timeline);
+guint32
+clutter_timeline_alpha_ramp_func (ClutterTimeline *timeline);
-#define CLUTTER_ALPHA_RAMP_INC clutter_timeline_alpha_ramp_inc_func;
+#define CLUTTER_ALPHA_RAMP_INC clutter_timeline_alpha_ramp_inc_func
+#define CLUTTER_ALPHA_RAMP_DEC clutter_timeline_alpha_ramp_dec_func
+#define CLUTTER_ALPHA_RAMP clutter_timeline_alpha_ramp_func
G_END_DECLS
#include "clutter-util.h"
#include "clutter-event.h"
#include "clutter-timeline.h"
+#include "clutter-behaviour.h"
+#include "clutter-behaviours.h"
#include "clutter-stage.h"
#include "clutter-actor.h"
#include "clutter-rectangle.h"
-noinst_PROGRAMS = test video-player video-cube super-oh
+noinst_PROGRAMS = test video-player video-cube super-oh behave
INCLUDES = -I$(top_srcdir)/
$(GCONF_LIBS) \
$(top_builddir)/clutter/libclutter-@CLUTTER_MAJORMINOR@.la
+behave_SOURCES = behave.c
+behave_CFLAGS = $(CLUTTER_CFLAGS) $(GST_CFLAGS) $(GCONF_CFLAGS)
+behave_LDFLAGS = \
+ $(CLUTTER_LIBS) \
+ $(GST_LIBS) \
+ $(GCONF_LIBS) \
+ $(top_builddir)/clutter/libclutter-@CLUTTER_MAJORMINOR@.la
+
+
EXTRA_DIST = redhand.png \
clutter-logo-800x600.png \
media-actions-pause.png \
--- /dev/null
+#include <clutter/clutter.h>
+
+int
+main (int argc, char *argv[])
+{
+ ClutterTimeline *timeline;
+ ClutterBehaviour *behave;
+ ClutterActor *stage, *hand;
+ ClutterColor stage_color = { 0xcc, 0xcc, 0xcc, 0xff };
+ GdkPixbuf *pixbuf;
+
+
+ clutter_init (&argc, &argv);
+
+ stage = clutter_stage_get_default ();
+
+ 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, 100, 100);
+ clutter_group_add (CLUTTER_GROUP (stage), hand);
+
+ /* Make a timeline */
+ timeline = clutter_timeline_new (100, 30); /* num frames, fps */
+ g_object_set(timeline, "loop", TRUE, 0);
+
+ /* Set an alpha func to power behaviour - ramp is constant rise/fall */
+ clutter_timeline_set_alpha_func (timeline, CLUTTER_ALPHA_RAMP);
+
+ /* Create a behaviour for that time line */
+ behave = clutter_behaviour_opacity_new (timeline, 0X33 ,0xff);
+
+ /* Apply it to our actor */
+ clutter_behaviour_apply (behave, hand);
+
+ /* start the timeline */
+ clutter_timeline_start (timeline);
+
+ clutter_group_show_all (CLUTTER_GROUP (stage));
+
+ clutter_main();
+
+ return 0;
+}