public void RefreshViewport(IGameSettings settings, IGameWindow gameWindow) { if (settings.PreserveAspectRatio) //http://www.david-amador.com/2013/04/opengl-2d-independent-resolution-rendering/ { float targetAspectRatio = (float)settings.VirtualResolution.Width / settings.VirtualResolution.Height; Size screen = new Size(gameWindow.Width, gameWindow.Height); int width = screen.Width; int height = (int)(width / targetAspectRatio + 0.5f); if (height > screen.Height) { //It doesn't fit our height, we must switch to pillarbox then height = screen.Height; width = (int)(height * targetAspectRatio + 0.5f); } // set up the new viewport centered in the backbuffer int viewX = (screen.Width / 2) - (width / 2); int viewY = (screen.Height / 2) - (height / 2); _graphics.Viewport(viewX, viewY, width, height); } else { _graphics.Viewport(0, 0, gameWindow.Width, gameWindow.Height); } }
public static void Run() { FakeAGSTestGameStarter starter = new FakeAGSTestGameStarter(); var game = AGSGame.CreateEmpty(); _gameDebugView = new Lazy <GameDebugView>(() => { var gameDebugView = new GameDebugView(game, new KeyboardBindings(game.Input)); gameDebugView.Load(); return(gameDebugView); }); starter.StartGame(game); Size screenSize = new AGS.API.Size(320, 200); int factor = 2; AGSGameSettings settings = new AGSGameSettings( "Demo Game", screenSize, windowSize: new AGS.API.Size(screenSize.Width * factor, screenSize.Height * factor), windowState: WindowState.Normal); game.Start(settings); }
public AGSGameLoop(IGameState gameState, AGS.API.Size virtualResolution, IDisplayList displayList, IInput input) { _displayList = displayList; _gameState = gameState; _virtualResolution = virtualResolution; _input = input; }
public AGSGameLoop(IGameState gameState, AGS.API.Size virtualResolution, IAGSRoomTransitions roomTransitions, IGameEvents events) { _gameState = gameState; _events = events; _virtualResolution = virtualResolution; _roomTransitions = roomTransitions; }
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 GLFrameBuffer(Size size, IGraphicsBackend graphics) { _width = size.Width; _height = size.Height; Texture = new GLTexture(null, graphics); _graphics = graphics; _graphics.TexImage2D(_width, _height, IntPtr.Zero); _fbo = _graphics.GenFrameBuffer(); }
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 AGSGameLoop(IGameState gameState, AGS.API.Size virtualResolution, IAGSRoomTransitions roomTransitions, IGameEvents events, IDisplayList displayList, IInput input) { _displayList = displayList; _gameState = gameState; _events = events; _virtualResolution = virtualResolution; _roomTransitions = roomTransitions; _input = input; }
public AGSGameSettings(string title, AGS.API.Size virtualResolution, WindowState windowState = WindowState.Maximized, AGS.API.Size?windowSize = null, VsyncMode vsync = VsyncMode.Adaptive, bool preserveAspectRatio = true, WindowBorder windowBorder = WindowBorder.Resizable) { Title = title; VirtualResolution = virtualResolution; WindowState = windowState; WindowSize = windowSize.HasValue ? windowSize.Value : virtualResolution; Vsync = vsync; PreserveAspectRatio = preserveAspectRatio; WindowBorder = windowBorder; }
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 void SetSize(OpenTK.INativeWindow gameWindow, AGS.API.Size size) { }
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)); }; }
public void SetSize(OpenTK.INativeWindow gameWindow, AGS.API.Size size) { gameWindow.Size = new System.Drawing.Size(size.Width, size.Height); }
public AGSGameLoop (IGameState gameState, AGS.API.Size virtualResolution, IAGSRoomTransitions roomTransitions) { this._gameState = gameState; this._virtualResolution = virtualResolution; this._roomTransitions = roomTransitions; }
private ObjectPool <IBitmap> getPool(int width, int height) { AGS.API.Size size = new AGS.API.Size(width, height); return(_bitmaps.GetOrAdd(size, _ => new ObjectPool <IBitmap> (() => _bitmapLoader.Load(width, height), 3, bitmap => bitmap.Clear()))); }
public AGSRenderLayer(int z, PointF? parallaxSpeed = null, Size? independentResolution = null) { Z = z; ParallaxSpeed = parallaxSpeed ?? new PointF(1f, 1f); IndependentResolution = independentResolution; }
private ObjectPool<IBitmap> getPool(int width, int height) { AGS.API.Size size = new AGS.API.Size (width, height); return _bitmaps.GetOrAdd(size, _ => new ObjectPool<IBitmap> (() => Hooks.BitmapLoader.Load(width, height), 3, bitmap => bitmap.Clear())); }
public AGSGameLoop(IGameState gameState, AGS.API.Size virtualResolution, IAGSRoomTransitions roomTransitions) { this._gameState = gameState; this._virtualResolution = virtualResolution; this._roomTransitions = roomTransitions; }
public void Init(AGS.API.Size virtualResolution) { API.MousePosition.VirtualResolution = virtualResolution; }
public bool Equals(Size other) => (Width == other.Width) && (Height == other.Height);