protected override void OnStart(AppHost host)
        {
            var box1 = new LayoutFarm.CustomWidgets.Box(50, 50);

            box1.BackColor = Color.Red;
            box1.SetLocation(10, 10);
            //box1.dbugTag = 1;
            SetupActiveBoxProperties(box1);
            host.AddChild(box1);
            var box2 = new LayoutFarm.CustomWidgets.Box(30, 30);

            box2.SetLocation(50, 50);
            //box2.dbugTag = 2;
            SetupActiveBoxProperties(box2);
            host.AddChild(box2);
            _controllerBox1 = new UIControllerBox(40, 40);
            Color c = KnownColors.FromKnownColor(KnownColor.Yellow);

            _controllerBox1.BackColor = new Color(100, c.R, c.G, c.B);
            _controllerBox1.SetLocation(200, 200);
            //controllerBox1.dbugTag = 3;
            _controllerBox1.Visible = false;
            SetupControllerBoxProperties(_controllerBox1);
            host.AddChild(_controllerBox1);
        }
        UIControllerBox GetFreeUserControllerBox()
        {
            if (userControllerPool.Count > 0)
            {
                var controlBox = userControllerPool.Dequeue();
                //-------------------------------------------
                //register to working box list
                workingControllerBoxes.Add(controlBox);
                return controlBox;
            }
            else
            {
                //create new one

                //controller box 1 (red corners)
                var controllerBox1 = new UIControllerBox(40, 40);
                Color c = KnownColors.FromKnownColor(KnownColor.Yellow);
                controllerBox1.BackColor = new Color(100, c.R, c.G, c.B);
                controllerBox1.SetLocation(200, 200);
                //controllerBox1.dbugTag = 3;
                controllerBox1.Visible = false;
                SetupControllerBoxProperties(controllerBox1);
                //-------------------------------------------
                //register to working box list
                workingControllerBoxes.Add(controllerBox1);
                return controllerBox1;
            }
        }
示例#3
0
        protected override void OnStartDemo(SampleViewport viewport)
        {
            var box1 = new LayoutFarm.CustomWidgets.SimpleBox(50, 50);

            box1.BackColor = Color.Red;
            box1.SetLocation(10, 10);
            //box1.dbugTag = 1;
            SetupActiveBoxProperties(box1);
            viewport.AddContent(box1);

            var box2 = new LayoutFarm.CustomWidgets.SimpleBox(30, 30);

            box2.SetLocation(50, 50);
            //box2.dbugTag = 2;
            SetupActiveBoxProperties(box2);
            viewport.AddContent(box2);


            controllerBox1 = new UIControllerBox(40, 40);
            Color c = KnownColors.FromKnownColor(KnownColor.Yellow);

            controllerBox1.BackColor = new Color(100, c.R, c.G, c.B);
            controllerBox1.SetLocation(200, 200);
            //controllerBox1.dbugTag = 3;
            controllerBox1.Visible = false;
            SetupControllerBoxProperties(controllerBox1);
            viewport.AddContent(controllerBox1);
        }
        protected override void OnStartDemo(SampleViewport viewport)
        {
            var bgbox = new LayoutFarm.CustomWidgets.SimpleBox(800, 600);
            bgbox.BackColor = Color.White;
            bgbox.SetLocation(0, 0);
            SetupBackgroundProperties(bgbox);
            viewport.AddContent(bgbox);
            //--------------------------------

            var box1 = new LayoutFarm.CustomWidgets.SimpleBox(150, 150);
            box1.BackColor = Color.Red;
            box1.SetLocation(10, 10);
            //box1.dbugTag = 1;
            SetupActiveBoxProperties(box1);
            viewport.AddContent(box1);
            //--------------------------------
            var box2 = new LayoutFarm.CustomWidgets.SimpleBox(60, 60);
            box2.SetLocation(50, 50);
            //box2.dbugTag = 2;
            SetupActiveBoxProperties(box2);
            viewport.AddContent(box2);
            controllerBox1 = new UIControllerBox(40, 40);
            Color c = KnownColors.FromKnownColor(KnownColor.Yellow);
            controllerBox1.BackColor = new Color(100, c.R, c.G, c.B);
            controllerBox1.SetLocation(200, 200);
            //controllerBox1.dbugTag = 3;
            controllerBox1.Visible = false;
            SetupControllerBoxProperties(controllerBox1);
            viewport.AddContent(controllerBox1);
        }
        UIControllerBox GetFreeUserControllerBox()
        {
            if (userControllerPool.Count > 0)
            {
                var controlBox = userControllerPool.Dequeue();
                //-------------------------------------------
                //register to working box list
                workingControllerBoxes.Add(controlBox);
                return(controlBox);
            }
            else
            {
                //create new one

                //controller box 1 (red corners)
                var   controllerBox1 = new UIControllerBox(40, 40);
                Color c = KnownColors.FromKnownColor(KnownColor.Yellow);
                controllerBox1.BackColor = new Color(100, c.R, c.G, c.B);
                controllerBox1.SetLocation(200, 200);
                //controllerBox1.dbugTag = 3;
                controllerBox1.Visible = false;
                SetupControllerBoxProperties(controllerBox1);
                //-------------------------------------------
                //register to working box list
                workingControllerBoxes.Add(controllerBox1);

                return(controllerBox1);
            }
        }
示例#6
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 ReleaseUserControllerBox(UIControllerBox userControllerBox)
 {
     workingControllerBoxes.Remove(userControllerBox);
     userControllerBox.Visible   = false;
     userControllerBox.TargetBox = null;
     userControllerBox.RemoveSelf();
     this.userControllerPool.Enqueue(userControllerBox);
 }
 static void SetupControllerBoxProperties(UIControllerBox controllerBox)
 {
     //for controller box
     controllerBox.MouseDrag += (s, e) =>
     {
         MoveWithSnapToGrid(controllerBox, e.DiffCapturedX, e.DiffCapturedY);
         e.MouseCursorStyle = MouseCursorStyle.Pointer;
         e.CancelBubbling   = true;
     };
 }
        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);
                }
            }
        }
示例#10
0
 static void SetupControllerBoxProperties(UIControllerBox controllerBox)
 {
     //for controller box
     controllerBox.MouseDrag += (s, e) =>
     {
         Point pos  = controllerBox.Position;
         int   newX = pos.X + e.XDiff;
         int   newY = pos.Y + e.YDiff;
         controllerBox.SetLocation(newX, newY);
         var targetBox = controllerBox.TargetBox;
         if (targetBox != null)
         {
             //move target box too
             targetBox.SetLocation(newX + 5, newY + 5);
         }
         e.CancelBubbling = true;
     };
 }
 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);
     var targetBox = controllerBox.TargetBox;
     if (targetBox != null)
     {
         //move target box too
         targetBox.SetLocation(nearestX + gridSize, nearestY + gridSize);
     }
 }
 static void SetupControllerBoxProperties(UIControllerBox controllerBox)
 {
     //for controller box  
     controllerBox.MouseDrag += (s, e) =>
     {
         Point pos = controllerBox.Position;
         int newX = pos.X + e.XDiff;
         int newY = pos.Y + e.YDiff;
         controllerBox.SetLocation(newX, newY);
         var targetBox = controllerBox.TargetBox;
         if (targetBox != null)
         {
             //move target box too
             targetBox.SetLocation(newX + 5, newY + 5);
         }
         e.CancelBubbling = true;
     };
 }
        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);
            var targetBox = controllerBox.TargetBox;

            if (targetBox != null)
            {
                //move target box too
                targetBox.SetLocation(nearestX + gridSize, nearestY + gridSize);
            }
        }
示例#14
0
        static void MoveWithSnapToGrid(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;
            controllerBox.SetLocation(nearestX, nearestY);
            var targetBox = controllerBox.TargetBox;
            if (targetBox != null)
            {
                //move target box too

                targetBox.SetLocation(nearestX + gridSize, nearestY + gridSize);
            }
        }
示例#15
0
        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)
        {
            var       dragOverElements  = new List <LayoutFarm.UI.UIBox>();
            Rectangle controllerBoxArea = controllerBox.Bounds;
            int       j = bgbox.ChildCount;

            for (int i = 0; i < j; ++i)
            {
                var box = bgbox.GetChild(i) as LayoutFarm.UI.UIBox;
                if (box == null || controllerBox.TargetBox == box)
                {
                    continue;
                }

                //-------------
                if (controllerBoxArea.IntersectsWith(box.Bounds))
                {
                    dragOverElements.Add(box);
                }
            }
            return(dragOverElements);
        }
示例#17
0
        static void MoveWithSnapToGrid(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;

            controllerBox.SetLocation(nearestX, nearestY);
            var targetBox = controllerBox.TargetBox;

            if (targetBox != null)
            {
                //move target box too

                targetBox.SetLocation(nearestX + gridSize, nearestY + gridSize);
            }
        }
 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)
        {
            var dragOverElements = new List<LayoutFarm.UI.UIBox>();
            Rectangle controllerBoxArea = controllerBox.Bounds;
            int j = bgbox.ChildCount;
            for (int i = 0; i < j; ++i)
            {
                var box = bgbox.GetChild(i) as LayoutFarm.UI.UIBox;
                if (box == null || controllerBox.TargetBox == box)
                {
                    continue;
                }

                //------------- 
                if (controllerBoxArea.IntersectsWith(box.Bounds))
                {
                    dragOverElements.Add(box);
                }
            }
            return dragOverElements;
        }
            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 SetupControllerBoxProperties(UIControllerBox controllerBox)
        {
            //for controller box
            controllerBox.MouseUp += (s, e) =>
            {
                if (e.IsDragging)
                {
                    //this is dropping
                    //find underlying element to drop into

                    var dragOverElements = FindUnderlyingElements(controllerBox);
                    if (dragOverElements.Count > 0)
                    {
                        //TODO: review here
                        //this version we select the first one

                        var listener = dragOverElements[0] as IEventListener;
                        if (listener != null)
                        {
                            var talkMsg = new UIGuestTalkEventArgs();
                            talkMsg.Sender       = controllerBox;
                            talkMsg.UserMsgFlags = 3;//send drop notify
                            listener.ListenGuestTalk(talkMsg);
                        }
                    }
                }
            };
            controllerBox.MouseDrag += (s, e) =>
            {
                MoveWithSnapToGrid(controllerBox, e.DiffCapturedX, e.DiffCapturedY);
                e.MouseCursorStyle = MouseCursorStyle.Pointer;
                e.CancelBubbling   = true;
                //test here -----------------------------------------------------
                //find dragover element ***

                var dragOverElements = FindUnderlyingElements(controllerBox);
                if (dragOverElements.Count == 0)
                {
                    Dictionary <UIElement, int> prevDragOverElements = controllerBox.LastestDragOverElements;
                    if (prevDragOverElements != null)
                    {
                        foreach (var leavingElement in prevDragOverElements.Keys)
                        {
                            var listener = leavingElement as IEventListener;
                            if (listener != null)
                            {
                                var talkMsg = new UIGuestTalkEventArgs();
                                talkMsg.Sender       = controllerBox;
                                talkMsg.UserMsgFlags = 2;//leaving //sample only
                                listener.ListenGuestTalk(talkMsg);
                            }
                        }
                    }

                    controllerBox.LastestDragOverElements = null;
                }
                else
                {
                    //send notification to another box
                    //use guest talk msg***
                    //check state of guest
                    Dictionary <UIElement, int> prevDragOverElements   = controllerBox.LastestDragOverElements;
                    Dictionary <UIElement, int> latestDragOverElements = new Dictionary <UIElement, int>();
                    if (prevDragOverElements != null)
                    {
                        int j = dragOverElements.Count;
                        for (int i = 0; i < j; ++i)
                        {
                            var dragOverE = dragOverElements[i];

                            int state;
                            if (prevDragOverElements.TryGetValue(dragOverE, out state))
                            {
                                //found in latest drag overelement
                                //remove
                                prevDragOverElements.Remove(dragOverE);
                            }

                            latestDragOverElements.Add(dragOverE, ++state);
                        }
                        //remaining elements
                        foreach (var leavingElement in prevDragOverElements.Keys)
                        {
                            var listener = leavingElement as IEventListener;
                            if (listener != null)
                            {
                                var talkMsg = new UIGuestTalkEventArgs();
                                talkMsg.Sender       = controllerBox;
                                talkMsg.UserMsgFlags = 2;//leaving //sample only
                                listener.ListenGuestTalk(talkMsg);
                            }
                        }
                    }
                    else
                    {
                        foreach (var drgElement in dragOverElements)
                        {
                            latestDragOverElements.Add(drgElement, 0);
                        }
                    }

                    controllerBox.LastestDragOverElements = latestDragOverElements;
                    foreach (var drgElement in latestDragOverElements.Keys)
                    {
                        var listener = drgElement as IEventListener;
                        if (listener != null)
                        {
                            var talkMsg = new UIGuestTalkEventArgs();
                            talkMsg.Sender       = controllerBox;
                            talkMsg.UserMsgFlags = 1;//sample only
                            listener.ListenGuestTalk(talkMsg);
                        }
                    }
                }
            };
        }
        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;
                }
            };
        }
        void SetupControllerBoxProperties(UIControllerBox controllerBox)
        {
            //for controller box
            controllerBox.MouseUp += (s, e) =>
            {
                if (e.IsDragging)
                {
                    //this is dropping 
                    //find underlying element to drop into  

                    var dragOverElements = FindUnderlyingElements(controllerBox);
                    if (dragOverElements.Count > 0)
                    {
                        //TODO: review here
                        //this version we select the first one

                        var listener = dragOverElements[0] as IEventListener;
                        if (listener != null)
                        {
                            var talkMsg = new UIGuestTalkEventArgs();
                            talkMsg.Sender = controllerBox;
                            talkMsg.UserMsgFlags = 3;//send drop notify                             
                            listener.ListenGuestTalk(talkMsg);
                        }
                    }
                }
            };
            controllerBox.MouseDrag += (s, e) =>
            {
                MoveWithSnapToGrid(controllerBox, e.DiffCapturedX, e.DiffCapturedY);
                e.MouseCursorStyle = MouseCursorStyle.Pointer;
                e.CancelBubbling = true;
                //test here -----------------------------------------------------
                //find dragover element ***

                var dragOverElements = FindUnderlyingElements(controllerBox);
                if (dragOverElements.Count == 0)
                {
                    Dictionary<UIElement, int> prevDragOverElements = controllerBox.LastestDragOverElements;
                    if (prevDragOverElements != null)
                    {
                        foreach (var leavingElement in prevDragOverElements.Keys)
                        {
                            var listener = leavingElement as IEventListener;
                            if (listener != null)
                            {
                                var talkMsg = new UIGuestTalkEventArgs();
                                talkMsg.Sender = controllerBox;
                                talkMsg.UserMsgFlags = 2;//leaving //sample only
                                listener.ListenGuestTalk(talkMsg);
                            }
                        }
                    }

                    controllerBox.LastestDragOverElements = null;
                }
                else
                {
                    //send notification to another box 
                    //use guest talk msg*** 
                    //check state of guest 
                    Dictionary<UIElement, int> prevDragOverElements = controllerBox.LastestDragOverElements;
                    Dictionary<UIElement, int> latestDragOverElements = new Dictionary<UIElement, int>();
                    if (prevDragOverElements != null)
                    {
                        int j = dragOverElements.Count;
                        for (int i = 0; i < j; ++i)
                        {
                            var dragOverE = dragOverElements[i];
                            int state;
                            if (prevDragOverElements.TryGetValue(dragOverE, out state))
                            {
                                //found in latest drag overelement 
                                //remove 
                                prevDragOverElements.Remove(dragOverE);
                            }

                            latestDragOverElements.Add(dragOverE, ++state);
                        }
                        //remaining elements
                        foreach (var leavingElement in prevDragOverElements.Keys)
                        {
                            var listener = leavingElement as IEventListener;
                            if (listener != null)
                            {
                                var talkMsg = new UIGuestTalkEventArgs();
                                talkMsg.Sender = controllerBox;
                                talkMsg.UserMsgFlags = 2;//leaving //sample only
                                listener.ListenGuestTalk(talkMsg);
                            }
                        }
                    }
                    else
                    {
                        foreach (var drgElement in dragOverElements)
                        {
                            latestDragOverElements.Add(drgElement, 0);
                        }
                    }

                    controllerBox.LastestDragOverElements = latestDragOverElements;
                    foreach (var drgElement in latestDragOverElements.Keys)
                    {
                        var listener = drgElement as IEventListener;
                        if (listener != null)
                        {
                            var talkMsg = new UIGuestTalkEventArgs();
                            talkMsg.Sender = controllerBox;
                            talkMsg.UserMsgFlags = 1;//sample only
                            listener.ListenGuestTalk(talkMsg);
                        }
                    }
                }
            };
        }
 void ReleaseUserControllerBox(UIControllerBox userControllerBox)
 {
     workingControllerBoxes.Remove(userControllerBox);
     userControllerBox.Visible = false;
     userControllerBox.TargetBox = null;
     userControllerBox.RemoveSelf();
     this.userControllerPool.Enqueue(userControllerBox);
 }
示例#25
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;
     }
 }
示例#26
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);
                }
            }
 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;
         }
     };
 }
示例#28
0
        static void SetupControllerBoxProperties(UIControllerBox controllerBox)
        {
            //for controller box

            controllerBox.MouseDrag += (s, e) =>
            {
                MoveWithSnapToGrid(controllerBox, e);
                e.MouseCursorStyle = MouseCursorStyle.Pointer;
                e.CancelBubbling = true;
            };
        }