guiWindowCtrl parent edge snaping TGEA 1.8.1
by Nathan Bowhay - ESAL · 04/07/2009 (5:05 pm) · 1 comments
In guiWindowCtrl.h
After line 29 under:
In guiWindowCtrl.cpp.
Change line 27 from
On line 75 after
Change the code around line 359 from
Recompile and you are all done.
After line 29 under:
bool mEdgeSnap; ///< Should this window snap to other windows edges?add
bool mParentSnap; ///< Should this window snap to the parents edges?
In guiWindowCtrl.cpp.
Change line 27 from
mEdgeSnap(true)to
mEdgeSnap(true),
mParentSnap(true)On line 75 after
addField("EdgeSnap", TypeBool, Offset(mEdgeSnap,GuiWindowCtrl));addaddField("ParentSnap", TypeBool, Offset(mParentSnap,GuiWindowCtrl));Change the code around line 359 from
// Check snapping to other windows
if( mEdgeSnap )
{
RectI bounds = getGlobalBounds();
bounds.point = mOrigBounds.point + deltaMousePosition;
EdgeRectI edges = EdgeRectI( bounds, mResizeMargin );
Vector<EdgeRectI> snapList;
getSnappableRects( snapList );
for( S32 i =0; i < snapList.size(); i++ )
{
// Compare Edges for hit
EdgeRectI &snapRect = snapList[i];
if( edges.left.hit( snapRect.right ) )
newPosition.x = snapRect.right.position.x;
else if( edges.right.hit( snapRect.left ) )
newPosition.x = snapRect.left.position.x - bounds.extent.x;
if( edges.bottom.hit( snapRect.top ) )
newPosition.y = snapRect.top.position.y - bounds.extent.y;
else if( edges.top.hit( snapRect.bottom ) )
newPosition.y = snapRect.bottom.position.y;
}
}toif(mParentSnap || mEdgeSnap)
{
RectI bounds = getGlobalBounds();
bounds.point = mOrigBounds.point + deltaMousePosition;
EdgeRectI edges = EdgeRectI( bounds, mResizeMargin );
// Check snapping to other windows
if( mEdgeSnap )
{
Vector<EdgeRectI> snapList;
getSnappableRects( snapList );
for( S32 i =0; i < snapList.size(); i++ )
{
// Compare Edges for hit
EdgeRectI &snapRect = snapList[i];
if( edges.left.hit( snapRect.right ) )
newPosition.x = snapRect.right.position.x;
else if( edges.right.hit( snapRect.left ) )
newPosition.x = snapRect.left.position.x - bounds.extent.x;
if( edges.bottom.hit( snapRect.top ) )
newPosition.y = snapRect.top.position.y - bounds.extent.y;
else if( edges.top.hit( snapRect.bottom ) )
newPosition.y = snapRect.bottom.position.y;
}
}
//Check snapping to parent walls
if(mParentSnap)
{
//snap to parent walls
RectI parentRect(Point2I(0,0),parent->getGlobalBounds().extent);
EdgeRectI snapRect( parentRect,mResizeMargin);
if( edges.right.hit( snapRect.right ) )
newPosition.x = snapRect.right.position.x - bounds.extent.x;
else if( edges.left.hit( snapRect.left ) )
newPosition.x = snapRect.left.position.x;
if( edges.top.hit( snapRect.top ) )
newPosition.y = snapRect.top.position.y;
else if( edges.bottom.hit( snapRect.bottom ) )
newPosition.y = snapRect.bottom.position.y - bounds.extent.y;
}
}Recompile and you are all done.

Torque Owner Roland Orr
Roland Dynamics
i will bookmark this and try it out later. :P