Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Generals/Code/Tools/WorldBuilder/include/BorderTool.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
38 changes: 16 additions & 22 deletions Generals/Code/Tools/WorldBuilder/src/BorderTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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, &current);
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, &current);
} else {
pDoc->addBoundary(&current);
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, &current);
return;
}

Expand Down Expand Up @@ -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;
}

Expand All @@ -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
{
Expand All @@ -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;
}
}
3 changes: 2 additions & 1 deletion GeneralsMD/Code/Tools/WorldBuilder/include/BorderTool.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
38 changes: 16 additions & 22 deletions GeneralsMD/Code/Tools/WorldBuilder/src/BorderTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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, &current);
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, &current);
} else {
pDoc->addBoundary(&current);
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, &current);
return;
}

Expand Down Expand Up @@ -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;
}

Expand All @@ -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
{
Expand All @@ -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;
}
}