From 2e10e2a9aa2617ff30ed74ba4bed216b44e8f877 Mon Sep 17 00:00:00 2001 From: furo Date: Tue, 24 Sep 2024 03:17:46 +0200 Subject: [PATCH] Add "center pivot" for quads --- src/game/editor/editor.cpp | 2 +- src/game/editor/popups.cpp | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/game/editor/editor.cpp b/src/game/editor/editor.cpp index 39e957dab..e4793944e 100644 --- a/src/game/editor/editor.cpp +++ b/src/game/editor/editor.cpp @@ -2154,7 +2154,7 @@ void CEditor::DoQuad(int LayerIndex, const std::shared_ptr &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; diff --git a/src/game/editor/popups.cpp b/src/game/editor/popups.cpp index 6fc4d503c..7cc015834 100644 --- a/src/game/editor/popups.cpp +++ b/src/game/editor/popups.cpp @@ -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);