LayoutFarm.Demo_DragSelectionBox.MoveWithSnapToGrid C# (CSharp) Method

MoveWithSnapToGrid() static private method

static private MoveWithSnapToGrid ( UIControllerBox controllerBox, int dx, int dy ) : void
controllerBox UIControllerBox
dx int
dy int
return void
        static void MoveWithSnapToGrid(UIControllerBox controllerBox, int dx, int dy)
        {
            //sample move with snap to grid
            Point pos = controllerBox.Position;
            int newX = pos.X + dx;
            int newY = pos.Y + dy;
            int gridSize = 5;
            float halfGrid = (float)gridSize / 2f;
            int nearestX = (int)((newX + halfGrid) / gridSize) * gridSize;
            int nearestY = (int)((newY + halfGrid) / gridSize) * gridSize;
            controllerBox.SetLocation(nearestX, nearestY);
            UIBox targetBox = controllerBox.TargetBox;
            if (targetBox != null)
            {
                int xdiff = nearestX - pos.X;
                int ydiff = nearestY - pos.Y;
                targetBox.SetLocation(targetBox.Left + xdiff, targetBox.Top + ydiff);
            }
        }
        List<LayoutFarm.UI.UIBox> FindUnderlyingElements(UIControllerBox controllerBox)