mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-19 14:38:18 +00:00
Reduce duplicate code by moving it outside of branches
This commit is contained in:
parent
d35975c9b9
commit
5425708b27
|
@ -1469,14 +1469,13 @@ void CEditor::DoQuad(CQuad *pQuad, int Index)
|
|||
}
|
||||
else if(s_Operation == OP_MOVE_ALL)
|
||||
{
|
||||
CLayerQuads *pLayer = (CLayerQuads *)GetSelectedLayerType(0, LAYERTYPE_QUADS);
|
||||
float x = wx;
|
||||
float y = wy;
|
||||
// move all points including pivot
|
||||
if(m_GridActive && !IgnoreGrid)
|
||||
{
|
||||
int LineDistance = GetLineDistance();
|
||||
|
||||
float x = 0.0f;
|
||||
float y = 0.0f;
|
||||
if(wx >= 0)
|
||||
x = (int)((wx + (LineDistance / 2) * m_GridFactor) / (LineDistance * m_GridFactor)) * (LineDistance * m_GridFactor);
|
||||
else
|
||||
|
@ -1485,10 +1484,12 @@ void CEditor::DoQuad(CQuad *pQuad, int Index)
|
|||
y = (int)((wy + (LineDistance / 2) * m_GridFactor) / (LineDistance * m_GridFactor)) * (LineDistance * m_GridFactor);
|
||||
else
|
||||
y = (int)((wy - (LineDistance / 2) * m_GridFactor) / (LineDistance * m_GridFactor)) * (LineDistance * m_GridFactor);
|
||||
}
|
||||
|
||||
int OffsetX = f2fx(x) - pQuad->m_aPoints[4].x;
|
||||
int OffsetY = f2fx(y) - pQuad->m_aPoints[4].y;
|
||||
|
||||
CLayerQuads *pLayer = (CLayerQuads *)GetSelectedLayerType(0, LAYERTYPE_QUADS);
|
||||
for(auto &Selected : m_vSelectedQuads)
|
||||
{
|
||||
CQuad *pCurrentQuad = &pLayer->m_vQuads[Selected];
|
||||
|
@ -1499,22 +1500,6 @@ void CEditor::DoQuad(CQuad *pQuad, int Index)
|
|||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int OffsetX = f2fx(wx) - pQuad->m_aPoints[4].x;
|
||||
int OffsetY = f2fx(wy) - pQuad->m_aPoints[4].y;
|
||||
|
||||
for(auto &Selected : m_vSelectedQuads)
|
||||
{
|
||||
CQuad *pCurrentQuad = &pLayer->m_vQuads[Selected];
|
||||
for(auto &Point : pCurrentQuad->m_aPoints)
|
||||
{
|
||||
Point.x += OffsetX;
|
||||
Point.y += OffsetY;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(s_Operation == OP_ROTATE)
|
||||
{
|
||||
CLayerQuads *pLayer = (CLayerQuads *)GetSelectedLayerType(0, LAYERTYPE_QUADS);
|
||||
|
@ -1700,13 +1685,12 @@ void CEditor::DoQuadPoint(CQuad *pQuad, int QuadIndex, int V)
|
|||
{
|
||||
if(s_Operation == OP_MOVEPOINT)
|
||||
{
|
||||
CLayerQuads *pLayer = (CLayerQuads *)GetSelectedLayerType(0, LAYERTYPE_QUADS);
|
||||
float x = wx;
|
||||
float y = wy;
|
||||
if(m_GridActive && !IgnoreGrid)
|
||||
{
|
||||
int LineDistance = GetLineDistance();
|
||||
|
||||
float x = 0.0f;
|
||||
float y = 0.0f;
|
||||
if(wx >= 0)
|
||||
x = (int)((wx + (LineDistance / 2) * m_GridFactor) / (LineDistance * m_GridFactor)) * (LineDistance * m_GridFactor);
|
||||
else
|
||||
|
@ -1715,30 +1699,17 @@ void CEditor::DoQuadPoint(CQuad *pQuad, int QuadIndex, int V)
|
|||
y = (int)((wy + (LineDistance / 2) * m_GridFactor) / (LineDistance * m_GridFactor)) * (LineDistance * m_GridFactor);
|
||||
else
|
||||
y = (int)((wy - (LineDistance / 2) * m_GridFactor) / (LineDistance * m_GridFactor)) * (LineDistance * m_GridFactor);
|
||||
}
|
||||
|
||||
int OffsetX = f2fx(x) - pQuad->m_aPoints[V].x;
|
||||
int OffsetY = f2fx(y) - pQuad->m_aPoints[V].y;
|
||||
|
||||
CLayerQuads *pLayer = (CLayerQuads *)GetSelectedLayerType(0, LAYERTYPE_QUADS);
|
||||
for(auto &Selected : m_vSelectedQuads)
|
||||
{
|
||||
CQuad *pCurrentQuad = &pLayer->m_vQuads[Selected];
|
||||
for(int m = 0; m < 4; m++)
|
||||
if(m_SelectedPoints & (1 << m))
|
||||
{
|
||||
pCurrentQuad->m_aPoints[m].x += OffsetX;
|
||||
pCurrentQuad->m_aPoints[m].y += OffsetY;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int OffsetX = f2fx(wx) - pQuad->m_aPoints[V].x;
|
||||
int OffsetY = f2fx(wy) - pQuad->m_aPoints[V].y;
|
||||
|
||||
for(auto &Selected : m_vSelectedQuads)
|
||||
{
|
||||
CQuad *pCurrentQuad = &pLayer->m_vQuads[Selected];
|
||||
for(int m = 0; m < 4; m++)
|
||||
if(m_SelectedPoints & (1 << m))
|
||||
{
|
||||
pCurrentQuad->m_aPoints[m].x += OffsetX;
|
||||
|
|
Loading…
Reference in a new issue