internal XNAWinFormsHostAppWrapper(XNALogic logic, Application parent, WinFormsHostControl host) { this.parent = parent; this.logic = logic; this.control = host; System.Windows.Forms.Control parentControl = this.control; while (parentControl != null) { if (parentControl is System.Windows.Forms.Form) { this.parentForm = (System.Windows.Forms.Form)parentControl; break; } parentControl = parentControl.Parent; } if (parentForm == null) { throw new ArgumentException("Unable to find Parent Form for display handle"); } parentForm.MouseWheel += new System.Windows.Forms.MouseEventHandler(parentControl_MouseWheel); parentForm.FormClosed += new System.Windows.Forms.FormClosedEventHandler(parentForm_FormClosed); formsDeviceService = new WinFormsHostGraphicsDeviceService(this, this.control.ClientSize.Width, this.control.ClientSize.Height); services = new GameServiceContainer(); services.AddService(typeof(IGraphicsDeviceService), formsDeviceService); services.AddService(typeof(IGraphicsDeviceManager), formsDeviceService); presentation = RenderTargetUsage.PlatformContents; content = new ContentManager(services); int width = 0; int height = 0; SurfaceFormat format = SurfaceFormat.Color; width = control.ClientSize.Width; height = control.ClientSize.Height; parent.SetWindowSizeAndFormat(width, height, format, DepthFormat.Depth24Stencil8); parent.SetupGraphicsDeviceManager(null, ref presentation); formsDeviceService.CreateDevice(presentation, host); host.SetApplication(parent, this, formsDeviceService); host.BeginInvoke((EventHandler) delegate { parent.SetGraphicsDevice(GraphicsDevice); logic.Initialise(); logic.LoadContent(); }); }
public void CreateDevice(RenderTargetUsage usage, WinFormsHostControl host) { parameters.RenderTargetUsage = usage; graphicsDevice = new GraphicsDevice(GraphicsAdapter.DefaultAdapter, DeviceType.Hardware, host.Handle, parameters); graphicsDevice.DeviceReset += delegate { this.DeviceReset(this, EventArgs.Empty); }; graphicsDevice.Disposing += delegate { this.DeviceDisposing(this, EventArgs.Empty); }; graphicsDevice.DeviceResetting += delegate { this.DeviceResetting(this, EventArgs.Empty); }; if (DeviceCreated != null) { DeviceCreated(this, EventArgs.Empty); } }
internal XNALogic(Application parent, object host, out Microsoft.Xna.Framework.GamerServices.GamerServicesComponent gamerServicesComponent) { this.state = new AppState(parent); this.parent = parent; parent.UpdateManager.Add(state); parent.UpdateManager.Add(parent); gamerServicesComponent = null; if (host is GameComponentHost) { this.xnaGame = new XNAGameComponentHostAppWrapper(this, parent, host as GameComponentHost); } else { #if !XBOX360 if (host == null) { this.xnaGame = new XNAGameAppWrapper(this, parent, out gamerServicesComponent); } else { WinFormsHostControl _host = host as WinFormsHostControl; if (_host != null) { this.xnaGame = new XNAWinFormsHostAppWrapper(this, parent, _host); } else { this.xnaGame = new XNAGameAppWrapper(this, parent, out gamerServicesComponent); } } #else this.xnaGame = new XNAGameAppWrapper(this, parent, out gamerServicesComponent); #endif } this.Exiting += delegate { Xen.Graphics.Resource.ClearResourceTracking(); }; }
/// <summary> /// <para>Start the main application loop, running the application within a <see cref="WinFormsHostControl"/>. This method should be called from the entry point of the application</para> /// <para>Note: The application must be running within WinForms application started with <see cref="System.Windows.Forms.Application.Run(System.Windows.Forms.Form)"/></para> /// </summary> public void Run(WinFormsHostControl host) { if (host == null) { throw new ArgumentNullException(); } if (xnaLogic != null) { throw new InvalidOperationException("Application is already initalised"); } xnaLogic = new XNALogic(this, host, out this.gamerServicesComponent); xnaLogic.Services.AddService(typeof(ApplicationProviderService), new ApplicationProviderService(this)); xnaLogic.Exiting += new EventHandler(ShutdownThreadPool); xnaLogic.Content.RootDirectory += @"\Content"; content = new ContentRegister(this, xnaLogic.Content); content.Add(this); xnaLogic.Run(); }
internal XNAWinFormsHostAppWrapper(XNALogic logic, Application parent, WinFormsHostControl host) { this.parent = parent; this.logic = logic; this.control = host; System.Windows.Forms.Control parentControl = this.control; while (parentControl != null) { if (parentControl is System.Windows.Forms.Form) { this.parentForm = (System.Windows.Forms.Form)parentControl; break; } parentControl = parentControl.Parent; } if (parentForm == null) throw new ArgumentException("Unable to find Parent Form for display handle"); parentForm.MouseWheel += new System.Windows.Forms.MouseEventHandler(parentControl_MouseWheel); parentForm.FormClosed += new System.Windows.Forms.FormClosedEventHandler(parentForm_FormClosed); formsDeviceService = new WinFormsHostGraphicsDeviceService(this, this.control.ClientSize.Width, this.control.ClientSize.Height); services = new GameServiceContainer(); services.AddService(typeof(IGraphicsDeviceService), formsDeviceService); services.AddService(typeof(IGraphicsDeviceManager), formsDeviceService); presentation = RenderTargetUsage.PlatformContents; content = new ContentManager(services); int width = 0; int height = 0; SurfaceFormat format = SurfaceFormat.Color; width = control.ClientSize.Width; height = control.ClientSize.Height; parent.SetWindowSizeAndFormat(width, height, format, DepthFormat.Depth24Stencil8); parent.SetupGraphicsDeviceManager(null, ref presentation); formsDeviceService.CreateDevice(presentation, host); host.SetApplication(parent, this, formsDeviceService); host.BeginInvoke((EventHandler)delegate { parent.SetGraphicsDevice(GraphicsDevice); logic.Initialise(); logic.LoadContent(); }); }
public void CreateDevice(RenderTargetUsage usage, WinFormsHostControl host) { parameters.RenderTargetUsage = usage; graphicsDevice = new GraphicsDevice(GraphicsAdapter.DefaultAdapter, DeviceType.Hardware, host.Handle, parameters); graphicsDevice.DeviceReset += delegate { this.DeviceReset(this, EventArgs.Empty); }; graphicsDevice.Disposing += delegate { this.DeviceDisposing(this, EventArgs.Empty); }; graphicsDevice.DeviceResetting += delegate { this.DeviceResetting(this, EventArgs.Empty); }; if (DeviceCreated != null) DeviceCreated(this, EventArgs.Empty); }