Add "center pivot" for quads

This commit is contained in:
furo 2024-09-24 03:17:46 +02:00
parent f9df4a85be
commit 2e10e2a9aa
2 changed files with 32 additions and 1 deletions

View file

@ -2154,7 +2154,7 @@ void CEditor::DoQuad(int LayerIndex, const std::shared_ptr<CLayerQuads> &pLayer,
m_SelectedQuadIndex = FindSelectedQuadIndex(Index);
static SPopupMenuId s_PopupQuadId;
Ui()->DoPopupMenu(&s_PopupQuadId, Ui()->MouseX(), Ui()->MouseY(), 120, 198, this, PopupQuad);
Ui()->DoPopupMenu(&s_PopupQuadId, Ui()->MouseX(), Ui()->MouseY(), 120, 222, this, PopupQuad);
Ui()->DisableMouseLock();
}
s_Operation = OP_NONE;

View file

@ -869,6 +869,37 @@ CUi::EPopupMenuFunctionResult CEditor::PopupQuad(void *pContext, CUIRect View, b
}
}
// center pivot button
View.HSplitBottom(6.0f, &View, nullptr);
View.HSplitBottom(12.0f, &View, &Button);
static int s_CenterButton = 0;
if(pEditor->DoButton_Editor(&s_CenterButton, "Center pivot", 0, &Button, 0, "Centers the pivot of the current quad"))
{
pEditor->m_QuadTracker.BeginQuadTrack(pLayer, pEditor->m_vSelectedQuads);
int Top = pCurrentQuad->m_aPoints[0].y;
int Left = pCurrentQuad->m_aPoints[0].x;
int Bottom = pCurrentQuad->m_aPoints[0].y;
int Right = pCurrentQuad->m_aPoints[0].x;
for(int k = 1; k < 4; k++)
{
if(pCurrentQuad->m_aPoints[k].y < Top)
Top = pCurrentQuad->m_aPoints[k].y;
if(pCurrentQuad->m_aPoints[k].x < Left)
Left = pCurrentQuad->m_aPoints[k].x;
if(pCurrentQuad->m_aPoints[k].y > Bottom)
Bottom = pCurrentQuad->m_aPoints[k].y;
if(pCurrentQuad->m_aPoints[k].x > Right)
Right = pCurrentQuad->m_aPoints[k].x;
}
pCurrentQuad->m_aPoints[4].x = Left + (Right - Left) / 2;
pCurrentQuad->m_aPoints[4].y = Top + (Bottom - Top) / 2;
pEditor->m_QuadTracker.EndQuadTrack();
pEditor->m_Map.OnModify();
return CUi::POPUP_CLOSE_CURRENT;
}
// align button
View.HSplitBottom(6.0f, &View, nullptr);
View.HSplitBottom(12.0f, &View, &Button);