Example #1
0
        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");
        }
Example #2
0
        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));
 }
Example #4
0
        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();
        }
Example #5
0
 /// <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);
Example #6
0
 /// <summary>
 /// Initializes the GameWindow with the specified window context.
 /// </summary>
 /// <param name="gameContext">The window context.</param>
 internal abstract bool CanHandle(GameContext gameContext);
Example #7
0
        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;
 }
Example #9
0
        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;
        }
Example #10
0
 /// <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();
 }
Example #11
0
 /// <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();
 }
Example #12
0
 /// <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);
Example #13
0
 internal abstract void Initialize(GameContext gameContext);
Example #14
0
 /// <summary>
 /// Initializes the GameWindow with the specified window context.
 /// </summary>
 /// <param name="gameContext">The window context.</param>
 internal abstract bool CanHandle(GameContext 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();
 }
Example #16
0
 internal override void Initialize(GameContext windowContext)
 {
     if (windowContext != null)
     {
         BindSurfaceControl(windowContext);
     }
 }
Example #17
0
 /// <inheritdoc />
 internal override bool CanHandle(GameContext gameContext)
 {
     return(gameContext.ContextType == GameContextType.Desktop || gameContext.ContextType == GameContextType.DesktopHwndWpf);
 }
Example #18
0
        /// <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);
            }
        }
Example #19
0
 internal override bool CanHandle(GameContext windowContext)
 {
     return(windowContext.ContextType == GameContextType.WinRT);
 }
Example #20
0
 internal override void Initialize(GameContext gameContext)
 {
     drawingSurfaceBackgroundGrid = (DrawingSurfaceBackgroundGrid)gameContext.Control;
     graphicsDeviceManager        = (IGraphicsDeviceManager)Services.GetService(typeof(IGraphicsDeviceManager));
 }
Example #21
0
 internal override void Initialize(GameContext windowContext)
 {
 }
Example #22
0
 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;
 }
Example #24
0
 internal abstract void Initialize(GameContext gameContext);
Example #25
0
        /// <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;

            }
        }
Example #27
0
        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;
 }
Example #29
0
 internal override void Initialize(GameContext windowContext)
 {
 }
        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);
        }
Example #31
0
 internal override void Switch(GameContext context)
 {
     // Nothing to switch here, GameContext is not used in this implementation.
 }
 /// <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();
 }
        internal override bool CanHandle(GameContext gameContext)
        {
            if (gameContext == null) throw new ArgumentNullException("gameContext");

            return gameContext.ContextType == GameContextType.DesktopWpf;
        }
Example #34
0
        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;
        }
Example #36
0
 /// <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;
        }
Example #38
0
        /// <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;
        }
Example #39
0
        internal override void Switch(GameContext context)
        {
            surfaceControl.SizeChanged -= SurfaceControlSizeChanged;

            BindSurfaceControl(context);
        }
Example #40
0
        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;

            }
        }
Example #41
0
 internal override bool CanHandle(GameContext gameContext)
 {
     return(gameContext.ContextType == GameContextType.WindowsPhoneBackgroundXaml);
 }