gnomemm r1666 - in clutter-box2dmm/trunk: . clutter-box2d clutter-box2d/src examples examples/bridge scripts tools/m4



Author: murrayc
Date: Sun Aug 10 11:54:24 2008
New Revision: 1666
URL: http://svn.gnome.org/viewvc/gnomemm?rev=1666&view=rev

Log:
2008-08-10  Murray Cumming  <murrayc murrayc com>

* clutter-box2d/clutter-box2dmm.h: Added an include for box2d.h.
* clutter-box2d/src/box2d.hg: Added wrappers for the weird joint 
functoins, though this must be done properly.
* configure.in:
* examples/Makefile.am:
* examples/bridge/Makefile.am:
* examples/bridge/main.cc: Added a first working example, based on 
the first part of the C example.

Added:
   clutter-box2dmm/trunk/examples/bridge/
   clutter-box2dmm/trunk/examples/bridge/Makefile.am
   clutter-box2dmm/trunk/examples/bridge/main.cc
Removed:
   clutter-box2dmm/trunk/scripts/config.guess
   clutter-box2dmm/trunk/scripts/config.sub
Modified:
   clutter-box2dmm/trunk/ChangeLog
   clutter-box2dmm/trunk/clutter-box2d/clutter-box2dmm.h
   clutter-box2dmm/trunk/clutter-box2d/src/box2d.hg
   clutter-box2dmm/trunk/configure.in
   clutter-box2dmm/trunk/examples/Makefile.am
   clutter-box2dmm/trunk/tools/m4/convert_clutter-box2dmm.m4

Modified: clutter-box2dmm/trunk/clutter-box2d/clutter-box2dmm.h
==============================================================================
--- clutter-box2dmm/trunk/clutter-box2d/clutter-box2dmm.h	(original)
+++ clutter-box2dmm/trunk/clutter-box2d/clutter-box2dmm.h	Sun Aug 10 11:54:24 2008
@@ -0,0 +1,32 @@
+/* clutter-box2dmm - a C++ wrapper for clutter-gtk
+ *
+ * Copyright 2008 The cluttermm Development Team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef LIBCLUTTER_BOX2DMM_H
+#define LIBCLUTTER_BOX2DMM_H
+
+/* cluttermm version.  */
+extern const int clutter_box2dmm_major_version;
+extern const int clutter_box2dmm_minor_version;
+extern const int clutter_box2dmm_micro_version;
+
+#include <cluttermm.h>
+#include <clutter-box2dmm/init.h>
+#include <clutter-box2dmm/box2d.h>
+
+#endif /* #ifndef LIBCLUTTER_BOX2DMM_H */

Modified: clutter-box2dmm/trunk/clutter-box2d/src/box2d.hg
==============================================================================
--- clutter-box2dmm/trunk/clutter-box2d/src/box2d.hg	(original)
+++ clutter-box2dmm/trunk/clutter-box2d/src/box2d.hg	Sun Aug 10 11:54:24 2008
@@ -17,17 +17,19 @@
 
 #include <cluttermm/group.h>
 #include <cluttermm/types.h> //For Clutter::Vertex.
+#include <clutter-box2d/clutter-box2d-joint.h>
  
 _DEFS(clutter-box2dmm,clutter-box2d)
 _PINCLUDE(cluttermm/private/group_p.h)
 
-
 namespace Clutter
 {
 
 namespace Box2D
 {
 
+_WRAP_ENUM(Type, ClutterBox2DType, NO_GTYPE)
+
 /** TODO: Documentation.
  * Use set_child_property() on the child actors.
  */
@@ -46,6 +48,35 @@
   _WRAP_METHOD(void set_simulating(bool simulating = true), clutter_box2d_set_simulating)
   _WRAP_METHOD(bool get_simulating() const, clutter_box2d_get_simulating)
 
+  //TODO: Wrap ClutterBox2DJoint properly - ideally it would be a registered type, with hidden implementation.
+  _WRAP_METHOD(ClutterBox2DJoint* add_revolute_joint(const Glib::RefPtr<Clutter::Actor>& actor1,
+                                                     const Glib::RefPtr<Clutter::Actor>& actor2,
+                                                     const ClutterVertex *anchor1,
+                                                     const ClutterVertex *anchor2,
+                                                     double reference_angle), clutter_box2d_add_revolute_joint)
+
+
+  _WRAP_METHOD(ClutterBox2DJoint* add_revolute_joint2(const Glib::RefPtr<Clutter::Actor>& actor1,
+                                                      const Glib::RefPtr<Clutter::Actor>& actor2,
+                                                      const ClutterVertex *anchor), clutter_box2d_add_revolute_joint2)
+
+
+  _WRAP_METHOD(ClutterBox2DJoint* add_distance_joint(const Glib::RefPtr<Clutter::Actor>& actor1,
+                                                     const Glib::RefPtr<Clutter::Actor>& actor2,
+                                                     const ClutterVertex *anchor1,
+                                                     const ClutterVertex *anchor2,
+                                                     double length, double frequency, double damping_ratio), clutter_box2d_add_distance_joint)
+
+
+  _WRAP_METHOD(ClutterBox2DJoint* add_prismatic_joint(const Glib::RefPtr<Clutter::Actor>& actor1,
+                                                      const Glib::RefPtr<Clutter::Actor>& actor2,
+                                                      const ClutterVertex *anchor1,
+                                                      const ClutterVertex *anchor2,
+                                                      double min_length, double max_length, const ClutterVertex *axis), clutter_box2d_add_prismatic_joint)
+
+
+  _WRAP_METHOD(ClutterBox2DJoint* add_mouse_joint(const Glib::RefPtr<Clutter::Actor>& actor, ClutterVertex    *target), clutter_box2d_add_mouse_joint)
+
   _WRAP_PROPERTY("gravity", Clutter::Vertex)
   _WRAP_PROPERTY("simulating", bool)
 };

Modified: clutter-box2dmm/trunk/configure.in
==============================================================================
--- clutter-box2dmm/trunk/configure.in	(original)
+++ clutter-box2dmm/trunk/configure.in	Sun Aug 10 11:54:24 2008
@@ -119,5 +119,6 @@
 
   demo/Makefile
   examples/Makefile
+    examples/bridge/Makefile
 ])
 :

Modified: clutter-box2dmm/trunk/examples/Makefile.am
==============================================================================
--- clutter-box2dmm/trunk/examples/Makefile.am	(original)
+++ clutter-box2dmm/trunk/examples/Makefile.am	Sun Aug 10 11:54:24 2008
@@ -1,3 +1,3 @@
-SUBDIRS = 
+SUBDIRS = bridge
 
 

Added: clutter-box2dmm/trunk/examples/bridge/Makefile.am
==============================================================================
--- (empty file)
+++ clutter-box2dmm/trunk/examples/bridge/Makefile.am	Sun Aug 10 11:54:24 2008
@@ -0,0 +1,7 @@
+SUBDIRS = 
+
+include $(top_srcdir)/examples/Makefile.am_fragment
+
+noinst_PROGRAMS = example
+example_SOURCES = main.cc
+

Added: clutter-box2dmm/trunk/examples/bridge/main.cc
==============================================================================
--- (empty file)
+++ clutter-box2dmm/trunk/examples/bridge/main.cc	Sun Aug 10 11:54:24 2008
@@ -0,0 +1,112 @@
+#include <cluttermm.h>
+#include <clutter-box2dmm.h>
+#include <iostream>
+
+static void
+add_static_box(const Glib::RefPtr<Clutter::Container>& group,
+                int x, int y, int width, int height)
+{
+  Glib::RefPtr<Clutter::Rectangle> rect = Clutter::Rectangle::create();
+  rect->set_size(width, height);
+  rect->set_position(x, y);
+  group->add_actor(rect);
+
+  group->set_child_property(rect, "mode", (int)Clutter::Box2D::BOX2D_STATIC);
+}
+
+void
+add_cage (const Glib::RefPtr<Clutter::Container>& group, bool roof)
+{
+  Glib::RefPtr<Clutter::Stage> stage = Clutter::Stage::get_default(); //TODO: There could be more than one stage.
+  int width = stage->get_width();
+  int height = stage->get_height();
+
+  if(roof)
+    add_static_box(group, -100, -100, width + 200, 100);
+  else
+    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);
+}
+
+
+int main(int argc, char *argv[])
+{
+
+ try
+  {
+    // TODO: Pass context to init as soon as that init() overload has been
+    // uncommented in cluttermm. This depends on a clutter release with
+    // clutter bug #1033 fixed.
+    // initialize the C++ wrapper types
+    Clutter::init(&argc, &argv); //, context);
+  }
+  catch(const Glib::Exception& ex)
+  {
+    std::cerr << "Failed to initialize clutter: " << ex.what() << std::endl;
+    return -1;
+  }
+
+  Clutter::Color stage_color(0x61, 0x64, 0x8c, 0xff);
+  Glib::RefPtr<Clutter::Stage> stage = Clutter::Stage::get_default();
+  stage->set_size(800, 600);
+
+  stage->set_title("Actors Test");
+  stage->set_color(stage_color);
+
+
+  Glib::RefPtr<Clutter::Box2D::Box2D> box2d = Clutter::Box2D::Box2D::create();
+  stage->add_actor(box2d);
+  
+
+  add_cage(box2d, true /* roof */);
+
+  int y = stage->get_height() / 2;
+  int numplanks = stage->get_width() / 20 - 2;
+  Glib::RefPtr<Clutter::Rectangle> rect = Clutter::Rectangle::create();
+  rect->set_size(18, 5);
+  rect->set_position(10, y);
+  box2d->add_actor(rect);
+
+  box2d->set_child_property(rect, "mode", (int)Clutter::Box2D::BOX2D_STATIC);  //TODO: Avoid the need for the int cast.
+
+  Glib::RefPtr<Clutter::Actor> prev_actor = rect;
+
+  for(int i = 0; i < numplanks; ++i)
+  {
+    Glib::RefPtr<Clutter::Rectangle> box = Clutter::Rectangle::create();
+    box->set_size(18, 5);
+    box->set_position(20 + 20 * i, y);
+    box2d->add_actor(box);
+
+    box2d->set_child_property(box, "manipulatable", true);
+    box2d->set_child_property(box, "mode", (int)Clutter::Box2D::BOX2D_DYNAMIC);
+
+    ClutterVertex anchor = { CLUTTER_UNITS_FROM_FLOAT (20 + 20 * i), CLUTTER_UNITS_FROM_FLOAT (y) };
+    box2d->add_revolute_joint2(prev_actor, box, &anchor);
+   
+    prev_actor = box;
+  }
+
+  Glib::RefPtr<Clutter::Rectangle> box = Clutter::Rectangle::create();
+  box->set_size(18, 5);
+  box->set_position(20 + 20 * numplanks, y);
+  box2d->add_actor(box);
+
+  box2d->set_child_property(box, "mode", (int)Clutter::Box2D::BOX2D_STATIC);
+
+  ClutterVertex anchor = { CLUTTER_UNITS_FROM_FLOAT (20 + 20 * numplanks),
+             CLUTTER_UNITS_FROM_FLOAT (y) };
+  box2d->add_revolute_joint2(prev_actor, box, &anchor);
+
+  box2d->set_simulating();
+
+  stage->show();
+
+  Clutter::main();
+
+  return 0;
+}

Modified: clutter-box2dmm/trunk/tools/m4/convert_clutter-box2dmm.m4
==============================================================================
--- clutter-box2dmm/trunk/tools/m4/convert_clutter-box2dmm.m4	(original)
+++ clutter-box2dmm/trunk/tools/m4/convert_clutter-box2dmm.m4	Sun Aug 10 11:54:24 2008
@@ -3,6 +3,7 @@
 
 _CONVERSION(`ClutterActor*',`Glib::RefPtr<Actor>',`Glib::wrap($3)')
 _CONVERSION(`ClutterActor*',`Glib::RefPtr<const Actor>',`Glib::wrap($3)')
+_CONVERSION(`const Glib::RefPtr<Clutter::Actor>&',`ClutterActor*',__CONVERT_REFPTR_TO_P)
 
 _CONVERSION(`const Glib::RefPtr<Shader>&',`ClutterShader*',__CONVERT_REFPTR_TO_P)
 _CONVERSION(`ClutterShader*',`Glib::RefPtr<Shader>', `Glib::wrap($3)')
@@ -69,3 +70,4 @@
 _CONV_ENUM(Pango,WrapMode)
 
 _CONVERSION(`const gchar*', `const Glib::ustring&',__GCHARP_TO_USTRING)
+



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