[cluttermm] Updated Clutter::Script example to use Clutter::Script::get_object.



commit dc636cc3badb1879e0396b9e7fd41614d18431df
Author: Chris Kühl <chrisk openismus com>
Date:   Mon Mar 28 15:50:56 2011 +0200

    Updated Clutter::Script example to use Clutter::Script::get_object.
    
    * example/script.cc: Using Clutter::Script::get_object to avoid an
    ugly cast.

 ChangeLog          |    7 ++++++
 examples/script.cc |   62 +++++++++++++++++++++++++++++++++------------------
 2 files changed, 47 insertions(+), 22 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 964d4b7..cc00982 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2011-03-28  Chris Kühl  <chrisk openismus com>
 
+	Updated Clutter::Script example to use Clutter::Script::get_object.
+
+	* example/script.cc: Using Clutter::Script::get_object to avoid an
+	ugly cast.
+
+2011-03-28  Chris Kühl  <chrisk openismus com>
+
 	Added get_object convienience method.
 
 	* clutter/src/script.[h|cc]g: Added get_object and helper functions.
diff --git a/examples/script.cc b/examples/script.cc
index 85877fc..28af302 100644
--- a/examples/script.cc
+++ b/examples/script.cc
@@ -1,4 +1,5 @@
 #include <cluttermm.h>
+#include <iostream>
 
 // This is the JSON node. Notice that all types are C-types.
 // One can not currenty use C++-types.
@@ -6,28 +7,34 @@ static const Glib::ustring jsonNode("[                   \
   {                                                      \
     \"id\" : \"stage\",                                  \
     \"type\" : \"ClutterStage\",                         \
-    \"width\" : 200,                                     \
-    \"height\" : 200,                                    \
+    \"width\" : 300,                                     \
+    \"height\" : 300,                                    \
     \"color\" : \"#20456f\",                             \
+    \"children\" : [ \"mybox\"]                          \
+  },                                                     \
+  {                                                      \
+    \"id\" : \"mybox\",                                  \
+    \"type\" : \"ClutterBox\",                           \
+    \"width\" : 300,                                     \
+    \"height\" : 300,                                    \
+    \"layout-manager\": {                                \
+               \"type\"  : \"ClutterFlowLayout\"         \
+    },                                                   \
     \"children\" : [ \"text-box\", \"rect1\", \"rect2\"] \
   },                                                     \
   {                                                      \
     \"id\" : \"rect1\",                                  \
     \"type\" : \"ClutterRectangle\",                     \
-    \"width\" :  100,                                    \
+    \"width\" : 100,                                     \
     \"height\" : 100,                                    \
-    \"x\" : 10,                                          \
-    \"y\" : 10,                                          \
     \"color\" : \"#523202\",                             \
     \"opacity\" : 127                                    \
   },                                                     \
   {                                                      \
     \"id\" : \"rect2\",                                  \
     \"type\" : \"ClutterRectangle\",                     \
-    \"width\" :  100,                                    \
+    \"width\" : 100,                                     \
     \"height\" : 100,                                    \
-    \"x\" : 50,                                          \
-    \"y\" : 50,                                          \
     \"color\" : \"#cc99ee\"                              \
   },                                                     \
   {                                                      \
@@ -35,31 +42,42 @@ static const Glib::ustring jsonNode("[                   \
     \"type\" : \"ClutterText\",                          \
     \"width\" : 100,                                     \
     \"height\" : 60,                                     \
-    \"x\" : 20,                                          \
-    \"y\" : 20,                                          \
     \"text\" : \"This is text!\",                        \
     \"color\" : \"#ddeeee\"                              \
-  }                                                      \
+} \
 ]");
 
 int main(int argc, char** argv)
 {
-  Clutter::init(&argc, &argv);
+  try
+  {
+    Clutter::init(&argc, &argv);
+
+    Glib::RefPtr<Clutter::Script> script = Clutter::Script::create();
+
+    // Load the JSON node from a string.
+    script->load_from_data(jsonNode);
 
-  Glib::RefPtr<Clutter::Script> script = Clutter::Script::create();
+    // Get the stage by name, casting it to the correct C++-type.
+    Glib::RefPtr<Clutter::Stage> stage;
+    script->get_object("stage", stage);
 
-  // Load the JSON node from a string.
-  script->load_from_data(jsonNode);
+    Glib::RefPtr<Clutter::Box> box;
+    script->get_object("mybox", box);
 
-  // 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"));
+    std::cout << "Box->width: "  << box->get_width() << std::endl;
 
-  // Show the stage:
-  stage->show();
+    // Show the stage:
+    stage->show();
 
-  // Start the main loop, so we can respond to events:
-  Clutter::main();
+    // Start the main loop, so we can respond to events:
+    Clutter::main();
+  }
+  catch (const Glib::Error& error)
+  {
+      std::cerr << "Exception: " << error.what() << std::endl;
+      return 1;
+  }
 
   return 0;
 }



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