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

Method findSnaps

Engine/source/gui/editor/guiEditCtrl.cpp:1912–1995  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1910//-----------------------------------------------------------------------------
1911
1912void GuiEditCtrl::findSnaps( snappingAxis axis, const Point2I& mousePoint, const RectI& minRegion, const RectI& midRegion, const RectI& maxRegion )
1913{
1914 // Find controls with edge in either minRegion, midRegion, or maxRegion
1915 // (depending on snap settings).
1916
1917 for( U32 i = 0, num = mSnapHits[ axis ].size(); i < num; ++ i )
1918 {
1919 GuiControl* ctrl = mSnapHits[ axis ][ i ];
1920 if( ctrl == getContentControl() && !mSnapToCanvas )
1921 continue;
1922
1923 RectI bounds = ctrl->getGlobalBounds();
1924 bounds.point = getContentControl()->globalToLocalCoord( bounds.point );
1925
1926 // Compute points on min, mid, and max lines of control.
1927
1928 Point2I min = bounds.point;
1929 Point2I max = min + bounds.extent - Point2I( 1, 1 );
1930
1931 Point2I mid = min;
1932 mid.x += bounds.extent.x / 2;
1933 mid.y += bounds.extent.y / 2;
1934
1935 // Test edge snap cases.
1936
1937 if( mSnapToEdges )
1938 {
1939 // Min to min.
1940
1941 if( minRegion.pointInRect( min ) )
1942 registerSnap( axis, mousePoint, min, SnapEdgeMin, ctrl );
1943
1944 // Max to max.
1945
1946 if( maxRegion.pointInRect( max ) )
1947 registerSnap( axis, mousePoint, max, SnapEdgeMax, ctrl );
1948
1949 // Min to max.
1950
1951 if( minRegion.pointInRect( max ) )
1952 registerSnap( axis, mousePoint, max, SnapEdgeMin, ctrl );
1953
1954 // Max to min.
1955
1956 if( maxRegion.pointInRect( min ) )
1957 registerSnap( axis, mousePoint, min, SnapEdgeMax, ctrl );
1958 }
1959
1960 // Test center snap cases.
1961
1962 if( mSnapToCenters )
1963 {
1964 // Mid to mid.
1965
1966 if( midRegion.pointInRect( mid ) )
1967 registerSnap( axis, mousePoint, mid, SnapEdgeMid, ctrl );
1968 }
1969

Callers

nothing calls this directly

Calls 5

getContentControlFunction · 0.85
globalToLocalCoordMethod · 0.80
pointInRectMethod · 0.80
Point2IClass · 0.50
sizeMethod · 0.45

Tested by

no test coverage detected