gnome-games r8395 - trunk/gnometris



Author: jclinton
Date: Mon Jan  5 06:18:07 2009
New Revision: 8395
URL: http://svn.gnome.org/viewvc/gnome-games?rev=8395&view=rev

Log:
Initial modifications that get actual clutter rendering working.

Modified:
   trunk/gnometris/field.cpp
   trunk/gnometris/field.h
   trunk/gnometris/main.cpp
   trunk/gnometris/preview.cpp
   trunk/gnometris/preview.h
   trunk/gnometris/renderer.cpp
   trunk/gnometris/renderer.h

Modified: trunk/gnometris/field.cpp
==============================================================================
--- trunk/gnometris/field.cpp	(original)
+++ trunk/gnometris/field.cpp	Mon Jan  5 06:18:07 2009
@@ -23,29 +23,31 @@
 #include "blocks.h"
 #include "renderer.h"
 
-#include <libgames-support/games-clutter-embed.h>
+#include <clutter-gtk/gtk-clutter-embed.h>
+#include <clutter-cairo/clutter-cairo.h>
 
 #define FONT "Sans Bold"
 
 Field::Field():
 	BlockOps(),
-	buffer(NULL),
 	background(NULL),
+	foreground(NULL),
 	showPause(false),
 	showGameOver(false),
 	backgroundImage(NULL),
 	backgroundImageTiled(false),
-useBGImage(false),
+	useBGImage(false),
 	backgroundColor(NULL)
 {
 	themeID = 0;
 	renderer = NULL;
 	rendererTheme = -1;
 
-	w = games_clutter_embed_new();
+	w = gtk_clutter_embed_new();
 
 	g_signal_connect (w, "configure_event", G_CALLBACK (configure), this);
-	/* We do our own double-buffering. */
+
+	/* I don't know if this helps or not FIXME */
 	gtk_widget_set_double_buffered(w, FALSE);
 
 	gtk_widget_set_size_request (w, COLUMNS*190/LINES, 190);
@@ -93,8 +95,8 @@
 
 		/* FIXME: This doesn't handle tiled backgrounds in the obvious way. */
 		gdk_cairo_set_source_pixbuf(bg_cr, backgroundImage, 0, 0);
-		xscale = 1.0*gdk_pixbuf_get_width (backgroundImage)/width;
-		yscale = 1.0*gdk_pixbuf_get_height (backgroundImage)/height;
+		xscale = 1.0*gdk_pixbuf_get_width (backgroundImage)/w->allocation.width;
+		yscale = 1.0*gdk_pixbuf_get_height (backgroundImage)/w->allocation.height;
 		cairo_matrix_init_scale (&m, xscale, yscale);
 		cairo_pattern_set_matrix (cairo_get_source (bg_cr), &m);
 	} else if (backgroundColor)
@@ -132,10 +134,10 @@
 {
 	cairo_t *cr;
 
-	cr = gdk_cairo_create (w->window);
+	cr = clutter_cairo_create (CLUTTER_CAIRO(foreground));
 
-	cairo_set_source_surface (cr, buffer, 0, 0);
-	cairo_rectangle (cr, x, y, wd, ht);
+	//cairo_set_source_surface (cr, buffer, 0, 0);
+	//cairo_rectangle (cr, x, y, wd, ht);
 	cairo_fill (cr);
 
 	cairo_destroy (cr);
@@ -195,21 +197,20 @@
 {
 	cairo_t *cr;
 
-	g_return_if_fail(buffer);
-
 	generateTarget ();
 
+	cr = clutter_cairo_create (CLUTTER_CAIRO(foreground));
+
 	if (rendererTheme != themeID) {
 
-	if (renderer)
-		delete renderer;
+		if (renderer)
+			delete renderer;
 
-	renderer = rendererFactory (themeID, buffer, background, field,
-			     COLUMNS, LINES, width, height);
-	rendererTheme = themeID;
+		renderer = rendererFactory (themeID, cairo_get_target(cr), field,
+				     COLUMNS, LINES, width, height);
+		rendererTheme = themeID;
 	} else {
-		renderer->setTarget (buffer);
-		renderer->setBackground (background);
+		renderer->setTarget (cairo_get_target(cr));
 		renderer->data = field;
 		renderer->width = COLUMNS;
 		renderer->height = LINES;
@@ -238,7 +239,7 @@
 	useBGImage = true;
 //	backgroundImageTiled = tiled;
 
-	rescaleBackground ();
+	rescaleField ();
 }
 
 void
@@ -251,7 +252,7 @@
 	}
 	useBGImage = false;
 
-	rescaleBackground ();
+	rescaleField ();
 }
 
 void

Modified: trunk/gnometris/field.h
==============================================================================
--- trunk/gnometris/field.h	(original)
+++ trunk/gnometris/field.h	Mon Jan  5 06:18:07 2009
@@ -50,8 +50,8 @@
 	int width;
 	int height;
 
-	cairo_surface_t *buffer;
-	cairo_surface_t *background;
+	ClutterActor *background;
+	ClutterActor *foreground;
 	cairo_surface_t **blocks;
 
 	bool showPause;
@@ -69,7 +69,7 @@
 	void redrawAll ();
 	void draw (gint x, gint y, gint w, gint h);
 	void draw ();
-	void rescaleBackground ();
+	void rescaleField ();
 	void rescaleBlockCache ();
 
 	static gboolean configure (GtkWidget * widget, GdkEventConfigure * event,

Modified: trunk/gnometris/main.cpp
==============================================================================
--- trunk/gnometris/main.cpp	(original)
+++ trunk/gnometris/main.cpp	Mon Jan  5 06:18:07 2009
@@ -27,7 +27,7 @@
 #include <libgames-support/games-runtime.h>
 
 #ifdef HAVE_CLUTTER
-#include <libgames-support/games-clutter-embed.h>
+#include <clutter-gtk/gtk-clutter-embed.h>
 #endif
 
 #include "tetris.h"
@@ -81,7 +81,7 @@
 	games_conf_initialise ("Gnometris");
 
 #ifdef HAVE_CLUTTER
-        if (games_clutter_init_with_args (NULL, NULL, NULL, NULL, NULL, &error) != CLUTTER_INIT_SUCCESS) {
+        if (gtk_clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS) {
 		g_printerr ("Failed to initialise clutter: %s\n", error->message);
 		g_error_free (error);
 		return 1;

Modified: trunk/gnometris/preview.cpp
==============================================================================
--- trunk/gnometris/preview.cpp	(original)
+++ trunk/gnometris/preview.cpp	Mon Jan  5 06:18:07 2009
@@ -21,7 +21,6 @@
  */
 
 #include "preview.h"
-#include "blocks.h"
 
 #define PREVIEW_WIDTH 6
 #define PREVIEW_HEIGHT 6
@@ -46,7 +45,7 @@
 		}
 	}
 
-	w = gtk_drawing_area_new();
+	w = gtk_clutter_embed_new();
 
 	g_signal_connect (w, "configure_event", G_CALLBACK (configure), this);
 
@@ -71,7 +70,6 @@
 Preview::enable(bool en)
 {
 	enabled = en;
-	gtk_widget_queue_draw (w);
 }
 
 void

Modified: trunk/gnometris/preview.h
==============================================================================
--- trunk/gnometris/preview.h	(original)
+++ trunk/gnometris/preview.h	Mon Jan  5 06:18:07 2009
@@ -25,6 +25,10 @@
 #include "tetris.h"
 #include "blockops.h"
 #include "renderer.h"
+#include "blocks.h"
+
+#include <clutter-gtk/gtk-clutter-embed.h>
+#include <clutter-cairo/clutter-cairo.h>
 
 class Preview {
 public:

Modified: trunk/gnometris/renderer.cpp
==============================================================================
--- trunk/gnometris/renderer.cpp	(original)
+++ trunk/gnometris/renderer.cpp	Mon Jan  5 06:18:07 2009
@@ -52,19 +52,19 @@
 }
 
 Renderer * rendererFactory (gint id, cairo_surface_t *dst,
-			    cairo_surface_t *bg, Block **src, int w,
+			    Block **src, int w,
 			    int h, int pxw, int pxh)
 {
 	switch (id) {
 	case 3:
-		return new TangoBlock (dst, bg, src, w, h, pxw, pxh, TRUE);
+		return new TangoBlock (dst, src, w, h, pxw, pxh, TRUE);
 	case 2:
-		return new TangoBlock (dst, bg, src, w, h, pxw, pxh, FALSE);
+		return new TangoBlock (dst, src, w, h, pxw, pxh, FALSE);
 	case 1:
-		return new JoinedUp (dst, bg, src, w, h, pxw, pxh);
+		return new JoinedUp (dst, src, w, h, pxw, pxh);
 	case 0:
 	default:
-		return new Renderer (dst, bg, src, w, h, pxw, pxh);
+		return new Renderer (dst, src, w, h, pxw, pxh);
 	}
 }
 
@@ -82,11 +82,10 @@
    for the preview widget and possibly the theme previewer, so make no
    assumptions. */
 
-Renderer::Renderer (cairo_surface_t *dst, cairo_surface_t *bg, Block **src,
+Renderer::Renderer (cairo_surface_t *dst, Block **src,
 		    int w, int h, int pxw, int pxh)
 {
 	target = cairo_surface_reference (dst);
-	background = cairo_surface_reference (bg);
 	block_cache = new GnometrisBlockCache(5);
 	data = src;
 	width = w;
@@ -98,7 +97,6 @@
 Renderer::~Renderer ()
 {
 	cairo_surface_destroy (target);
-	cairo_surface_destroy (background);
 }
 
 void Renderer::setTarget (cairo_surface_t * dst)
@@ -107,12 +105,6 @@
 	target = cairo_surface_reference (dst);
 }
 
-void Renderer::setBackground (cairo_surface_t *bg)
-{
-	cairo_surface_destroy (background);
-	background = cairo_surface_reference (bg);
-}
-
 void Renderer::drawCell (cairo_t *cr, gint x, gint y)
 {
 	int i;
@@ -143,12 +135,6 @@
 	cairo_fill (cr);
 }
 
-void Renderer::drawBackground (cairo_t *cr)
-{
-	cairo_set_source_surface (cr, background, 0, 0);
-	cairo_paint (cr);
-}
-
 void Renderer::drawForeground (cairo_t *cr)
 {
 	int x, y;
@@ -168,7 +154,6 @@
 
 	cr = cairo_create (target);
 
-	drawBackground (cr);
 	drawForeground (cr);
 
 	cairo_destroy (cr);
@@ -365,8 +350,8 @@
 
 /*--------------------------------------------------------*/
 
-TangoBlock::TangoBlock (cairo_surface_t * dst, cairo_surface_t * bg, Block ** src,
-	    int w, int h, int pxw, int pxh, gboolean grad) : Renderer (dst, bg, src, w, h, pxw, pxh)
+TangoBlock::TangoBlock (cairo_surface_t * dst, Block ** src,
+	    int w, int h, int pxw, int pxh, gboolean grad) : Renderer (dst, src, w, h, pxw, pxh)
 {
 	usegrads = grad;
 }

Modified: trunk/gnometris/renderer.h
==============================================================================
--- trunk/gnometris/renderer.h	(original)
+++ trunk/gnometris/renderer.h	Mon Jan  5 06:18:07 2009
@@ -39,13 +39,12 @@
 
 class Renderer {
 public:
-	Renderer (cairo_surface_t * dst, cairo_surface_t * bg, Block ** src,
+	Renderer (cairo_surface_t * dst, Block ** src,
 		  int w, int h, int pxw, int pxh);
 	virtual ~ Renderer ();
 	virtual void render ();
 
 	void setTarget (cairo_surface_t *target);
-	void setBackground (cairo_surface_t *background);
 
 	Block **data;
 	int width;
@@ -55,22 +54,20 @@
 protected:
 	GnometrisBlockCache *block_cache;
 	cairo_surface_t *target;
-	cairo_surface_t *background;
 
 	virtual void drawCell (cairo_t * cr, gint x, gint y);
-	virtual void drawBackground (cairo_t * cr);
 	virtual void drawForeground (cairo_t * cr);
 };
 
 Renderer *rendererFactory (gint id, cairo_surface_t * dst,
-			   cairo_surface_t * bg, Block ** src, int w,
+			   Block ** src, int w,
 			   int h, int pxw, int pxh);
 gint themeNameToNumber (const gchar * id);
 
 class JoinedUp:public Renderer {
 public:
-	JoinedUp (cairo_surface_t * dst, cairo_surface_t * bg, Block ** src,
-	int w, int h, int pxw, int pxh):Renderer (dst, bg, src, w, h, pxw,
+	JoinedUp (cairo_surface_t * dst, Block ** src,
+	int w, int h, int pxw, int pxh):Renderer (dst, src, w, h, pxw,
 						  pxh) {}
 protected:
 	virtual void drawCell (cairo_t * cr, gint x, gint y);
@@ -85,7 +82,7 @@
 
 class TangoBlock:public Renderer {
 public:
-	TangoBlock (cairo_surface_t * dst, cairo_surface_t * bg, Block ** src,
+	TangoBlock (cairo_surface_t * dst, Block ** src,
 		    int w, int h, int pxw, int pxh, gboolean grad);
 
 protected:



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