[cluttermm] Example: Simple Clutter::Script example.
- From: Chris Kühl <chriskuehl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [cluttermm] Example: Simple Clutter::Script example.
- Date: Fri, 25 Feb 2011 00:26:23 +0000 (UTC)
commit be14bbccd745c2ba1708241af94831d8bc072e0e
Author: Chris Kühl <chrisk openismus com>
Date: Fri Feb 25 01:25:14 2011 +0100
Example: Simple Clutter::Script example.
examples/script.cc | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 65 insertions(+), 0 deletions(-)
---
diff --git a/examples/script.cc b/examples/script.cc
new file mode 100644
index 0000000..85877fc
--- /dev/null
+++ b/examples/script.cc
@@ -0,0 +1,65 @@
+#include <cluttermm.h>
+
+// This is the JSON node. Notice that all types are C-types.
+// One can not currenty use C++-types.
+static const Glib::ustring jsonNode("[ \
+ { \
+ \"id\" : \"stage\", \
+ \"type\" : \"ClutterStage\", \
+ \"width\" : 200, \
+ \"height\" : 200, \
+ \"color\" : \"#20456f\", \
+ \"children\" : [ \"text-box\", \"rect1\", \"rect2\"] \
+ }, \
+ { \
+ \"id\" : \"rect1\", \
+ \"type\" : \"ClutterRectangle\", \
+ \"width\" : 100, \
+ \"height\" : 100, \
+ \"x\" : 10, \
+ \"y\" : 10, \
+ \"color\" : \"#523202\", \
+ \"opacity\" : 127 \
+ }, \
+ { \
+ \"id\" : \"rect2\", \
+ \"type\" : \"ClutterRectangle\", \
+ \"width\" : 100, \
+ \"height\" : 100, \
+ \"x\" : 50, \
+ \"y\" : 50, \
+ \"color\" : \"#cc99ee\" \
+ }, \
+ { \
+ \"id\" : \"text-box\", \
+ \"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);
+
+ Glib::RefPtr<Clutter::Script> script = Clutter::Script::create();
+
+ // Load the JSON node from a string.
+ script->load_from_data(jsonNode);
+
+ // 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"));
+
+ // Show the stage:
+ stage->show();
+
+ // Start the main loop, so we can respond to events:
+ Clutter::main();
+
+ return 0;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]