MCPcopy Create free account
hub / github.com/GarageGames/Torque3D / doControlSnap

Method doControlSnap

Engine/source/gui/editor/guiEditCtrl.cpp:1986–2079  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1984//-----------------------------------------------------------------------------
1985
1986void GuiEditCtrl::doControlSnap( const GuiEvent& event, const RectI& selectionBounds, const RectI& selectionBoundsGlobal, Point2I& delta )
1987{
1988 if( !mSnapToControls || ( !mSnapToEdges && !mSnapToCenters ) )
1989 return;
1990
1991 // Allow restricting to just vertical (ALT+SHIFT) or just horizontal (ALT+CTRL)
1992 // snaps.
1993
1994 bool snapAxisEnabled[ 2 ];
1995
1996 if( event.modifier & SI_PRIMARY_ALT && event.modifier & SI_SHIFT )
1997 snapAxisEnabled[ SnapHorizontal ] = false;
1998 else
1999 snapAxisEnabled[ SnapHorizontal ] = true;
2000
2001 if( event.modifier & SI_PRIMARY_ALT && event.modifier & SI_CTRL )
2002 snapAxisEnabled[ SnapVertical ] = false;
2003 else
2004 snapAxisEnabled[ SnapVertical ] = true;
2005
2006 // Compute snap regions. There is one region centered on and aligned with
2007 // each of the selection bounds edges plus two regions aligned on the selection
2008 // bounds center. For the selection bounds origin, we use the point that the
2009 // selection would be at, if we had already done the mouse drag.
2010
2011 RectI snapRegions[ 2 ][ 3 ];
2012 Point2I projectedOrigin( selectionBounds.point + delta );
2013 dMemset( snapRegions, 0, sizeof( snapRegions ) );
2014
2015 for( U32 axis = 0; axis < 2; ++ axis )
2016 {
2017 if( !snapAxisEnabled[ axis ] )
2018 continue;
2019
2020 if( mSizingMode == sizingNone ||
2021 ( axis == 0 && mSizingMode & sizingLeft ) ||
2022 ( axis == 1 && mSizingMode & sizingTop ) )
2023 snapRegions[ axis ][ 0 ] = getSnapRegion( ( snappingAxis ) axis, projectedOrigin );
2024
2025 if( mSizingMode == sizingNone )
2026 snapRegions[ axis ][ 1 ] = getSnapRegion( ( snappingAxis ) axis, projectedOrigin + Point2I( selectionBounds.extent.x / 2, selectionBounds.extent.y / 2 ) );
2027
2028 if( mSizingMode == sizingNone ||
2029 ( axis == 0 && mSizingMode & sizingRight ) ||
2030 ( axis == 1 && mSizingMode & sizingBottom ) )
2031 snapRegions[ axis ][ 2 ] = getSnapRegion( ( snappingAxis ) axis, projectedOrigin + selectionBounds.extent - Point2I( 1, 1 ) );
2032 }
2033
2034 // Find hit controls.
2035
2036 canHitSelectedControls( false );
2037
2038 if( mSnapToEdges )
2039 {
2040 for( U32 axis = 0; axis < 2; ++ axis )
2041 if( snapAxisEnabled[ axis ] )
2042 {
2043 getContentControl()->findHitControls( snapRegions[ axis ][ 0 ], mSnapHits[ axis ], HIT_NoCanHitNoRecurse );

Callers

nothing calls this directly

Calls 6

getContentControlFunction · 0.85
findHitControlsMethod · 0.80
dMemsetFunction · 0.50
Point2IClass · 0.50
push_backMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected