Пример #1
0
        protected virtual void HandleEvents()
        {
            var evt = Event.current;

            bool done = false;

            switch (evt.type)
            {
            case EventType.MouseDown:
                var mouseInside = MouseInActualRect(evt);
                if (Selectable)
                {
                    HasMouseFocus    = mouseInside;
                    HasKeyboardFocus = mouseInside;
                }
                if (mouseInside)
                {
                    int cc = evt.clickCount;
                    done = HandleMouseDown(evt);
                    if (cc == 2)
                    {
                        HandleMouseDoubleClick(evt);
                    }
                    else if (cc == 3)
                    {
                        HandleMouseTripleClick(evt);
                    }

                    MouseDown.NPInvoke(this, evt);
                    if (cc == 2)
                    {
                        MouseDoubleClick.NPInvoke(this, evt);
                    }
                    else if (cc == 3)
                    {
                        MouseTripleClick.NPInvoke(this, evt);
                    }
                }
                break;

            case EventType.MouseUp:
                if (HasMouseFocus)
                {
                    done          = HandleMouseUp(evt);
                    HasMouseFocus = false;
                    MouseUp.NPInvoke(this, evt);
                }
                break;

            // Only available when EditorWindow.wantsMouseMove set to true in EditorWindow.
            case EventType.MouseMove:
                //var hoverOnLastEvent = IsMouseHover;
                //IsMouseHover = MouseInActualRect(evt);
                //if (!hoverOnLastEvent && IsMouseHover)
                //{
                //    done = HandleMouseEnter(evt);
                //    MouseEnter.NPInvoke(this, evt);
                //}
                //else if (hoverOnLastEvent && !IsMouseHover)
                //{
                //    done = HandleMouseLeave(evt);
                //    MouseLeave.NPInvoke(this, evt);
                //}
                //else if (IsMouseHover)
                //{
                //    done = HandleMouseHover(evt);
                //    MouseHover.NPInvoke(this, evt);
                //}
                break;

            case EventType.MouseDrag:
                done = HandleMouseDrag(evt);
                break;

            case EventType.KeyDown:
                if (HasKeyboardFocus)
                {
                    done = HandleKeyDown(evt);
                    KeyDown.NPInvoke(this, evt);
                }
                break;

            case EventType.KeyUp:
                if (HasKeyboardFocus)
                {
                    done = HandleKeyUp(evt);
                    KeyUp.NPInvoke(this, evt);
                }
                break;

            case EventType.ScrollWheel:
                if (MouseInActualRect(evt))
                {
                    done = HandleScrollWheel(evt);
                }
                break;

            case EventType.Repaint:
                HandleRepaint(evt);
                break;

            case EventType.Layout:
                HandleLayout(evt);
                break;

            case EventType.DragUpdated:
                done = HandleDragUpdated(evt);
                break;

            case EventType.DragPerform:
                done = HandleDragPerform(evt);
                break;

            case EventType.DragExited:
                done = HandleDragExited(evt);
                break;

            case EventType.Ignore:
                done = HandleIgnore(evt);
                break;

            case EventType.Used:
                HandleUsed(evt);
                break;

            case EventType.ValidateCommand:
                done = HandleValidateCommand(evt);
                break;

            case EventType.ExecuteCommand:
                done = HandleExecuteCommand(evt);
                break;

            case EventType.ContextClick:
                done = HandleContextClick(evt);
                break;

            case EventType.MouseEnterWindow:
                done = HandleMouseEnterWindow(evt);
                break;

            case EventType.MouseLeaveWindow:
                done = HandleMouseLeaveWindow(evt);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            if (done)
            {
                evt.Use();
            }
        }