Esempio n. 1
0
        internal void Update()
        {
            var focusedControl = root.FocusManager.FocusedControl;

            var path = focusedControl == null
                ? EventPropagationPath.Empty
                : EventRouter.FindPropagationPath(root, focusedControl);

            var modifierKeys = ModifierKeys.FromInputManager(inputManager);

            foreach (var(eventArgs, isPressed) in inputManager.KeyEvents)
            {
                var args = new KeyEventArgs(eventArgs.Key, modifierKeys);

                if (isPressed)
                {
                    path.PropagateEvent(
                        args,
                        (c, e) => c.PreviewKeyHit(e),
                        (c, e) => c.KeyHit(e));
                    if (!args.Handled)
                    {
                        eventsCapturer?.KeyHit(args);
                    }
                }
                else
                {
                    path.PropagateEvent(
                        args,
                        (c, e) => c.PreviewKeyReleased(e),
                        (c, e) => c.KeyReleased(e));
                    if (!args.Handled)
                    {
                        eventsCapturer?.KeyReleased(args);
                    }
                }
            }

            foreach (var pressedChar in inputManager.PressedCharacters)
            {
                path.PropagateEvent(
                    new CharEventArgs(pressedChar),
                    (c, e) => c.PreviewCharacterTyped(e),
                    (c, e) => c.CharacterTyped(e));
            }
        }
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;
        }