gnomemm r1597 - in cluttermm/trunk: . clutter clutter/cluttermm clutter/src examples



Author: arminb
Date: Sat Jul  5 14:36:27 2008
New Revision: 1597
URL: http://svn.gnome.org/viewvc/gnomemm?rev=1597&view=rev

Log:
2008-07-05  Armin Burgmeier  <armin openismus com>

	* clutter/cluttermm/event.h:
	* clutter/cluttermm/event.cc: Wrapped some of the clutter_event_*
	functions. Don't wrap those taking a raw ClutterEvent* for now since
	"derived" events such as ClutterEventKey would need an ugly
	reinterpret_cast<> to use those functions anyway. We should probably
	think of a cleverer API for this.

	* clutter/cluttermm/Makefile.am: Add the new files to the build.

	* clutter/cluttermm.h: Include cluttermm/event.h.

	* clutter/src/actor.hg:
	* clutter/src/types.hg: Moved event typedefs from actor.hg to
	types.hg.

	* clutter/src/behaviour-scale.hg: Fixed order of arguments in
	constructors and create functions to match the order of
	clutter_behaviour_scale_new and the set_bounds functions.

	* clutter/cluttermm/init.h:
	* clutter/cluttermm/init.cc: Removed the Clutter::init overload that
	takes an array of Glib::OptionEntry objects since that could not be
	actually used in C++, because in C++ we need a Glib::OptionGroup to
	associate a variable to an entry. Instead, take a Context that is used
	to parse the arguments, as gtkmm does.

	* clutter/cluttermm/frame-source.cc: Include
	<clutter/clutter-frame-source.h> explicitely since this is not
	included from <clutter/clutter.h>. See clutter bug #1019.

	* examples/effect.cc:
	* examples/flowers.cc:
	* examples/test-actors.cc:
	* examples/simple-cairo.cc: Make use of the new C++ API to remove most
	of the C stuff the examples were still using.


Added:
   cluttermm/trunk/clutter/cluttermm/event.cc
   cluttermm/trunk/clutter/cluttermm/event.h
Modified:
   cluttermm/trunk/ChangeLog
   cluttermm/trunk/clutter/cluttermm.h
   cluttermm/trunk/clutter/cluttermm/Makefile.am
   cluttermm/trunk/clutter/cluttermm/frame-source.cc
   cluttermm/trunk/clutter/cluttermm/init.cc
   cluttermm/trunk/clutter/cluttermm/init.h
   cluttermm/trunk/clutter/src/actor.hg
   cluttermm/trunk/clutter/src/behaviour-scale.hg
   cluttermm/trunk/clutter/src/types.hg
   cluttermm/trunk/examples/effect.cc
   cluttermm/trunk/examples/flowers.cc
   cluttermm/trunk/examples/simple-cairo.cc
   cluttermm/trunk/examples/test-actors.cc

Modified: cluttermm/trunk/clutter/cluttermm.h
==============================================================================
--- cluttermm/trunk/clutter/cluttermm.h	(original)
+++ cluttermm/trunk/clutter/cluttermm.h	Sat Jul  5 14:36:27 2008
@@ -41,6 +41,7 @@
 #include <cluttermm/color.h>
 #include <cluttermm/effecttemplate.h>
 #include <cluttermm/entry.h>
+#include <cluttermm/event.h>
 #include <cluttermm/frame-source.h>
 #include <cluttermm/group.h>
 #include <cluttermm/init.h>

Modified: cluttermm/trunk/clutter/cluttermm/Makefile.am
==============================================================================
--- cluttermm/trunk/clutter/cluttermm/Makefile.am	(original)
+++ cluttermm/trunk/clutter/cluttermm/Makefile.am	Sat Jul  5 14:36:27 2008
@@ -11,8 +11,8 @@
 sublib_topdir = clutter
 
 
-files_extra_h	= init.h main.h utility.h threads.h frame-source.h wrap_init.h
-files_extra_cc	= init.cc main.cc utility.cc threads.cc frame-source.cc
+files_extra_h	= init.h main.h utility.h threads.h frame-source.h event.h wrap_init.h
+files_extra_cc	= init.cc main.cc utility.cc threads.cc frame-source.cc event.cc
 
 include $(top_srcdir)/build_shared/Makefile_build_gensrc.am_fragment
 

Added: cluttermm/trunk/clutter/cluttermm/event.cc
==============================================================================
--- (empty file)
+++ cluttermm/trunk/clutter/cluttermm/event.cc	Sat Jul  5 14:36:27 2008
@@ -0,0 +1,51 @@
+// -*- c++ -*-
+/*
+ * Copyright 2008 Jonathon Jongsma
+ *
+ * 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.
+ */
+
+#include <cluttermm/event.h>
+#include <clutter/clutter.h>
+
+namespace Clutter
+{
+
+bool events_pending()
+{
+  return clutter_events_pending();
+}
+
+guint key_event_symbol(KeyEvent* keyev)
+{
+  return clutter_key_event_symbol(keyev);
+}
+
+guint16 key_event_code(KeyEvent* keyev)
+{
+  return clutter_key_event_code(keyev);
+}
+
+guint32 key_event_unicode(KeyEvent* keyev)
+{
+  return clutter_key_event_unicode(keyev);
+}
+
+guint32 keysym_to_unicode(guint keyval)
+{
+  return clutter_keysym_to_unicode(keyval);
+}
+
+} //namespace Clutter

Added: cluttermm/trunk/clutter/cluttermm/event.h
==============================================================================
--- (empty file)
+++ cluttermm/trunk/clutter/cluttermm/event.h	Sat Jul  5 14:36:27 2008
@@ -0,0 +1,69 @@
+// -*- c++ -*-
+#ifndef _LIBCLUTTERMM_EVENT_H
+#define _LIBCLUTTERMM_EVENT_H
+/*
+ * Copyright 2008 Jonathon Jongsma
+ *
+ * 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.
+ */
+
+#include <glibmm.h>
+#include <cluttermm/types.h>
+#include <clutter/clutter-event.h>
+// We also need these in C++:
+#include <clutter/clutter-keysyms.h>
+
+namespace Clutter
+{
+
+// TODO: Wrap the functions that take a ClutterEvent*. I guess we need proper
+// C++ inheritance for the events to allow passing a ClutterEventButton* to
+// a function taking a ClutterEvent*, for example.
+
+/** Checks if events are pending in the event queue.
+ * @return true if there are pending events, false otherwise.
+ */
+bool events_pending();
+
+/** Retrieves the value of the key that caused @a keyev.
+ * @param keyev A KeyEvent.
+ * @return The keysym representing the key.
+ */
+guint key_event_symbol(KeyEvent* keyev);
+
+/** Retrieves the keycode of the key that caused @a keyev.
+ * @param keyev A KeyEvent.
+ * @return The keycode representing the key
+ */
+guint16 key_event_code(KeyEvent* keyev);
+
+/** Retrieves the unicode value for the key that caused @a keyev.
+ * @param keyev A KeyEvent
+ * @return The unicode value representing the key
+ */
+guint32 key_event_unicode(KeyEvent* keyev);
+
+/** Convert from a Clutter key symbol to the corresponding ISO10646 (Unicode)
+ * character.
+ * @param keyval a clutter key symbol
+ * @return the corresponding unicode character, or 0 if there is no
+ * corresponding character.
+ */
+guint32 keysym_to_unicode(guint keyval);
+
+} //namespace Clutter
+
+#endif //_LIBCLUTTERMM_EVENT_H
+

Modified: cluttermm/trunk/clutter/cluttermm/frame-source.cc
==============================================================================
--- cluttermm/trunk/clutter/cluttermm/frame-source.cc	(original)
+++ cluttermm/trunk/clutter/cluttermm/frame-source.cc	Sat Jul  5 14:36:27 2008
@@ -20,6 +20,9 @@
 #include <cluttermm/frame-source.h>
 #include <clutter/clutter.h>
 
+// TODO: Remove this as soon as it is included from clutter.h:
+#include <clutter/clutter-frame-source.h> 
+
 namespace
 {
 

Modified: cluttermm/trunk/clutter/cluttermm/init.cc
==============================================================================
--- cluttermm/trunk/clutter/cluttermm/init.cc	(original)
+++ cluttermm/trunk/clutter/cluttermm/init.cc	Sat Jul  5 14:36:27 2008
@@ -51,17 +51,20 @@
   init(&argc, &argv);
 }
 
-void init(int* argc, gchar** argv[], const Glib::ustring& parameter_string, const ArrayHandle_OptionEntries& entries, const std::string& translation_domain)
+void init(int* argc, gchar** argv[], Glib::OptionContext& option_context)
 {
   common_init();
   GError* error = NULL;
-  clutter_init_with_args(argc, argv, const_cast<char*>(parameter_string.c_str()), const_cast<GOptionEntry*>(entries.data()), const_cast<char*>(translation_domain.c_str()), &error);
+  add_clutter_option_group(option_context);
+  option_context.parse(*argc, *argv);
+  // option_context_parse already parsed the clutter arguments:
+  clutter_init_with_args(NULL, NULL, NULL, NULL, NULL, &error);
   if(error != NULL) Glib::Error::throw_exception(error);
 }
 
-void init(int& argc, gchar**& argv, const Glib::ustring& parameter_string, const ArrayHandle_OptionEntries& entries, const std::string& translation_domain)
+void init(int& argc, gchar**& argv, Glib::OptionContext& option_context)
 {
-  init(&argc, &argv, parameter_string, entries, translation_domain);
+  init(&argc, &argv, option_context);
 }
 
 void add_clutter_option_group(Glib::OptionContext& option_context)

Modified: cluttermm/trunk/clutter/cluttermm/init.h
==============================================================================
--- cluttermm/trunk/clutter/cluttermm/init.h	(original)
+++ cluttermm/trunk/clutter/cluttermm/init.h	Sat Jul  5 14:36:27 2008
@@ -30,7 +30,7 @@
  *
  * @param argc a pointer to the number of command line arguments
  * @param argv a pointer to the array of comman line arguments
- * @throws InitError
+ * @throws InitError, Glib::OptionError
  */
 void init(int* argc, gchar** argv[]);
 
@@ -38,61 +38,35 @@
  * some standard command line options. argc and argv are adjusted accordingly
  * so your own code will never see those standard arguments.
  *
- * @param argc a pointer to the number of command line arguments
- * @param argv a pointer to the array of comman line arguments
- * @throws InitError
+ * @param argc a reference to the number of command line arguments
+ * @param argv a reference to the array of comman line arguments
+ * @throws InitError, Glib::OptionError
  */
 void init(int& argc, gchar**& argv);
 
-#ifndef DOXYGEN_SHOULD_SKIP_THIS
-struct OptionEntryTraits
-{
-  typedef Glib::OptionEntry CppType;
-  typedef GOptionEntry CType;
-
-  static CppType to_cpp_type(const CType& obj)
-  {
-    // We only convert the other way around:
-    g_assert_not_reached();
-    return CppType();
-  }
-
-  static CType to_c_type(CppType& obj) { return *obj.gobj(); }
-};
-#endif
-typedef Glib::ArrayHandle<Glib::OptionEntry, OptionEntryTraits> ArrayHandle_OptionEntries;
-
-/** This function does the same work as init(). Additionally, it
- * allows you to add your own command line options, and it automatically
- * generates nicely formatted --help output. Note that your program will be
- * terminated after writing out the help output. Also note that, in case of
- * error, the error message will be placed inside error instead of being
- * printed on the display.
+/** It will initialise everything needed to operate with Clutter and parses
+ * some standard command line options and the options specified in your
+ * @a option_context. Add a Glib::OptionGroup to the Glib::OptionContext to
+ * parse your own command-line arguments.
  *
  * @param argc a pointer to the number of command line arguments
  * @param argv a pointer to the array of comman line arguments
- * @param parameter_string a string which is displayed in the first line of --help output, after programname [OPTION...]
- * @param entries an array of Glib::OptionEntrys describing the options of your program
- * @param translation_domain a translation domain to use for translating the --help output for the options in entries with gettext()
- * @throws InitError
+ * @param option_context A Glib::OptionContext containing Glib::OptionGroups which described the command-line arguments taken by your program.
+ * @throws InitError, Glib::OptionError
  */
-void init(int* argc, gchar** argv[], const Glib::ustring& parameter_string, const ArrayHandle_OptionEntries& entries, const std::string& translation_domain);
+void init(int* argc, char** argv[], Glib::OptionContext& option_context);
 
-/** This function does the same work as init(). Additionally, it
- * allows you to add your own command line options, and it automatically
- * generates nicely formatted --help output. Note that your program will be
- * terminated after writing out the help output. Also note that, in case of
- * error, the error message will be placed inside error instead of being
- * printed on the display.
+/** It will initialise everything needed to operate with Clutter and parses
+ * some standard command line options and the options specified in your
+ * @a option_context. Add a Glib::OptionGroup to the Glib::OptionContext to
+ * parse your own command-line arguments.
  *
- * @param argc a pointer to the number of command line arguments
- * @param argv a pointer to the array of comman line arguments
- * @param parameter_string a string which is displayed in the first line of --help output, after programname [OPTION...]
- * @param entries an array of Glib::OptionEntrys describing the options of your program
- * @param translation_domain a translation domain to use for translating the --help output for the options in entries with gettext()
- * @throws InitError
+ * @param argc a reference to the number of command line arguments
+ * @param argv a reference to the array of comman line arguments
+ * @param option_context A Glib::OptionContext containing Glib::OptionGroups which described the command-line arguments taken by your program.
+ * @throws InitError, Glib::OptionError
  */
-void init(int& argc, gchar**& argv, const Glib::ustring& parameter_string, const ArrayHandle_OptionEntries& entries, const std::string& translation_domain);
+void init(int& argc, char**& argv, Glib::OptionContext& option_context);
 
 /** Adds a Glib::OptionGroup for the command line arguments recognized by
  * Clutter to the given context. This is useful if you are using

Modified: cluttermm/trunk/clutter/src/actor.hg
==============================================================================
--- cluttermm/trunk/clutter/src/actor.hg	(original)
+++ cluttermm/trunk/clutter/src/actor.hg	Sat Jul  5 14:36:27 2008
@@ -19,8 +19,8 @@
 #include <cluttermm/color.h>
 #include <cluttermm/scriptable.h>
 #include <cluttermm/shader.h>
+#include <cluttermm/types.h> // For Event*
 #include <clutter/clutter-actor.h> // For ClutterActorBox
-#include <clutter/clutter-event.h> //For Clutter*Event
  
 _DEFS(cluttermm,clutter)
 _PINCLUDE(glibmm/private/object_p.h)
@@ -29,13 +29,6 @@
 namespace Clutter
 {
 
-typedef ClutterEvent Event;
-typedef ClutterButtonEvent ButtonEvent;
-typedef ClutterKeyEvent KeyEvent;
-typedef ClutterMotionEvent MotionEvent;
-typedef ClutterScrollEvent ScrollEvent;
-typedef ClutterCrossingEvent CrossingEvent;
-
 class ActorBox
 {
   _CLASS_BOXEDTYPE_STATIC(ActorBox, ClutterActorBox)

Modified: cluttermm/trunk/clutter/src/behaviour-scale.hg
==============================================================================
--- cluttermm/trunk/clutter/src/behaviour-scale.hg	(original)
+++ cluttermm/trunk/clutter/src/behaviour-scale.hg	Sat Jul  5 14:36:27 2008
@@ -31,12 +31,12 @@
   _CLASS_GOBJECT(BehaviourScale, ClutterBehaviourScale, CLUTTER_BEHAVIOUR_SCALE, Behaviour, ClutterBehaviour)
 
 protected:
-  _WRAP_CTOR(BehaviourScale(const Glib::RefPtr<Alpha>& alpha, double x_scale_start, double x_scale_end, double y_scale_start, double y_scale_end), clutter_behaviour_scale_new)
-  _WRAP_CTOR(BehaviourScale(const Glib::RefPtr<Alpha>& alpha, Fixed x_scale_start, Fixed x_scale_end, Fixed y_scale_start, Fixed y_scale_end), clutter_behaviour_scale_newx)
+  _WRAP_CTOR(BehaviourScale(const Glib::RefPtr<Alpha>& alpha, double x_scale_start, double y_scale_start, double x_scale_end, double y_scale_end), clutter_behaviour_scale_new)
+  _WRAP_CTOR(BehaviourScale(const Glib::RefPtr<Alpha>& alpha, Fixed x_scale_start, Fixed y_scale_start, Fixed x_scale_end, Fixed y_scale_end), clutter_behaviour_scale_newx)
 
 public:
-  _WRAP_CREATE(const Glib::RefPtr<Alpha>& alpha, double x_scale_start, double x_scale_end, double y_scale_start, double y_scale_end)
-  _WRAP_CREATE(const Glib::RefPtr<Alpha>& alpha, Fixed x_scale_start, Fixed x_scale_end, Fixed y_scale_start, Fixed y_scale_end)
+  _WRAP_CREATE(const Glib::RefPtr<Alpha>& alpha, double x_scale_start, double y_scale_start, double x_scale_end, double y_scale_end)
+  _WRAP_CREATE(const Glib::RefPtr<Alpha>& alpha, Fixed x_scale_start, Fixed y_scale_start, Fixed x_scale_end, Fixed y_scale_end)
 
   _WRAP_METHOD(void set_bounds(double x_scale_start, double y_scale_start, double x_scale_end, double y_scale_end), clutter_behaviour_scale_set_bounds)
   _WRAP_METHOD(void get_bounds(double& x_scale_start, double& y_scale_start, double& x_scale_end, double& y_scale_end) const, clutter_behaviour_scale_get_bounds)

Modified: cluttermm/trunk/clutter/src/types.hg
==============================================================================
--- cluttermm/trunk/clutter/src/types.hg	(original)
+++ cluttermm/trunk/clutter/src/types.hg	Sat Jul  5 14:36:27 2008
@@ -16,6 +16,7 @@
  */
 
 #include <clutter/clutter-types.h>
+#include <clutter/clutter-event.h>
 #include <clutter/clutter-units.h>
 #include <clutter/clutter-color.h>
 #include <clutter/clutter-main.h>
@@ -25,6 +26,13 @@
 namespace Clutter
 {
 
+typedef ClutterEvent Event;
+typedef ClutterButtonEvent ButtonEvent;
+typedef ClutterKeyEvent KeyEvent;
+typedef ClutterMotionEvent MotionEvent;
+typedef ClutterScrollEvent ScrollEvent;
+typedef ClutterCrossingEvent CrossingEvent;
+
 //TODO: Maybe redefine these, to avoid including a C header in our C++ header:
 typedef ClutterUnit Unit;
 typedef ClutterFixed Fixed;

Modified: cluttermm/trunk/examples/effect.cc
==============================================================================
--- cluttermm/trunk/examples/effect.cc	(original)
+++ cluttermm/trunk/examples/effect.cc	Sat Jul  5 14:36:27 2008
@@ -1,13 +1,7 @@
 #include <cluttermm.h>
 #include <cluttermm/init.h>
-// FIXME: remove this when enough stuff is wrapped
-#include <clutter/clutter.h>
 #include <iostream>
 
-#if defined (_MSC_VER) && !defined (_USE_MATH_DEFINES)
-#define _USE_MATH_DEFINES
-#endif
-
 void move_finished(const Glib::RefPtr<Clutter::Actor>& actor, const Glib::RefPtr<Clutter::EffectTemplate>& effect)
 {
   // Restart
@@ -29,7 +23,6 @@
 
     Glib::RefPtr<Clutter::Timeline> timeline =
         Clutter::Timeline::create (360, 60); // num frames, fps
-    //timeline->set_loop (true); // have it loop
     Glib::RefPtr<Clutter::EffectTemplate> effect = Clutter::EffectTemplate::create(timeline, Clutter::ALPHA_RAMP);
 
     Glib::RefPtr<Clutter::Texture> texture(Clutter::Texture::create());
@@ -41,6 +34,6 @@
     timeline->start();
     effect->move(texture, 450, 450, sigc::bind(sigc::ptr_fun(move_finished), effect));
 
-    clutter_main ();
+    Clutter::main();
     return 0;
 }

Modified: cluttermm/trunk/examples/flowers.cc
==============================================================================
--- cluttermm/trunk/examples/flowers.cc	(original)
+++ cluttermm/trunk/examples/flowers.cc	Sat Jul  5 14:36:27 2008
@@ -3,14 +3,15 @@
  * This is a very cursory translation from C to C++.  As such, you will notice
  * that there are a lot of C-isms in this example yet, but it should still give
  * an idea of how to use cluttermm-cairo
+ *
+ * I C++ified this a bit. armin.
  */
 
 #include <cluttermm-cairo.h>
-#include <clutter/clutter.h>
+#include <cluttermm.h>
 
-#include <unistd.h> 		/* for sleep(), used for screenshots */
-#include <stdlib.h>
-#include "math.h"
+#include <cstdlib>
+#include <ctime>
 
 #define PETAL_MIN 20
 #define PETAL_VAR 40
@@ -22,12 +23,12 @@
     {
         gint size;
         gint petal_size; 
-        petal_size = PETAL_MIN + rand() % PETAL_VAR;
+        petal_size = PETAL_MIN + std::rand() % PETAL_VAR;
         size = petal_size * 8;
 
         return Glib::RefPtr<Flower> (new Flower (size));
 
-        petal_size -= rand() % (size/8);
+        petal_size -= std::rand() % (size/8);
     }
 
     Flower (guint size) :
@@ -35,7 +36,7 @@
     {
         gint i, j;
 
-        double colors[] = {
+        const double colors[] = {
             0.71, 0.81, 0.83,
             1.0,  0.78, 0.57,
             0.64, 0.30, 0.35,
@@ -54,7 +55,7 @@
 
         gint idx, last_idx = -1;
 
-        n_groups = rand() % 3 + 1;
+        n_groups = std::rand() % 3 + 1;
 
         gint petal_size = size / 8; 
         Cairo::RefPtr<Cairo::Context> cr = create_cairo_context ();
@@ -70,13 +71,13 @@
 
         for (i=0; i<n_groups; i++)
         {
-            n_petals = rand() % 5 + 4;
+            n_petals = std::rand() % 5 + 4;
             cr->save ();
 
-            cr->rotate (rand() % 6);
+            cr->rotate (std::rand() % 6);
 
             do {
-                idx = (rand() % (sizeof (colors) / sizeof (double) / 3)) * 3;
+                idx = (std::rand() % (sizeof (colors) / sizeof (double) / 3)) * 3;
             } while (idx == last_idx);
 
             cr->set_source_rgba (colors[idx], colors[idx+1],
@@ -85,8 +86,8 @@
             last_idx = idx;
 
             /* some bezier randomness */
-            pm1 = rand() % 20;
-            pm2 = rand() % 4;
+            pm1 = std::rand() % 20;
+            pm2 = std::rand() % 4;
 
             for (j=1; j<n_petals+1; j++)
             {
@@ -112,11 +113,11 @@
 
         /* Finally draw flower center */
         do {
-            idx = (rand() % (sizeof (colors) / sizeof (double) / 3)) * 3;
+            idx = (std::rand() % (sizeof (colors) / sizeof (double) / 3)) * 3;
         } while (idx == last_idx);
 
         if (petal_size < 0)
-            petal_size = rand() % 10;
+            petal_size = std::rand() % 10;
 
         cr->set_source_rgba (colors[idx], colors[idx+1], colors[idx+2], 0.5);
 
@@ -128,41 +129,40 @@
 };
 
 bool
-tick (Glib::RefPtr<Flower> flowers[])
+tick (const std::vector<Glib::RefPtr<Flower> >& flowers)
 {
     gint i = 0;
 
-    for (i=0; i< N_FLOWERS; i++)
+    for (std::vector<Glib::RefPtr<Flower> >::const_iterator iter = flowers.begin(); iter != flowers.end(); ++ iter)
     {
-        flowers[i]->y   += flowers[i]->v;
-        flowers[i]->rot += flowers[i]->rv;
-
-        if (flowers[i]->y > (gint) Clutter::Stage::get_default ()->get_height ())
-            flowers[i]->y = -flowers[i]->get_height ();
-
-        flowers[i]->set_position (flowers[i]->x, flowers[i]->y);
-
-        flowers[i]->set_rotation (Clutter::Z_AXIS,
-                flowers[i]->rot,
-                flowers[i]->get_width ()/2,
-                flowers[i]->get_height ()/2,
+        Glib::RefPtr<Flower> flower = *iter;
+        flower->y   += flower->v;
+        flower->rot += flower->rv;
+
+        if (flower->y > (gint) Clutter::Stage::get_default ()->get_height ())
+            flower->y = -flower->get_height ();
+
+        flower->set_position (flower->x, flower->y);
+
+        flower->set_rotation (Clutter::Z_AXIS,
+                flower->rot,
+                flower->get_width ()/2,
+                flower->get_height ()/2,
                 0);
     }
 
     return true;
 }
 
-void foo(void) { g_usleep(10000000); }
-
 int
 main (int argc, char **argv)
 {
   int              i;
   Glib::RefPtr<Clutter::Stage> stage;
   Clutter::Color stage_color (0x0, 0x0, 0x0, 0xff);
-  Glib::RefPtr<Flower> flowers[N_FLOWERS];
+  std::vector<Glib::RefPtr<Flower> > flowers;
 
-  srand(time(NULL));
+  std::srand(std::time(NULL));
 
   Clutter::Cairo::init (&argc, &argv);
 
@@ -172,26 +172,27 @@
 
   stage->fullscreen ();
 
+  flowers.reserve(N_FLOWERS);
   for (i=0; i< N_FLOWERS; i++)
     {
-      flowers[i]      = Flower::create ();
-      flowers[i]->x   = rand() % stage->get_width()
-                            - (PETAL_MIN+PETAL_VAR)*2;
-      flowers[i]->y   = rand() % stage->get_height();
-      flowers[i]->rv  = rand() % 5 + 1;
-      flowers[i]->v   = rand() % 10 + 2;
-
-      stage->add_actor (flowers[i]);
-      flowers[i]->set_position (flowers[i]->x, flowers[i]->y);
+      Glib::RefPtr<Flower> flower = Flower::create();
+      flower->x   = std::rand() % stage->get_width() - (PETAL_MIN+PETAL_VAR)*2;
+      flower->y   = std::rand() % stage->get_height();
+      flower->rv  = std::rand() % 5 + 1;
+      flower->v   = std::rand() % 10 + 2;
+
+      stage->add_actor (flower);
+      flower->set_position (flower->x, flower->y);
+      flowers.push_back(flower);
     }
 
-  Glib::signal_timeout ().connect (sigc::bind (sigc::ptr_fun (&tick), flowers), 50);
+  Clutter::frame_source_add (sigc::bind (sigc::ptr_fun (&tick), sigc::ref(flowers)), 50);
+  //Glib::signal_timeout ().connect (sigc::bind (sigc::ptr_fun (&tick), sigc::ref(flowers)), 50);
 
   stage->show_all ();
-  stage->signal_key_press_event ().connect (sigc::hide (sigc::bind_return (sigc::ptr_fun (&clutter_main_quit), true)));
+  stage->signal_key_press_event ().connect (sigc::hide (sigc::bind_return (sigc::ptr_fun (&Clutter::main_quit), true)));
 
-  // TODO: wrap clutter_main ?
-  clutter_main();
+  Clutter::main();
 
-  return 1;
+  return 0;
 }

Modified: cluttermm/trunk/examples/simple-cairo.cc
==============================================================================
--- cluttermm/trunk/examples/simple-cairo.cc	(original)
+++ cluttermm/trunk/examples/simple-cairo.cc	Sat Jul  5 14:36:27 2008
@@ -43,8 +43,7 @@
   stage->show_all ();
   stage->signal_key_press_event ().connect (sigc::hide (sigc::bind_return (sigc::ptr_fun (&clutter_main_quit), true)));
 
-  // TODO: wrap clutter_main ?
-  clutter_main();
+  Clutter::main();
 
   return 0;
 }

Modified: cluttermm/trunk/examples/test-actors.cc
==============================================================================
--- cluttermm/trunk/examples/test-actors.cc	(original)
+++ cluttermm/trunk/examples/test-actors.cc	Sat Jul  5 14:36:27 2008
@@ -1,62 +1,32 @@
 #include <cluttermm.h>
-#include <cluttermm/init.h>
-// FIXME: remove this when enough stuff is wrapped
-#include <clutter/clutter.h>
 #include <iostream>
 
-#if defined (_MSC_VER) && !defined (_USE_MATH_DEFINES)
-#define _USE_MATH_DEFINES
-#endif
+namespace
+{
 
-#include <math.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <glib.h>
-
-#define TRAILS  0
-#define NACTORS  6
-#define RADIUS  ((Clutter::Stage::get_default ()->get_width ()+Clutter::Stage::get_default ()->get_height ())/NACTORS)
+const unsigned int TRAILS = 0;
+const unsigned int N_ACTORS = 6;
 
-typedef struct SuperOH
+unsigned int get_radius(unsigned int num_actors)
+{
+    return (Clutter::Stage::get_default()->get_height()
+            + Clutter::Stage::get_default()->get_height()) / num_actors;
+}
+
+struct SuperOH
 {
     std::vector<Glib::RefPtr<Clutter::Actor> > hands;
     Glib::RefPtr<Clutter::Actor> bgtex;
     Glib::RefPtr<Clutter::Group> group;
-} SuperOH; 
-
-static gint s_num_actors = NACTORS;
-
-// FIXME: use glibmm types
-static GOptionEntry super_oh_entries[] = {
-    {
-        "num-actors", 'n',
-        0,
-        G_OPTION_ARG_INT, &s_num_actors,
-        "Number of actors", "ACTORS"
-    },
-    { NULL }
 };
 
-    static gint
-get_radius (void)
-{
-    return (Clutter::Stage::get_default ()->get_width ()
-            + Clutter::Stage::get_default ()->get_height ()) / s_num_actors ;
-}
-
 bool on_button_press (Clutter::ButtonEvent *event, const Glib::RefPtr<Clutter::Stage>& stage)
 {
-    gint x, y;
-
-    clutter_event_get_coords ((ClutterEvent*)event, &x, &y);
-
     g_print ("*** button press event (button:%d) ***\n",
             event->button);
 
-    Glib::RefPtr<Clutter::Actor> e = stage->get_actor_at_pos (x, y);
-
-    if (e)
-        e->hide ();
+    Glib::RefPtr<Clutter::Actor> e = stage->get_actor_at_pos(event->x, event->y);
+    if(e) e->hide();
 
     return false;
 }
@@ -64,10 +34,10 @@
 bool on_key_release (Clutter::KeyEvent *event)
 {
     g_print ("*** key press event (key:%c) ***\n",
-            clutter_key_event_symbol (event));
+            Clutter::key_event_symbol(event));
 
-    if (clutter_key_event_symbol (event) == CLUTTER_q)
-        clutter_main_quit ();
+    if(Clutter::key_event_symbol(event) == CLUTTER_q)
+        Clutter::main_quit();
 
     return false;
 }
@@ -82,7 +52,7 @@
                              Clutter::Stage::get_default ()->get_height () / 2,
                              0);
 
-    for (int i = 0; i < s_num_actors; i++)
+    for (unsigned int i = 0; i < oh->hands.size(); i++)
     {
         double scale_x, scale_y;
 
@@ -95,65 +65,46 @@
          * unit based functions to fix.
          */
         oh->hands[i]->set_rotation (Clutter::Z_AXIS,
-                                  - 6.0 * frame_num,
-#if 0
-                (oh->hands[i]->get_width () / 2) * scale_x,
-                (oh->hands[i]->get_height () / 2) * scale_y
-#else
-                (oh->hands[i]->get_width () / 2),
-                (oh->hands[i]->get_height () / 2)
-#endif
-                , 0);
+                                  - 6.0 * frame_num, 0, 0, 0);
     }
 }
 
-    int
-main (int argc, char *argv[])
-{
-    // FIXME: wrap init function with args
-    /*
-       GError *error;
-
-       error = NULL;
-
-       clutter_init_with_args (&argc, &argv,
-       NULL,
-       super_oh_entries,
-       NULL,
-       &error);
-       if (error)
-       {
-       g_warning ("Unable to initialise Clutter:\n%s",
-       error->message);
-       g_error_free (error);
-
-       exit (1);
-       }
-       */
+} // anonymous namespace
 
-    // initialize the C++ wrapper types
-    Clutter::init(&argc, &argv);
+int main(int argc, char *argv[])
+{
+    Glib::OptionEntry entry;
+    entry.set_short_name('n');
+    entry.set_long_name("num-actors");
+    entry.set_description("Number of actors");
+    entry.set_arg_description("ACTORS");
+
+    Glib::OptionGroup group("actor", "Specifies actor properties");
+    int num_actors = N_ACTORS;
+    group.add_entry(entry, num_actors);
 
-    Clutter::Color stage_color (0x61, 0x64, 0x8c, 0xff);
-    Glib::RefPtr<Clutter::Stage> stage = Clutter::Stage::get_default ();
-    stage->set_size (800, 600);
+    Glib::OptionContext context;
+    context.set_main_group(group);
 
-    /*Glib::RefPtr<Gdk::Pixbuf> pixbuf;
     try
     {
-        pixbuf = Gdk::Pixbuf::create_from_file ("actor.png");
+      // initialize the C++ wrapper types
+      Clutter::init(&argc, &argv, context);
     }
-    catch (const Glib::FileError& ex)
+    catch(const Glib::Error& ex)
     {
-        std::cerr << ex.what () << std::endl;
-        std::cerr << "You may need to run this example from the 'examples' directory" << std::endl;
-        return 1;
-    }*/
+        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);
 
-    SuperOH *oh = new SuperOH ();
+    SuperOH oh;
 
     // Create a timeline to manage animation
     Glib::RefPtr<Clutter::Timeline> timeline =
@@ -162,12 +113,13 @@
 
     // fire a callback for frame change
     timeline->signal_new_frame ().connect
-        (sigc::bind (sigc::ptr_fun(on_new_frame), oh));
+        (sigc::bind (sigc::ptr_fun(on_new_frame), &oh));
 
     // TODO: these next 3 objects are not currently used in the example, but
     // they cause problems on application exit.  If they are commented out, the
     // program runs and exits without problems.  There seems to be some sort of
     // reference-counting issue
+    // Perhaps that's clutter bug #856.
 
     // Set up some behaviours to handle scaling
     Glib::RefPtr<Clutter::Alpha> alpha =
@@ -184,58 +136,67 @@
                 0.5, 0.5);
 
     // create a new group to hold multiple actors in a group
-    oh->group = Clutter::Group::create ();
+    oh.group = Clutter::Group::create();
 
-    oh->hands.reserve (s_num_actors);
-    for (int i = 0; i < s_num_actors; i++)
+    oh.hands.reserve(num_actors);
+    for (int i = 0; i < num_actors; i++)
     {
         gint x, y, w, h;
-        gint radius = get_radius ();
+        gint radius = get_radius(num_actors);
 
         // Create a texture from file, then clone it to save resources
         if (i == 0)
         {
-	    Glib::RefPtr<Clutter::Texture> texture(Clutter::Texture::create());
-	    texture->set_from_file("actor.png");
-            oh->hands.push_back (texture);
+	    try
+	    {
+                Glib::RefPtr<Clutter::Texture> texture(Clutter::Texture::create());
+                texture->set_from_file("actor.png");
+                oh.hands.push_back (texture);
+            }
+            catch(const Glib::Exception& ex)
+            {
+                std::cerr << "Could not load texture: " << ex.what() << std::endl;
+		return -1;
+            }
         }
         else
         {
-            oh->hands.push_back (Clutter::CloneTexture::create
+            oh.hands.push_back(Clutter::CloneTexture::create
                     (Glib::RefPtr<Clutter::Texture>::cast_dynamic
-                     (oh->hands[0])));
+                     (oh.hands[0])));
         }
 
         // Place around a circle
-        w = oh->hands[0]->get_width ();
-        h = oh->hands[0]->get_height ();
+        w = oh.hands[0]->get_width ();
+        h = oh.hands[0]->get_height ();
 
         x = Clutter::Stage::get_default ()->get_width () / 2 
             + radius
-            * cos (i * M_PI / (s_num_actors / 2))
+            * cos (i * M_PI / (num_actors / 2))
             - w / 2;
         y = Clutter::Stage::get_default ()->get_height () / 2 
             + radius
-            * sin (i * M_PI / (s_num_actors / 2))
+            * sin (i * M_PI / (num_actors / 2))
             - h / 2;
 
-        oh->hands[i]->set_position (x, y);
+        oh.hands[i]->set_position (x, y);
+	oh.hands[i]->move_anchor_point_from_gravity(Clutter::GRAVITY_CENTER);
 
         // Add to our group group
-        oh->group->add_actor (oh->hands[i]);
+        oh.group->add_actor(oh.hands[i]);
 
-#if 0 /* FIXME: disabled as causes drift - see comment above */
+#if 1 /* FIXME: disabled as causes drift - see comment above */
         if (i % 2)
-            scaler_1->apply (oh->hands[i]);
+            scaler_1->apply (oh.hands[i]);
         else
-            scaler_2->apply (oh->hands[i]);
+            scaler_2->apply (oh.hands[i]);
 #endif
     }
 
-    oh->group->show_all ();
+    oh.group->show_all ();
 
     // Add the group to the stage
-    stage->add_actor (oh->group);
+    stage->add_actor (oh.group);
 
     // Show everying ( and map window )
     stage->show_all ();
@@ -249,9 +210,7 @@
     timeline->start ();
 
     // TODO: wrap clutter_main ?
-    clutter_main ();
-
-    delete oh;
+    Clutter::main();
 
     return 0;
 }



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