From 9f1801b37c1a7b968b3e844ce866dfc7ce23f628 Mon Sep 17 00:00:00 2001 From: Omar Aglan Date: Fri, 9 Oct 2026 18:53:43 +0300 Subject: [PATCH] bugfix(worldbuilder): Create boundaries only when dragging --- .../Tools/WorldBuilder/include/BorderTool.h | 3 +- .../Tools/WorldBuilder/src/BorderTool.cpp | 38 ++++++++----------- .../Tools/WorldBuilder/include/BorderTool.h | 3 +- .../Tools/WorldBuilder/src/BorderTool.cpp | 38 ++++++++----------- 4 files changed, 36 insertions(+), 46 deletions(-) diff --git a/Generals/Code/Tools/WorldBuilder/include/BorderTool.h b/Generals/Code/Tools/WorldBuilder/include/BorderTool.h index 8991e5cdbca..947446dae3a 100644 --- a/Generals/Code/Tools/WorldBuilder/include/BorderTool.h +++ b/Generals/Code/Tools/WorldBuilder/include/BorderTool.h @@ -24,7 +24,8 @@ class BorderTool : public Tool { protected: enum ModificationType { MOD_TYPE_INVALID, MOD_TYPE_UP, MOD_TYPE_FREE, MOD_TYPE_RIGHT }; - Bool m_mouseDown; + Bool m_newBorderCreated; + CPoint m_mouseDownPoint; Bool m_addingNewBorder; Int m_modifyBorderNdx; ModificationType m_modificationType; diff --git a/Generals/Code/Tools/WorldBuilder/src/BorderTool.cpp b/Generals/Code/Tools/WorldBuilder/src/BorderTool.cpp index db1213e8e56..b27f371b24e 100644 --- a/Generals/Code/Tools/WorldBuilder/src/BorderTool.cpp +++ b/Generals/Code/Tools/WorldBuilder/src/BorderTool.cpp @@ -28,7 +28,7 @@ const long BOUNDARY_PICK_DISTANCE = 5.0f; BorderTool::BorderTool() : Tool(ID_BORDERTOOL, IDC_POINTER), - m_mouseDown(false), + m_newBorderCreated(false), m_addingNewBorder(false), m_modifyBorderNdx(-1) @@ -63,23 +63,20 @@ void BorderTool::mouseMoved(TTrackingMode m, CPoint viewPt, WbView* pView, CWorl } if (m_addingNewBorder) { - Int count = pDoc->getNumBoundaries(); - ICoord2D current; - pDoc->getBoundary(count - 1, ¤t); + if (!m_newBorderCreated && viewPt == m_mouseDownPoint) { + return; + } Coord3D new3DPoint; pView->viewToDocCoords(viewPt, &new3DPoint, false); - - if (current.x < 0) { - current.x = 0; - } - - if (current.y < 0) { - current.y = 0; + ICoord2D current; + current.x = max(0, REAL_TO_INT((new3DPoint.x / MAP_XY_FACTOR) + 0.5f)); + current.y = max(0, REAL_TO_INT((new3DPoint.y / MAP_XY_FACTOR) + 0.5f)); + if (m_newBorderCreated) { + pDoc->changeBoundary(pDoc->getNumBoundaries() - 1, ¤t); + } else { + pDoc->addBoundary(¤t); + m_newBorderCreated = true; } - - current.x = REAL_TO_INT((new3DPoint.x / MAP_XY_FACTOR) + 0.5f); - current.y = REAL_TO_INT((new3DPoint.y / MAP_XY_FACTOR) + 0.5f); - pDoc->changeBoundary(count - 1, ¤t); return; } @@ -124,15 +121,15 @@ void BorderTool::mouseDown(TTrackingMode m, CPoint viewPt, WbView* pView, CWorld return; } + m_newBorderCreated = false; + m_mouseDownPoint = viewPt; + //static Coord3D zero = {0.0f, 0.0f, 0.0f}; Coord3D groundPt; pView->viewToDocCoords(viewPt, &groundPt); if (groundPt.length() < BOUNDARY_PICK_DISTANCE) { m_addingNewBorder = true; - - ICoord2D initialBoundary = { 1, 1 }; - pDoc->addBoundary(&initialBoundary); return; } @@ -150,9 +147,6 @@ void BorderTool::mouseDown(TTrackingMode m, CPoint viewPt, WbView* pView, CWorld { // add a boundary m_addingNewBorder = true; - - ICoord2D initialBoundary = { 1, 1 }; - pDoc->addBoundary(&initialBoundary); } else { @@ -168,6 +162,6 @@ void BorderTool::mouseUp(TTrackingMode m, CPoint viewPt, WbView* pView, CWorldBu if (m_addingNewBorder) { m_addingNewBorder = false; - // Do the undoable on the last border + m_newBorderCreated = false; } } diff --git a/GeneralsMD/Code/Tools/WorldBuilder/include/BorderTool.h b/GeneralsMD/Code/Tools/WorldBuilder/include/BorderTool.h index 9a1e5c43631..00ca7e91ee6 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/include/BorderTool.h +++ b/GeneralsMD/Code/Tools/WorldBuilder/include/BorderTool.h @@ -24,7 +24,8 @@ class BorderTool : public Tool { protected: enum ModificationType { MOD_TYPE_INVALID, MOD_TYPE_UP, MOD_TYPE_FREE, MOD_TYPE_RIGHT }; - Bool m_mouseDown; + Bool m_newBorderCreated; + CPoint m_mouseDownPoint; Bool m_addingNewBorder; Int m_modifyBorderNdx; ModificationType m_modificationType; diff --git a/GeneralsMD/Code/Tools/WorldBuilder/src/BorderTool.cpp b/GeneralsMD/Code/Tools/WorldBuilder/src/BorderTool.cpp index 1db6efb14da..1d73b7e755d 100644 --- a/GeneralsMD/Code/Tools/WorldBuilder/src/BorderTool.cpp +++ b/GeneralsMD/Code/Tools/WorldBuilder/src/BorderTool.cpp @@ -28,7 +28,7 @@ const long BOUNDARY_PICK_DISTANCE = 5.0f; BorderTool::BorderTool() : Tool(ID_BORDERTOOL, IDC_POINTER), - m_mouseDown(false), + m_newBorderCreated(false), m_addingNewBorder(false), m_modifyBorderNdx(-1) @@ -63,23 +63,20 @@ void BorderTool::mouseMoved(TTrackingMode m, CPoint viewPt, WbView* pView, CWorl } if (m_addingNewBorder) { - Int count = pDoc->getNumBoundaries(); - ICoord2D current; - pDoc->getBoundary(count - 1, ¤t); + if (!m_newBorderCreated && viewPt == m_mouseDownPoint) { + return; + } Coord3D new3DPoint; pView->viewToDocCoords(viewPt, &new3DPoint, false); - - if (current.x < 0) { - current.x = 0; - } - - if (current.y < 0) { - current.y = 0; + ICoord2D current; + current.x = max(0, REAL_TO_INT((new3DPoint.x / MAP_XY_FACTOR) + 0.5f)); + current.y = max(0, REAL_TO_INT((new3DPoint.y / MAP_XY_FACTOR) + 0.5f)); + if (m_newBorderCreated) { + pDoc->changeBoundary(pDoc->getNumBoundaries() - 1, ¤t); + } else { + pDoc->addBoundary(¤t); + m_newBorderCreated = true; } - - current.x = REAL_TO_INT((new3DPoint.x / MAP_XY_FACTOR) + 0.5f); - current.y = REAL_TO_INT((new3DPoint.y / MAP_XY_FACTOR) + 0.5f); - pDoc->changeBoundary(count - 1, ¤t); return; } @@ -124,15 +121,15 @@ void BorderTool::mouseDown(TTrackingMode m, CPoint viewPt, WbView* pView, CWorld return; } + m_newBorderCreated = false; + m_mouseDownPoint = viewPt; + //static Coord3D zero = {0.0f, 0.0f, 0.0f}; Coord3D groundPt; pView->viewToDocCoords(viewPt, &groundPt); if (groundPt.length() < BOUNDARY_PICK_DISTANCE) { m_addingNewBorder = true; - - ICoord2D initialBoundary = { 1, 1 }; - pDoc->addBoundary(&initialBoundary); return; } @@ -150,9 +147,6 @@ void BorderTool::mouseDown(TTrackingMode m, CPoint viewPt, WbView* pView, CWorld { // add a boundary m_addingNewBorder = true; - - ICoord2D initialBoundary = { 1, 1 }; - pDoc->addBoundary(&initialBoundary); } else { @@ -168,6 +162,6 @@ void BorderTool::mouseUp(TTrackingMode m, CPoint viewPt, WbView* pView, CWorldBu if (m_addingNewBorder) { m_addingNewBorder = false; - // Do the undoable on the last border + m_newBorderCreated = false; } }