diff options
| author | oy <Tom_Adams@web.de> | 2010-09-05 19:01:01 +0200 |
|---|---|---|
| committer | oy <Tom_Adams@web.de> | 2010-09-05 19:01:01 +0200 |
| commit | 995d63d7f447d68771f0ea87a599a0d804cff8d3 (patch) | |
| tree | cdf596cc646d6ac5ce002e84bcf5b7e1bf1d5630 /src/game/editor | |
| parent | 5588e1ec8caff39e2a21ce6d9d7c13c5f4d603f1 (diff) | |
| download | zcatch-995d63d7f447d68771f0ea87a599a0d804cff8d3.tar.gz zcatch-995d63d7f447d68771f0ea87a599a0d804cff8d3.zip | |
added the possibility to rotate tiles in the editor by SushiTee
Diffstat (limited to 'src/game/editor')
| -rw-r--r-- | src/game/editor/ed_editor.cpp | 19 | ||||
| -rw-r--r-- | src/game/editor/ed_editor.h | 3 | ||||
| -rw-r--r-- | src/game/editor/ed_layer_tiles.cpp | 40 |
3 files changed, 53 insertions, 9 deletions
diff --git a/src/game/editor/ed_editor.cpp b/src/game/editor/ed_editor.cpp index aa6b7829..7046f1c4 100644 --- a/src/game/editor/ed_editor.cpp +++ b/src/game/editor/ed_editor.cpp @@ -463,7 +463,7 @@ void CEditor::RenderBackground(CUIRect View, int Texture, float Size, float Brig Graphics()->QuadsEnd(); } -int CEditor::UiDoValueSelector(void *pId, CUIRect *r, const char *pLabel, int Current, int Min, int Max, float Scale, const char *pToolTip) +int CEditor::UiDoValueSelector(void *pId, CUIRect *r, const char *pLabel, int Current, int Min, int Max, int Step, float Scale, const char *pToolTip) { // logic static float s_Value; @@ -490,7 +490,7 @@ int CEditor::UiDoValueSelector(void *pId, CUIRect *r, const char *pLabel, int Cu { int Count = (int)(s_Value/Scale); s_Value = fmod(s_Value, Scale); - Current += Count; + Current += Step*Count; if(Current < Min) Current = Min; if(Current > Max) @@ -731,7 +731,16 @@ void CEditor::DoToolbar(CUIRect ToolBar) TB_Top.VSplitLeft(30.0f, &Button, &TB_Top); static int s_RotationAmount = 90; - s_RotationAmount = UiDoValueSelector(&s_RotationAmount, &Button, "", s_RotationAmount, 1, 360, 2.0f, Localize("Rotation of the brush in degrees. Use left mouse button to drag and change the value. Hold shift to be more precise.")); + bool TileLayer = false; + // check for tile layers in brush selection + for(int i = 0; i < m_Brush.m_lLayers.size(); i++) + if(m_Brush.m_lLayers[i]->m_Type == LAYERTYPE_TILES) + { + TileLayer = true; + s_RotationAmount = max(90, (s_RotationAmount/90)*90); + break; + } + s_RotationAmount = UiDoValueSelector(&s_RotationAmount, &Button, "", s_RotationAmount, TileLayer?90:1, 360, TileLayer?90:1, TileLayer?10.0f:2.0f, Localize("Rotation of the brush in degrees. Use left mouse button to drag and change the value. Hold shift to be more precise.")); TB_Top.VSplitLeft(5.0f, &Button, &TB_Top); TB_Top.VSplitLeft(30.0f, &Button, &TB_Top); @@ -1608,7 +1617,7 @@ int CEditor::DoProperties(CUIRect *pToolBox, CProperty *pProps, int *pIds, int * } else if(pProps[i].m_Type == PROPTYPE_INT_SCROLL) { - int NewValue = UiDoValueSelector(&pIds[i], &Shifter, "", pProps[i].m_Value, pProps[i].m_Min, pProps[i].m_Max, 1.0f, Localize("Use left mouse button to drag and change the value. Hold shift to be more precise.")); + int NewValue = UiDoValueSelector(&pIds[i], &Shifter, "", pProps[i].m_Value, pProps[i].m_Min, pProps[i].m_Max, 1, 1.0f, Localize("Use left mouse button to drag and change the value. Hold shift to be more precise.")); if(NewValue != pProps[i].m_Value) { *pNewVal = NewValue; @@ -1624,7 +1633,7 @@ int CEditor::DoProperties(CUIRect *pToolBox, CProperty *pProps, int *pIds, int * for(int c = 0; c < 4; c++) { int v = (pProps[i].m_Value >> s_aShift[c])&0xff; - NewColor |= UiDoValueSelector(((char *)&pIds[i])+c, &Shifter, s_paTexts[c], v, 0, 255, 1.0f, Localize("Use left mouse button to drag and change the color value. Hold shift to be more precise."))<<s_aShift[c]; + NewColor |= UiDoValueSelector(((char *)&pIds[i])+c, &Shifter, s_paTexts[c], v, 0, 255, 1, 1.0f, Localize("Use left mouse button to drag and change the color value. Hold shift to be more precise."))<<s_aShift[c]; if(c != 3) { diff --git a/src/game/editor/ed_editor.h b/src/game/editor/ed_editor.h index bbc3c45f..95491ccd 100644 --- a/src/game/editor/ed_editor.h +++ b/src/game/editor/ed_editor.h @@ -369,6 +369,7 @@ public: virtual void BrushDraw(CLayer *pBrush, float wx, float wy); virtual void BrushFlipX(); virtual void BrushFlipY(); + virtual void BrushRotate(float Amount); virtual int RenderProperties(CUIRect *pToolbox); @@ -576,7 +577,7 @@ public: void UiInvokePopupMenu(void *pId, int Flags, float x, float y, float w, float h, int (*pfnFunc)(CEditor *pEditor, CUIRect Rect), void *pExtra=0); void UiDoPopupMenu(); - int UiDoValueSelector(void *pId, CUIRect *r, const char *pLabel, int Current, int Min, int Max, float Scale, const char *pToolTip); + int UiDoValueSelector(void *pId, CUIRect *r, const char *pLabel, int Current, int Min, int Max, int Step, float Scale, const char *pToolTip); static int PopupGroup(CEditor *pEditor, CUIRect View); static int PopupLayer(CEditor *pEditor, CUIRect View); 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) |