gnomemm r1654 - in clutter-cairomm/trunk: . examples



Author: murrayc
Date: Wed Jul 30 10:30:24 2008
New Revision: 1654
URL: http://svn.gnome.org/viewvc/gnomemm?rev=1654&view=rev

Log:
2008-07-30  Murray Cumming  <murrayc murrayc com>

* examples/Makefile.am:
* examples/effect.cc:
* examples/test-actors.cc:
* examples/test-boxes.cc: Removed these because they are in 
cairomm instead.
* examples/flowers.cc:
* examples/simple-cairo.cc: Corrected the syntax formatting.

Removed:
   clutter-cairomm/trunk/examples/effect.cc
   clutter-cairomm/trunk/examples/test-actors.cc
   clutter-cairomm/trunk/examples/test-boxes.cc
Modified:
   clutter-cairomm/trunk/ChangeLog
   clutter-cairomm/trunk/examples/Makefile.am
   clutter-cairomm/trunk/examples/flowers.cc
   clutter-cairomm/trunk/examples/simple-cairo.cc

Modified: clutter-cairomm/trunk/examples/Makefile.am
==============================================================================
--- clutter-cairomm/trunk/examples/Makefile.am	(original)
+++ clutter-cairomm/trunk/examples/Makefile.am	Wed Jul 30 10:30:24 2008
@@ -2,12 +2,9 @@
 
 include Makefile.am_fragment
 
-noinst_PROGRAMS = actors flowers simple-cairo effect
-actors_SOURCES = test-actors.cc
+noinst_PROGRAMS = flowers simple-cairo 
 flowers_SOURCES = flowers.cc
 simple_cairo_SOURCES = simple-cairo.cc
-effect_SOURCES = effect.cc
-#boxes_SOURCES = test-boxes.cc
 
 EXTRA_DIST = actor.png
 

Modified: clutter-cairomm/trunk/examples/flowers.cc
==============================================================================
--- clutter-cairomm/trunk/examples/flowers.cc	(original)
+++ clutter-cairomm/trunk/examples/flowers.cc	Wed Jul 30 10:30:24 2008
@@ -13,184 +13,176 @@
 #include <cstdlib>
 #include <ctime>
 
-#define PETAL_MIN 20
-#define PETAL_VAR 40
-#define N_FLOWERS 40 /* reduce if you have a small card */
+const int PETAL_MIN = 20;
+const int PETAL_VAR = 40;
+const int N_FLOWERS = 40; /* reduce if you have a small card */
 
-struct Flower : public Clutter::Cairo::CairoTexture
+class Flower : public Clutter::Cairo::CairoTexture
 {
-    static Glib::RefPtr<Flower> create ()
-    {
-        gint size;
-        gint petal_size; 
-        petal_size = PETAL_MIN + std::rand() % PETAL_VAR;
-        size = petal_size * 8;
+public:
+  static Glib::RefPtr<Flower> create()
+  {
+    const int petal_size = PETAL_MIN + std::rand() % PETAL_VAR;
+    const int size = petal_size * 8;
+
+    return Glib::RefPtr<Flower>(new Flower(size));
+  }
+
+  Flower(guint size)
+  : Clutter::Cairo::CairoTexture(size, size),
+    m_x(0), m_y(0), m_rot(0), m_v(0), m_rv(0)
+  {
+    const double colors[] = {
+      0.71, 0.81, 0.83,
+      1.0,  0.78, 0.57,
+      0.64, 0.30, 0.35,
+      0.73, 0.40, 0.39,
+      0.91, 0.56, 0.64,
+      0.70, 0.47, 0.45,
+      0.92, 0.75, 0.60,
+      0.82, 0.86, 0.85,
+      0.51, 0.56, 0.67,
+      1.0, 0.79, 0.58,
+    };
+
+    /* Num groups of petals 1-3:  */
+    const int n_groups = std::rand() % 3 + 1;
+
+    int petal_size = size / 8; 
+    Cairo::RefPtr<Cairo::Context> cr = create_cairo_context();
+
+    cr->set_tolerance(0.1);
+
+    /* Clear */
+    cr->set_operator(Cairo::OPERATOR_CLEAR);
+    cr->paint();
+    cr->set_operator(Cairo::OPERATOR_OVER);
 
-        return Glib::RefPtr<Flower> (new Flower (size));
+    cr->translate(size/2, size/2);
 
-        petal_size -= std::rand() % (size/8);
-    }
+    int idx, last_idx = -1;
 
-    Flower (guint size) :
-        CairoTexture (size, size)
+    for(int i = 0; i < n_groups; ++i)
     {
-        gint i, j;
+      /* num of petals 4 - 8: */
+      const int n_petals = std::rand() % 5 + 4;
+      cr->save();
+
+      cr->rotate(std::rand() % 6);
+
+      do
+      {
+        idx = (std::rand() % (sizeof(colors) / sizeof(double) / 3)) * 3;
+      } while(idx == last_idx);
+
+      cr->set_source_rgba(colors[idx], colors[idx+1],
+          colors[idx+2], 0.5);
+
+      last_idx = idx;
+
+      /* some bezier randomness */
+      int pm1 = std::rand() % 20;
+      int pm2 = std::rand() % 4;
+
+      for(int j = 1; j < n_petals + 1; j++)
+      {
+        cr->save();
+        cr->rotate(((2*M_PI)/n_petals)*j);
+
+        /* Petals are made up beziers */
+        cr->begin_new_path();
+        cr->move_to(0, 0);
+        cr->rel_curve_to(petal_size, petal_size,
+                 (pm2+2)*petal_size, petal_size,
+                 (2*petal_size) + pm1, 0);
+        cr->rel_curve_to(0 + (pm2*petal_size), -petal_size,
+                  -petal_size, -petal_size,
+                  -((2*petal_size) + pm1), 0);
+        cr->close_path();
+        cr->fill();
+        cr->restore();
+      }
 
-        const double colors[] = {
-            0.71, 0.81, 0.83,
-            1.0,  0.78, 0.57,
-            0.64, 0.30, 0.35,
-            0.73, 0.40, 0.39,
-            0.91, 0.56, 0.64,
-            0.70, 0.47, 0.45,
-            0.92, 0.75, 0.60,
-            0.82, 0.86, 0.85,
-            0.51, 0.56, 0.67,
-            1.0, 0.79, 0.58,
-
-        };
-        gint n_groups;    /* Num groups of petals 1-3 */
-        gint n_petals;    /* num of petals 4 - 8  */
-        gint pm1, pm2;
-
-        gint idx, last_idx = -1;
-
-        n_groups = std::rand() % 3 + 1;
-
-        gint petal_size = size / 8; 
-        Cairo::RefPtr<Cairo::Context> cr = create_cairo_context ();
-
-        cr->set_tolerance (0.1);
-
-        /* Clear */
-        cr->set_operator (Cairo::OPERATOR_CLEAR);
-        cr->paint();
-        cr->set_operator (Cairo::OPERATOR_OVER);
-
-        cr->translate(size/2, size/2);
-
-        for (i=0; i<n_groups; i++)
-        {
-            n_petals = std::rand() % 5 + 4;
-            cr->save ();
-
-            cr->rotate (std::rand() % 6);
-
-            do {
-                idx = (std::rand() % (sizeof (colors) / sizeof (double) / 3)) * 3;
-            } while (idx == last_idx);
-
-            cr->set_source_rgba (colors[idx], colors[idx+1],
-                    colors[idx+2], 0.5);
-
-            last_idx = idx;
-
-            /* some bezier randomness */
-            pm1 = std::rand() % 20;
-            pm2 = std::rand() % 4;
-
-            for (j=1; j<n_petals+1; j++)
-            {
-                cr->save ();
-                cr->rotate (((2*M_PI)/n_petals)*j);
-
-                /* Petals are made up beziers */
-                cr->begin_new_path ();
-                cr->move_to (0, 0);
-                cr->rel_curve_to (petal_size, petal_size,
-                                  (pm2+2)*petal_size, petal_size,
-                                  (2*petal_size) + pm1, 0);
-                cr->rel_curve_to (0 + (pm2*petal_size), -petal_size,
-                                  -petal_size, -petal_size,
-                                  -((2*petal_size) + pm1), 0);
-                cr->close_path ();
-                cr->fill ();
-                cr->restore ();
-            }
-
-            cr->restore ();
-        }
-
-        /* Finally draw flower center */
-        do {
-            idx = (std::rand() % (sizeof (colors) / sizeof (double) / 3)) * 3;
-        } while (idx == last_idx);
+      cr->restore();
+    }
 
-        if (petal_size < 0)
-            petal_size = std::rand() % 10;
+    /* Finally draw flower center */
+    do
+    {
+      idx = (std::rand() % (sizeof(colors) / sizeof(double) / 3)) * 3;
+    } while(idx == last_idx);
 
-        cr->set_source_rgba (colors[idx], colors[idx+1], colors[idx+2], 0.5);
+    if(petal_size < 0)
+      petal_size = std::rand() % 10;
 
-        cr->arc(0, 0, petal_size, 0, M_PI * 2);
-        cr->fill();
-    }
+    cr->set_source_rgba(colors[idx], colors[idx+1], colors[idx+2], 0.5);
 
-    gint x,y,rot,v,rv;
+    cr->arc(0, 0, petal_size, 0, M_PI * 2);
+    cr->fill();
+  }
+
+public:
+  int m_x, m_y, m_rot, m_v, m_rv;
 };
 
-bool
-tick (const std::vector<Glib::RefPtr<Flower> >& flowers)
+bool tick(const std::vector<Glib::RefPtr<Flower> >& flowers)
 {
-    gint i = 0;
+  int i = 0;
 
-    for (std::vector<Glib::RefPtr<Flower> >::const_iterator iter = flowers.begin(); iter != flowers.end(); ++ iter)
-    {
-        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);
-    }
+  for(std::vector<Glib::RefPtr<Flower> >::const_iterator iter = flowers.begin(); iter != flowers.end(); ++ iter)
+  {
+    Glib::RefPtr<Flower> flower = *iter;
+    flower->m_y += flower->m_v;
+    flower->m_rot += flower->m_rv;
+
+    if(flower->m_y > (int) Clutter::Stage::get_default()->get_height())
+      flower->m_y = -flower->get_height();
+
+    flower->set_position(flower->m_x, flower->m_y);
+
+    flower->set_rotation(Clutter::Z_AXIS,
+      flower->m_rot,
+      flower->get_width()/2,
+      flower->get_height()/2,
+      0);
+  }
 
-    return true;
+  return true;
 }
 
 int
-main (int argc, char **argv)
+main(int argc, char **argv)
 {
-  int              i;
-  Glib::RefPtr<Clutter::Stage> stage;
-  Clutter::Color stage_color (0x0, 0x0, 0x0, 0xff);
+  Clutter::Color stage_color(0x0, 0x0, 0x0, 0xff);
   std::vector<Glib::RefPtr<Flower> > flowers;
 
   std::srand(std::time(NULL));
 
-  Clutter::Cairo::init (&argc, &argv);
-
-  stage = Clutter::Stage::get_default ();
+  Clutter::Cairo::init(&argc, &argv);
 
-  stage->set_color (stage_color);
-
-  stage->fullscreen ();
+  Glib::RefPtr<Clutter::Stage> stage = Clutter::Stage::get_default();
+  stage->set_color(stage_color);
+  stage->fullscreen();
 
   flowers.reserve(N_FLOWERS);
-  for (i=0; i< N_FLOWERS; i++)
-    {
-      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);
-    }
+  for(int i = 0; i <  N_FLOWERS; ++i)
+  {
+    Glib::RefPtr<Flower> flower = Flower::create();
+    flower->m_x   = std::rand() % stage->get_width() - (PETAL_MIN+PETAL_VAR)*2;
+    flower->m_y   = std::rand() % stage->get_height();
+    flower->m_rv  = std::rand() % 5 + 1;
+    flower->m_v   = std::rand() % 10 + 2;
+
+    stage->add_actor(flower);
+    flower->set_position(flower->m_x, flower->m_y);
+    flowers.push_back(flower);
+  }
 
-  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);
+  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->show_all();
+  stage->signal_key_press_event().connect(sigc::hide(sigc::bind_return(sigc::ptr_fun(&Clutter::main_quit), true)));
 
   Clutter::main();
 

Modified: clutter-cairomm/trunk/examples/simple-cairo.cc
==============================================================================
--- clutter-cairomm/trunk/examples/simple-cairo.cc	(original)
+++ clutter-cairomm/trunk/examples/simple-cairo.cc	Wed Jul 30 10:30:24 2008
@@ -6,42 +6,44 @@
 #include <clutter/clutter.h>
 
 int
-main (int argc, char **argv)
+main(int argc, char **argv)
 {
-  Clutter::Cairo::init (&argc, &argv);
+  Clutter::Cairo::init(&argc, &argv);
 
-  Glib::RefPtr<Clutter::Stage> stage = Clutter::Stage::get_default ();
-  Clutter::Color stage_color (0x0, 0x0, 0x0, 0xff);
-  stage->set_color (stage_color);
+  Glib::RefPtr<Clutter::Stage> stage = Clutter::Stage::get_default();
+  Clutter::Color stage_color(0x0, 0x0, 0x0, 0xff);
+  stage->set_color(stage_color);
 
-  guint size = stage->get_height () / 4;
+  guint size = stage->get_height() / 4;
   Glib::RefPtr<Clutter::Cairo::CairoTexture> circle =
-      Clutter::Cairo::CairoTexture::create (size, size);
+    Clutter::Cairo::CairoTexture::create(size, size);
+
   // TODO: These brackets are necessary at the moment to limit the scope of the
   // Cairo::Context object.  Because of the way ClutterCairo is implemented,
   // whatever is drawn to the cairo context is not transferred to the Clutter
   // actor until the cairo context is destroyed.  So we need to force it to be
   // destroyed before we call clutter_main here
   {
-      Cairo::RefPtr<Cairo::Context> cr = circle->create_cairo_context ();
-      cr->set_operator (Cairo::OPERATOR_CLEAR);
-      cr->paint ();
-      cr->set_operator (Cairo::OPERATOR_OVER);
-      cr->set_source_rgba (0.686, 0.96, 0.235, 0.8);
-      cr->translate (size / 2, size / 2);
-      cr->begin_new_path ();
-      cr->arc (0.0,
-              0.0,
-              size / 2,
-              0.0, 2 * M_PI);
-      cr->fill ();
+    Cairo::RefPtr<Cairo::Context> cr = circle->create_cairo_context();
+    cr->set_operator(Cairo::OPERATOR_CLEAR);
+    cr->paint();
+    cr->set_operator(Cairo::OPERATOR_OVER);
+    cr->set_source_rgba(0.686, 0.96, 0.235, 0.8);
+    cr->translate(size / 2, size / 2);
+    cr->begin_new_path();
+    cr->arc(0.0,
+      0.0,
+      size / 2,
+      0.0, 2 * M_PI);
+    cr->fill();
   }
-  circle->set_position (stage->get_width () / 2 - size / 2,
-                        stage->get_height () / 2 - size / 2);
-  stage->add_actor (circle);
 
-  stage->show_all ();
-  stage->signal_key_press_event ().connect (sigc::hide (sigc::bind_return (sigc::ptr_fun (&clutter_main_quit), true)));
+  circle->set_position(stage->get_width() / 2 - size / 2,
+    stage->get_height() / 2 - size / 2);
+  stage->add_actor(circle);
+
+  stage->show_all();
+  stage->signal_key_press_event().connect(sigc::hide(sigc::bind_return(sigc::ptr_fun(&clutter_main_quit), true)));
 
   Clutter::main();
 



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