mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
added the possibility to rotate tiles in the editor by SushiTee
This commit is contained in:
parent
5588e1ec8c
commit
995d63d7f4
|
@ -244,26 +244,46 @@ void CRenderTools::RenderTilemap(CTile *pTiles, int w, int h, float Scale, vec4
|
|||
int Px1 = Px0+(1024/16)-1;
|
||||
int Py1 = Py0+(1024/16)-1;
|
||||
|
||||
float u0 = Nudge + Px0/TexSize+Frac;
|
||||
float v0 = Nudge + Py0/TexSize+Frac;
|
||||
float u1 = Nudge + Px1/TexSize-Frac;
|
||||
float v1 = Nudge + Py1/TexSize-Frac;
|
||||
float x0 = Nudge + Px0/TexSize+Frac;
|
||||
float y0 = Nudge + Py0/TexSize+Frac;
|
||||
float x1 = Nudge + Px1/TexSize-Frac;
|
||||
float y1 = Nudge + Py0/TexSize+Frac;
|
||||
float x2 = Nudge + Px1/TexSize-Frac;
|
||||
float y2 = Nudge + Py1/TexSize-Frac;
|
||||
float x3 = Nudge + Px0/TexSize+Frac;
|
||||
float y3 = Nudge + Py1/TexSize-Frac;
|
||||
|
||||
if(Flags&TILEFLAG_VFLIP)
|
||||
{
|
||||
float Tmp = u0;
|
||||
u0 = u1;
|
||||
u1 = Tmp;
|
||||
x0 = x2;
|
||||
x1 = x3;
|
||||
x2 = x3;
|
||||
x3 = x0;
|
||||
}
|
||||
|
||||
if(Flags&TILEFLAG_HFLIP)
|
||||
{
|
||||
float Tmp = v0;
|
||||
v0 = v1;
|
||||
v1 = Tmp;
|
||||
y0 = y3;
|
||||
y2 = y1;
|
||||
y3 = y1;
|
||||
y1 = y0;
|
||||
}
|
||||
|
||||
Graphics()->QuadsSetSubset(u0,v0,u1,v1);
|
||||
if(Flags&TILEFLAG_ROTATE)
|
||||
{
|
||||
float Tmp = x0;
|
||||
x0 = x3;
|
||||
x3 = x2;
|
||||
x2 = x1;
|
||||
x1 = Tmp;
|
||||
Tmp = y0;
|
||||
y0 = y3;
|
||||
y3 = y2;
|
||||
y2 = y1;
|
||||
y1 = Tmp;
|
||||
}
|
||||
|
||||
Graphics()->QuadsSetSubsetFree(x0, y0, x1, y1, x2, y2, x3, y3);
|
||||
IGraphics::CQuadItem QuadItem(x*Scale, y*Scale, Scale, Scale);
|
||||
Graphics()->QuadsDrawTL(&QuadItem, 1);
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -48,6 +48,7 @@ enum
|
|||
TILEFLAG_VFLIP=1,
|
||||
TILEFLAG_HFLIP=2,
|
||||
TILEFLAG_OPAQUE=4,
|
||||
TILEFLAG_ROTATE=8,
|
||||
|
||||
LAYERFLAG_DETAIL=1,
|
||||
|
||||
|
|
Loading…
Reference in a new issue