about summary refs log tree commit diff
path: root/src/editor
diff options
context:
space:
mode:
authorMagnus Auvinen <magnus.auvinen@gmail.com>2007-10-28 23:14:18 +0000
committerMagnus Auvinen <magnus.auvinen@gmail.com>2007-10-28 23:14:18 +0000
commita33870845628fea75c96e4b3acebca0a2cd10f7a (patch)
treea34ed282e9acc39091aec7fe2af4adef93aa8fa5 /src/editor
parentdab34697e79f5d6a97462b24249ef7c5b0f1813a (diff)
downloadzcatch-a33870845628fea75c96e4b3acebca0a2cd10f7a.tar.gz
zcatch-a33870845628fea75c96e4b3acebca0a2cd10f7a.zip
fixed support for flipped tiles
Diffstat (limited to 'src/editor')
-rw-r--r--src/editor/editor.cpp62
1 files changed, 57 insertions, 5 deletions
diff --git a/src/editor/editor.cpp b/src/editor/editor.cpp
index 6d6cea57..c35bb08c 100644
--- a/src/editor/editor.cpp
+++ b/src/editor/editor.cpp
@@ -154,6 +154,37 @@ static void tilemap_destroy(tilemap *tm)
 	tm->height = 0;
 }
 
+static void tilemap_vflip(tilemap *tm)
+{
+	for(int iy = 0; iy < tm->height; iy++)
+		for(int ix = 0; ix < tm->width/2; ix++)
+		{
+			tile tmp = tm->tiles[iy*tm->width+ix];
+			tm->tiles[iy*tm->width+ix] = tm->tiles[iy*tm->width+tm->width-ix-1];
+			tm->tiles[iy*tm->width+tm->width-ix-1] = tmp;
+		}
+		
+	for(int iy = 0; iy < tm->height; iy++)
+		for(int ix = 0; ix < tm->width; ix++)
+			tm->tiles[iy*tm->width+ix].flags ^= TILEFLAG_VFLIP;
+
+}
+
+static void tilemap_hflip(tilemap *tm)
+{
+	for(int iy = 0; iy < tm->height/2; iy++)
+		for(int ix = 0; ix < tm->width; ix++)
+		{
+			tile tmp = tm->tiles[iy*tm->width+ix];
+			tm->tiles[iy*tm->width+ix] = tm->tiles[tm->height*tm->width-tm->width-tm->width*iy+ix];
+			tm->tiles[tm->height*tm->width-tm->width-tm->width*iy+ix] = tmp;
+		}
+
+	for(int iy = 0; iy < tm->height; iy++)
+		for(int ix = 0; ix < tm->width; ix++)
+			tm->tiles[iy*tm->width+ix].flags ^= TILEFLAG_HFLIP;
+}
+
 static int tilemap_blit(tilemap *dst, tilemap *src, int x, int y)
 {
 	int count = 0;
@@ -353,13 +384,28 @@ static void render_tilemap(tilemap *tm, float sx, float sy, float scale)
 		for(int x = 0; x < tm->width; x++)
 		{
 			unsigned char d = tm->tiles[y*tm->width+x].index;
+			unsigned char f = tm->tiles[y*tm->width+x].flags;
 			if(d)
 			{
-				gfx_quads_setsubset(
-					(d%16)/16.0f+frac,
-					(d/16)/16.0f+frac,
-					(d%16)/16.0f+1.0f/16.0f-frac,
-					(d/16)/16.0f+1.0f/16.0f-frac);
+				float u0 = (d%16)/16.0f+frac;
+				float v0 = (d/16)/16.0f+frac;
+				float u1 = (d%16)/16.0f+1.0f/16.0f-frac;
+				float v1 = (d/16)/16.0f+1.0f/16.0f-frac;
+				if(f&TILEFLAG_VFLIP)
+				{
+					float tmp = u0;
+					u0 = u1;
+					u1 = tmp;
+				}
+
+				if(f&TILEFLAG_HFLIP)
+				{
+					float tmp = v0;
+					v0 = v1;
+					v1 = tmp;
+				}
+				
+				gfx_quads_setsubset(u0,v0,u1,v1);
 				gfx_quads_drawTL(sx+x*scale, sy+y*scale, scale, scale);
 			}
 
@@ -861,6 +907,12 @@ static void editor_render()
 			if(ui_mouse_button(1) || inp_key_pressed('C'))
 				tilemap_destroy(&brush);
 		}
+
+		// flip buttons
+		if(inp_key_down('N') && brush.tiles)
+			tilemap_vflip(&brush);
+		if(inp_key_down('M') && brush.tiles)
+			tilemap_hflip(&brush);
 		
 		if(inp_key_pressed(KEY_SPACE))
 		{