gnome-games r8667 - trunk/gnometris



Author: jclinton
Date: Fri Feb  6 16:57:10 2009
New Revision: 8667
URL: http://svn.gnome.org/viewvc/gnome-games?rev=8667&view=rev

Log:
Reinstitute color tracking in the Block class

This change enables the rescaleBlockPos function to access the correct
cache object when recloning the textures (done to ensure that the theme
is correctly updated.)

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

Modified: trunk/gnometris/blockops.cpp
==============================================================================
--- trunk/gnometris/blockops.cpp	(original)
+++ trunk/gnometris/blockops.cpp	Fri Feb  6 16:57:10 2009
@@ -55,6 +55,7 @@
 {
 	if (this != &b) {
 		what = b.what;
+		color = b.color;
 		if (actor) {
 			clutter_actor_destroy (CLUTTER_ACTOR(actor));
 		}
@@ -259,9 +260,8 @@
 			field[x][y - 1].actor = NULL;
 		}
 	}
-	ClutterActor *stage;
-	stage = games_clutter_embed_get_stage (GAMES_CLUTTER_EMBED (w));
-	rescaleBlockPos (stage);
+	//FIXME remove me once we animate this
+	rescaleBlockPos ();
 }
 
 int
@@ -347,9 +347,10 @@
 
 			if ((y>=(LINES - filled_lines)) && (x != blank) &&
 			    ((g_random_int_range(0, 10)) < fill_prob)) {
+				guint tmpColor = g_random_int_range(0, NCOLOURS);
 				field[x][y].what = LAYING;
-				field[x][y].createActor (stage, renderer->getCacheCellById
-							 (g_random_int_range(0, NCOLOURS)));
+				field[x][y].color = tmpColor;
+				field[x][y].createActor (stage, renderer->getCacheCellById (tmpColor));
 				clutter_actor_set_position (CLUTTER_ACTOR(field[x][y].actor),
 							    x*(cell_height), y*(cell_height));
 			}
@@ -377,9 +378,10 @@
 				int j = y + by;
 
 				field[i][j].what = fill;
+				field[i][j].color = color;
 				if ((fill == FALLING) || (fill == LAYING)) {
-					field[i][j].createActor (stage, renderer->getCacheCellById
-								 (color));
+					field[i][j].createActor (stage,
+								 renderer->getCacheCellById (color));
 					clutter_actor_set_position (CLUTTER_ACTOR(field[i][j].actor),
 								    i*(cell_height), j*(cell_height));
 				} else {
@@ -434,13 +436,16 @@
 }
 
 void
-BlockOps::rescaleBlockPos (ClutterActor* stage)
+BlockOps::rescaleBlockPos ()
 {
 	for (int y = 0; y < LINES; ++y) {
 		for (int x = 0; x < COLUMNS; ++x) {
-			if (field[x][y].actor)
+			if (field[x][y].actor) {
 				clutter_actor_set_position (CLUTTER_ACTOR(field[x][y].actor),
 							    x*(cell_height), y*(cell_height));
+				clutter_clone_texture_set_parent_texture (CLUTTER_CLONE_TEXTURE(field[x][y].actor),
+									  CLUTTER_TEXTURE(renderer->getCacheCellById (field[x][y].color)));
+			}
 		}
 	}
 }
@@ -476,7 +481,7 @@
 					    0, 0);
 	}
 
-	rescaleBlockPos (stage);
+	rescaleBlockPos ();
 
 	if (foreground) {
 		clutter_actor_set_size (CLUTTER_ACTOR(foreground),
@@ -643,4 +648,5 @@
 		renderer = rendererFactory (themeID, cell_width,
 					    cell_height);
 	}
+	rescaleBlockPos();
 }

Modified: trunk/gnometris/blockops.h
==============================================================================
--- trunk/gnometris/blockops.h	(original)
+++ trunk/gnometris/blockops.h	Fri Feb  6 16:57:10 2009
@@ -41,6 +41,7 @@
 	Block& operator=(const Block& b);
 
 	SlotType what;
+	guint color;
 	ClutterActor* actor;
 
 	void createActor (ClutterActor* chamber, ClutterActor* texture_source);
@@ -112,7 +113,7 @@
 	GdkColor *backgroundColor;
 
 	void rescaleField ();
-	void rescaleBlockPos (ClutterActor *stage);
+	void rescaleBlockPos ();
 
 	int posx;
 	int posy;



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