Re: Help with Clutter::Scriptable




 // Get the stage by name, casting it to the correct C++-type.
 const Glib::RefPtr<Clutter::Stage> stage =
   Glib::RefPtr<Clutter::Stage>::cast_static(script->get_object("stage"));

A cast_dyanmic<>, with an if() check, would be generally safer. That's
what we generally use with Gtk::Builder::get_widget() too.

I believe Glib::wrap does a cast_dynamic, I was using that instead to wrap the C types after they come out of the script.  Here's what I've got working:

 66 int main(int argc, char** argv)
 67 {
 68   try
 69   {
 70     Clutter::init(&argc, &argv);
 71 
 72     // This is needed on OS X to make fonts appear correctly
 73     clutter_set_font_flags(CLUTTER_FONT_HINTING);
 74 
 75     Glib::RefPtr<Clutter::Stage> stage = Clutter::Stage::get_default();
 76     stage->set_size(1024, 768);
 77 
 78     // Call this to instantiate the MainGridActor custom type
 79     MainGridActor::create();
 80 
 81     ClutterScript *script = clutter_script_new();
 82     clutter_script_load_from_file(script, "GameActor.js", NULL);
 83 
 84     Glib::RefPtr<NavManager> navManager = NavManager::create(stage);
 85 
 86     ClutterRectangle *rect = CLUTTER_RECTANGLE(clutter_script_get_object(script, "active_rect"));
 87     ClutterAnimation *anim = clutter_actor_animate(CLUTTER_ACTOR(rect), Clutter::EASE_IN_OUT_CUBIC, 600,
 88                     "x", 540.0, "y", 284.0, NULL);
 89 
 90     // Need to do this in C API since Clutter::Box is not a Clutter::Actor
 91     ClutterBox *box = CLUTTER_BOX(clutter_script_get_object(script, "game_box"));
 92     clutter_container_add_actor(CLUTTER_CONTAINER(stage->gobj()), CLUTTER_ACTOR(box));
 93 
 94     stage->show();
 95 
 96     // Start the main loop, so we can respond to events:
 97     Clutter::main();
 98   }
 99   catch (const Glib::Error& error)
100   {
101     std::cerr << "Exception: " << error.what() << std::endl;
102     return 1;
103   }
104 
105   return 0;
106 }
And my script file:

 2     {
  3         "id"    : "game_box",
  4         "type"  : "ClutterBox",
  5         "width" : 1024,
  6         "height": 768,
  7         "layout-manager": {
  8             "type"  : "ClutterFixedLayout"
  9         },
 10         "children"  : [
 11             
...
{
 46                 "type"  : "gtkmm__CustomObject_MainGridActor",
 47                 "x"     : 340,
 48                 "y"     : 84,
 49                 "width" : 600,
 50                 "height": 600
 51             },
You notice in my main.cpp file that I used mostly the C API to get what I wanted from the script.  I tried to use cluttermm objects first, but this would often not work as expected.

Brian



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]