static VALUE rbclt_script_load_from_data (VALUE self, VALUE data) { ClutterScript *script = CLUTTER_SCRIPT (RVAL2GOBJ (self)); guint merge_id; GError *error = NULL; StringValuePtr (data); merge_id = clutter_script_load_from_data (script, RSTRING (data)->ptr, RSTRING (data)->len, &error); if (error) RAISE_GERROR (error); return UINT2NUM (merge_id); }
int main (int argc, char *argv[]) { GObject *stage, *blue_button, *red_button; GError *error = NULL; gint res; clutter_init (&argc, &argv); script = clutter_script_new (); g_assert (CLUTTER_IS_SCRIPT (script)); clutter_script_load_from_data (script, test_behaviour, -1, &error); if (error) { g_print ("*** Error:\n" "*** %s\n", error->message); g_error_free (error); g_object_unref (script); return EXIT_FAILURE; } clutter_script_load_from_file (script, "test-script.json", &error); if (error) { g_print ("*** Error:\n" "*** %s\n", error->message); g_error_free (error); g_object_unref (script); return EXIT_FAILURE; } merge_id = clutter_script_load_from_data (script, test_unmerge, -1, &error); if (error) { g_print ("*** Error:\n" "*** %s\n", error->message); g_error_free (error); g_object_unref (script); return EXIT_FAILURE; } clutter_script_connect_signals (script, NULL); res = clutter_script_get_objects (script, "main-stage", &stage, "red-button", &red_button, "blue-button", &blue_button, NULL); g_assert (res == 3); clutter_actor_show (CLUTTER_ACTOR (stage)); g_signal_connect (red_button, "button-press-event", G_CALLBACK (red_button_press), NULL); g_signal_connect (blue_button, "button-press-event", G_CALLBACK (blue_button_press), NULL); clutter_main (); g_object_unref (script); return EXIT_SUCCESS; }
GnibblesBoard * gnibbles_board_new (gint t_w, gint t_h) { ClutterColor stage_color = {0x00,0x00,0x00,0xff}; GnibblesBoard *board = g_new (GnibblesBoard, 1); board->width = t_w; board->height = t_h; board->level = NULL; board->surface =NULL; board->clutter_widget = gtk_clutter_embed_new (); ClutterActor *stage; load_pixmap (); stage = gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (board->clutter_widget)); clutter_stage_set_color (CLUTTER_STAGE(stage), &stage_color); clutter_stage_set_user_resizable (CLUTTER_STAGE(stage), FALSE); clutter_actor_set_size (CLUTTER_ACTOR (stage), properties->tilesize * BOARDWIDTH, properties->tilesize * BOARDHEIGHT); clutter_stage_set_user_resizable (CLUTTER_STAGE (stage), FALSE); clutter_actor_show (stage); gchar *filename; const char *dirname; dirname = games_runtime_get_directory (GAMES_RUNTIME_GAME_PIXMAP_DIRECTORY); filename = g_build_filename (dirname, "wall-small-empty.svg", NULL); /* Using ClutterScript to set special texture property such as "repeat-x", * "repeat-y" and "keep-aspect-ratio" */ gchar texture_script[200]; g_sprintf (texture_script, "[" " {" " \"id\" : \"surface\"," " \"type\" : \"ClutterTexture\"," " \"filename\" : \"%s\"," " \"x\" : 0," " \"y\" : 0," " \"width\" : %d," " \"height\" : %d," " \"keep-aspect-ratio\" : true" " \"visible\" : true," " \"repeat-x\" : true," " \"repeat-y\" : true" " }" "]", filename, properties->tilesize, properties->tilesize); ClutterScript *script = clutter_script_new (); clutter_script_load_from_data (script, texture_script, -1, NULL); clutter_script_get_objects (script, "surface", &(board->surface), NULL); clutter_actor_set_size (CLUTTER_ACTOR (board->surface), properties->tilesize * BOARDWIDTH, properties->tilesize * BOARDHEIGHT); clutter_container_add_actor (CLUTTER_CONTAINER (stage), board->surface); clutter_actor_show (board->surface); g_object_unref (script); return board; }