gnome-games r8396 - trunk/gnometris



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

Log:
Most of the way there to working rendering.

Modified:
   trunk/gnometris/field.cpp
   trunk/gnometris/field.h

Modified: trunk/gnometris/field.cpp
==============================================================================
--- trunk/gnometris/field.cpp	(original)
+++ trunk/gnometris/field.cpp	Mon Jan  5 06:18:59 2009
@@ -57,37 +57,65 @@
 
 Field::~Field()
 {
-	if (buffer)
-		cairo_surface_destroy(buffer);
 	if (background)
-		cairo_surface_destroy(background);
+		clutter_actor_destroy(background);
 
 	if (renderer)
 		delete renderer;
 }
 
 void
-Field::rescaleBackground ()
+Field::rescaleField ()
 {
+	ClutterActor *stage;
 	cairo_t *bg_cr;
-	cairo_t *tmp_cr;
 
-	if (!buffer)
-		return;
-
-	tmp_cr = cairo_create (buffer);
-
-	if (background)
-		cairo_surface_destroy(background);
+	if (background) {
+		clutter_actor_set_size (CLUTTER_ACTOR(background),
+					w->allocation.width,
+					w->allocation.height);
+		clutter_cairo_surface_resize (CLUTTER_CAIRO(background),
+					      w->allocation.width,
+					      w->allocation.height);
+	} else {
+		background = clutter_cairo_new (w->allocation.width,
+						w->allocation.height);
+		stage = gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (w));
+		/*FIXMEjclinton: eventually allow solid color background
+		 * for software rendering case */
+		ClutterColor stage_color = { 0x61, 0x64, 0x8c, 0xff };
+		clutter_stage_set_color (CLUTTER_STAGE (stage),
+					 &stage_color);
+		clutter_group_add (CLUTTER_GROUP (stage),
+				   background);
+		clutter_actor_set_position (CLUTTER_ACTOR(background),
+					    0, 0);
+	}
 
-	background =  cairo_surface_create_similar (cairo_get_target (tmp_cr),
-						    CAIRO_CONTENT_COLOR,
-						    w->allocation.width,
-						    w->allocation.height);
+	if (foreground) {
+		clutter_actor_set_size (CLUTTER_ACTOR(foreground),
+					w->allocation.width,
+					w->allocation.height);
+		clutter_cairo_surface_resize (CLUTTER_CAIRO(foreground),
+					      w->allocation.width,
+					      w->allocation.height);
+	} else {
+		foreground = clutter_cairo_new (w->allocation.width,
+						w->allocation.height);
+		stage = gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (w));
+		clutter_group_add (CLUTTER_GROUP (stage),
+				   foreground);
+		clutter_actor_set_position (CLUTTER_ACTOR(foreground),
+					    0, 0);
+		clutter_actor_raise (CLUTTER_ACTOR(foreground),
+				     CLUTTER_ACTOR(background));
+	}
 
-	cairo_destroy (tmp_cr);
 
-	bg_cr = cairo_create (background);
+	bg_cr = clutter_cairo_create (CLUTTER_CAIRO(background));
+	cairo_set_operator (bg_cr, CAIRO_OPERATOR_CLEAR);
+	cairo_paint(bg_cr);
+	cairo_set_operator (bg_cr, CAIRO_OPERATOR_OVER);
 
 	if (useBGImage && backgroundImage) {
 		gdouble xscale, yscale;
@@ -123,33 +151,13 @@
 	field->width = widget->allocation.width;
 	field->height = widget->allocation.height;
 
-	field->rescaleBackground ();
+	field->rescaleField ();
 	field->rescaleBlockCache ();
 
 	return TRUE;
 }
 
 void
-Field::draw (gint x, gint y, gint wd, gint ht)
-{
-	cairo_t *cr;
-
-	cr = clutter_cairo_create (CLUTTER_CAIRO(foreground));
-
-	//cairo_set_source_surface (cr, buffer, 0, 0);
-	//cairo_rectangle (cr, x, y, wd, ht);
-	cairo_fill (cr);
-
-	cairo_destroy (cr);
-}
-
-void
-Field::draw (void)
-{
-  draw (0, 0, width, height);
-}
-
-void
 Field::drawMessage(cairo_t *cr, const char *msg)
 {
 	PangoLayout *dummy_layout;
@@ -220,8 +228,6 @@
 
 	renderer->render ();
 
-	cr = cairo_create(buffer);
-
 	if (showPause)
 		drawMessage(cr, _("Paused"));
 	else if (showGameOver)

Modified: trunk/gnometris/field.h
==============================================================================
--- trunk/gnometris/field.h	(original)
+++ trunk/gnometris/field.h	Mon Jan  5 06:18:59 2009
@@ -66,9 +66,6 @@
 	gint themeID;
 
 	void drawMessage (cairo_t * cr, const char *msg);
-	void redrawAll ();
-	void draw (gint x, gint y, gint w, gint h);
-	void draw ();
 	void rescaleField ();
 	void rescaleBlockCache ();
 



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