Beispiel #1
0
        internal static ClickEvent GetPooled(PointerUpEvent pointerEvent, int clickCount)
        {
            var evt = PointerEventBase <ClickEvent> .GetPooled(pointerEvent);

            evt.clickCount = clickCount;
            return(evt);
        }
Beispiel #2
0
        internal static ClickEvent GetPooled(PointerUpEvent pointerEvent, int clickCount)
        {
            ClickEvent pooled = PointerEventBase <ClickEvent> .GetPooled(pointerEvent);

            pooled.clickCount = clickCount;
            return(pooled);
        }
        internal new static T GetPooled(EventBase e)
        {
            IPointerEvent pointerEvent = e as IPointerEvent;
            bool          flag         = pointerEvent != null;
            T             pooled;

            if (flag)
            {
                pooled = PointerEventBase <T> .GetPooled(pointerEvent);
            }
            else
            {
                IMouseEvent mouseEvent = e as IMouseEvent;
                bool        flag2      = mouseEvent != null;
                if (flag2)
                {
                    pooled = PointerEventBase <T> .GetPooled(mouseEvent);
                }
                else
                {
                    pooled = EventBase <T> .GetPooled(e);
                }
            }
            return(pooled);
        }
        internal static T GetPooled(IPointerEvent triggerEvent, Vector2 position, int pointerId)
        {
            bool flag = triggerEvent != null;
            T    result;

            if (flag)
            {
                result = PointerEventBase <T> .GetPooled(triggerEvent);
            }
            else
            {
                T pooled = EventBase <T> .GetPooled();

                pooled.position      = position;
                pooled.localPosition = position;
                pooled.pointerId     = pointerId;
                pooled.pointerType   = PointerType.GetPointerType(pointerId);
                result = pooled;
            }
            return(result);
        }
        internal static void SendOverOut(VisualElement previousTopElementUnderPointer, VisualElement currentTopElementUnderPointer, IPointerEvent triggerEvent, Vector2 position, int pointerId)
        {
            bool flag = previousTopElementUnderPointer != null && previousTopElementUnderPointer.panel != null;

            if (flag)
            {
                using (PointerOutEvent pooled = PointerEventBase <PointerOutEvent> .GetPooled(triggerEvent, position, pointerId))
                {
                    pooled.target = previousTopElementUnderPointer;
                    previousTopElementUnderPointer.SendEvent(pooled);
                }
            }
            bool flag2 = currentTopElementUnderPointer != null;

            if (flag2)
            {
                using (PointerOverEvent pooled2 = PointerEventBase <PointerOverEvent> .GetPooled(triggerEvent, position, pointerId))
                {
                    pooled2.target = currentTopElementUnderPointer;
                    currentTopElementUnderPointer.SendEvent(pooled2);
                }
            }
        }
Beispiel #6
0
        internal static void SendEnterLeave <TLeaveEvent, TEnterEvent>(VisualElement previousTopElementUnderPointer, VisualElement currentTopElementUnderPointer, IPointerEvent triggerEvent, Vector2 position, int pointerId) where TLeaveEvent : PointerEventBase <TLeaveEvent>, new() where TEnterEvent : PointerEventBase <TEnterEvent>, new()
        {
            if (previousTopElementUnderPointer != null && previousTopElementUnderPointer.panel == null)
            {
                // If previousTopElementUnderPointer has been removed from panel,
                // do as if there is no element under the pointer.
                previousTopElementUnderPointer = null;
            }

            // We want to find the common ancestor CA of previousTopElementUnderPointer and currentTopElementUnderPointer,
            // send Leave (PointerLeave) events to elements between CA and previousTopElementUnderPointer
            // and send Enter (PointerEnter) events to elements between CA and currentTopElementUnderPointer.

            int prevDepth = 0;
            var p         = previousTopElementUnderPointer;

            while (p != null)
            {
                prevDepth++;
                p = p.hierarchy.parent;
            }

            int currDepth = 0;
            var c         = currentTopElementUnderPointer;

            while (c != null)
            {
                currDepth++;
                c = c.hierarchy.parent;
            }

            p = previousTopElementUnderPointer;
            c = currentTopElementUnderPointer;

            while (prevDepth > currDepth)
            {
                using (var leaveEvent = PointerEventBase <TLeaveEvent> .GetPooled(triggerEvent, position, pointerId))
                {
                    leaveEvent.target = p;
                    p.SendEvent(leaveEvent);
                }

                prevDepth--;
                p = p.hierarchy.parent;
            }

            // We want to send enter events after all the leave events.
            // We will store the elements being entered in this list.
            List <VisualElement> enteringElements = VisualElementListPool.Get(currDepth);

            while (currDepth > prevDepth)
            {
                enteringElements.Add(c);

                currDepth--;
                c = c.hierarchy.parent;
            }

            // Now p and c are at the same depth. Go up the tree until p == c.
            while (p != c)
            {
                using (var leaveEvent = PointerEventBase <TLeaveEvent> .GetPooled(triggerEvent, position, pointerId))
                {
                    leaveEvent.target = p;
                    p.SendEvent(leaveEvent);
                }

                enteringElements.Add(c);

                p = p.hierarchy.parent;
                c = c.hierarchy.parent;
            }

            for (var i = enteringElements.Count - 1; i >= 0; i--)
            {
                using (var enterEvent = PointerEventBase <TEnterEvent> .GetPooled(triggerEvent, position, pointerId))
                {
                    enterEvent.target = enteringElements[i];
                    enteringElements[i].SendEvent(enterEvent);
                }
            }

            VisualElementListPool.Release(enteringElements);
        }
Beispiel #7
0
        internal static EventBase CreateEvent(Event systemEvent, EventType eventType)
        {
            EventBase pooled;

            switch (eventType)
            {
            case EventType.MouseDown:
            {
                bool flag = PointerDeviceState.HasAdditionalPressedButtons(PointerId.mousePointerId, systemEvent.button);
                if (flag)
                {
                    pooled = PointerEventBase <PointerMoveEvent> .GetPooled(systemEvent);

                    return(pooled);
                }
                pooled = PointerEventBase <PointerDownEvent> .GetPooled(systemEvent);

                return(pooled);
            }

            case EventType.MouseUp:
            {
                bool flag2 = PointerDeviceState.HasAdditionalPressedButtons(PointerId.mousePointerId, systemEvent.button);
                if (flag2)
                {
                    pooled = PointerEventBase <PointerMoveEvent> .GetPooled(systemEvent);

                    return(pooled);
                }
                pooled = PointerEventBase <PointerUpEvent> .GetPooled(systemEvent);

                return(pooled);
            }

            case EventType.MouseMove:
                pooled = PointerEventBase <PointerMoveEvent> .GetPooled(systemEvent);

                return(pooled);

            case EventType.MouseDrag:
                pooled = PointerEventBase <PointerMoveEvent> .GetPooled(systemEvent);

                return(pooled);

            case EventType.KeyDown:
                pooled = KeyboardEventBase <KeyDownEvent> .GetPooled(systemEvent);

                return(pooled);

            case EventType.KeyUp:
                pooled = KeyboardEventBase <KeyUpEvent> .GetPooled(systemEvent);

                return(pooled);

            case EventType.ScrollWheel:
                pooled = WheelEvent.GetPooled(systemEvent);
                return(pooled);

            case EventType.DragUpdated:
                pooled = DragUpdatedEvent.GetPooled(systemEvent);
                return(pooled);

            case EventType.DragPerform:
                pooled = MouseEventBase <DragPerformEvent> .GetPooled(systemEvent);

                return(pooled);

            case EventType.ValidateCommand:
                pooled = CommandEventBase <ValidateCommandEvent> .GetPooled(systemEvent);

                return(pooled);

            case EventType.ExecuteCommand:
                pooled = CommandEventBase <ExecuteCommandEvent> .GetPooled(systemEvent);

                return(pooled);

            case EventType.DragExited:
                pooled = DragExitedEvent.GetPooled(systemEvent);
                return(pooled);

            case EventType.ContextClick:
                pooled = MouseEventBase <ContextClickEvent> .GetPooled(systemEvent);

                return(pooled);

            case EventType.MouseEnterWindow:
                pooled = MouseEventBase <MouseEnterWindowEvent> .GetPooled(systemEvent);

                return(pooled);

            case EventType.MouseLeaveWindow:
                pooled = MouseLeaveWindowEvent.GetPooled(systemEvent);
                return(pooled);
            }
            pooled = IMGUIEvent.GetPooled(systemEvent);
            return(pooled);
        }
        internal static void SendEnterLeave <TLeaveEvent, TEnterEvent>(VisualElement previousTopElementUnderPointer, VisualElement currentTopElementUnderPointer, IPointerEvent triggerEvent, Vector2 position, int pointerId) where TLeaveEvent : PointerEventBase <TLeaveEvent>, new() where TEnterEvent : PointerEventBase <TEnterEvent>, new()
        {
            bool flag = previousTopElementUnderPointer != null && previousTopElementUnderPointer.panel == null;

            if (flag)
            {
                previousTopElementUnderPointer = null;
            }
            int           i = 0;
            VisualElement visualElement;

            for (visualElement = previousTopElementUnderPointer; visualElement != null; visualElement = visualElement.hierarchy.parent)
            {
                i++;
            }
            int           j = 0;
            VisualElement visualElement2;

            for (visualElement2 = currentTopElementUnderPointer; visualElement2 != null; visualElement2 = visualElement2.hierarchy.parent)
            {
                j++;
            }
            visualElement  = previousTopElementUnderPointer;
            visualElement2 = currentTopElementUnderPointer;
            while (i > j)
            {
                using (TLeaveEvent pooled = PointerEventBase <TLeaveEvent> .GetPooled(triggerEvent, position, pointerId))
                {
                    pooled.target = visualElement;
                    visualElement.SendEvent(pooled);
                }
                i--;
                visualElement = visualElement.hierarchy.parent;
            }
            List <VisualElement> list = VisualElementListPool.Get(j);

            while (j > i)
            {
                list.Add(visualElement2);
                j--;
                visualElement2 = visualElement2.hierarchy.parent;
            }
            while (visualElement != visualElement2)
            {
                using (TLeaveEvent pooled2 = PointerEventBase <TLeaveEvent> .GetPooled(triggerEvent, position, pointerId))
                {
                    pooled2.target = visualElement;
                    visualElement.SendEvent(pooled2);
                }
                list.Add(visualElement2);
                visualElement  = visualElement.hierarchy.parent;
                visualElement2 = visualElement2.hierarchy.parent;
            }
            for (int k = list.Count - 1; k >= 0; k--)
            {
                using (TEnterEvent pooled3 = PointerEventBase <TEnterEvent> .GetPooled(triggerEvent, position, pointerId))
                {
                    pooled3.target = list[k];
                    list[k].SendEvent(pooled3);
                }
            }
            VisualElementListPool.Release(list);
        }