编写clutter的helloworld

      编译完clutter之后,需要写一个hello world。这里我参考了资料1,具体的流程如下:

      在源代码目录下创建目录myapp,同时创建文件example.c,加入如下代码:

#include 
#include 
// six empty rectangles and our stage
ClutterActor *stage = NULL;
ClutterActor *rect1 = NULL;
ClutterActor *rect2 = NULL;
ClutterActor *rect3 = NULL;
ClutterActor *rect4 = NULL;
ClutterActor *rect5 = NULL;
ClutterActor *rect6 = NULL;
// the create_rect() function needs to create actual rectangles rather than text boxes
ClutterActor *create_rect(ClutterColor col) {
  ClutterActor *rect = clutter_rectangle_new_with_color(&col);
  clutter_actor_set_size(rect, 256, 128);
  clutter_actor_set_position(rect, 256, 256);
  clutter_actor_set_anchor_point(rect, 128, 64);
  clutter_container_add_actor (CLUTTER_CONTAINER (stage), rect);
  clutter_actor_show (rect);
  return rect;
}
void move_rect(ClutterActor *rect) {
    clutter_actor_animate (rect,
            // CLUTTER_LINEAR,          // animate in linear
            CLUTTER_EASE_IN_OUT_BACK,   // animate like iphone
            500,
            "x", (float)(rand() % 512),
            "y", (float)(rand() % 512),
            "rotation-angle-z", (float)(rand() % 360),
            NULL);
}
// we'll be filling in this function later
void on_stage_button_press (ClutterStage *stage, ClutterEvent *event, gpointer data) {
    move_rect(rect1);
    move_rect(rect2);
    move_rect(rect3);
    move_rect(rect4);
    move_rect(rect5);
    move_rect(rect6);
}
int main(int argc, char *argv[]) {
    ClutterColor stage_color = { 0, 0, 0, 255 };
    ClutterColor red = { 255, 0, 0, 128 };
    ClutterColor green = { 0, 255, 0, 128 };
    ClutterColor blue = { 0, 0, 255, 128 };
    ClutterColor yellow = { 255, 255, 0, 128 };
    ClutterColor cyan = { 0, 255, 255, 128 };
    ClutterColor purple = { 255, 0, 255, 128 };
    clutter_init (&argc, &argv);
    stage = clutter_stage_get_default();
    clutter_actor_set_size (stage, 512, 512);
    clutter_stage_set_color (CLUTTER_STAGE(stage), &stage_color);
    rect1 = create_rect(red);
    rect2 = create_rect(green);
    rect3 = create_rect(blue);
    rect4 = create_rect(yellow);
    rect5 = create_rect(cyan);
    rect6 = create_rect(purple);
    g_signal_connect (stage, "button-press-event", G_CALLBACK (on_stage_button_press), NULL);
    clutter_stage_set_title(CLUTTER_STAGE(stage), "Spinny boxes ahoy!");
    clutter_actor_show (stage);
    clutter_main ();
    return EXIT_SUCCESS;
}

      然后,在msys控制台下,切换到myapp目录执行如下命令

libtool --mode=link gcc -Wall -g -o example.exe example.c /
-I/clutter-work/clutter-cross/include /
`PKG_CONFIG_PATH=/clutter-work/clutter-cross/lib/pkgconfig pkg-config clutter-win32-1.0 --cflags --libs`

      这样会生成example.exe,执行以下,效果不错吧。具体细节参考参考资料1。

      源代码目录下有参考文档,位于clutter-1.2.12/doc/reference目录下。

参考资料:

1. Clutter: a beginner's tutorial

你可能感兴趣的:(编写clutter的helloworld)