Esempio n. 1
0
        private float convertY(float y)
        {
            var viewport      = getViewport();
            var virtualHeight = _virtualHeight / viewport.ScaleY;

            y = MathUtils.Lerp(0f, virtualHeight, _windowSize.GetHeight(_game), 0f, y);
            return(y + viewport.Y);
        }
Esempio n. 2
0
        public AndroidInput(AndroidSimpleGestures gestures, AGS.API.Size virtualResolution,
                            IGameState state, IShouldBlockInput shouldBlockInput, IGameWindowSize windowSize)
        {
            MousePosition     = new MousePosition(0f, 0f, state.Viewport);
            _shouldBlockInput = shouldBlockInput;
            _windowSize       = windowSize;
            _state            = state;
            API.MousePosition.VirtualResolution = virtualResolution;
            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);
        }
Esempio n. 3
0
        private float convertY(float y)
        {
            var   viewport      = getViewport();
            var   virtualHeight = _virtualHeight / viewport.ScaleY;
            float density       = Resources.System.DisplayMetrics.Density;

            y = (y - GLUtils.ScreenViewport.Y) / density;
            float height = _windowSize.GetHeight(null) - ((GLUtils.ScreenViewport.Y * 2) / density);

            y = MathUtils.Lerp(0f, virtualHeight, height, 0f, y);
            return(y + viewport.Y);
        }
Esempio n. 4
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);
            }
        }
Esempio n. 5
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));
            };
        }