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

Method doControlSnap

Engine/source/gui/editor/guiEditCtrl.cpp:1999–2092  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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