示例#1
0
        private bool IsEventInsideLocalWindow(EventBase evt)
        {
            Rect   clippingRect = GetCurrentClipRect();
            string pointerType  = (evt as IPointerEvent)?.pointerType;
            bool   isDirectManipulationDevice = (pointerType == PointerType.touch || pointerType == PointerType.pen);

            return(GUIUtility.HitTest(clippingRect, evt.originalMousePosition, isDirectManipulationDevice));
        }
示例#2
0
        private bool IsEventInsideLocalWindow(EventBase evt)
        {
            Rect          currentClipRect = this.GetCurrentClipRect();
            IPointerEvent expr_0E         = evt as IPointerEvent;
            string        a = (expr_0E != null) ? expr_0E.pointerType : null;
            bool          isDirectManipulationDevice = a == PointerType.touch || a == PointerType.pen;

            return(GUIUtility.HitTest(currentClipRect, evt.originalMousePosition, isDirectManipulationDevice));
        }
示例#3
0
        internal static Vector2 MouseDeltaReader(Rect position, bool activated)
        {
            int   id  = EditorGUIUtility.GetControlID(s_MouseDeltaReaderHash, FocusType.Passive, position);
            Event evt = Event.current;

            switch (evt.GetTypeForControl(id))
            {
            case EventType.MouseDown:
                if (activated && GUIUtility.hotControl == 0 && GUIUtility.HitTest(position, evt) && evt.button == 0)
                {
                    GUIUtility.hotControl      = id;
                    GUIUtility.keyboardControl = 0;
                    s_MouseDeltaReaderLastPos  = GUIClip.Unclip(evt.mousePosition);    // We unclip to screenspace to prevent being affected by scrollviews
                    evt.Use();
                }
                break;

            case EventType.MouseDrag:
                if (GUIUtility.hotControl == id)
                {
                    Vector2 screenPos = GUIClip.Unclip(evt.mousePosition);      // We unclip to screenspace to prevent being affected by scrollviews
                    Vector2 delta     = (screenPos - s_MouseDeltaReaderLastPos);
                    s_MouseDeltaReaderLastPos = screenPos;
                    evt.Use();
                    return(delta);
                }
                break;

            case EventType.MouseUp:
                if (GUIUtility.hotControl == id && evt.button == 0)
                {
                    GUIUtility.hotControl = 0;
                    evt.Use();
                }
                break;
            }
            return(Vector2.zero);
        }
示例#4
0
        public static void BeginSplit(SplitterState state, GUIStyle style, bool vertical, params GUILayoutOption[] options)
        {
            float pos;
            var   g = (GUISplitterGroup)GUILayoutUtility.BeginLayoutGroup(style, null, typeof(GUISplitterGroup));

            state.ID = GUIUtility.GetControlID(splitterHash, FocusType.Passive);

            switch (Event.current.GetTypeForControl(state.ID))
            {
            case EventType.Layout:
            {
                g.state       = state;
                g.resetCoords = false;
                g.isVertical  = vertical;
                g.ApplyOptions(options);
                break;
            }

            case EventType.MouseDown:
            {
                if ((Event.current.button == 0) && (Event.current.clickCount == 1))
                {
                    float cursor = GUIUtility.RoundToPixelGrid(g.isVertical ? g.rect.y : g.rect.x);
                    pos = GUIUtility.RoundToPixelGrid(g.isVertical ? Event.current.mousePosition.y : Event.current.mousePosition.x);

                    for (int i = 0; i < state.relativeSizes.Length - 1; i++)
                    {
                        Rect splitterRect = g.isVertical ?
                                            new Rect(state.xOffset + g.rect.x, cursor + state.realSizes[i] - state.splitSize / 2, g.rect.width, state.splitSize) :
                                            new Rect(state.xOffset + cursor + state.realSizes[i] - state.splitSize / 2, g.rect.y, state.splitSize, g.rect.height);

                        if (GUIUtility.HitTest(splitterRect, Event.current))
                        {
                            state.splitterInitialOffset = pos;
                            state.currentActiveSplitter = i;
                            GUIUtility.hotControl       = state.ID;
                            Event.current.Use();
                            break;
                        }

                        cursor = GUIUtility.RoundToPixelGrid(cursor + state.realSizes[i]);
                    }
                }
                break;
            }

            case EventType.MouseDrag:
            {
                if ((GUIUtility.hotControl == state.ID) && (state.currentActiveSplitter >= 0))
                {
                    pos = g.isVertical ? Event.current.mousePosition.y : Event.current.mousePosition.x;
                    GUIUtility.RoundToPixelGrid(pos);
                    float diff = pos - state.splitterInitialOffset;

                    if (diff != 0)
                    {
                        state.splitterInitialOffset = pos;
                        state.DoSplitter(state.currentActiveSplitter, state.currentActiveSplitter + 1, diff);
                    }

                    Event.current.Use();
                }
                break;
            }

            case EventType.MouseUp:
            {
                if (GUIUtility.hotControl == state.ID)
                {
                    GUIUtility.hotControl       = 0;
                    state.currentActiveSplitter = -1;
                    state.RealToRelativeSizes();
                    Event.current.Use();
                }
                break;
            }

            case EventType.Repaint:
            {
                float cursor = GUIUtility.RoundToPixelGrid(g.isVertical ? g.rect.y : g.rect.x);

                for (var i = 0; i < state.relativeSizes.Length - 1; i++)
                {
                    var splitterRect = g.isVertical ?
                                       new Rect(state.xOffset + g.rect.x, cursor + state.realSizes[i] - state.splitSize / 2, g.rect.width, state.splitSize) :
                                       new Rect(state.xOffset + cursor + state.realSizes[i] - state.splitSize / 2, g.rect.y, state.splitSize, g.rect.height);

                    EditorGUIUtility.AddCursorRect(splitterRect, g.isVertical ? MouseCursor.ResizeVertical : MouseCursor.SplitResizeLeftRight, state.ID);

                    cursor += state.realSizes[i];
                }
            }

            break;
            }
        }
示例#5
0
        public void SplitGUI(Event evt)
        {
            if (splitState == null)
            {
                SetupSplitter();
            }

            SplitView sp = parent as SplitView;

            if (sp)
            {
                Event e = new Event(evt);
                e.mousePosition += new Vector2(position.x, position.y);
                sp.SplitGUI(e);
                if (e.type == EventType.Used)
                {
                    evt.Use();
                }
            }

            float pos = vertical ? evt.mousePosition.y : evt.mousePosition.x;
            int   id  = GUIUtility.GetControlID(546739, FocusType.Passive);

            controlID = id;

            switch (evt.GetTypeForControl(id))
            {
            case EventType.MouseDown:
                if (children.Length != 1)     // is there a splitter
                {
                    int cursor = vertical ? (int)children[0].position.y : (int)children[0].position.x;

                    for (int i = 0; i < children.Length - 1; i++)
                    {
                        if (i >= splitState.realSizes.Length)
                        {
                            DockArea dock = GUIView.current as DockArea;
                            string   name = "Non-dock area " + GUIView.current.GetType();
                            if (dock && dock.m_Selected < dock.m_Panes.Count && dock.m_Panes[dock.m_Selected])
                            {
                                name = dock.m_Panes[dock.m_Selected].GetType().ToString();
                            }

                            if (Unsupported.IsDeveloperMode())
                            {
                                Debug.LogError("Real sizes out of bounds for: " + name + " index: " + i + " RealSizes: " + splitState.realSizes.Length);
                            }

                            SetupSplitter();
                        }
                        Rect splitterRect = vertical ?
                                            new Rect(children[0].position.x, cursor + splitState.realSizes[i] - splitState.splitSize / 2, children[0].position.width, splitState.splitSize) :
                                            new Rect(cursor + splitState.realSizes[i] - splitState.splitSize / 2, children[0].position.y, splitState.splitSize, children[0].position.height);

                        if (GUIUtility.HitTest(splitterRect, evt))
                        {
                            splitState.splitterInitialOffset = (int)pos;
                            splitState.currentActiveSplitter = i;
                            GUIUtility.hotControl            = id;
                            evt.Use();
                            break;
                        }

                        cursor += splitState.realSizes[i];
                    }
                }
                break;

            case EventType.MouseDrag:
                if (children.Length > 1 && (GUIUtility.hotControl == id) && (splitState.currentActiveSplitter >= 0))
                {
                    int diff = (int)pos - splitState.splitterInitialOffset;

                    if (diff != 0)
                    {
                        splitState.splitterInitialOffset = (int)pos;
                        splitState.DoSplitter(splitState.currentActiveSplitter, splitState.currentActiveSplitter + 1, diff);
                    }

                    SetupRectsFromSplitter();


                    evt.Use();
                }
                break;

            case EventType.MouseUp:
                if (GUIUtility.hotControl == id)
                {
                    GUIUtility.hotControl = 0;
                }
                break;
            }
        }