about summary refs log tree commit diff
path: root/src/game/editor/ed_layer_tiles.cpp
diff options
context:
space:
mode:
authoroy <Tom_Adams@web.de>2010-09-05 19:01:01 +0200
committeroy <Tom_Adams@web.de>2010-09-05 19:01:01 +0200
commit995d63d7f447d68771f0ea87a599a0d804cff8d3 (patch)
treecdf596cc646d6ac5ce002e84bcf5b7e1bf1d5630 /src/game/editor/ed_layer_tiles.cpp
parent5588e1ec8caff39e2a21ce6d9d7c13c5f4d603f1 (diff)
downloadzcatch-995d63d7f447d68771f0ea87a599a0d804cff8d3.tar.gz
zcatch-995d63d7f447d68771f0ea87a599a0d804cff8d3.zip
added the possibility to rotate tiles in the editor by SushiTee
Diffstat (limited to 'src/game/editor/ed_layer_tiles.cpp')
-rw-r--r--src/game/editor/ed_layer_tiles.cpp40
1 files changed, 37 insertions, 3 deletions
diff --git a/src/game/editor/ed_layer_tiles.cpp b/src/game/editor/ed_layer_tiles.cpp
index e7751d09..6f1fc85e 100644
--- a/src/game/editor/ed_layer_tiles.cpp
+++ b/src/game/editor/ed_layer_tiles.cpp
@@ -32,7 +32,7 @@ void CLayerTiles::PrepareForSave()
 {
 	for(int y = 0; y < m_Height; y++)
 		for(int x = 0; x < m_Width; x++)
-			m_pTiles[y*m_Width+x].m_Flags &= TILEFLAG_VFLIP|TILEFLAG_HFLIP;
+			m_pTiles[y*m_Width+x].m_Flags &= TILEFLAG_VFLIP|TILEFLAG_HFLIP|TILEFLAG_ROTATE;
 
 	if(m_Image != -1)
 	{
@@ -206,7 +206,7 @@ void CLayerTiles::BrushFlipX()
 
 	for(int y = 0; y < m_Height; y++)
 		for(int x = 0; x < m_Width; x++)
-			m_pTiles[y*m_Width+x].m_Flags ^= TILEFLAG_VFLIP;
+			m_pTiles[y*m_Width+x].m_Flags ^= m_pTiles[y*m_Width+x].m_Flags&TILEFLAG_ROTATE ? TILEFLAG_HFLIP : TILEFLAG_VFLIP;
 }
 
 void CLayerTiles::BrushFlipY()
@@ -221,7 +221,41 @@ void CLayerTiles::BrushFlipY()
 
 	for(int y = 0; y < m_Height; y++)
 		for(int x = 0; x < m_Width; x++)
-			m_pTiles[y*m_Width+x].m_Flags ^= TILEFLAG_HFLIP;
+			m_pTiles[y*m_Width+x].m_Flags ^= m_pTiles[y*m_Width+x].m_Flags&TILEFLAG_ROTATE ? TILEFLAG_VFLIP : TILEFLAG_HFLIP;
+}
+
+void CLayerTiles::BrushRotate(float Amount)
+{
+	int Rotation = (round(360.0f*Amount/(pi*2))/90)%4;	// 0=0°, 1=90°, 2=180°, 3=270°
+	if(Rotation < 0)
+		Rotation +=4;
+
+	if(Rotation == 1 || Rotation == 3)
+	{
+		// 90° rotation
+		CTile *pTempData = new CTile[m_Width*m_Height];
+		mem_copy(pTempData, m_pTiles, m_Width*m_Height*sizeof(CTile));
+		CTile *pDst = m_pTiles;
+		for(int x = 0; x < m_Width; ++x)
+			for(int y = m_Height-1; y >= 0; --y, ++pDst)
+			{
+				*pDst = pTempData[y*m_Width+x];
+				if(pDst->m_Flags&TILEFLAG_ROTATE)
+					pDst->m_Flags ^= (TILEFLAG_HFLIP|TILEFLAG_VFLIP);
+				pDst->m_Flags ^= TILEFLAG_ROTATE;
+			}
+
+		int Temp = m_Width;
+		m_Width = m_Height;
+		m_Height = Temp;
+		delete[] pTempData;
+	}
+
+	if(Rotation == 2 || Rotation == 3)
+	{
+		BrushFlipX();
+		BrushFlipY();
+	}
 }
 
 void CLayerTiles::Resize(int NewW, int NewH)