[cluttermm] test-actors: Replace Texture with Image content in an Actor.



commit 94e5ac61d233899ec8d5526729468d12a4207bea
Author: Murray Cumming <murrayc murrayc com>
Date:   Wed Mar 26 21:20:32 2014 +0100

    test-actors: Replace Texture with Image content in an Actor.
    
    * configure.ac:
    * tests/Makefile.am: Use gdkmm in examples.
    * tests/test-actors.cc: Comment out the unused behaviours.
      Replace use the of Texture actor with a regular Actor with an
      Image via Actor::set_content(), using Gdk::Pixbuf to load the
      and interrogate image data.
      This use of ClutterImage is based on this Clutter example:
      https://git.gnome.org/browse/clutter/tree/examples/image-content.c?h=clutter-1.18

 configure.ac            |    2 ++
 examples/Makefile.am    |    4 ++--
 examples/test-actors.cc |   38 +++++++++++++++++++++++++++++---------
 3 files changed, 33 insertions(+), 11 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 06b7fae..e37f532 100644
--- a/configure.ac
+++ b/configure.ac
@@ -46,6 +46,8 @@ PKG_CHECK_MODULES([CLUTTERMM], [$CLUTTERMM_MODULES])
 MM_PKG_CONFIG_SUBST([GMMPROC_DIR], [--variable=gmmprocdir glibmm-2.4])
 MM_PKG_CONFIG_SUBST([GMMPROC_EXTRA_M4_DIR], [--variable=gmmprocm4dir pangomm-1.4 atkmm-1.6])
 
+PKG_CHECK_MODULES([CLUTTERMM_EXAMPLES], [$CLUTTERMM_MODULES] gtkmm-3.0 >= 3.10)
+
 MM_ARG_ENABLE_DOCUMENTATION
 MM_ARG_WITH_TAGFILE_DOC([libstdc++.tag], [mm-common-libstdc++])
 MM_ARG_WITH_TAGFILE_DOC([libsigc++-2.0.tag], [sigc++-2.0])
diff --git a/examples/Makefile.am b/examples/Makefile.am
index 6d3f757..658fd2c 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -22,11 +22,11 @@ dist_noinst_DATA = actor.png test-boxes.cc
 local_includes = -I$(top_builddir)/clutter $(if $(srcdir:.=),-I$(top_srcdir)/clutter)
 local_libs = $(top_builddir)/clutter/cluttermm/libcluttermm-$(CLUTTERMM_API_VERSION).la
 
-AM_CPPFLAGS = -I$(top_builddir) $(local_includes) $(CLUTTERMM_CFLAGS)
+AM_CPPFLAGS = -I$(top_builddir) $(local_includes) $(CLUTTERMM_EXAMPLES_CFLAGS)
 AM_CXXFLAGS = $(CLUTTERMM_WXXFLAGS) \
   -DGLIBMM_DISABLE_DEPRECATED -DGIOMM_DISABLE_DEPRECATED -DGTKMM_DISABLE_DEPRECATED 
-DGDKMM_DISABLE_DEPRECATED \
   -DCLUTTERMM_DISABLE_DEPRECATED
-LDADD = $(CLUTTERMM_LIBS) $(local_libs)
+LDADD = $(CLUTTERMM_EXAMPLES_LIBS) $(local_libs)
 
 actors_SOURCES = test-actors.cc
 stage_SOURCES = example-stage.cc
diff --git a/examples/test-actors.cc b/examples/test-actors.cc
index 629f7b6..2df62a4 100644
--- a/examples/test-actors.cc
+++ b/examples/test-actors.cc
@@ -1,4 +1,6 @@
 #include <cluttermm.h>
+#include <gdkmm/wrap_init.h>
+#include <gdkmm/pixbuf.h>
 #include <iostream>
 
 namespace
@@ -77,6 +79,9 @@ void on_new_frame(int frame_num, SuperOH* oh)
 
 int main(int argc, char *argv[])
 {
+  Glib::init(); //Otherwise Gdk::wrap_init() will fail.
+  Gdk::wrap_init(); //TODO: Add a Gdk::init() in gtkmm?
+
   Glib::OptionEntry entry;
   entry.set_short_name('n');
   entry.set_long_name("num-actors");
@@ -129,6 +134,7 @@ int main(int argc, char *argv[])
   // Perhaps that's clutter bug #856.
 
   // Set up some behaviours to handle scaling
+/* TODO:
   Glib::RefPtr<Clutter::Alpha> alpha =
     Clutter::Alpha::create(timeline, Clutter::EASE_IN_SINE);
 
@@ -141,6 +147,7 @@ int main(int argc, char *argv[])
     Clutter::BehaviourScale::create(alpha,
       1.0, 1.0,
       0.5, 0.5);
+*/
 
   // create a new group to hold multiple actors in a group
   oh.group = Clutter::Actor::create();
@@ -150,26 +157,39 @@ int main(int argc, char *argv[])
   {
     int radius = get_radius(stage, num_actors);
 
-    // Create a texture from file, then clone it to save resources
+    // Create an image from a file, then clone it to save resources
     if(i == 0)
     {
+      Glib::RefPtr<Gdk::Pixbuf> pixbuf;
       try
       {
-        Glib::RefPtr<Clutter::Texture> texture(Clutter::Texture::create());
-        texture->set_from_file("actor.png");
-        oh.hands.push_back(texture);
+        pixbuf = Gdk::Pixbuf::create_from_file("actor.png");
+
+        Glib::RefPtr<Clutter::Image> image = Clutter::Image::create();
+        image->set(pixbuf->get_pixels(),
+          (pixbuf->get_has_alpha() ? COGL_PIXEL_FORMAT_RGBA_8888 : COGL_PIXEL_FORMAT_RGB_888),
+          pixbuf->get_width(),
+          pixbuf->get_height(),
+          pixbuf->get_rowstride());
+        Glib::RefPtr<Clutter::Actor> actor = Clutter::Actor::create();
+        actor->set_content(image);
+
+        actor->set_content_scaling_filters(Clutter::SCALING_FILTER_TRILINEAR,
+          Clutter::SCALING_FILTER_LINEAR);
+        //TODO?: actor->set_content_gravity();
+
+        oh.hands.push_back(actor);
       }
       catch(const Glib::Exception& ex)
       {
-        std::cerr << "Could not load texture: " << ex.what() << std::endl;
+        std::cerr << "Could not load pixbuf: " << ex.what() << std::endl;
        return -1;
       }
     }
     else
     {
       oh.hands.push_back(Clutter::Clone::create
-        (Glib::RefPtr<Clutter::Texture>::cast_dynamic
-          (oh.hands[0])));
+        (oh.hands[0]));
     }
 
     // Place around a circle
@@ -186,12 +206,12 @@ int main(int argc, char *argv[])
       - h / 2;
 
     oh.hands[i]->set_position(x, y);
-    oh.hands[i]->move_anchor_point_from_gravity(Clutter::GRAVITY_CENTER);
+    //TODO? oh.hands[i]->move_anchor_point_from_gravity(Clutter::GRAVITY_CENTER);
 
     // Add to our group group
     oh.group->add_child(oh.hands[i]);
 
-#if 1 /* TODO: disabled as causes drift - see comment above */
+#if 0 /* TODO: disabled as causes drift - see comment above */
     if(i % 2)
       scaler_1->apply(oh.hands[i]);
     else


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