예제 #1
0
            static void ResizeTargetWithSnapToGrid2(UIControllerBox controllerBox, UIMouseEventArgs e)
            {
                //sample move with snap to grid
                Point pos  = controllerBox.Position;
                int   newX = pos.X + e.XDiff;
                int   newY = pos.Y + e.YDiff;
                //snap to gridsize =5;
                //find nearest snap x
                int   gridSize = 5;
                float halfGrid = (float)gridSize / 2f;
                int   nearestX = (int)((newX + halfGrid) / gridSize) * gridSize;
                int   nearestY = (int)((newY + halfGrid) / gridSize) * gridSize;
                int   xdiff    = nearestX - pos.X;

                if (xdiff != 0)
                {
                    controllerBox.SetSize(controllerBox.Width + xdiff, controllerBox.Height);
                }

                var targetBox = controllerBox.TargetBox;

                if (targetBox != null)
                {
                    //move target box too
                    targetBox.SetLocationAndSize(controllerBox.Left + 5,
                                                 controllerBox.Top + 5,
                                                 controllerBox.Width - 10,
                                                 controllerBox.Height - 10);
                }
            }
        void FindSelectedUserBoxes()
        {
            //find users box in selected area



            int j = this.bgbox.ChildCount;

            var primSelectionBox = selectionBox.GetPrimaryRenderElement(rootgfx);
            var primGlobalPoint  = primSelectionBox.GetGlobalLocation();
            var selectedRectArea = new Rectangle(primGlobalPoint, primSelectionBox.Size);

            List <UIBox> selectedList = new List <UIBox>();

            for (int i = 0; i < j; ++i)
            {
                var box = bgbox.GetChild(i) as UIBox;
                if (box == null)
                {
                    continue;
                }
                var primElement = box.GetPrimaryRenderElement(rootgfx);
                if (!primElement.Visible)
                {
                    continue;
                }
                //get global area
                Point globalLocation  = primElement.GetGlobalLocation();
                var   userElementArea = new Rectangle(globalLocation, primElement.Size);
                if (selectedRectArea.Contains(userElementArea))
                {
                    //selected= true;
                    selectedList.Add(box);
                    //------
                    //create user controller box for the selected box
                    UIControllerBox userControllerBox = GetFreeUserControllerBox();

                    userControllerBox.TargetBox = box;
                    var globalTargetPos = box.GetGlobalLocation();

                    userControllerBox.SetLocation(globalTargetPos.X - 5, globalTargetPos.Y - 5);
                    userControllerBox.SetSize(box.Width + 10, box.Height + 10);
                    userControllerBox.Visible = true;
                    viewport.AddContent(userControllerBox);
                }
            }
        }
            static void ResizeTargetWithSnapToGrid(SpaceName tinyBoxSpaceName, 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;
                //snap to gridsize =5;
                //find nearest snap x
                int   gridSize = 5;
                float halfGrid = (float)gridSize / 2f;
                int   nearestX = (int)((newX + halfGrid) / gridSize) * gridSize;
                int   nearestY = (int)((newY + halfGrid) / gridSize) * gridSize;

                int xdiff = nearestX - pos.X;
                int ydiff = nearestY - pos.Y;

                switch (tinyBoxSpaceName)
                {
                case SpaceName.LeftTop:
                {
                    if (xdiff != 0 || ydiff != 0)
                    {
                        controllerBox.SetBounds(controllerBox.Left + xdiff, controllerBox.Top + ydiff,
                                                controllerBox.Width - xdiff, controllerBox.Height - ydiff);

                        var targetBox = controllerBox.TargetBox;
                        if (targetBox != null)
                        {
                            //move target box too
                            targetBox.SetBounds(targetBox.Left + xdiff, targetBox.Top + ydiff,
                                                targetBox.Width - xdiff, targetBox.Height - ydiff);
                        }
                    }
                } break;

                case SpaceName.RightTop:
                {
                    if (xdiff != 0 || ydiff != 0)
                    {
                        controllerBox.SetBounds(controllerBox.Left, controllerBox.Top + ydiff,
                                                controllerBox.Width + xdiff, controllerBox.Height - ydiff);

                        var targetBox = controllerBox.TargetBox;
                        if (targetBox != null)
                        {
                            targetBox.SetBounds(targetBox.Left, targetBox.Top + ydiff,
                                                targetBox.Width + xdiff, targetBox.Height - ydiff);
                        }
                    }
                } break;

                case SpaceName.RightBottom:
                {
                    if (xdiff != 0 || ydiff != 0)
                    {
                        controllerBox.SetSize(controllerBox.Width + xdiff, controllerBox.Height + ydiff);
                        var targetBox = controllerBox.TargetBox;
                        if (targetBox != null)
                        {
                            //move target box too
                            targetBox.SetSize(targetBox.Width + xdiff, targetBox.Height + ydiff);
                        }
                    }
                } break;

                case SpaceName.LeftBottom:
                {
                    if (xdiff != 0 || ydiff != 0)
                    {
                        controllerBox.SetBounds(controllerBox.Left + xdiff, controllerBox.Top,
                                                controllerBox.Width - xdiff, controllerBox.Height + ydiff);

                        var targetBox = controllerBox.TargetBox;
                        if (targetBox != null)
                        {
                            //move target box too
                            targetBox.SetBounds(targetBox.Left + xdiff, targetBox.Top,
                                                targetBox.Width - xdiff, targetBox.Height + ydiff);
                        }
                    }
                } break;
                }
            }
        void SetupActiveBoxProperties(LayoutFarm.CustomWidgets.EaseBox box)
        {
            //1. mouse down
            box.MouseDown += (s, e) =>
            {
                box.BackColor      = KnownColors.FromKnownColor(KnownColor.DeepSkyBlue);
                e.MouseCursorStyle = MouseCursorStyle.Pointer;

                UIControllerBox userControllerBox = null;
                if (this.controllerBoxMode == ControllerBoxMode.MultipleBoxes)
                {
                    //multiple box
                    userControllerBox = GetFreeUserControllerBox();
                }
                else
                {
                    //single box
                    if (singleControllerBox != null)
                    {
                        ReleaseUserControllerBox(singleControllerBox);
                    }
                    //get new one
                    userControllerBox = singleControllerBox = GetFreeUserControllerBox();
                }
                //request user controller for this box
                userControllerBox.TargetBox = box;
                viewport.AddContent(userControllerBox);
                //location relative to global position of target box
                var globalTargetPos = box.GetGlobalLocation();

                userControllerBox.SetLocation(globalTargetPos.X - 5, globalTargetPos.Y - 5);
                userControllerBox.SetSize(box.Width + 10, box.Height + 10);
                userControllerBox.Visible = true;

                //move mouse capture to new controller box
                //for next drag
                e.SetMouseCapture(userControllerBox);
            };

            //2. mouse up
            box.MouseUp += (s, e) =>
            {
                e.MouseCursorStyle = MouseCursorStyle.Default;
                box.BackColor      = Color.LightGray;

                RemoveAllUserControllerBoxes();
            };
            box.DragOver += (s, e) =>
            {
                switch (e.UserMsgFlags)
                {
                case 1:
                {           //sample only
                    box.BackColor = Color.Green;
                } break;

                case 2:
                {
                    //sample only
                    //leaving
                    box.BackColor = Color.Blue;
                } break;

                case 3:
                {
                    //drop
                    var sender      = e.Sender as UIControllerBox;
                    var droppingBox = sender.TargetBox as UIBox;
                    if (droppingBox != null)
                    {
                        //move from original
                        var parentBox = droppingBox.ParentUI as LayoutFarm.CustomWidgets.SimpleBox;
                        if (parentBox != null)
                        {
                            var newParentGlobalLoca = box.GetGlobalLocation();
                            var droppingGlobalLoca  = droppingBox.GetGlobalLocation();

                            parentBox.RemoveChild(droppingBox);
                            box.AddChild(droppingBox);

                            //TODO: review here ,
                            //set location relative to other element
                            droppingBox.SetLocation(
                                droppingGlobalLoca.X - newParentGlobalLoca.X,
                                droppingGlobalLoca.Y - newParentGlobalLoca.Y);
                        }
                        else
                        {
                        }
                    }
                } break;
                }
            };
        }
예제 #5
0
            static void ResizeTargetWithSnapToGrid2(UIControllerBox controllerBox, UIMouseEventArgs e)
            {
                //sample move with snap to grid
                Point pos = controllerBox.Position;
                int newX = pos.X + e.XDiff;
                int newY = pos.Y + e.YDiff;
                //snap to gridsize =5;
                //find nearest snap x 
                int gridSize = 5;
                float halfGrid = (float)gridSize / 2f;
                int nearestX = (int)((newX + halfGrid) / gridSize) * gridSize;
                int nearestY = (int)((newY + halfGrid) / gridSize) * gridSize;
                int xdiff = nearestX - pos.X;
                if (xdiff != 0)
                {
                    controllerBox.SetSize(controllerBox.Width + xdiff, controllerBox.Height);
                }

                var targetBox = controllerBox.TargetBox;
                if (targetBox != null)
                {
                    //move target box too 
                    targetBox.SetBounds(controllerBox.Left + 5,
                        controllerBox.Top + 5,
                        controllerBox.Width - 10,
                        controllerBox.Height - 10);
                }
            }
예제 #6
0
 static void ResizeTargetWithSnapToGrid(SpaceName tinyBoxSpaceName, UIControllerBox controllerBox, UIMouseEventArgs e)
 {
     //sample move with snap to grid
     Point pos = controllerBox.Position;
     int newX = pos.X + e.XDiff;
     int newY = pos.Y + e.YDiff;
     //snap to gridsize =5;
     //find nearest snap x 
     int gridSize = 5;
     float halfGrid = (float)gridSize / 2f;
     int nearestX = (int)((newX + halfGrid) / gridSize) * gridSize;
     int nearestY = (int)((newY + halfGrid) / gridSize) * gridSize;
     int xdiff = nearestX - pos.X;
     int ydiff = nearestY - pos.Y;
     switch (tinyBoxSpaceName)
     {
         case SpaceName.LeftTop:
             {
                 if (xdiff != 0 || ydiff != 0)
                 {
                     controllerBox.SetLocation(controllerBox.Left + xdiff, controllerBox.Top + ydiff);
                     controllerBox.SetSize(controllerBox.Width - xdiff, controllerBox.Height - ydiff);
                     var targetBox = controllerBox.TargetBox;
                     if (targetBox != null)
                     {
                         //move target box too 
                         targetBox.SetBounds(controllerBox.Left + 5,
                             controllerBox.Top + 5,
                             controllerBox.Width - 10,
                             controllerBox.Height - 10);
                     }
                 }
             }
             break;
         case SpaceName.RightTop:
             {
                 if (xdiff != 0 || ydiff != 0)
                 {
                     controllerBox.SetLocation(controllerBox.Left, controllerBox.Top + ydiff);
                     controllerBox.SetSize(controllerBox.Width + xdiff, controllerBox.Height - ydiff);
                     var targetBox = controllerBox.TargetBox;
                     if (targetBox != null)
                     {
                         //move target box too 
                         targetBox.SetBounds(controllerBox.Left + 5,
                             controllerBox.Top + 5,
                             controllerBox.Width - 10,
                             controllerBox.Height - 10);
                     }
                 }
             }
             break;
         case SpaceName.RightBottom:
             {
                 if (xdiff != 0 || ydiff != 0)
                 {
                     controllerBox.SetSize(controllerBox.Width + xdiff, controllerBox.Height + ydiff);
                     var targetBox = controllerBox.TargetBox;
                     if (targetBox != null)
                     {
                         //move target box too 
                         targetBox.SetBounds(controllerBox.Left + 5,
                             controllerBox.Top + 5,
                             controllerBox.Width - 10,
                             controllerBox.Height - 10);
                     }
                 }
             }
             break;
         case SpaceName.LeftBottom:
             {
                 if (xdiff != 0 || ydiff != 0)
                 {
                     controllerBox.SetLocation(controllerBox.Left + xdiff, controllerBox.Top);
                     controllerBox.SetSize(controllerBox.Width - xdiff, controllerBox.Height + ydiff);
                     var targetBox = controllerBox.TargetBox;
                     if (targetBox != null)
                     {
                         //move target box too 
                         targetBox.SetBounds(controllerBox.Left + 5,
                             controllerBox.Top + 5,
                             controllerBox.Width - 10,
                             controllerBox.Height - 10);
                     }
                 }
             }
             break;
     }
 }