Ejemplo n.º 1
0
        SnapToSpacingResult GetSnapToSpacingResult(Rect sourceRect, float middlePos, ReferenceRects referenceRects)
        {
            float sourceRectCenter = referenceRects.Orientation == Orientation.Vertical ? GetMaxPos(sourceRect, SnapReference.VerticalCenter).y : GetMaxPos(sourceRect, SnapReference.HorizontalCenter).x;
            float offset           = sourceRectCenter - middlePos;

            SnapToSpacingResult minResult = new SnapToSpacingResult {
                Offset         = offset,
                ReferenceRects = referenceRects
            };

            return(minResult.Distance <= SnapDistance * 1 / m_CurrentScale ? minResult : null);
        }
Ejemplo n.º 2
0
        SnapToSpacingResult GetClosestSpacingPosition(Rect sourceRect, Orientation orientation)
        {
            SnapToSpacingResult minResult = null;
            float minDistance             = float.MaxValue;

            foreach (var spacingPos in m_SpacingPositions.Where(spacingPos => spacingPos.Value.Orientation == orientation))
            {
                SnapToSpacingResult result = GetSnapToSpacingResult(sourceRect, spacingPos.Key, spacingPos.Value);
                if (result != null && minDistance > result.Distance)
                {
                    minDistance = result.Distance;
                    minResult   = result;
                }
            }

            return(minResult);
        }
Ejemplo n.º 3
0
        List <SnapToSpacingResult> GetClosestSpacingPositions(Rect sourceRect)
        {
            List <SnapToSpacingResult> results = new List <SnapToSpacingResult>();

            SnapToSpacingResult horizontalResult = GetClosestSpacingPosition(sourceRect, Orientation.Horizontal);

            if (horizontalResult != null)
            {
                results.Add(horizontalResult);
            }

            SnapToSpacingResult verticalResult = GetClosestSpacingPosition(sourceRect, Orientation.Vertical);

            if (verticalResult != null)
            {
                results.Add(verticalResult);
            }

            return(results);
        }
Ejemplo n.º 4
0
 static void ApplySnapToSpacingResult(ref Vector2 snappingOffset, Rect sourceRect, ref Rect r1, SnapToSpacingResult result)
 {
     if (result.ReferenceRects.Orientation == Orientation.Horizontal)
     {
         r1.x             = sourceRect.x - result.Offset;
         snappingOffset.x = snappingOffset.x < float.MaxValue ? snappingOffset.x + result.Offset : result.Offset;
     }
     else
     {
         r1.y             = sourceRect.y - result.Offset;
         snappingOffset.y = snappingOffset.y < float.MaxValue ? snappingOffset.y + result.Offset : result.Offset;
     }
 }