public virtual GameWindow CreateWindow(GameContext gameContext) { gameContext = gameContext ?? new GameContext(); var windows = GetSupportedGameWindows(); foreach (var gameWindowToTest in windows) { if (gameWindowToTest.CanHandle(gameContext)) { gameWindowToTest.Initialize(gameContext); return gameWindowToTest; } } throw new ArgumentException("Game Window context not supported on this platform"); }
internal override void Initialize(GameContext gameContext) { this.GameContext = gameContext; Control = (Control)gameContext.Control; // Setup the initial size of the window var width = gameContext.RequestedWidth; if (width == 0) { width = Control is Form ? GraphicsDeviceManager.DefaultBackBufferWidth : Control.ClientSize.Width; } var height = gameContext.RequestedHeight; if (height == 0) { height = Control is Form ? GraphicsDeviceManager.DefaultBackBufferHeight : Control.ClientSize.Height; } Control.ClientSize = new System.Drawing.Size(width, height); Control.MouseEnter += GameWindowForm_MouseEnter; Control.MouseLeave += GameWindowForm_MouseLeave; gameForm = Control as RenderForm; if (gameForm != null) { gameForm.AppActivated += OnActivated; gameForm.AppDeactivated += OnDeactivated; gameForm.UserResized += OnClientSizeChanged; } else { Control.Resize += OnClientSizeChanged; } }
internal override void Initialize(GameContext gameContext) { drawingSurface = (DrawingSurface)gameContext.Control; graphicsDeviceService = (IGraphicsDeviceService)Services.GetService(typeof(IGraphicsDeviceService)); graphicsDeviceManager = (IGraphicsDeviceManager)Services.GetService(typeof(IGraphicsDeviceManager)); }
public void Run(GameContext gameContext) { gameWindow = CreateWindow(gameContext); // Register on Activated gameWindow.Activated += OnActivated; gameWindow.Deactivated += OnDeactivated; gameWindow.InitCallback = game.InitializeBeforeRun; gameWindow.RunCallback = game.Tick; gameWindow.ExitCallback = () => OnExiting(this, EventArgs.Empty); var windowCreated = WindowCreated; if (windowCreated != null) { windowCreated(this, EventArgs.Empty); } gameWindow.Run(); }
/// <summary> /// Switches the rendering onto another game context. /// </summary> /// <param name="context">The new context to switch to.</param> internal abstract void Switch(GameContext context);
/// <summary> /// Initializes the GameWindow with the specified window context. /// </summary> /// <param name="gameContext">The window context.</param> internal abstract bool CanHandle(GameContext gameContext);
private void BindSurfaceControl(GameContext windowContext) { surfaceControl = windowContext.Control as FrameworkElement; if (surfaceControl == null) throw new ArgumentException("A FrameworkElement expected."); surfaceControl.SizeChanged += SurfaceControlSizeChanged; }
internal override bool CanHandle(GameContext windowContext) { return windowContext.ContextType == GameContextType.WinRTBackgroundXaml; }
private void BindSurfaceControl(GameContext windowContext) { surfaceControl = windowContext.Control as FrameworkElement; if (surfaceControl == null) throw new ArgumentException("A FrameworkElement expected."); surfaceControl.SizeChanged += SurfaceControlSizeChanged; var swapChainPanel = surfaceControl as SwapChainPanel; if (swapChainPanel != null) swapChainPanel.CompositionScaleChanged += SwapChainPanelCompositionScaleChanged; }
/// <summary> /// Initializes a new instance of the <see cref="GameWindowRenderer" /> class. /// </summary> /// <param name="game">The game.</param> /// <param name="gameContext">The window context.</param> public GameWindowRenderer(Game game, GameContext gameContext = null) : base(game) { GameContext = gameContext ?? new GameContext(); }
/// <summary> /// Initializes a new instance of the <see cref="GameWindowRenderer" /> class. /// </summary> /// <param name="registry">The registry.</param> /// <param name="gameContext">The window context.</param> public GameWindowRenderer(IServiceRegistry registry, GameContext gameContext = null) : base(registry) { GameContext = gameContext ?? new GameContext(); }
internal abstract void Initialize(GameContext gameContext);
internal override void Initialize(GameContext windowContext) { if (windowContext != null) { BindSurfaceControl(windowContext); } }
/// <inheritdoc /> internal override bool CanHandle(GameContext gameContext) { return(gameContext.ContextType == GameContextType.Desktop || gameContext.ContextType == GameContextType.DesktopHwndWpf); }
/// <inheritdoc /> internal override void Initialize(GameContext gameContext) { GameContext = gameContext; if (gameContext.ContextType == GameContextType.Desktop) { Control = (Control)gameContext.Control; InitializeFromWinForm(); } else if (gameContext.ContextType == GameContextType.DesktopHwndWpf) { InitializeFromWpfControl(gameContext.Control); } }
internal override bool CanHandle(GameContext windowContext) { return(windowContext.ContextType == GameContextType.WinRT); }
internal override void Initialize(GameContext gameContext) { drawingSurfaceBackgroundGrid = (DrawingSurfaceBackgroundGrid)gameContext.Control; graphicsDeviceManager = (IGraphicsDeviceManager)Services.GetService(typeof(IGraphicsDeviceManager)); }
internal override void Initialize(GameContext windowContext) { }
internal override void Switch(GameContext context) { // Nothing to switch here, GameContext is not used in this implementation. }
internal override void Initialize(GameContext gameContext) { drawingSurface = (DrawingSurface)gameContext.Control; }
/// <summary> /// Switches the game to a new game context. /// </summary> /// <param name="context">The new game context.</param> /// <exception cref="NotSupportedException">Is thrown when a different game context type is passed (for example initially it was WinForms and became WPF).</exception> public void Switch(GameContext context) { if (context == null) throw new ArgumentNullException("context"); if (gameWindow.CanHandle(context)) { gameWindow.Switch(context); CreatePresenter(game.GraphicsDevice, null, context.Control); } else throw new NotSupportedException("Switching to a different game window type is not supported yet."); }
internal override void Initialize(GameContext windowContext) { if (windowContext != null) { swapChainBackgroundPanel = windowContext.Control as SwapChainBackgroundPanel; if (swapChainBackgroundPanel == null) { throw new NotSupportedException(string.Format("Unsupported window context [{0}]. Only SwapChainBackgroundPanel", windowContext.Control.GetType().FullName)); } //clientBounds = new DrawingRectangle(0, 0, (int)swapChainBackgroundPanel.ActualWidth, (int)swapChainBackgroundPanel.ActualHeight); swapChainBackgroundPanel.SizeChanged += swapChainBackgroundPanel_SizeChanged; } }
public void Run(GameContext gameContext) { gameWindow = CreateWindow(gameContext); // set the mouse visibility in case if it was set in the game constructor: gameWindow.IsMouseVisible = game.IsMouseVisible; // Register on Activated gameWindow.Activated += OnActivated; gameWindow.Deactivated += OnDeactivated; gameWindow.InitCallback = game.InitializeBeforeRun; gameWindow.RunCallback = game.Tick; gameWindow.ExitCallback = () => OnExiting(this, EventArgs.Empty); var windowCreated = WindowCreated; if (windowCreated != null) { windowCreated(this, EventArgs.Empty); } gameWindow.Run(); }
internal override bool CanHandle(GameContext gameContext) { return gameContext.ContextType == GameContextType.WindowsPhoneXaml; }
internal override void Switch(GameContext context) { drawingSurface.Loaded -= DrawingSurfaceOnLoaded; drawingSurface.Unloaded -= DrawingSurfaceUnloaded; drawingSurface.SetContentProvider(null); drawingSurface = (DrawingSurface)context.Control; isInitialized = false; synchronizedTexture.Dispose(); synchronizedTexture = null; drawingSurface.Loaded += DrawingSurfaceOnLoaded; drawingSurface.Unloaded += DrawingSurfaceUnloaded; drawingSurface.SetContentProvider(this); }
internal override bool CanHandle(GameContext gameContext) { if (gameContext == null) throw new ArgumentNullException("gameContext"); return gameContext.ContextType == GameContextType.DesktopWpf; }
internal override void Switch(GameContext context) { surfaceControl.SizeChanged -= SurfaceControlSizeChanged; var swapChainPanel = surfaceControl as SwapChainPanel; if (swapChainPanel != null) swapChainPanel.CompositionScaleChanged -= SwapChainPanelCompositionScaleChanged; BindSurfaceControl(context); }
internal override void Initialize(GameContext gameContext) { if (gameContext == null) throw new ArgumentNullException("gameContext"); element = gameContext.Control as SharpDXElement; if (element == null) throw new ArgumentException("Only SharpDXElement is supported at this time", "gameContext"); var width = gameContext.RequestedWidth; if (width <= 0) width = GraphicsDeviceManager.DefaultBackBufferWidth; var height = gameContext.RequestedHeight; if (height <= 0) height = GraphicsDeviceManager.DefaultBackBufferHeight; element.TrySetSize(width, height); element.ResizeCompleted += OnClientSizeChanged; element.MouseEnter += OnMouseEnter; element.MouseLeave += OnMouseLeave; }
/// <inheritdoc /> internal override bool CanHandle(GameContext gameContext) { return gameContext.ContextType == GameContextType.Desktop || gameContext.ContextType == GameContextType.DesktopHwndWpf; }
internal override void Switch(GameContext context) { isInitialized = false; drawingSurfaceBackgroundGrid.Loaded -= DrawingSurfaceBackgroundGridOnLoaded; drawingSurfaceBackgroundGrid.Unloaded -= drawingSurfaceBackgroundGrid_Unloaded; drawingSurfaceBackgroundGrid.SetBackgroundContentProvider(null); drawingSurfaceBackgroundGrid = (DrawingSurfaceBackgroundGrid)context.Control; BindDrawingSurfaceBackgroundGridEvents(); // TODO: check if this can cause issues as event "Loaded" never gets called drawingSurfaceBackgroundGrid.SetBackgroundContentProvider(this); currentDevice = null; currentDeviceContext = null; }
/// <inheritdoc /> internal override void Switch(GameContext context) { // unbind event handlers from previous control Control.MouseEnter -= HandleControlMouseEnter; Control.MouseLeave -= HandleControlMouseLeave; gameForm = Control as RenderForm; if (gameForm != null) { gameForm.AppActivated -= OnActivated; gameForm.AppDeactivated -= OnDeactivated; gameForm.UserResized -= OnClientSizeChanged; } else { Control.Resize -= OnClientSizeChanged; } // setup and bind event handlers to new control Initialize(context); Control.Show(); // Make sure the control is visible renderLoop.Control = Control; }
internal override void Switch(GameContext context) { surfaceControl.SizeChanged -= SurfaceControlSizeChanged; BindSurfaceControl(context); }
internal override void Initialize(GameContext windowContext) { if (windowContext != null) { surfaceControl = windowContext.Control as FrameworkElement; if (surfaceControl == null) throw new ArgumentException("A FrameworkElement expected."); surfaceControl.SizeChanged += SurfaceControlSizeChanged; } }
internal override bool CanHandle(GameContext gameContext) { return(gameContext.ContextType == GameContextType.WindowsPhoneBackgroundXaml); }