mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-20 06:58:20 +00:00
Merge pull request #7956 from archimede67/editor-fix-quads
Editor: fix several quads related issues
This commit is contained in:
commit
a7bbcf00a6
|
@ -319,7 +319,7 @@ int CEditor::DoButton_DraggableEx(const void *pID, const char *pText, int Checke
|
|||
return UI()->DoDraggableButtonLogic(pID, Checked, pRect, pClicked, pAbrupted);
|
||||
}
|
||||
|
||||
void CEditor::RenderBackground(CUIRect View, IGraphics::CTextureHandle Texture, float Size, float Brightness)
|
||||
void CEditor::RenderBackground(CUIRect View, IGraphics::CTextureHandle Texture, float Size, float Brightness) const
|
||||
{
|
||||
Graphics()->TextureSet(Texture);
|
||||
Graphics()->BlendNormal();
|
||||
|
@ -1547,7 +1547,7 @@ void CEditor::DoPointDrag(const std::shared_ptr<CLayerQuads> &pLayer, CQuad *pQu
|
|||
pQuad->m_aPoints[PointIndex].y = m_QuadDragOriginalPoints[QuadIndex][PointIndex].y + OffsetY;
|
||||
}
|
||||
|
||||
CEditor::EAxis CEditor::GetDragAxis(int OffsetX, int OffsetY)
|
||||
CEditor::EAxis CEditor::GetDragAxis(int OffsetX, int OffsetY) const
|
||||
{
|
||||
if(Input()->ShiftIsPressed())
|
||||
if(absolute(OffsetX) < absolute(OffsetY))
|
||||
|
@ -1558,7 +1558,7 @@ CEditor::EAxis CEditor::GetDragAxis(int OffsetX, int OffsetY)
|
|||
return EAxis::AXIS_NONE;
|
||||
}
|
||||
|
||||
void CEditor::DrawAxis(EAxis Axis, CPoint &OriginalPoint, CPoint &Point)
|
||||
void CEditor::DrawAxis(EAxis Axis, CPoint &OriginalPoint, CPoint &Point) const
|
||||
{
|
||||
if(Axis == EAxis::AXIS_NONE)
|
||||
return;
|
||||
|
@ -1587,6 +1587,8 @@ void CEditor::ComputePointAlignments(const std::shared_ptr<CLayerQuads> &pLayer,
|
|||
if(!g_Config.m_EdAlignQuads)
|
||||
return;
|
||||
|
||||
bool IgnoreGrid = Input()->AltIsPressed();
|
||||
|
||||
// Perform computation from the original position of this point
|
||||
int Threshold = f2fx(maximum(10.0f, 10.0f * m_MouseWScale));
|
||||
CPoint OrigPoint = m_QuadDragOriginalPoints.at(QuadIndex)[PointIndex];
|
||||
|
@ -1605,8 +1607,14 @@ void CEditor::ComputePointAlignments(const std::shared_ptr<CLayerQuads> &pLayer,
|
|||
int DiffX = absolute(DX);
|
||||
int DiffY = absolute(DY);
|
||||
|
||||
// Check the X axis
|
||||
if(DiffX <= Threshold)
|
||||
const float PX = fx2f(pQuadPoint->x);
|
||||
const float PY = fx2f(pQuadPoint->y);
|
||||
float SnappedPX = PX;
|
||||
float SnappedPY = PY;
|
||||
if(MapView()->MapGrid()->IsEnabled() && !IgnoreGrid)
|
||||
MapView()->MapGrid()->SnapToGrid(SnappedPX, SnappedPY);
|
||||
|
||||
if(DiffX <= Threshold && (SnappedPX == PX || DiffX == 0))
|
||||
{
|
||||
// Only store alignments that have the smallest difference
|
||||
if(DiffX < SmallestDiffX)
|
||||
|
@ -1627,7 +1635,8 @@ void CEditor::ComputePointAlignments(const std::shared_ptr<CLayerQuads> &pLayer,
|
|||
});
|
||||
}
|
||||
}
|
||||
if(DiffY <= Threshold)
|
||||
|
||||
if(DiffY <= Threshold && (SnappedPY == PY || DiffY == 0))
|
||||
{
|
||||
// Only store alignments that have the smallest difference
|
||||
if(DiffY < SmallestDiffY)
|
||||
|
@ -1777,6 +1786,8 @@ void CEditor::ComputeAABBAlignments(const std::shared_ptr<CLayerQuads> &pLayer,
|
|||
int SmallestDiffX = Threshold + 1, SmallestDiffY = Threshold + 1;
|
||||
std::vector<SAlignmentInfo> vAlignmentsX, vAlignmentsY;
|
||||
|
||||
bool IgnoreGrid = Input()->AltIsPressed();
|
||||
|
||||
auto &&CheckAlignment = [&](CPoint &Aligned, int Point) {
|
||||
CPoint ToCheck = AABB.m_aPoints[Point] + ivec2(OffsetX, OffsetY);
|
||||
int DX = Aligned.x - ToCheck.x;
|
||||
|
@ -1784,7 +1795,14 @@ void CEditor::ComputeAABBAlignments(const std::shared_ptr<CLayerQuads> &pLayer,
|
|||
int DiffX = absolute(DX);
|
||||
int DiffY = absolute(DY);
|
||||
|
||||
if(DiffX <= Threshold)
|
||||
const float PX = fx2f(Aligned.x);
|
||||
const float PY = fx2f(Aligned.y);
|
||||
float SnappedPX = PX;
|
||||
float SnappedPY = PY;
|
||||
if(MapView()->MapGrid()->IsEnabled() && !IgnoreGrid)
|
||||
MapView()->MapGrid()->SnapToGrid(SnappedPX, SnappedPY);
|
||||
|
||||
if(DiffX <= Threshold && (SnappedPX == PX || DiffX == 0))
|
||||
{
|
||||
if(DiffX < SmallestDiffX)
|
||||
{
|
||||
|
@ -1803,7 +1821,8 @@ void CEditor::ComputeAABBAlignments(const std::shared_ptr<CLayerQuads> &pLayer,
|
|||
});
|
||||
}
|
||||
}
|
||||
if(DiffY <= Threshold)
|
||||
|
||||
if(DiffY <= Threshold && (SnappedPY == PY || DiffY == 0))
|
||||
{
|
||||
if(DiffY < SmallestDiffY)
|
||||
{
|
||||
|
@ -1873,7 +1892,7 @@ void CEditor::ComputeAABBAlignments(const std::shared_ptr<CLayerQuads> &pLayer,
|
|||
vAlignments.insert(vAlignments.end(), vAlignmentsY.begin(), vAlignmentsY.end());
|
||||
}
|
||||
|
||||
void CEditor::DrawPointAlignments(const std::vector<SAlignmentInfo> &vAlignments, int OffsetX, int OffsetY)
|
||||
void CEditor::DrawPointAlignments(const std::vector<SAlignmentInfo> &vAlignments, int OffsetX, int OffsetY) const
|
||||
{
|
||||
if(!g_Config.m_EdAlignQuads)
|
||||
return;
|
||||
|
@ -1897,7 +1916,7 @@ void CEditor::DrawPointAlignments(const std::vector<SAlignmentInfo> &vAlignments
|
|||
}
|
||||
}
|
||||
|
||||
void CEditor::DrawAABB(const SAxisAlignedBoundingBox &AABB, int OffsetX, int OffsetY)
|
||||
void CEditor::DrawAABB(const SAxisAlignedBoundingBox &AABB, int OffsetX, int OffsetY) const
|
||||
{
|
||||
// Drawing an AABB is simply converting the points from fixed to float
|
||||
// Then making lines out of quads and drawing them
|
||||
|
@ -1935,12 +1954,13 @@ void CEditor::QuadSelectionAABB(const std::shared_ptr<CLayerQuads> &pLayer, SAxi
|
|||
for(int Selected : m_vSelectedQuads)
|
||||
{
|
||||
CQuad *pQuad = &pLayer->m_vQuads[Selected];
|
||||
for(auto &Point : pQuad->m_aPoints)
|
||||
for(int i = 0; i < 4; i++)
|
||||
{
|
||||
Min.x = minimum(Min.x, Point.x);
|
||||
Min.y = minimum(Min.y, Point.y);
|
||||
Max.x = maximum(Max.x, Point.x);
|
||||
Max.y = maximum(Max.y, Point.y);
|
||||
auto *pPoint = &pQuad->m_aPoints[i];
|
||||
Min.x = minimum(Min.x, pPoint->x);
|
||||
Min.y = minimum(Min.y, pPoint->y);
|
||||
Max.x = maximum(Max.x, pPoint->x);
|
||||
Max.y = maximum(Max.y, pPoint->y);
|
||||
}
|
||||
}
|
||||
CPoint Center = (Min + Max) / 2.0f;
|
||||
|
@ -1986,7 +2006,7 @@ void CEditor::ApplyAlignments(const std::vector<SAlignmentInfo> &vAlignments, in
|
|||
OffsetY += AdjustY;
|
||||
}
|
||||
|
||||
void CEditor::ApplyAxisAlignment(int &OffsetX, int &OffsetY)
|
||||
void CEditor::ApplyAxisAlignment(int &OffsetX, int &OffsetY) const
|
||||
{
|
||||
// This is used to preserve axis alignment when pressing `Shift`
|
||||
// Should be called before any other computation
|
||||
|
@ -3363,7 +3383,7 @@ void CEditor::DoMapEditor(CUIRect View)
|
|||
m_pBrush->Clear();
|
||||
}
|
||||
|
||||
if(UI()->MouseButton(0) && s_Operation == OP_NONE && !m_QuadKnifeActive)
|
||||
if(!Input()->ModifierIsPressed() && UI()->MouseButton(0) && s_Operation == OP_NONE && !m_QuadKnifeActive)
|
||||
{
|
||||
UI()->SetActiveItem(s_pEditorID);
|
||||
|
||||
|
@ -8341,7 +8361,7 @@ void CEditor::Reset(bool CreateDefault)
|
|||
m_MapSettingsCommandContext.Reset();
|
||||
}
|
||||
|
||||
int CEditor::GetTextureUsageFlag()
|
||||
int CEditor::GetTextureUsageFlag() const
|
||||
{
|
||||
return Graphics()->Uses2DTextureArrays() ? IGraphics::TEXLOAD_TO_2D_ARRAY_TEXTURE : IGraphics::TEXLOAD_TO_3D_TEXTURE;
|
||||
}
|
||||
|
|
|
@ -288,7 +288,7 @@ class CEditor : public IEditor
|
|||
IGraphics::CTextureHandle m_SwitchTexture;
|
||||
IGraphics::CTextureHandle m_TuneTexture;
|
||||
|
||||
int GetTextureUsageFlag();
|
||||
int GetTextureUsageFlag() const;
|
||||
|
||||
enum EPreviewState
|
||||
{
|
||||
|
@ -301,16 +301,16 @@ class CEditor : public IEditor
|
|||
static const ColorRGBA ms_DefaultPropColor;
|
||||
|
||||
public:
|
||||
class IInput *Input() { return m_pInput; }
|
||||
class IClient *Client() { return m_pClient; }
|
||||
class IConfigManager *ConfigManager() { return m_pConfigManager; }
|
||||
class CConfig *Config() { return m_pConfig; }
|
||||
class IConsole *Console() { return m_pConsole; }
|
||||
class IEngine *Engine() { return m_pEngine; }
|
||||
class IGraphics *Graphics() { return m_pGraphics; }
|
||||
class ISound *Sound() { return m_pSound; }
|
||||
class ITextRender *TextRender() { return m_pTextRender; }
|
||||
class IStorage *Storage() { return m_pStorage; }
|
||||
class IInput *Input() const { return m_pInput; }
|
||||
class IClient *Client() const { return m_pClient; }
|
||||
class IConfigManager *ConfigManager() const { return m_pConfigManager; }
|
||||
class CConfig *Config() const { return m_pConfig; }
|
||||
class IConsole *Console() const { return m_pConsole; }
|
||||
class IEngine *Engine() const { return m_pEngine; }
|
||||
class IGraphics *Graphics() const { return m_pGraphics; }
|
||||
class ISound *Sound() const { return m_pSound; }
|
||||
class ITextRender *TextRender() const { return m_pTextRender; }
|
||||
class IStorage *Storage() const { return m_pStorage; }
|
||||
CUI *UI() { return &m_UI; }
|
||||
CRenderTools *RenderTools() { return &m_RenderTools; }
|
||||
|
||||
|
@ -823,7 +823,7 @@ public:
|
|||
template<typename T>
|
||||
int RenderEditBoxDropdown(SEditBoxDropdownContext *pDropdown, CUIRect View, CLineInput *pLineInput, int x, float MaxHeight, bool AutoWidth, const std::vector<T> &vData, const FDropdownRenderCallback<T> &fnMatchCallback);
|
||||
|
||||
void RenderBackground(CUIRect View, IGraphics::CTextureHandle Texture, float Size, float Brightness);
|
||||
void RenderBackground(CUIRect View, IGraphics::CTextureHandle Texture, float Size, float Brightness) const;
|
||||
|
||||
SEditResult<int> UiDoValueSelector(void *pID, CUIRect *pRect, const char *pLabel, int Current, int Min, int Max, int Step, float Scale, const char *pToolTip, bool IsDegree = false, bool IsHex = false, int corners = IGraphics::CORNER_ALL, const ColorRGBA *pColor = nullptr, bool ShowValue = true);
|
||||
|
||||
|
@ -919,9 +919,9 @@ public:
|
|||
void DoQuad(int LayerIndex, const std::shared_ptr<CLayerQuads> &pLayer, CQuad *pQuad, int Index);
|
||||
void PreparePointDrag(const std::shared_ptr<CLayerQuads> &pLayer, CQuad *pQuad, int QuadIndex, int PointIndex);
|
||||
void DoPointDrag(const std::shared_ptr<CLayerQuads> &pLayer, CQuad *pQuad, int QuadIndex, int PointIndex, int OffsetX, int OffsetY);
|
||||
EAxis GetDragAxis(int OffsetX, int OffsetY);
|
||||
void DrawAxis(EAxis Axis, CPoint &OriginalPoint, CPoint &Point);
|
||||
void DrawAABB(const SAxisAlignedBoundingBox &AABB, int OffsetX = 0, int OffsetY = 0);
|
||||
EAxis GetDragAxis(int OffsetX, int OffsetY) const;
|
||||
void DrawAxis(EAxis Axis, CPoint &OriginalPoint, CPoint &Point) const;
|
||||
void DrawAABB(const SAxisAlignedBoundingBox &AABB, int OffsetX = 0, int OffsetY = 0) const;
|
||||
ColorRGBA GetButtonColor(const void *pID, int Checked);
|
||||
|
||||
// Alignment methods
|
||||
|
@ -945,10 +945,10 @@ public:
|
|||
void ComputePointAlignments(const std::shared_ptr<CLayerQuads> &pLayer, CQuad *pQuad, int QuadIndex, int PointIndex, int OffsetX, int OffsetY, std::vector<SAlignmentInfo> &vAlignments, bool Append = false) const;
|
||||
void ComputePointsAlignments(const std::shared_ptr<CLayerQuads> &pLayer, bool Pivot, int OffsetX, int OffsetY, std::vector<SAlignmentInfo> &vAlignments) const;
|
||||
void ComputeAABBAlignments(const std::shared_ptr<CLayerQuads> &pLayer, const SAxisAlignedBoundingBox &AABB, int OffsetX, int OffsetY, std::vector<SAlignmentInfo> &vAlignments) const;
|
||||
void DrawPointAlignments(const std::vector<SAlignmentInfo> &vAlignments, int OffsetX, int OffsetY);
|
||||
void DrawPointAlignments(const std::vector<SAlignmentInfo> &vAlignments, int OffsetX, int OffsetY) const;
|
||||
void QuadSelectionAABB(const std::shared_ptr<CLayerQuads> &pLayer, SAxisAlignedBoundingBox &OutAABB);
|
||||
void ApplyAlignments(const std::vector<SAlignmentInfo> &vAlignments, int &OffsetX, int &OffsetY);
|
||||
void ApplyAxisAlignment(int &OffsetX, int &OffsetY);
|
||||
void ApplyAxisAlignment(int &OffsetX, int &OffsetY) const;
|
||||
|
||||
bool ReplaceImage(const char *pFilename, int StorageType, bool CheckDuplicate);
|
||||
static bool ReplaceImageCallback(const char *pFilename, int StorageType, void *pUser);
|
||||
|
|
Loading…
Reference in a new issue