Ejemplo n.º 1
0
        public void Init(GameWindow game)
        {
            if (_game != null)
            {
                return;
            }
            _game = game;
            this._originalOSCursor = _game.Cursor;

            game.MouseDown += (sender, e) =>
            {
                if (isInputBlocked())
                {
                    return;
                }
                var button = convert(e.Button);
                _actions.Enqueue(() => MouseDown.InvokeAsync(new AGS.API.MouseButtonEventArgs(null, button, MousePosition)));
            };
            game.MouseUp += (sender, e) =>
            {
                if (isInputBlocked())
                {
                    return;
                }
                var button = convert(e.Button);
                _actions.Enqueue(() => MouseUp.InvokeAsync(new AGS.API.MouseButtonEventArgs(null, button, MousePosition)));
            };
            game.MouseMove += (sender, e) =>
            {
                if (isInputBlocked())
                {
                    return;
                }
                _mouseX = e.Mouse.X;
                _mouseY = e.Mouse.Y;
                _actions.Enqueue(() => MouseMove.InvokeAsync(new MousePositionEventArgs(MousePosition)));
            };
            game.KeyDown += (sender, e) =>
            {
                API.Key key = convert(e.Key);
                _keysDown.Add(key);
                if (isInputBlocked())
                {
                    return;
                }
                _actions.Enqueue(() => KeyDown.InvokeAsync(new KeyboardEventArgs(key)));
            };
            game.KeyUp += (sender, e) =>
            {
                API.Key key = convert(e.Key);
                _keysDown.Remove(key);
                if (isInputBlocked())
                {
                    return;
                }
                _actions.Enqueue(() => KeyUp.InvokeAsync(new KeyboardEventArgs(key)));
            };

            _events.OnRepeatedlyExecuteAlways.Subscribe(onRepeatedlyExecute);
        }
Ejemplo n.º 2
0
        private async Task onRepeatedlyExecute(object sender, EventArgs args)
        {
            if (!_enabled.Enabled || !_visible.Visible)
            {
                return;
            }
            IRoom room = _state.Room;

            if (room == null)
            {
                return;
            }

            PointF position = _input.MousePosition;

            var  obj     = room.GetObjectAt(position.X, position.Y);
            bool mouseIn = obj == _entity;

            bool leftMouseDown  = _input.LeftMouseButtonDown;
            bool rightMouseDown = _input.RightMouseButtonDown;

            bool fireMouseMove  = mouseIn && (_mouseX != position.X || _mouseY != position.Y);
            bool fireMouseEnter = mouseIn && !IsMouseIn;
            bool fireMouseLeave = !mouseIn && IsMouseIn;

            _mouseX   = position.X;
            _mouseY   = position.Y;
            IsMouseIn = mouseIn;

            bool wasLeftMouseDown  = _leftMouseDown;
            bool wasRightMouseDown = _rightMouseDown;

            _leftMouseDown  = leftMouseDown;
            _rightMouseDown = rightMouseDown;

            await handleMouseButton(_leftMouseClickTimer, _leftMouseDoubleClickTimer, wasLeftMouseDown, leftMouseDown, MouseButton.Left);
            await handleMouseButton(_rightMouseClickTimer, _rightMouseDoubleClickTimer, wasRightMouseDown, rightMouseDown, MouseButton.Right);

            if (fireMouseEnter)
            {
                await MouseEnter.InvokeAsync(_entity, new MousePositionEventArgs (position.X, position.Y));
            }
            else if (fireMouseLeave)
            {
                await MouseLeave.InvokeAsync(_entity, new MousePositionEventArgs (position.X, position.Y));
            }
            if (fireMouseMove)
            {
                await MouseMove.InvokeAsync(_entity, new MousePositionEventArgs(position.X, position.Y));
            }
        }
Ejemplo n.º 3
0
        private void init(GameWindow game)
        {
            if (_game != null)
            {
                return;
            }
            _game             = game;
            _originalOSCursor = game.Cursor;

            _cursor.PropertyChanged += (sender, e) =>
            {
                if (_cursor.Cursor != null)
                {
                    _game.Cursor = MouseCursor.Empty;
                }
            };
            game.MouseDown += (sender, e) =>
            {
                if (isInputBlocked())
                {
                    return;
                }
                var button = convert(e.Button);
                _actions.Enqueue(() => MouseDown.InvokeAsync(new API.MouseButtonEventArgs(_hitTest.ObjectAtMousePosition, button, MousePosition)));
            };
            game.MouseUp += (sender, e) =>
            {
                if (isInputBlocked())
                {
                    return;
                }
                var button = convert(e.Button);
                _actions.Enqueue(() => MouseUp.InvokeAsync(new API.MouseButtonEventArgs(_hitTest.ObjectAtMousePosition, button, MousePosition)));
            };
            game.MouseMove += (sender, e) =>
            {
                _mouseX = e.Mouse.X;
                _mouseY = e.Mouse.Y;
                _actions.Enqueue(() => MouseMove.InvokeAsync(new MousePositionEventArgs(MousePosition)));
            };
            game.KeyDown += (sender, e) =>
            {
                API.Key key = convert(e.Key);
                _keysDown.Add(key);
                if (isInputBlocked())
                {
                    return;
                }
                _actions.Enqueue(() => KeyDown.InvokeAsync(new KeyboardEventArgs(key)));
            };
            game.KeyUp += (sender, e) =>
            {
                API.Key key = convert(e.Key);
                _keysDown.Remove(key);
                if (isInputBlocked())
                {
                    return;
                }
                _actions.Enqueue(() => KeyUp.InvokeAsync(new KeyboardEventArgs(key)));
            };

            _events.OnRepeatedlyExecuteAlways.Subscribe(onRepeatedlyExecute);
        }