Actually, after testing this, it gives no errors or warnings, but it's not doing what I expect. My on_paint method is never called, and in fact the Clutter::Actor::on_paint method is never called. My constructor is only called once to create the type:
3 MainGridActor::MainGridActor() : Glib::ObjectBase("MainGridActor"), padding(10)
4 {
5 std::cout << "In MainGridActor constructor.";
6 } I don't know how the object is constructed out of the script, but it seems the C types are constructed correctly (it works if I subclass ClutterRectangle because its paint method is implemented in C). If the on_paint is a C++ method only, then it's not being called.
Brian On Feb 26, 2011, at 9:51 PM, Brian Gregg wrote: // 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
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
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
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
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
|