Exemple #1
0
 /// <summary>
 /// Initializes the <see cref="Common.UI.DragAndDrop.DragData"/> class.
 /// </summary>
 static DragData()
 {
     mType          = DraggingType.None;
     mDraggingImage = null;
     mWidth         = 0f;
     mHeight        = 0f;
     mDragPosX      = 0f;
     mDragPosY      = 0f;
 }
Exemple #2
0
        /// <summary>
        /// Set the dragging type
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnDragModeChanged(object sender, RoutedEventArgs e)
        {
            //Dock Dragging Type
            MenuItem item = sender as MenuItem;

            OnMenuItemClick(item);
            DraggingType type = ( DraggingType )Enum.Parse(typeof(DraggingType),
                                                           ( string )item.Header);

            DockingManager.DraggingType = type;
        }
        /// <summary>
        /// Initializes the <see cref="Common.UI.DragAndDrop.DragData"/> class.
        /// </summary>
        static DragData()
        {
            DebugEx.Verbose("Static class DragData initialized");

            sType          = DraggingType.None;
            sDraggingImage = null;
            sWidth         = 0f;
            sHeight        = 0f;
            sDragPosX      = 0f;
            sDragPosY      = 0f;
        }
Exemple #4
0
        /// <summary>
        /// Initializes the <see cref="Common.UI.DragAndDrop.DragData"/> class.
        /// </summary>
        static DragData()
        {
            DebugEx.Verbose("Static class DragData initialized");

            sType          = DraggingType.None;
            sDraggingImage = null;
            sWidth         = 0f;
            sHeight        = 0f;
            sDragPosX      = 0f;
            sDragPosY      = 0f;
        }
Exemple #5
0
        /// <summary>
        /// Ends dragging.
        /// </summary>
        public static void EndDrag()
        {
            DebugEx.Verbose("DragData.EndDrag()");

            if (sType != DraggingType.None)
            {
                UnityEngine.Object.DestroyObject(sDraggingImage);

                sType          = DraggingType.None;
                sDraggingImage = null;
                sWidth         = 0f;
                sHeight        = 0f;
                sDragPosX      = 0f;
                sDragPosY      = 0f;
            }
        }
Exemple #6
0
        void ProcessLeftClick(Event p_event, Rect p_rect)
        {
            if (p_event.button != 0)
            {
                return;
            }

            if (p_event.type == EventType.MouseDown)
            {
                GUI.FocusControl("");
            }

            // Select
            if (p_event.type == EventType.MouseDown && !p_event.alt && Graph != null && !p_event.control)
            {
                DashEditorWindow.SetDirty(true);

                NodeBase hitNode      = Graph.HitsNode(p_event.mousePosition * Zoom - new Vector2(p_rect.x, p_rect.y));
                int      hitNodeIndex = Graph.Nodes.IndexOf(hitNode);

                if (!SelectionManager.IsSelected(hitNodeIndex) && (!p_event.shift || hitNodeIndex == 0))
                {
                    SelectionManager.ClearSelection();
                }

                if (hitNodeIndex >= 0)
                {
                    AddSelectedNode(hitNodeIndex);

                    dragging = DraggingType.NODE_DRAG;
                }
                else
                {
                    GraphBox box = Graph.HitsBoxDrag(p_event.mousePosition * Zoom - new Vector2(p_rect.x, p_rect.y));

                    if (box != null)
                    {
                        DashEditorCore.selectedBox = box;
                        DashEditorCore.selectedBox.StartDrag();
                        dragging = DraggingType.BOX_DRAG;
                    }
                    else
                    {
                        box = Graph.HitsBoxResize(p_event.mousePosition * Zoom - new Vector2(p_rect.x, p_rect.y));

                        if (box != null)
                        {
                            DashEditorCore.selectedBox = box;
                            DashEditorCore.selectedBox.StartResize();
                            dragging = DraggingType.BOX_RESIZE;
                        }
                        else
                        {
                            dragging = DraggingType.SELECTION;
                            DashEditorCore.selectedBox = null;
                            Graph.connectingNode       = null;
                            selectedRegion             = new Rect(p_event.mousePosition.x, p_event.mousePosition.y, 0, 0);
                        }
                    }
                }
            }

            // Dragging
            if (p_event.type == EventType.MouseDrag)
            {
                switch (dragging)
                {
                case DraggingType.NODE_DRAG:
                    Vector2 delta = p_event.alt ? Snapping.Snap(p_event.delta, new Vector2(10, 10)): p_event.delta;
                    SelectionManager.DragSelectedNodes(delta, Graph);
                    break;

                case DraggingType.BOX_DRAG:
                    DashEditorCore.selectedBox.Drag(new Vector2(p_event.delta.x * Zoom, p_event.delta.y * Zoom));
                    break;

                case DraggingType.BOX_RESIZE:
                    DashEditorCore.selectedBox.Resize(new Vector2(p_event.delta.x * Zoom, p_event.delta.y * Zoom));
                    break;

                case DraggingType.SELECTION:
                    selectedRegion.width  += p_event.delta.x;
                    selectedRegion.height += p_event.delta.y;
                    Rect fixedRect = FixRect(selectedRegion);
                    SelectionManager.SelectingNodes(Graph.Nodes.FindAll(n => n.IsInsideRect(fixedRect)).Select(n => n.Index).ToList());
                    break;
                }

                DashEditorWindow.SetDirty(true);
            }

            if (p_event.type == EventType.MouseUp)
            {
                if (dragging == DraggingType.SELECTION)
                {
                    SelectionManager.SelectingToSelected();
                }

                if (dragging == DraggingType.NODE_DRAG || dragging == DraggingType.BOX_DRAG || dragging == DraggingType.BOX_RESIZE)
                {
                    DashEditorCore.SetDirty();
                }

                dragging       = DraggingType.NONE;
                selectedRegion = Rect.zero;
                DashEditorWindow.SetDirty(true);
            }
        }
        /// <summary>
        /// Ends dragging.
        /// </summary>
        public static void EndDrag()
        {
            DebugEx.Verbose("DragData.EndDrag()");

            if (sType != DraggingType.None)
            {
                UnityEngine.Object.DestroyObject(sDraggingImage);

                sType          = DraggingType.None;
                sDraggingImage = null;
                sWidth         = 0f;
                sHeight        = 0f;
                sDragPosX      = 0f;
                sDragPosY      = 0f;
            }
        }
        /// <summary>
        /// Begins dragging according to specified parameters.
        /// </summary>
        /// <param name="draggingType">Dragging type.</param>
        /// <param name="gameObject">Game object.</param>
        /// <param name="sprite">Sprite image.</param>
        /// <param name="width">Width.</param>
        /// <param name="height">Height.</param>
        /// <param name="dragPosX">Mouse dragged position X.</param>
        /// <param name="dragPosY">Mouse dragged position Y.</param>
        public static void BeginDrag(
                                       DraggingType draggingType
                                     , GameObject gameObject
                                     , Sprite sprite
                                     , float width
                                     , float height
                                     , float dragPosX = 0f
                                     , float dragPosY = 0f
                                    )
        {
            DebugEx.VerboseFormat("DragData.BeginDrag(gameObject = {0}, sprite = {1}, width = {2}, height = {3}, dragPosX = {4}, dragPosY = {5})"
                                  , gameObject
                                  , sprite
                                  , width
                                  , height
                                  , dragPosX
                                  , dragPosY);

            if (draggingType == DraggingType.None)
            {
                DebugEx.ErrorFormat("Invalid dragging type value: {0}", draggingType);
                return;
            }

            if (sType == DraggingType.None)
            {
                Canvas canvas = Utils.FindInParents<Canvas>(gameObject);

                if (canvas != null)
                {
                    sType     = draggingType;
                    sWidth    = width;
                    sHeight   = height;
                    sDragPosX = dragPosX;
                    sDragPosY = dragPosY;

                    //===========================================================================
                    // Image GameObject
                    //===========================================================================
                    #region Image GameObject
                    sDraggingImage = new GameObject("DraggingImage");
                    Utils.InitUIObject(sDraggingImage, canvas.transform);

                    //===========================================================================
                    // RectTransform Component
                    //===========================================================================
                    #region RectTransform Component
                    RectTransform imageTransform = sDraggingImage.AddComponent<RectTransform>();
                    Utils.AlignRectTransformTopLeft(imageTransform, sWidth, sHeight);
                    #endregion

                    //===========================================================================
                    // CanvasRenderer Component
                    //===========================================================================
                    #region CanvasRenderer Component
                    sDraggingImage.AddComponent<CanvasRenderer>();
                    #endregion

                    //===========================================================================
                    // Image Component
                    //===========================================================================
                    #region Image Component
                    Image image = sDraggingImage.AddComponent<Image>();

                    image.sprite = sprite;
                    image.type   = Image.Type.Sliced;
                    #endregion

                    //===========================================================================
                    // IgnoreRaycast Component
                    //===========================================================================
                    #region IgnoreRaycast Component
                    sDraggingImage.AddComponent<IgnoreRaycast>();
                    #endregion
                    #endregion

                    SetDraggedPosition();
                }
                else
                {
                    DebugEx.Error("Canvas not found");
                }
            }
            else
            {
                DebugEx.Error("Dragging in progress already");
            }
        }
Exemple #9
0
        /// <summary>
        /// Begins dragging according to specified parameters.
        /// </summary>
        /// <param name="draggingType">Dragging type.</param>
        /// <param name="gameObject">Game object.</param>
        /// <param name="sprite">Sprite image.</param>
        /// <param name="width">Width.</param>
        /// <param name="height">Height.</param>
        /// <param name="dragPosX">Mouse dragged position X.</param>
        /// <param name="dragPosY">Mouse dragged position Y.</param>
        public static void BeginDrag(
            DraggingType draggingType
            , GameObject gameObject
            , Sprite sprite
            , float width
            , float height
            , float dragPosX = 0f
            , float dragPosY = 0f
            )
        {
            DebugEx.VerboseFormat("DragData.BeginDrag(gameObject = {0}, sprite = {1}, width = {2}, height = {3}, dragPosX = {4}, dragPosY = {5})"
                                  , gameObject
                                  , sprite
                                  , width
                                  , height
                                  , dragPosX
                                  , dragPosY);

            if (draggingType == DraggingType.None)
            {
                DebugEx.ErrorFormat("Invalid dragging type value: {0}", draggingType);
                return;
            }

            if (sType == DraggingType.None)
            {
                Canvas canvas = Utils.FindInParents <Canvas>(gameObject);

                if (canvas != null)
                {
                    sType     = draggingType;
                    sWidth    = width;
                    sHeight   = height;
                    sDragPosX = dragPosX;
                    sDragPosY = dragPosY;

                    //===========================================================================
                    // Image GameObject
                    //===========================================================================
                    #region Image GameObject
                    sDraggingImage = new GameObject("DraggingImage");
                    Utils.InitUIObject(sDraggingImage, canvas.transform);

                    //===========================================================================
                    // RectTransform Component
                    //===========================================================================
                    #region RectTransform Component
                    RectTransform imageTransform = sDraggingImage.AddComponent <RectTransform>();
                    Utils.AlignRectTransformTopLeft(imageTransform, sWidth, sHeight);
                    #endregion

                    //===========================================================================
                    // CanvasRenderer Component
                    //===========================================================================
                    #region CanvasRenderer Component
                    sDraggingImage.AddComponent <CanvasRenderer>();
                    #endregion

                    //===========================================================================
                    // Image Component
                    //===========================================================================
                    #region Image Component
                    Image image = sDraggingImage.AddComponent <Image>();

                    image.sprite = sprite;
                    image.type   = Image.Type.Sliced;
                    #endregion

                    //===========================================================================
                    // IgnoreRaycast Component
                    //===========================================================================
                    #region IgnoreRaycast Component
                    sDraggingImage.AddComponent <IgnoreRaycast>();
                    #endregion
                    #endregion

                    SetDraggedPosition();
                }
                else
                {
                    DebugEx.Error("Canvas not found");
                }
            }
            else
            {
                DebugEx.Error("Dragging in progress already");
            }
        }
Exemple #10
0
        /// <summary>
        /// Begins dragging according to specified parameters.
        /// </summary>
        /// <param name="eventData">Pointer data.</param>
        /// <param name="draggingType">Dragging type.</param>
        /// <param name="gameObject">Game object.</param>
        /// <param name="sprite">Sprite image.</param>
        /// <param name="width">Width.</param>
        /// <param name="height">Height.</param>
        /// <param name="dragPosX">Mouse dragged position X.</param>
        /// <param name="dragPosY">Mouse dragged position Y.</param>
        public static void BeginDrag(
									   PointerEventData eventData
									 , DraggingType draggingType
									 , GameObject gameObject
									 , Sprite sprite
									 , float width
									 , float height
									 , float dragPosX = 0f
									 , float dragPosY = 0f
									)
        {
            if (draggingType == DraggingType.None)
            {
                Debug.LogError("Invalid type value");
                return;
            }

            if (mType == DraggingType.None)
            {
                Canvas canvas = Utils.FindInParents<Canvas>(gameObject);

                if (canvas != null)
                {
                    mType     = draggingType;
                    mWidth    = width;
                    mHeight   = height;
                    mDragPosX = dragPosX;
                    mDragPosY = dragPosY;

                    //===========================================================================
                    // Image GameObject
                    //===========================================================================
                    #region Image GameObject
                    mDraggingImage = new GameObject("DraggingImage");
                    Utils.InitUIObject(mDraggingImage, canvas.transform);

                    //===========================================================================
                    // RectTransform Component
                    //===========================================================================
                    #region RectTransform Component
                    RectTransform imageTransform = mDraggingImage.AddComponent<RectTransform>();
                    Utils.AlignRectTransformTopLeft(imageTransform, width, height);
                    #endregion

                    //===========================================================================
                    // CanvasRenderer Component
                    //===========================================================================
                    #region CanvasRenderer Component
                    mDraggingImage.AddComponent<CanvasRenderer>();
                    #endregion

                    //===========================================================================
                    // Image Component
                    //===========================================================================
                    #region Image Component
                    Image image = mDraggingImage.AddComponent<Image>();

                    image.sprite = sprite;
                    image.type   = Image.Type.Sliced;
                    #endregion

                    //===========================================================================
                    // IgnoreRaycast Component
                    //===========================================================================
                    #region IgnoreRaycast Component
                    mDraggingImage.AddComponent<IgnoreRaycast>();
                    #endregion
                    #endregion

                    SetDraggedPosition(eventData);
                }
                else
                {
                    Debug.LogError("Canvas not found");
                }
            }
            else
            {
                Debug.LogError("Dragging in progress already");
            }
        }
Exemple #11
0
        /// <summary>
        /// Ends dragging.
        /// </summary>
        /// <param name="eventData">Pointer data.</param>
        public static void EndDrag(PointerEventData eventData)
        {
            if (mType != DraggingType.None)
            {
                UnityEngine.Object.DestroyObject(mDraggingImage);

                mType          = DraggingType.None;
                mDraggingImage = null;
                mWidth         = 0f;
                mHeight        = 0f;
                mDragPosX      = 0f;
                mDragPosY      = 0f;
            }
        }