[gnome-games] Second pass at getting Gnometris to render with new Clutter master API
- From: Jason Clinton <jclinton src gnome org>
- To: svn-commits-list gnome org
- Subject: [gnome-games] Second pass at getting Gnometris to render with new Clutter master API
- Date: Mon, 15 Jun 2009 19:20:59 -0400 (EDT)
commit 1d7c24d4954b100ff163915290d78f22fe51e41e
Author: Jason D. Clinton <me jasonclinton com>
Date: Mon Jun 15 18:18:37 2009 -0500
Second pass at getting Gnometris to render with new Clutter master API
Upstream no longers allow clones for off-screen Actors that haven't been
parented yet. So, instead, as a first attempt, the cache is now an array
of cairo_surface_t's which can be copied in to each actor's cache. This
is less-than-ideal as the old way was extremely memory efficient.
gnometris/blockops.cpp | 12 ++++++++++--
gnometris/blockops.h | 2 +-
gnometris/renderer.cpp | 23 ++++++++++++-----------
gnometris/renderer.h | 5 ++---
4 files changed, 25 insertions(+), 17 deletions(-)
---
diff --git a/gnometris/blockops.cpp b/gnometris/blockops.cpp
index d18fa1e..385bfdc 100644
--- a/gnometris/blockops.cpp
+++ b/gnometris/blockops.cpp
@@ -51,11 +51,19 @@ Block::~Block ()
}
void
-Block::createActor (ClutterActor *chamber, ClutterActor *texture_source)
+Block::createActor (ClutterActor *chamber, cairo_surface_t *texture_source)
{
if (actor)
clutter_actor_destroy (CLUTTER_ACTOR(actor));
- actor = clutter_clone_new (CLUTTER_ACTOR(texture_source));
+ actor = clutter_texture_new ();
+ // FIXME jclinton ... this should really be cluttercairo somehow for efficiency
+ clutter_texture_set_from_rgb_data (CLUTTER_TEXTURE(actor),
+ cairo_image_surface_get_data(texture_source),
+ TRUE,
+ cairo_image_surface_get_width(texture_source),
+ cairo_image_surface_get_height(texture_source),
+ cairo_image_surface_get_stride(texture_source),
+ 32, CLUTTER_TEXTURE_NONE, NULL);
clutter_group_add (CLUTTER_GROUP (chamber), actor);
clutter_actor_set_position (CLUTTER_ACTOR(actor), x, y);
clutter_actor_show (CLUTTER_ACTOR(actor));
diff --git a/gnometris/blockops.h b/gnometris/blockops.h
index 85909fe..54ea06c 100644
--- a/gnometris/blockops.h
+++ b/gnometris/blockops.h
@@ -46,7 +46,7 @@ public:
int x;
int y;
- void createActor (ClutterActor *chamber, ClutterActor *texture_source);
+ void createActor (ClutterActor *chamber, cairo_surface_t *texture_source);
void bindAnimations (BlockOps *f);
/* Every block will have a unique position
diff --git a/gnometris/renderer.cpp b/gnometris/renderer.cpp
index d488996..ccbc29c 100644
--- a/gnometris/renderer.cpp
+++ b/gnometris/renderer.cpp
@@ -95,11 +95,11 @@ Renderer::~Renderer ()
{
for (int i = 0; i<NCOLOURS; i++) {
if (cache[i])
- clutter_actor_destroy (CLUTTER_ACTOR(cache[i]));
+ cairo_surface_destroy (cache[i]);
}
}
-ClutterActor* Renderer::getCacheCellById (gint id)
+cairo_surface_t* Renderer::getCacheCellById (gint id)
{
return cache[id];
}
@@ -114,20 +114,21 @@ void Renderer::rescaleCache (gint x, gint y)
if(cache[0]) {
for (int i = 0; i<NCOLOURS; i++) {
- clutter_actor_set_size (CLUTTER_ACTOR(cache[i]),
- pxwidth, pxheight);
- clutter_cairo_texture_set_surface_size (CLUTTER_CAIRO_TEXTURE(cache[i]),
- pxwidth, pxheight);
- cairo_t *cr = clutter_cairo_texture_create (CLUTTER_CAIRO_TEXTURE(cache[i]));
- cairo_scale(cr, 1.0 * pxwidth, 1.0 * pxheight);
+ g_object_unref (cache[i]);
+ cache[i] = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
+ pxwidth,
+ pxheight);
+ cairo_t *cr = cairo_create (cache[i]);
+ cairo_scale (cr, 1.0 * pxwidth, 1.0 * pxheight);
drawCell (cr, i);
cairo_destroy (cr);
}
} else {
for (int i = 0; i<NCOLOURS; i++) {
- cache[i] = clutter_cairo_texture_new (pxwidth, pxheight);
- cairo_t *cr = clutter_cairo_texture_create (CLUTTER_CAIRO_TEXTURE(cache[i]));
- cairo_scale(cr, 1.0 * pxwidth, 1.0 * pxheight);
+ cache[i] = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
+ pxwidth, pxheight);
+ cairo_t *cr = cairo_create (cache[i]);
+ cairo_scale (cr, 1.0 * pxwidth, 1.0 * pxheight);
drawCell (cr, i);
cairo_destroy (cr);
}
diff --git a/gnometris/renderer.h b/gnometris/renderer.h
index c647634..920daea 100644
--- a/gnometris/renderer.h
+++ b/gnometris/renderer.h
@@ -26,7 +26,6 @@
#include <cairo.h>
#include <glib.h>
-#include <clutter/clutter.h>
#include "blocks.h"
#include "tetris.h"
@@ -44,12 +43,12 @@ public:
virtual ~ Renderer ();
void rescaleCache (gint pxw, gint pxh);
- ClutterActor* getCacheCellById (gint id);
+ cairo_surface_t* getCacheCellById (gint id);
gint pxwidth;
gint pxheight;
protected:
- ClutterActor* cache[NCOLOURS];
+ cairo_surface_t* cache[NCOLOURS];
virtual void drawCell (cairo_t * cr, guint color);
};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]