[seed] clutter-pad: Add ClutterBox2D example



commit e616fac4f939d96d204081314a70b3d922f01816
Author: Robert Carr <racarr svn gnome org>
Date:   Thu May 14 10:02:34 2009 -0400

    clutter-pad: Add ClutterBox2D example
---
 examples/clutter-pad/Makefile.am          |    6 ++-
 examples/clutter-pad/examples/Makefile.am |    6 ++-
 examples/clutter-pad/examples/box2d.js    |   64 +++++++++++++++++++++++++++++
 examples/clutter-pad/redhand.png          |  Bin 0 -> 3605 bytes
 4 files changed, 72 insertions(+), 4 deletions(-)

diff --git a/examples/clutter-pad/Makefile.am b/examples/clutter-pad/Makefile.am
index 2876b58..49d2ab8 100644
--- a/examples/clutter-pad/Makefile.am
+++ b/examples/clutter-pad/Makefile.am
@@ -4,10 +4,12 @@ if BUILD_SEED_EXAMPLES
 clutterpaddir=$(datadir)/doc/seed/examples/clutter-pad
 clutterpad_DATA = \
 	main.js \
-	clutter-pad.ui
+	clutter-pad.ui \
+	redhand.png
 endif
 
 EXTRA_DIST = \
 	main.js \
-	clutter-pad.ui
+	clutter-pad.ui \
+	redhand.png
 
diff --git a/examples/clutter-pad/examples/Makefile.am b/examples/clutter-pad/examples/Makefile.am
index a109197..2b42e7d 100644
--- a/examples/clutter-pad/examples/Makefile.am
+++ b/examples/clutter-pad/examples/Makefile.am
@@ -3,11 +3,13 @@ clutterpadexamplesdir=$(datadir)/doc/seed/examples/clutter-pad/examples
 clutterpadexamples_DATA = \
 	animated-rectangle.js \
 	pink-stage.js \
-	spring.js
+	spring.js \
+	box2d.js 
 endif
 
 EXTRA_DIST = \
 	animated-rectangle.js \
 	pink-stage.js \
-	spring.js
+	spring.js \
+	box2d.js
 
diff --git a/examples/clutter-pad/examples/box2d.js b/examples/clutter-pad/examples/box2d.js
new file mode 100644
index 0000000..1b947e0
--- /dev/null
+++ b/examples/clutter-pad/examples/box2d.js
@@ -0,0 +1,64 @@
+ClutterBox2D = imports.gi.ClutterBox2D;
+Clutter = imports.gi.Clutter;
+GObject = imports.gi.GObject;
+
+stage = Clutter.Stage.get_default();
+
+const ROWS = (stage.width/64)-1;
+
+function add_static_box(group,x,y,width,height){
+	var box = new Clutter.Rectangle();
+	box.width = width;
+	box.height = height;
+	box.x = x; box.y = y;
+	group.add_actor (box);
+	
+	group.child_set_property(box,
+		"mode", [GObject.TYPE_LONG, ClutterBox2D.Type.STATIC]);	
+}
+
+function add_hand (group,x,y){
+	var actor = new Clutter.Texture.from_file("redhand.png");
+	group.add_actor (actor);
+	actor.opacity = 0xff;
+	actor.x = x;
+	actor.y = y;
+
+	group.child_set_property(actor,
+		"mode", [GObject.TYPE_LONG, ClutterBox2D.Type.DYNAMIC]);	
+	group.child_set_property(actor,
+	"manipulatable", [GObject.TYPE_BOOLEAN, true]);
+}
+
+function add_cage(group){
+	var width = stage.width;
+	var height = stage.height;
+
+    add_static_box (group, -100, -height*(3-1)-100, width+200, 100);
+    add_static_box (group, -100, height, width + 200, 100);
+
+    add_static_box (group, -100, -(height*(5-1)) , 100, height * 5);
+    add_static_box (group, width, -(height*(5-1)) , 100, height * 5);	
+}
+
+box2d = new ClutterBox2D.ClutterBox2D();
+
+
+for (var row = 0; row <= ROWS; row++){
+	var count = ROWS - row + 1;
+	var y = 420 - (row + 1) * 120;
+	
+	for (var i = 0; i < count; i++){	
+		var x = stage.width/2-(count*64/2)+i*64;
+		add_hand (box2d, x, y);
+	}	
+}
+add_cage (box2d)
+
+stage.add_actor(box2d);
+box2d.simulating = true;
+
+stage.show_all();
+
+
+
diff --git a/examples/clutter-pad/redhand.png b/examples/clutter-pad/redhand.png
new file mode 100644
index 0000000..3a13fe3
Binary files /dev/null and b/examples/clutter-pad/redhand.png differ



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