Пример #1
0
        public GuiSystem(ViewportAdapter viewportAdapter, IGuiRenderer renderer)
        {
            _viewportAdapter = viewportAdapter;
            _renderer        = renderer;

            _mouseListener                  = new MouseListener(viewportAdapter);
            _mouseListener.MouseMoved      += (s, e) => OnPointerMoved(GuiPointerEventArgs.FromMouseArgs(e));
            _mouseListener.MouseDown       += (s, e) => OnPointerDown(GuiPointerEventArgs.FromMouseArgs(e));
            _mouseListener.MouseUp         += (s, e) => OnPointerUp(GuiPointerEventArgs.FromMouseArgs(e));
            _mouseListener.MouseWheelMoved += (s, e) => _focusedControl?.OnScrolled(e.ScrollWheelDelta);

            _touchListener = new TouchListener(viewportAdapter);
            _touchListener.TouchStarted += (s, e) => OnPointerDown(GuiPointerEventArgs.FromTouchArgs(e));
            _touchListener.TouchMoved   += (s, e) => OnPointerMoved(GuiPointerEventArgs.FromTouchArgs(e));
            _touchListener.TouchEnded   += (s, e) => OnPointerUp(GuiPointerEventArgs.FromTouchArgs(e));

            _keyboardListener             = new KeyboardListener();
            _keyboardListener.KeyTyped   += (sender, args) => _focusedControl?.OnKeyTyped(this, args);
            _keyboardListener.KeyPressed += (sender, args) => _focusedControl?.OnKeyPressed(this, args);

            Screens = new GuiScreenCollection(this)
            {
                ItemAdded = InitializeScreen
            };
        }
Пример #2
0
        private void OnPointerUp(GuiPointerEventArgs args)
        {
            if (Screen == null)
            {
                return;
            }

            var postFocusedControl = FindControlAtPoint(Screen.Controls, args.Position);

            if (_preFocusedControl == postFocusedControl)
            {
                var focusedControl = postFocusedControl;

                if (_focusedControl != focusedControl)
                {
                    if (_focusedControl != null)
                    {
                        _focusedControl.IsFocused = false;
                    }

                    _focusedControl = focusedControl;

                    if (_focusedControl != null)
                    {
                        _focusedControl.IsFocused = true;
                    }
                }
            }

            _preFocusedControl = null;
            _hoveredControl?.OnPointerUp(args);
        }
Пример #3
0
        private void OnPointerMoved(GuiPointerEventArgs args)
        {
            CursorPosition = args.Position.ToVector2();

            if (ActiveScreen == null || !ActiveScreen.IsVisible)
            {
                return;
            }

            var hoveredControl = FindControlAtPoint(args.Position);

            if (_hoveredControl != hoveredControl)
            {
                if (_hoveredControl != null && (hoveredControl == null || !hoveredControl.HasParent(_hoveredControl)))
                {
                    PropagateDown(_hoveredControl, x => x.OnPointerLeave(this, args));
                }
                _hoveredControl = hoveredControl;
                PropagateDown(_hoveredControl, x => x.OnPointerEnter(this, args));
            }
            else
            {
                PropagateDown(_hoveredControl, x => x.OnPointerMove(this, args));
            }
        }
Пример #4
0
        private void OnPointerDown(GuiPointerEventArgs args)
        {
            if (Screen == null)
            {
                return;
            }

            _preFocusedControl = FindControlAtPoint(Screen.Controls, args.Position);
            _hoveredControl?.OnPointerDown(args);
        }
Пример #5
0
        private void OnPointerDown(GuiPointerEventArgs args)
        {
            if (ActiveScreen == null || !ActiveScreen.IsVisible)
            {
                return;
            }

            _preFocusedControl = FindControlAtPoint(args.Position);
            _hoveredControl?.OnPointerDown(this, args);
        }
Пример #6
0
        private void OnPointerUp(GuiPointerEventArgs args)
        {
            if (ActiveScreen == null || !ActiveScreen.IsVisible)
            {
                return;
            }

            var postFocusedControl = FindControlAtPoint(args.Position);

            if (_preFocusedControl == postFocusedControl)
            {
                SetFocus(postFocusedControl);
            }

            _preFocusedControl = null;
            PropagateDown(_hoveredControl, x => x.OnPointerUp(this, args));
        }
Пример #7
0
        public GuiSystem(ViewportAdapter viewportAdapter, IGuiRenderer renderer)
        {
            _renderer = renderer;

            _mouseListener             = new MouseListener(viewportAdapter);
            _mouseListener.MouseMoved += (s, e) => OnPointerMoved(GuiPointerEventArgs.FromMouseArgs(e));
            _mouseListener.MouseDown  += (s, e) => OnPointerDown(GuiPointerEventArgs.FromMouseArgs(e));
            _mouseListener.MouseUp    += (s, e) => OnPointerUp(GuiPointerEventArgs.FromMouseArgs(e));

            _touchListener = new TouchListener(viewportAdapter);
            _touchListener.TouchStarted += (s, e) => OnPointerDown(GuiPointerEventArgs.FromTouchArgs(e));
            _touchListener.TouchMoved   += (s, e) => OnPointerMoved(GuiPointerEventArgs.FromTouchArgs(e));
            _touchListener.TouchEnded   += (s, e) => OnPointerUp(GuiPointerEventArgs.FromTouchArgs(e));

            _keyboardListener             = new KeyboardListener();
            _keyboardListener.KeyTyped   += (sender, args) => _focusedControl?.OnKeyTyped(args);
            _keyboardListener.KeyPressed += (sender, args) => _focusedControl?.OnKeyPressed(args);
        }
Пример #8
0
        private void OnPointerMoved(GuiPointerEventArgs args)
        {
            CursorPosition = args.Position.ToVector2();

            if (Screen == null)
            {
                return;
            }

            var hoveredControl = FindControlAtPoint(Screen.Controls, args.Position);

            if (_hoveredControl != hoveredControl)
            {
                _hoveredControl?.OnPointerLeave(args);
                _hoveredControl = hoveredControl;
                _hoveredControl?.OnPointerEnter(args);
            }
        }
Пример #9
0
        private void OnPointerMoved(GuiPointerEventArgs args)
        {
            CursorPosition = args.Position.ToVector2();

            if (ActiveScreen == null || !ActiveScreen.IsVisible)
            {
                return;
            }

            var hoveredControl = FindControlAtPoint(args.Position);

            if (_hoveredControl != hoveredControl)
            {
                _hoveredControl?.OnPointerLeave(this, args);
                _hoveredControl = hoveredControl;
                _hoveredControl?.OnPointerEnter(this, args);
            }
        }