示例#1
0
        public AndroidInput(AndroidSimpleGestures gestures, IGameState state, IShouldBlockInput shouldBlockInput, IGameWindowSize windowSize)
        {
            MousePosition     = new MousePosition(0f, 0f, state.Viewport);
            _shouldBlockInput = shouldBlockInput;
            _windowSize       = windowSize;
            _state            = state;
            float density = Resources.System.DisplayMetrics.Density;

            API.MousePosition.GetWindowWidth  = () => (int)(_windowSize.GetWidth(null) - ((GLUtils.ScreenViewport.X * 2) / density));
            API.MousePosition.GetWindowHeight = () => (int)(_windowSize.GetHeight(null) - ((GLUtils.ScreenViewport.Y * 2) / density));
            MouseDown = new AGSEvent <AGS.API.MouseButtonEventArgs>();
            MouseUp   = new AGSEvent <AGS.API.MouseButtonEventArgs>();
            MouseMove = new AGSEvent <MousePositionEventArgs>();
            KeyDown   = new AGSEvent <KeyboardEventArgs>();
            KeyUp     = new AGSEvent <KeyboardEventArgs>();

            gestures.OnUserDrag += async(sender, e) =>
            {
                if (isInputBlocked())
                {
                    return;
                }
                DateTime now = DateTime.Now;
                _lastDrag   = now;
                IsTouchDrag = true;
                setMousePosition(e);
                await MouseMove.InvokeAsync(new MousePositionEventArgs(MousePosition));

                await Task.Delay(300);

                if (_lastDrag <= now)
                {
                    IsTouchDrag = false;
                }
            };
            gestures.OnUserSingleTap += async(sender, e) =>
            {
                if (isInputBlocked())
                {
                    return;
                }
                setMousePosition(e);
                LeftMouseButtonDown = true;
                await MouseDown.InvokeAsync(new MouseButtonEventArgs(null, MouseButton.Left, MousePosition));

                await Task.Delay(250);

                await MouseUp.InvokeAsync(new MouseButtonEventArgs(null, MouseButton.Left, MousePosition));

                LeftMouseButtonDown = false;
            };
            AndroidGameWindow.Instance.OnNewView += onViewChanged;
            onViewChanged(null, AndroidGameWindow.Instance.View);
        }
示例#2
0
        private float convertX(float x)
        {
            var   viewport     = getViewport();
            var   virtualWidth = _virtualWidth / viewport.ScaleX;
            float density      = Resources.System.DisplayMetrics.Density;

            x = (x - GLUtils.ScreenViewport.X) / density;
            float width = _windowSize.GetWidth(null) - ((GLUtils.ScreenViewport.X * 2) / density);

            x = MathUtils.Lerp(0f, 0f, width, virtualWidth, x);
            return(x + viewport.X);
        }
示例#3
0
        private int _inUpdate; //For preventing re-entrancy

        public AGSInput(IGameState state, IGameEvents events,
                        IShouldBlockInput shouldBlockInput, IGameWindowSize windowSize)
        {
            _events                           = events;
            _actions                          = new ConcurrentQueue <Func <Task> >();
            _windowSize                       = windowSize;
            this._shouldBlockInput            = shouldBlockInput;
            API.MousePosition.GetWindowWidth  = () => _windowSize.GetWidth(_game);
            API.MousePosition.GetWindowHeight = () => _windowSize.GetHeight(_game);
            this._state                       = state;
            this._keysDown                    = new AGSConcurrentHashSet <API.Key>();

            MouseDown = new AGSEvent <AGS.API.MouseButtonEventArgs>();
            MouseUp   = new AGSEvent <AGS.API.MouseButtonEventArgs>();
            MouseMove = new AGSEvent <MousePositionEventArgs>();
            KeyDown   = new AGSEvent <KeyboardEventArgs>();
            KeyUp     = new AGSEvent <KeyboardEventArgs>();

            if (AGSGameWindow.GameWindow != null)
            {
                Init(AGSGameWindow.GameWindow);
            }
        }
示例#4
0
        public AGSInput(GameWindow game, AGS.API.Size virtualResolution, IGameState state,
                        IShouldBlockInput shouldBlockInput, IGameWindowSize windowSize)
        {
            _windowSize            = windowSize;
            this._shouldBlockInput = shouldBlockInput;
            API.MousePosition.VirtualResolution = virtualResolution;
            API.MousePosition.GetWindowWidth    = () => _windowSize.GetWidth(_game);
            API.MousePosition.GetWindowHeight   = () => _windowSize.GetHeight(_game);
            this._virtualWidth  = virtualResolution.Width;
            this._virtualHeight = virtualResolution.Height;
            this._state         = state;
            this._keysDown      = new AGSConcurrentHashSet <Key>();

            this._game             = game;
            this._originalOSCursor = _game.Cursor;

            MouseDown = new AGSEvent <AGS.API.MouseButtonEventArgs>();
            MouseUp   = new AGSEvent <AGS.API.MouseButtonEventArgs>();
            MouseMove = new AGSEvent <MousePositionEventArgs>();
            KeyDown   = new AGSEvent <KeyboardEventArgs>();
            KeyUp     = new AGSEvent <KeyboardEventArgs>();

            game.MouseDown += async(sender, e) =>
            {
                if (isInputBlocked())
                {
                    return;
                }
                var button = convert(e.Button);
                if (button == AGS.API.MouseButton.Left)
                {
                    LeftMouseButtonDown = true;
                }
                else if (button == AGS.API.MouseButton.Right)
                {
                    RightMouseButtonDown = true;
                }
                await MouseDown.InvokeAsync(new AGS.API.MouseButtonEventArgs(null, button, MousePosition));
            };
            game.MouseUp += async(sender, e) =>
            {
                if (isInputBlocked())
                {
                    return;
                }
                var button = convert(e.Button);
                if (button == AGS.API.MouseButton.Left)
                {
                    LeftMouseButtonDown = false;
                }
                else if (button == AGS.API.MouseButton.Right)
                {
                    RightMouseButtonDown = false;
                }
                await MouseUp.InvokeAsync(new AGS.API.MouseButtonEventArgs(null, button, MousePosition));
            };
            game.MouseMove += async(sender, e) =>
            {
                if (isInputBlocked())
                {
                    return;
                }
                await MouseMove.InvokeAsync(new MousePositionEventArgs(MousePosition));
            };
            game.KeyDown += async(sender, e) =>
            {
                Key key = convert(e.Key);
                _keysDown.Add(key);
                if (isInputBlocked())
                {
                    return;
                }
                await KeyDown.InvokeAsync(new KeyboardEventArgs(key));
            };
            game.KeyUp += async(sender, e) =>
            {
                Key key = convert(e.Key);
                _keysDown.Remove(key);
                if (isInputBlocked())
                {
                    return;
                }
                await KeyUp.InvokeAsync(new KeyboardEventArgs(key));
            };
        }