private int _inUpdate; //For preventing re-entrancy public AGSInput(IGameEvents events, IShouldBlockInput shouldBlockInput, IAGSCursor cursor, IAGSHitTest hitTest, IEvent <API.MouseButtonEventArgs> mouseDown, IEvent <API.MouseButtonEventArgs> mouseUp, IEvent <MousePositionEventArgs> mouseMove, IEvent <KeyboardEventArgs> keyDown, IEvent <KeyboardEventArgs> keyUp, ICoordinates coordinates) { _cursor = cursor; _events = events; _hitTest = hitTest; _actions = new ConcurrentQueue <Func <Task> >(); _coordinates = coordinates; _shouldBlockInput = shouldBlockInput; _keysDown = new AGSConcurrentHashSet <API.Key>(); MouseDown = mouseDown; MouseUp = mouseUp; MouseMove = mouseMove; KeyDown = keyDown; KeyUp = keyUp; if (AGSGameWindow.GameWindow != null) { init(AGSGameWindow.GameWindow); } else { AGSGameWindow.OnInit = () => init(AGSGameWindow.GameWindow); } }
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); }
public IOSInput(IOSGestures gestures, AGS.API.Size virtualResolution, IGameState state, IShouldBlockInput shouldBlockInput, IGameWindow gameWindow) { MousePosition = new MousePosition(0f, 0f, state.Viewport); _shouldBlockInput = shouldBlockInput; _gameWindow = gameWindow; _state = state; API.MousePosition.VirtualResolution = virtualResolution; updateWindowSizeFunctions(); MouseDown = new AGSEvent <AGS.API.MouseButtonEventArgs>(); MouseUp = new AGSEvent <AGS.API.MouseButtonEventArgs>(); MouseMove = new AGSEvent <MousePositionEventArgs>(); KeyDown = new AGSEvent <KeyboardEventArgs>(); KeyUp = new AGSEvent <KeyboardEventArgs>(); IOSGameWindow.Instance.View.OnInsertText += onInsertText; IOSGameWindow.Instance.View.OnDeleteBackward += onDeleteBackwards; 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; }; }
public IOSInput(IOSGestures gestures, IShouldBlockInput shouldBlockInput, ICoordinates coordinates, IAGSHitTest hitTest) { _gestures = gestures; _hitTest = hitTest; _coordinates = coordinates; MousePosition = new MousePosition(0f, 0f, _coordinates); _shouldBlockInput = shouldBlockInput; MouseDown = new AGSEvent <AGS.API.MouseButtonEventArgs>(); MouseUp = new AGSEvent <AGS.API.MouseButtonEventArgs>(); MouseMove = new AGSEvent <MousePositionEventArgs>(); KeyDown = new AGSEvent <KeyboardEventArgs>(); KeyUp = new AGSEvent <KeyboardEventArgs>(); IOSGameWindow.Instance.View.OnInsertText += onInsertText; IOSGameWindow.Instance.View.OnDeleteBackward += onDeleteBackwards; 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(_hitTest.ObjectAtMousePosition, MouseButton.Left, MousePosition)); await Task.Delay(250); await MouseUp.InvokeAsync(new MouseButtonEventArgs(_hitTest.ObjectAtMousePosition, MouseButton.Left, MousePosition)); LeftMouseButtonDown = false; }; }
public AndroidInput(AndroidSimpleGestures gestures, AGS.API.Size virtualResolution, IGameState state, IShouldBlockInput shouldBlockInput, IGameWindowSize windowSize) { _shouldBlockInput = shouldBlockInput; _windowSize = windowSize; _state = state; this._virtualWidth = virtualResolution.Width; this._virtualHeight = virtualResolution.Height; 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(sender, new MousePositionEventArgs(MouseX, MouseY)); await Task.Delay(300); if (_lastDrag <= now) { IsTouchDrag = false; } }; gestures.OnUserSingleTap += async(sender, e) => { if (isInputBlocked()) { return; } setMousePosition(e); LeftMouseButtonDown = true; await MouseDown.InvokeAsync(sender, new MouseButtonEventArgs(MouseButton.Left, MouseX, MouseY)); await Task.Delay(250); await MouseUp.InvokeAsync(sender, new MouseButtonEventArgs(MouseButton.Left, MouseX, MouseY)); LeftMouseButtonDown = false; }; AndroidGameWindow.Instance.OnNewView += onViewChanged; onViewChanged(null, AndroidGameWindow.Instance.View); }
public AndroidInput(AndroidSimpleGestures gestures, IShouldBlockInput shouldBlockInput, ICoordinates coordinates, IAGSHitTest hitTest) { _hitTest = hitTest; _coordinates = coordinates; MousePosition = new MousePosition(0f, 0f, coordinates); _shouldBlockInput = shouldBlockInput; 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(hitTest.ObjectAtMousePosition, MouseButton.Left, MousePosition)); await Task.Delay(250); await MouseUp.InvokeAsync(new MouseButtonEventArgs(hitTest.ObjectAtMousePosition, MouseButton.Left, MousePosition)); LeftMouseButtonDown = false; }; AndroidGameWindow.Instance.OnNewView += onViewChanged; onViewChanged(null, AndroidGameWindow.Instance.View); }
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); } }
public EditorShouldBlockEngineInput(IGameState state) { _defaultBlocker = new AGSShouldBlockInput(state); }
public AGSInput(GameWindow game, AGS.API.Size virtualResolution, IGameState state, IShouldBlockInput shouldBlockInput, IGameWindowSize windowSize) { _windowSize = windowSize; this._shouldBlockInput = shouldBlockInput; 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(sender, new AGS.API.MouseButtonEventArgs(button, convertX(e.X), convertY(e.Y))); }; 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(sender, new AGS.API.MouseButtonEventArgs(button, convertX(e.X), convertY(e.Y))); }; game.MouseMove += async(sender, e) => { if (isInputBlocked()) { return; } await MouseMove.InvokeAsync(sender, new MousePositionEventArgs(convertX(e.X), convertY(e.Y))); }; game.KeyDown += async(sender, e) => { Key key = convert(e.Key); _keysDown.Add(key); if (isInputBlocked()) { return; } await KeyDown.InvokeAsync(sender, new KeyboardEventArgs(key)); }; game.KeyUp += async(sender, e) => { Key key = convert(e.Key); _keysDown.Remove(key); if (isInputBlocked()) { return; } await KeyUp.InvokeAsync(sender, new KeyboardEventArgs(key)); }; }