mutter/examples/test.c

170 lines
4.2 KiB
C
Raw Normal View History

2006-05-29 04:59:36 -04:00
#include <clutter/clutter.h>
#define PARA_TEXT "This is a paragraph of text to check both " \
"word wrapping and basic clipping."
2006-05-29 04:59:36 -04:00
void
rect_cb (ClutterTimeline *timeline,
gint frame_num,
gpointer data)
2006-05-29 04:59:36 -04:00
{
ClutterActor *rect = CLUTTER_ACTOR(data);
gint x, y;
static gint direction = 1;
2006-05-29 04:59:36 -04:00
x = clutter_actor_get_x (rect);
y = clutter_actor_get_y (rect);
2006-05-29 04:59:36 -04:00
if (x > (CLUTTER_STAGE_WIDTH() - 200))
direction = -1;
if (x < 100)
direction = 1;
2006-05-29 04:59:36 -04:00
x += direction;
2006-05-29 04:59:36 -04:00
clutter_actor_set_position (rect, x, y);
2006-05-29 04:59:36 -04:00
}
2006-05-29 04:59:36 -04:00
void
text_cb (ClutterTimeline *timeline,
gint frame_num,
gpointer data)
2006-05-29 04:59:36 -04:00
{
ClutterLabel *label;
gchar buf[32];
gint opacity;
2006-05-29 04:59:36 -04:00
label = CLUTTER_LABEL(data);
opacity = frame_num/2;
g_snprintf(buf, 32, "--> %i <--", frame_num);
clutter_label_set_text (label, buf);
clutter_actor_set_size(CLUTTER_ACTOR(label), 150, 0);
clutter_label_set_ellipsize (label, PANGO_ELLIPSIZE_END);
clutter_actor_set_opacity (CLUTTER_ACTOR(label), opacity);
2006-05-29 04:59:36 -04:00
clutter_actor_rotate_z (CLUTTER_ACTOR(label),
2006-05-29 04:59:36 -04:00
frame_num,
clutter_actor_get_width (CLUTTER_ACTOR(label))/2,
clutter_actor_get_height (CLUTTER_ACTOR(label))/2);
2006-05-29 04:59:36 -04:00
}
void
para_cb (ClutterTimeline *timeline,
gint frame_num,
gpointer data)
{
}
2007-03-22 Emmanuele Bassi <ebassi@openedhand.com> * clutter/clutter-private.h: Remove inclusion of backend-specific headers; update the main context object; add the declarations for the event queue functions. * clutter/clutter-backend.[ch]: Add the abstract ClutterBackend object, which holds backend-specific settings, the main stage, and the event queue. Every backend must implement a subclass of ClutterBackend and ClutterStage. * clutter/clutter-feature.c: Protect the GLX specific calls behing #ifdef HAVE_CLUTTER_GLX. * clutter/clutter-actor.c: * clutter/clutter-group.c: * clutter/clutter-clone-texture.c: Include GL/gl.h * clutter/clutter-event.[ch]: Update public API and implement the event queue private API; hold a reference on the event objects; move out the keysym-to-unicode table; add the new event types. * clutter/clutter-color.h: Include clutter-fixed.h * clutter/clutter-main.c: Update API; get the main stage from the backend object; process the event received from the queue; lock/unlock the main mutex if we have one; move the initialisation process sooner in the init sequence, in order to have the backend object when we check for options; call the backed vfuncs in the pre/post parse hooks. * clutter/clutter-stage.c: Make ClutterStage and abstract class, implemented by the backends. * clutter/clutter/glx/clutter-glx.h: * clutter/clutter/glx/clutter-backend-glx.[ch]: * clutter/clutter/glx/clutter-event-glx.c: * clutter/clutter/glx/clutter-stage-glx.[ch]: * clutter/clutter/glx/Makefile.am: Add the GLX backend. * clutter/clutter/egl/clutter-backend-egl.[ch]: * clutter/clutter/egl/clutter-event-egl.c: * clutter/clutter/egl/clutter-stage-egl.[ch]: * clutter/clutter/egl/Makefile.am: Add the stub for a EGL backend. * examples/*.c: Update for the new API.
2007-03-22 14:21:59 -04:00
static void
key_press_cb (ClutterStage *stage,
ClutterKeyEvent *event,
gpointer data)
{
g_print ("key-press-event\n");
}
static void
key_release_cb (ClutterStage *stage,
ClutterKeyEvent *event,
gpointer data)
{
g_print ("key-release-event\n");
}
static gboolean
delete_event_cb (ClutterStage *stage,
ClutterEvent *event,
gpointer data)
{
static gboolean res = FALSE;
g_print ("delete-event: %s\n",
res == FALSE ? "first attempt" : "second attempt");
res = !res;
return res;
}
2006-05-29 04:59:36 -04:00
int
main (int argc, char *argv[])
{
ClutterActor *texture, *label, *rect, *para;
ClutterActor *stage;
2006-05-29 04:59:36 -04:00
ClutterTimeline *timeline;
ClutterColor rect_col = { 0xff, 0x0, 0x0, 0x99 };
2006-06-05 Emmanuele Bassi <ebassi@openedhand.com> * clutter-color.h: * clutter-color.c: Reimplement ClutterColor as a boxed type; add convenience API for color handling, like: add, subtract, shade, HSL color-space conversion, packing and unpacking. * clutter-private.h: Update ClutterMainContext, and export the main context pointer here. * clutter-rectangle.h: * clutter-rectangle.c: Update the color-related code; make clutter_rectangle_new() and empty constructor and provide clutter_rectangle_new_with_color(); provide color setter and getter API. * clutter-label.h: * clutter-label.c: Rename the "font" property to "font-name"; update the color-related code to the new ClutterColor object; rename clutter_label_new() to clutter_label_new_with_text(), and add setters and getters for the properties. * clutter-marshal.list: Add VOID:OBJECT and VOID:BOXED marshallers generators. * clutter-stage.h: * clutter-stage.c: Rework the API: provide a default constructor for a singleton object, named clutter_stage_get_default(), which supercedes the clutter_stage() function in clutter-main; provide new events: button-press-event, button-release-event, key-press-event and key-release-event; update the color-related code; (clutter_stage_snapshot): Allow negative width and height when taking a snapshot (meaning: use full width/height). (clutter_stage_get_element_at_pos): Rename clutter_stage_pick(). * clutter-element.c (clutter_element_paint): Clean up the stage and color related code. * clutter-event.h: * clutter-event.c: Add generic ClutterAnyEvent type; add clutter_event_new(), clutter_event_copy() and clutter_event_free(); make ClutterEvent a boxed type. * clutter-main.h: * clutter-main.c: Remove clutter_stage(); add clutter_main_quit(), for cleanly quitting from clutter_main(); add multiple mainloops support; allocate the ClutterCntx instead of adding it to the stack; re-work the ClutterEvent dispatching. * clutter-group.c (clutter_group_add), (clutter_group_remove): Keep a reference on the element when added to a ClutterGroup. * examples/rects.py * examples/test.c: * examples/test-text.c: * examples/video-cube.c: * examples/super-oh.c: * examples/test-video.c: Update.
2006-06-05 09:38:31 -04:00
GdkPixbuf *pixbuf;
2006-05-29 04:59:36 -04:00
clutter_init (&argc, &argv);
2006-06-05 Emmanuele Bassi <ebassi@openedhand.com> * clutter-color.h: * clutter-color.c: Reimplement ClutterColor as a boxed type; add convenience API for color handling, like: add, subtract, shade, HSL color-space conversion, packing and unpacking. * clutter-private.h: Update ClutterMainContext, and export the main context pointer here. * clutter-rectangle.h: * clutter-rectangle.c: Update the color-related code; make clutter_rectangle_new() and empty constructor and provide clutter_rectangle_new_with_color(); provide color setter and getter API. * clutter-label.h: * clutter-label.c: Rename the "font" property to "font-name"; update the color-related code to the new ClutterColor object; rename clutter_label_new() to clutter_label_new_with_text(), and add setters and getters for the properties. * clutter-marshal.list: Add VOID:OBJECT and VOID:BOXED marshallers generators. * clutter-stage.h: * clutter-stage.c: Rework the API: provide a default constructor for a singleton object, named clutter_stage_get_default(), which supercedes the clutter_stage() function in clutter-main; provide new events: button-press-event, button-release-event, key-press-event and key-release-event; update the color-related code; (clutter_stage_snapshot): Allow negative width and height when taking a snapshot (meaning: use full width/height). (clutter_stage_get_element_at_pos): Rename clutter_stage_pick(). * clutter-element.c (clutter_element_paint): Clean up the stage and color related code. * clutter-event.h: * clutter-event.c: Add generic ClutterAnyEvent type; add clutter_event_new(), clutter_event_copy() and clutter_event_free(); make ClutterEvent a boxed type. * clutter-main.h: * clutter-main.c: Remove clutter_stage(); add clutter_main_quit(), for cleanly quitting from clutter_main(); add multiple mainloops support; allocate the ClutterCntx instead of adding it to the stack; re-work the ClutterEvent dispatching. * clutter-group.c (clutter_group_add), (clutter_group_remove): Keep a reference on the element when added to a ClutterGroup. * examples/rects.py * examples/test.c: * examples/test-text.c: * examples/video-cube.c: * examples/super-oh.c: * examples/test-video.c: Update.
2006-06-05 09:38:31 -04:00
stage = clutter_stage_get_default ();
g_signal_connect (stage, "delete-event",
G_CALLBACK (delete_event_cb), NULL);
2007-03-22 Emmanuele Bassi <ebassi@openedhand.com> * clutter/clutter-private.h: Remove inclusion of backend-specific headers; update the main context object; add the declarations for the event queue functions. * clutter/clutter-backend.[ch]: Add the abstract ClutterBackend object, which holds backend-specific settings, the main stage, and the event queue. Every backend must implement a subclass of ClutterBackend and ClutterStage. * clutter/clutter-feature.c: Protect the GLX specific calls behing #ifdef HAVE_CLUTTER_GLX. * clutter/clutter-actor.c: * clutter/clutter-group.c: * clutter/clutter-clone-texture.c: Include GL/gl.h * clutter/clutter-event.[ch]: Update public API and implement the event queue private API; hold a reference on the event objects; move out the keysym-to-unicode table; add the new event types. * clutter/clutter-color.h: Include clutter-fixed.h * clutter/clutter-main.c: Update API; get the main stage from the backend object; process the event received from the queue; lock/unlock the main mutex if we have one; move the initialisation process sooner in the init sequence, in order to have the backend object when we check for options; call the backed vfuncs in the pre/post parse hooks. * clutter/clutter-stage.c: Make ClutterStage and abstract class, implemented by the backends. * clutter/clutter/glx/clutter-glx.h: * clutter/clutter/glx/clutter-backend-glx.[ch]: * clutter/clutter/glx/clutter-event-glx.c: * clutter/clutter/glx/clutter-stage-glx.[ch]: * clutter/clutter/glx/Makefile.am: Add the GLX backend. * clutter/clutter/egl/clutter-backend-egl.[ch]: * clutter/clutter/egl/clutter-event-egl.c: * clutter/clutter/egl/clutter-stage-egl.[ch]: * clutter/clutter/egl/Makefile.am: Add the stub for a EGL backend. * examples/*.c: Update for the new API.
2007-03-22 14:21:59 -04:00
g_signal_connect (stage, "key-press-event",
G_CALLBACK (key_press_cb), NULL);
g_signal_connect (stage, "key-release-event",
G_CALLBACK (key_release_cb), NULL);
g_signal_connect (stage, "button-press-event",
G_CALLBACK (clutter_main_quit),
NULL);
2006-05-29 04:59:36 -04:00
pixbuf = gdk_pixbuf_new_from_file ("clutter-logo-800x600.png", NULL);
if (!pixbuf)
g_error("pixbuf load failed");
texture = clutter_texture_new_from_pixbuf (pixbuf);
label = clutter_label_new_with_text("Sans Bold 32", "hello");
2006-05-29 04:59:36 -04:00
clutter_actor_set_opacity (CLUTTER_ACTOR(label), 0x99);
clutter_actor_set_position (CLUTTER_ACTOR(label), 550, 100);
clutter_actor_set_size(label, 400, 0);
2006-05-29 04:59:36 -04:00
rect = clutter_rectangle_new_with_color(&rect_col);
clutter_actor_set_size(rect, 100, 100);
clutter_actor_set_position(rect, 100, 100);
2006-05-29 04:59:36 -04:00
para = clutter_label_new_with_text ("Sans 24", PARA_TEXT);
clutter_actor_set_position(para, 10, 10);
clutter_actor_set_size(para, 200, 0);
2006-05-29 04:59:36 -04:00
2006-06-05 Emmanuele Bassi <ebassi@openedhand.com> * clutter-color.h: * clutter-color.c: Reimplement ClutterColor as a boxed type; add convenience API for color handling, like: add, subtract, shade, HSL color-space conversion, packing and unpacking. * clutter-private.h: Update ClutterMainContext, and export the main context pointer here. * clutter-rectangle.h: * clutter-rectangle.c: Update the color-related code; make clutter_rectangle_new() and empty constructor and provide clutter_rectangle_new_with_color(); provide color setter and getter API. * clutter-label.h: * clutter-label.c: Rename the "font" property to "font-name"; update the color-related code to the new ClutterColor object; rename clutter_label_new() to clutter_label_new_with_text(), and add setters and getters for the properties. * clutter-marshal.list: Add VOID:OBJECT and VOID:BOXED marshallers generators. * clutter-stage.h: * clutter-stage.c: Rework the API: provide a default constructor for a singleton object, named clutter_stage_get_default(), which supercedes the clutter_stage() function in clutter-main; provide new events: button-press-event, button-release-event, key-press-event and key-release-event; update the color-related code; (clutter_stage_snapshot): Allow negative width and height when taking a snapshot (meaning: use full width/height). (clutter_stage_get_element_at_pos): Rename clutter_stage_pick(). * clutter-element.c (clutter_element_paint): Clean up the stage and color related code. * clutter-event.h: * clutter-event.c: Add generic ClutterAnyEvent type; add clutter_event_new(), clutter_event_copy() and clutter_event_free(); make ClutterEvent a boxed type. * clutter-main.h: * clutter-main.c: Remove clutter_stage(); add clutter_main_quit(), for cleanly quitting from clutter_main(); add multiple mainloops support; allocate the ClutterCntx instead of adding it to the stack; re-work the ClutterEvent dispatching. * clutter-group.c (clutter_group_add), (clutter_group_remove): Keep a reference on the element when added to a ClutterGroup. * examples/rects.py * examples/test.c: * examples/test-text.c: * examples/video-cube.c: * examples/super-oh.c: * examples/test-video.c: Update.
2006-06-05 09:38:31 -04:00
clutter_group_add (CLUTTER_GROUP (stage), texture);
clutter_group_add (CLUTTER_GROUP (stage), label);
clutter_group_add (CLUTTER_GROUP (stage), rect);
clutter_group_add (CLUTTER_GROUP (stage), para);
2006-05-29 04:59:36 -04:00
clutter_actor_set_size (CLUTTER_ACTOR (stage), 800, 600);
2006-05-29 04:59:36 -04:00
2006-12-12 Emmanuele Bassi <ebassi@openedhand.com> Rework part of the show/hide machinery. Allow groups sub-classes and composite actors to override show_all/hide_all in order to decide which children they wish to show/hide. This means that if an actor overrides the default show/hide virtual methods, it'll have to chain up to the parent class show/hide. While we're at it, provide the fully recursive clutter_actor_show_all() and clutter_actor_hide_all() methods. * clutter/clutter-behaviour-path.c: Add apidoc for the ClutterKnot functions; add pathological equality case for clutter_knot_equal(). * clutter/clutter-event.h: * clutter/clutter-feature.h: * clutter/clutter-behaviour.c: * clutter/clutter-behaviour-scale.c:Fix parameters name so that gtk-doc doesn't complain. * clutter/clutter-actor.c: * clutter/clutter-event.c: Add apidoc * clutter/clutter-actor.h: * clutter/clutter-actor.c: Add a clutter_actor_show_all() and a clutter_actor_hide_all() functions; provide a mechanism for groups and composited actors to programmatically select what to show/hide when clutter_actor_show_all() and clutter_actor_hide_all() are called. If you are overriding the ClutterActor::show or the ClutterActor::hide virtual methods you should chain up with the parent class. * clutter/clutter-group.c: Override show_all and hide_all and recursively show/hide every child inside the group; clutter_group_show_all() and clutter_group_hide_all() remain as non recursive versions of clutter_actor_show_all() and clutter_actor_hide_all() (maybe we should rename them in order to avoid name clashes with the bindings). * clutter/clutter-stage.c: * clutter/clutter-texture.c: Chain up with parent class show and hide vfuncs. * clutter/clutter-clone-texture.h: * clutter/clutter-clone-texture.c: Provide API for changing the parent texture of a clone texture actor. * examples/behave.c: * examples/super-oh.c: * examples/test.c: Use clutter_actor_show_all() instead of clutter_group_show_all().
2006-12-12 15:20:04 -05:00
clutter_actor_show_all (CLUTTER_ACTOR (stage));
2006-05-29 04:59:36 -04:00
timeline = clutter_timeline_new (360, 200);
2006-06-05 Emmanuele Bassi <ebassi@openedhand.com> * clutter-color.h: * clutter-color.c: Reimplement ClutterColor as a boxed type; add convenience API for color handling, like: add, subtract, shade, HSL color-space conversion, packing and unpacking. * clutter-private.h: Update ClutterMainContext, and export the main context pointer here. * clutter-rectangle.h: * clutter-rectangle.c: Update the color-related code; make clutter_rectangle_new() and empty constructor and provide clutter_rectangle_new_with_color(); provide color setter and getter API. * clutter-label.h: * clutter-label.c: Rename the "font" property to "font-name"; update the color-related code to the new ClutterColor object; rename clutter_label_new() to clutter_label_new_with_text(), and add setters and getters for the properties. * clutter-marshal.list: Add VOID:OBJECT and VOID:BOXED marshallers generators. * clutter-stage.h: * clutter-stage.c: Rework the API: provide a default constructor for a singleton object, named clutter_stage_get_default(), which supercedes the clutter_stage() function in clutter-main; provide new events: button-press-event, button-release-event, key-press-event and key-release-event; update the color-related code; (clutter_stage_snapshot): Allow negative width and height when taking a snapshot (meaning: use full width/height). (clutter_stage_get_element_at_pos): Rename clutter_stage_pick(). * clutter-element.c (clutter_element_paint): Clean up the stage and color related code. * clutter-event.h: * clutter-event.c: Add generic ClutterAnyEvent type; add clutter_event_new(), clutter_event_copy() and clutter_event_free(); make ClutterEvent a boxed type. * clutter-main.h: * clutter-main.c: Remove clutter_stage(); add clutter_main_quit(), for cleanly quitting from clutter_main(); add multiple mainloops support; allocate the ClutterCntx instead of adding it to the stack; re-work the ClutterEvent dispatching. * clutter-group.c (clutter_group_add), (clutter_group_remove): Keep a reference on the element when added to a ClutterGroup. * examples/rects.py * examples/test.c: * examples/test-text.c: * examples/video-cube.c: * examples/super-oh.c: * examples/test-video.c: Update.
2006-06-05 09:38:31 -04:00
g_object_set (timeline, "loop", TRUE, 0);
g_signal_connect (timeline, "new-frame", G_CALLBACK (text_cb), label);
clutter_timeline_start (timeline);
timeline = clutter_timeline_new (1, 30);
g_object_set (timeline, "loop", TRUE, 0);
g_signal_connect (timeline, "new-frame", G_CALLBACK (rect_cb), rect);
clutter_timeline_start (timeline);
timeline = clutter_timeline_new (1, 10);
g_object_set (timeline, "loop", TRUE, 0);
g_signal_connect (timeline, "new-frame", G_CALLBACK (para_cb), rect);
2006-05-29 04:59:36 -04:00
clutter_timeline_start (timeline);
clutter_main();
return 0;
}