Ejemplo n.º 1
0
        async Task Viewport_DragDropProcess(EngineNS.PointF mousePt)
        {
            var rc = EngineNS.CEngine.Instance.RenderContext;

            // 计算一次鼠标所在的能够添加子的控件
            var uiElement = CalculateCanAddChildableUIElement(ref mousePt);

            if (uiElement == null)
            {
                return;
            }

            var mousePos = GetMouseInUserControl(ref mousePt);
            List <EngineNS.UISystem.UIElement> elemList = new List <EngineNS.UISystem.UIElement>();

            foreach (var dragObj in EditorCommon.DragDrop.DragDropManager.Instance.DragedObjectList)
            {
                var ctrlView = dragObj as UIEditor.ControlView;
                if (ctrlView == null)
                {
                    continue;
                }

                var atts = ctrlView.UIControlType.GetCustomAttributes(typeof(EngineNS.UISystem.Editor_UIControlInitAttribute), false);
                if (atts.Length <= 0)
                {
                    continue;
                }
                var att    = atts[0] as EngineNS.UISystem.Editor_UIControlInitAttribute;
                var init   = System.Activator.CreateInstance(att.InitializerType) as EngineNS.UISystem.UIElementInitializer;
                var uiCtrl = System.Activator.CreateInstance(ctrlView.UIControlType) as EngineNS.UISystem.UIElement;
                await uiCtrl.Initialize(rc, init);

                /*
                 *
                 * if (uiElement is EngineNS.UISystem.Controls.Containers.ContentControl)
                 * {
                 *  var ctrl = uiElement as EngineNS.UISystem.Controls.Containers.ContentControl;
                 *  ctrl.Content = uiCtrl;
                 *  var offsetX = mousePos.X;// - ctrl.DesignRect.X;
                 *  var offsetY = mousePos.Y;// - ctrl.DesignRect.Y;
                 *  var dr = uiCtrl.DesignRect;
                 *  var rect = new EngineNS.RectangleF(offsetX, offsetY, dr.Width, dr.Height);
                 *  uiCtrl.Slot.ProcessSetContentDesignRect(ref rect);
                 * }
                 * else if (uiElement is EngineNS.UISystem.Controls.Containers.Panel)
                 * {
                 *  var ctrl = uiElement as EngineNS.UISystem.Controls.Containers.Panel;
                 *  ctrl.AddChild(uiCtrl);
                 *  var offsetX = mousePos.X;// - ctrl.DesignRect.X;
                 *  var offsetY = mousePos.Y;// - ctrl.DesignRect.Y;
                 *  var dr = uiCtrl.DesignRect;
                 *  var rect = new EngineNS.RectangleF(offsetX, offsetY, dr.Width, dr.Height);
                 *  uiCtrl.Slot.ProcessSetContentDesignRect(ref rect);
                 * }*/

                elemList.Add(uiCtrl);
            }
            HostDesignPanel.BroadcastAddChildren(this, uiElement, mousePos, elemList.ToArray());
        }
Ejemplo n.º 2
0
        EngineNS.PointF GetMouseInUserControl(ref EngineNS.PointF mouseInViewport)
        {
            var pos = new EngineNS.PointF(mouseInViewport.X - mWindowDrawSize.Left, mouseInViewport.Y - mWindowDrawSize.Top);

            pos.X = pos.X * mWindowDesignSize.Width / mWindowDrawSize.Width;
            pos.Y = pos.Y * mWindowDesignSize.Height / mWindowDrawSize.Height;
            return(pos);
        }
Ejemplo n.º 3
0
        EngineNS.UISystem.UIElement CalculateCanAddChildableUIElement(ref EngineNS.PointF mouseInViewport)
        {
            if (HostDesignPanel.CurrentUI == null)
            {
                return(null);
            }

            var pos     = GetMouseInUserControl(ref mouseInViewport);
            var element = CheckPointAtUIElement(ref pos, true);

            return(CalculateCanAddChildableUIElement(element));
        }
Ejemplo n.º 4
0
        // 鼠标指向
        public bool ProcessMousePointAt(ref EngineNS.PointF mouseInViewport, Action <EngineNS.UISystem.Editor.enCursors> setCursorAction)
        {
            if (!mInitialized)
            {
                return(false);
            }
            var retVal = ProcessMousePointAtTransformHandles(ref mouseInViewport, setCursorAction);

            if (retVal == true)
            {
                return(retVal);
            }
            return(ProcessMousePointAtAnchorsHandle(ref mouseInViewport, setCursorAction));
        }
Ejemplo n.º 5
0
 void ProcessSelectTransformHandle(ref EngineNS.PointF mouseInViewport)
 {
     mSelectedHandleType = enTransformOPHandleType.Unknow;
     for (int i = 0; i < (int)enTransformOPHandleType.Count; i++)
     {
         var handle = mTransformHandles[i];
         if (handle == null)
         {
             continue;
         }
         if (handle.Show.Visibility != EngineNS.UISystem.Visibility.Visible)
         {
             continue;
         }
         if (handle.Show.DesignRect.Contains(ref mouseInViewport))
         {
             mSelectedHandleType = (enTransformOPHandleType)i;
         }
     }
 }
Ejemplo n.º 6
0
        EngineNS.UISystem.UIElement CheckPointAtUIElement(ref EngineNS.PointF pos, bool onlyClipped)
        {
            var pointAtUIElement = HostDesignPanel.CurrentUI.GetPointAtElement(ref pos, onlyClipped);
            var tempParent       = pointAtUIElement;

            while (tempParent != null)
            {
                if (tempParent is EngineNS.UISystem.Controls.UserControl)
                {
                    break;
                }

                tempParent = tempParent.Parent;
            }
            if (tempParent == HostDesignPanel.CurrentUI)
            {
                return(pointAtUIElement);
            }
            else
            {
                return(tempParent);
            }
        }
Ejemplo n.º 7
0
 private void Viewport_DragOver(object sender, System.Windows.Forms.DragEventArgs e)
 {
     if (EditorCommon.DragDrop.DragDropManager.Instance.DragType.Equals(EngineNS.UISystem.Program.ControlDragType))
     {
         var pt      = PointFromScreen(new System.Windows.Point(e.X, e.Y));
         var mousePt = new EngineNS.PointF((float)pt.X, (float)pt.Y);
         if (mWindowDrawSize.Contains(mousePt))
         {
             var uiElement = CalculateCanAddChildableUIElement(ref mousePt);
             if (uiElement == null)
             {
                 e.Effect = System.Windows.Forms.DragDropEffects.None;
             }
             else
             {
                 e.Effect = System.Windows.Forms.DragDropEffects.Copy;
             }
         }
         else
         {
             e.Effect = System.Windows.Forms.DragDropEffects.None;
         }
     }
 }
Ejemplo n.º 8
0
        bool ProcessMousePointAtTransformHandles(ref EngineNS.PointF mouseInViewport, Action <EngineNS.UISystem.Editor.enCursors> setCursorAction)
        {
            for (int i = 0; i < mTransformHandles.Length; i++)
            {
                var data = mTransformHandles[i];
                if (data == null)
                {
                    continue;
                }
                if (data.Show.Visibility != EngineNS.UISystem.Visibility.Visible)
                {
                    continue;
                }
                if (data.Show.DesignRect.Contains(ref mouseInViewport))
                {
                    switch ((enTransformOPHandleType)i)
                    {
                    case enTransformOPHandleType.Left:
                        //this.Cursor = System.Windows.Input.Cursors.SizeWE;
                        setCursorAction(Editor.enCursors.SizeWE);
                        break;

                    case enTransformOPHandleType.LeftTop:
                        //this.Cursor = System.Windows.Input.Cursors.SizeNWSE;
                        setCursorAction(Editor.enCursors.SizeNWSE);
                        break;

                    case enTransformOPHandleType.Top:
                        //this.Cursor = System.Windows.Input.Cursors.SizeNS;
                        setCursorAction(Editor.enCursors.SizeNS);
                        break;

                    case enTransformOPHandleType.RightTop:
                        //this.Cursor = System.Windows.Input.Cursors.SizeNESW;
                        setCursorAction(Editor.enCursors.SizeNESW);
                        break;

                    case enTransformOPHandleType.Right:
                        //this.Cursor = System.Windows.Input.Cursors.SizeWE;
                        setCursorAction(Editor.enCursors.SizeWE);
                        break;

                    case enTransformOPHandleType.RightBottom:
                        //this.Cursor = System.Windows.Input.Cursors.SizeNWSE;
                        setCursorAction(Editor.enCursors.SizeNWSE);
                        break;

                    case enTransformOPHandleType.Bottom:
                        //this.Cursor = System.Windows.Input.Cursors.SizeNS;
                        setCursorAction(Editor.enCursors.SizeNS);
                        break;

                    case enTransformOPHandleType.LeftBottom:
                        //this.Cursor = System.Windows.Input.Cursors.SizeNESW;
                        setCursorAction(Editor.enCursors.SizeNESW);
                        break;
                    }

                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 9
0
        bool ProcessMousePointAtAnchorsHandle(ref EngineNS.PointF mouseInViewport, Action <EngineNS.UISystem.Editor.enCursors> setCursorAction)
        {
            mSelectedAnchorHandleType = enCanvasAnchors.Unknow;
            for (int i = 0; i < mCanvasAnchorsHandles.Length; i++)
            {
                var data = mCanvasAnchorsHandles[i];
                if (data == null)
                {
                    continue;
                }
                if (data.Show.Visibility != EngineNS.UISystem.Visibility.Visible)
                {
                    continue;
                }
                if (data.Show.DesignRect.Contains(ref mouseInViewport))
                {
                    mSelectedAnchorHandleType = (enCanvasAnchors)i;
                    switch ((enCanvasAnchors)i)
                    {
                    case enCanvasAnchors.Center:
                        setCursorAction?.Invoke(Editor.enCursors.SizeAll);
                        //this.Cursor = System.Windows.Input.Cursors.SizeAll;
                        break;

                    case enCanvasAnchors.Left:
                        setCursorAction?.Invoke(Editor.enCursors.SizeWE);
                        //this.Cursor = System.Windows.Input.Cursors.SizeWE;
                        break;

                    case enCanvasAnchors.Top:
                        setCursorAction?.Invoke(Editor.enCursors.SizeNS);
                        //this.Cursor = System.Windows.Input.Cursors.SizeNS;
                        break;

                    case enCanvasAnchors.Right:
                        setCursorAction?.Invoke(Editor.enCursors.SizeWE);
                        //this.Cursor = System.Windows.Input.Cursors.SizeWE;
                        break;

                    case enCanvasAnchors.Bottom:
                        setCursorAction?.Invoke(Editor.enCursors.SizeNS);
                        //this.Cursor = System.Windows.Input.Cursors.SizeNS;
                        break;

                    case enCanvasAnchors.LeftTop:
                        setCursorAction?.Invoke(Editor.enCursors.SizeNWSE);
                        //this.Cursor = System.Windows.Input.Cursors.SizeNWSE;
                        break;

                    case enCanvasAnchors.RightTop:
                        setCursorAction?.Invoke(Editor.enCursors.SizeNESW);
                        //this.Cursor = System.Windows.Input.Cursors.SizeNESW;
                        break;

                    case enCanvasAnchors.RightBottom:
                        setCursorAction?.Invoke(Editor.enCursors.SizeNWSE);
                        //this.Cursor = System.Windows.Input.Cursors.SizeNWSE;
                        break;

                    case enCanvasAnchors.LeftBottom:
                        setCursorAction?.Invoke(Editor.enCursors.SizeNESW);
                        //this.Cursor = System.Windows.Input.Cursors.SizeNESW;
                        break;
                    }

                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 10
0
        void ProcessSelectAnchorsHandle(EngineNS.UISystem.Editor.SelectedData operationUIData, ref EngineNS.PointF mouseInViewport)
        {
            if (operationUIData == null || mSelectedAnchorHandleType == enCanvasAnchors.Unknow)
            {
                return;
            }
            var anchorOp = operationUIData.UI.Slot as EngineNS.UISystem.Controls.Containers.CanvasSlot;

            if (anchorOp == null)
            {
                return;
            }

            mCanvasAnchorsHandles[(int)mSelectedAnchorHandleType].StartMin = anchorOp.Minimum;
            mCanvasAnchorsHandles[(int)mSelectedAnchorHandleType].StartMax = anchorOp.Maximum;
        }
Ejemplo n.º 11
0
 // 选中操作点
 public void ProcessSelect(EngineNS.UISystem.Editor.SelectedData operationUIData, ref EngineNS.PointF mouseInViewport)
 {
     if (!mInitialized)
     {
         return;
     }
     ProcessSelectAnchorsHandle(operationUIData, ref mouseInViewport);
     ProcessSelectTransformHandle(ref mouseInViewport);
 }
Ejemplo n.º 12
0
        async Task SelectProcess(bool mouseUp)
        {
            mReSelectOnMouseUp = false;
            var mouseInViewport = new EngineNS.PointF(mMouseLoc.X, mMouseLoc.Y);

            // 判断是否在handle上
            if (mSelectedUIDatas.Count == 1)
            {
                mSlotOperator?.ProcessSelect(mSelectedUIDatas.First().Value, ref mouseInViewport);
            }
            if (mSlotOperator == null || (mSlotOperator != null && !mSlotOperator.IsSelectedOperator()))
            {
                var  pos   = GetMouseInUserControl(ref mouseInViewport);
                bool multi = false;
                if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
                {
                    multi = true;
                }

                List <EngineNS.UISystem.UIElement> selectUIs = new List <EngineNS.UISystem.UIElement>();
                var element = CheckPointAtUIElement(ref pos, false);
                if (element != null)
                {
                    bool find = false;
                    if (multi)
                    {
                        if (mSelectedUIDatas.ContainsKey(element))
                        {
                            find = true;
                            mSelectedUIDatas.Remove(element);
                        }
                        foreach (var ui in mSelectedUIDatas)
                        {
                            selectUIs.Add(ui.Key);
                        }
                    }
                    else
                    {
                        if (mSelectedUIDatas.ContainsKey(element) && !mouseUp)
                        {
                            find = true;
                            mReSelectOnMouseUp = true;
                            foreach (var ui in mSelectedUIDatas)
                            {
                                selectUIs.Add(ui.Key);
                            }
                        }
                        else
                        {
                            //mSelectedUIDatas.Clear();
                            selectUIs.Clear();
                        }
                    }

                    if (find == false)
                    {
                        //var data = new EngineNS.UISystem.Editor.SelectedData();
                        //data.UI = element;
                        //data.StartRect = element.DesignRect;
                        //var rc = EngineNS.CEngine.Instance.RenderContext;
                        //var showRectInit = new EngineNS.UISystem.Controls.ImageInitializer();
                        //showRectInit.ImageBrush.ImageName = EngineNS.RName.GetRName("uieditor/uva_selectrect.uvanim", EngineNS.RName.enRNameType.Editor);
                        //showRectInit.ImageBrush.TileMode = EngineNS.UISystem.Brush.enTileMode.None;
                        //var showRect = new EngineNS.UISystem.Controls.Image();
                        //await showRect.Initialize(rc, showRectInit);
                        //data.ShowRect = showRect;

                        //mSelectedUIDatas[element] = data;
                        selectUIs.Add(element);
                    }
                    // 刷新所有StartDesignRect
                    foreach (var data in mSelectedUIDatas.Values)
                    {
                        data.StartRect = data.UI.DesignRect;
                    }
                }
                else if (!multi)
                {
                    //mSelectedUIDatas.Clear();
                    selectUIs.Clear();
                }

                //var selectUIs = mSelectedUIDatas.Keys.ToArray();
                HostDesignPanel.BroadcastSelectedUI(this, selectUIs.ToArray());
                await InitSlotOperator();

                UpdateSelectedRectShow();
            }
            else
            {
                foreach (var data in mSelectedUIDatas.Values)
                {
                    data.StartRect = data.UI.DesignRect;
                }
            }
        }
Ejemplo n.º 13
0
        void Viewport_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            var delta = new EngineNS.Vector2(e.Location.X - mMouseLoc.X, e.Location.Y - mMouseLoc.Y);

            if (e.Button.HasFlag(System.Windows.Forms.MouseButtons.Right) && mDragViewport)
            {
                mGridDrawSize.X = mStartDrawSize.X + delta.X;
                mGridDrawSize.Y = mStartDrawSize.Y + delta.Y;

                mWindowDrawSize.X = mStartWindowDrawSize.X + delta.X;
                mWindowDrawSize.Y = mStartWindowDrawSize.Y + delta.Y;

                UpdateUIShow();
                UpdateUIAssistShow();
            }
            else if (e.Button.HasFlag(System.Windows.Forms.MouseButtons.Left) && mDragViewport)
            {
                if (System.Math.Abs(delta.X) > 2 || System.Math.Abs(delta.Y) > 2)
                {
                    mReSelectOnMouseUp = false;
                }

                var scaleDelta = mWindowDesignSize.Width / mWindowDrawSize.Width;
                //if(mSelectedHandleType != enTransformOPHandleType.Unknow)
                //{
                //    OperationTransformHandle(ref delta, scaleDelta);
                //}
                /*else */ if (mSlotOperator != null && mSlotOperator.IsSelectedOperator())
                {
                    if (mSelectedUIDatas.Count == 1)
                    {
                        mSlotOperator?.Operation(mSelectedUIDatas.First().Value, ref delta, scaleDelta);
                    }
                }
                //else if (mSelectedAnchorHandleType != enCanvasAnchors.Unknow)
                //{
                //    OperationAnchorsHandle(ref delta, scaleDelta);
                //}
                else
                {
                    foreach (var data in mSelectedUIDatas.Values)
                    {
                        var ds = data.UI.DesignRect;
                        ds.X = data.StartRect.X + delta.X * scaleDelta;
                        ds.Y = data.StartRect.Y + delta.Y * scaleDelta;
                        if (data.UI.Slot != null)
                        {
                            data.UI.Slot.ProcessSetContentDesignRect(ref ds);
                        }
                        else
                        {
                            data.UI.SetDesignRect(ref ds);
                        }
                    }
                }
                UpdateSelectedRectShow();
            }
            else if (HostDesignPanel.CurrentUI != null)
            {
                var mouseInViewport = new EngineNS.PointF(e.Location.X, e.Location.Y);
                // 判断鼠标是不是在控制点上
                //bool isInHandle = ProcessMousePointAtTransformHandles(ref mouseInViewport);
                //if(isInHandle == false)
                //    isInHandle = ProcessMousePointAtAnchorsHandle(ref mouseInViewport);
                bool isInHandle = false;
                if (mSlotOperator != null)
                {
                    isInHandle = mSlotOperator.ProcessMousePointAt(ref mouseInViewport, (cur) =>
                    {
                        switch (cur)
                        {
                        case EngineNS.UISystem.Editor.enCursors.SizeAll:
                            this.Cursor = System.Windows.Input.Cursors.SizeAll;
                            break;

                        case EngineNS.UISystem.Editor.enCursors.SizeWE:
                            this.Cursor = System.Windows.Input.Cursors.SizeWE;
                            break;

                        case EngineNS.UISystem.Editor.enCursors.SizeNS:
                            this.Cursor = System.Windows.Input.Cursors.SizeNS;
                            break;

                        case EngineNS.UISystem.Editor.enCursors.SizeNWSE:
                            this.Cursor = System.Windows.Input.Cursors.SizeNWSE;
                            break;

                        case EngineNS.UISystem.Editor.enCursors.SizeNESW:
                            this.Cursor = System.Windows.Input.Cursors.SizeNESW;
                            break;
                        }
                    });
                }

                if (!isInHandle)
                {
                    this.Cursor = System.Windows.Input.Cursors.Arrow;
                    // 判断鼠标位于哪个控件上
                    var pos = GetMouseInUserControl(ref mouseInViewport);
                    mMousePointAtUIElement = CheckPointAtUIElement(ref pos, false);
                    UpdatePointAtShow();
                }
            }
        }