Esempio n. 1
0
        public static (EventPropagationPath removed, EventPropagationPath added) CalculateDeviation(
            EventPropagationPath oldPath,
            EventPropagationPath newPath)
        {
            if (oldPath.IsEmpty)
            {
                return(Empty, newPath);
            }
            if (newPath.IsEmpty)
            {
                return(oldPath, Empty);
            }

            var shortestPathLength = Math.Min(oldPath.path.Count, newPath.path.Count);

            var firstDeviationIndex = 0;

            while (firstDeviationIndex < shortestPathLength)
            {
                if (oldPath.path[firstDeviationIndex] != newPath.path[firstDeviationIndex])
                {
                    break;
                }
                firstDeviationIndex++;
            }

            return(oldPath.getPathFromIndex(firstDeviationIndex), newPath.getPathFromIndex(firstDeviationIndex));
        }
Esempio n. 2
0
        internal void Update()
        {
            var mousePosition = root.TransformViewportPosToFramePos((Vector2d)inputManager.MousePosition);
            var modifierKeys  = ModifierKeys.FromInputManager(inputManager);

            var path = EventRouter.FindPropagationPath(
                root, control =>
            {
                if (!control.IsVisible || !control.Frame.ContainsPoint(mousePosition))
                {
                    return(EventRouter.PropagationTestOutcome.Miss);
                }

                return(control.IsClickThrough
                        ? EventRouter.PropagationTestOutcome.PassThrough
                        : EventRouter.PropagationTestOutcome.Hit);
            });

            var(removedFromPath, addedToPath) = previousPropagationPath != null
                ? EventPropagationPath.CalculateDeviation(previousPropagationPath, path)
                : (EventPropagationPath.Empty, path);

            var eventArgs = new MouseEventArgs(mousePosition, modifierKeys);

            // Mouse exit
            removedFromPath.PropagateEvent(
                eventArgs,
                (c, e) => c.PreviewMouseExited(e),
                (c, e) => c.MouseExited(e));

            // Mouse enter
            addedToPath.PropagateEvent(
                eventArgs,
                (c, e) => c.PreviewMouseEntered(e),
                (c, e) => c.MouseEntered(e));

            // Mouse move
            path.PropagateEvent(
                eventArgs,
                (c, e) => c.PreviewMouseMoved(e),
                (c, e) => c.MouseMoved(e));

            // Mouse clicks
            foreach (var btn in mouseButtons)
            {
                var action = inputManager.Actions.Mouse.FromButton(btn);
                if (action.Hit)
                {
                    path.PropagateEvent(
                        new MouseButtonEventArgs(mousePosition, modifierKeys, btn),
                        (c, e) => c.PreviewMouseButtonHit(e),
                        (c, e) => c.MouseButtonHit(e));
                }
                if (action.Released)
                {
                    path.PropagateEvent(
                        new MouseButtonEventArgs(mousePosition, modifierKeys, btn),
                        (c, e) => c.PreviewMouseButtonReleased(e),
                        (c, e) => c.MouseButtonReleased(e));
                }
            }

            // Mouse scroll
            // ReSharper disable once CompareOfFloatsByEqualityOperator
            if (inputManager.DeltaScrollF != 0)
            {
                path.PropagateEvent(
                    new MouseScrollEventArgs(
                        mousePosition, modifierKeys, inputManager.DeltaScroll, inputManager.DeltaScrollF),
                    (c, e) => c.PreviewMouseScrolled(e),
                    (c, e) => c.MouseScrolled(e));
            }

            previousPropagationPath = path;
        }