1 #region Using Statements
4 using System.Windows.Forms;
5 using Microsoft.Xna.Framework.Graphics;
11 using Color = System.Drawing.Color;
12 using Rectangle = Microsoft.Xna.Framework.Rectangle;
23 public bool swapBuffers =
true;
29 public GraphicsDevice GraphicsDevice
36 get {
return services; }
43 protected override void OnCreateControl()
52 services.AddService<IGraphicsDeviceService>(visGraphicsDevice);
61 base.OnCreateControl();
68 protected override void Dispose(
bool disposing)
70 if (visGraphicsDevice != null)
72 visGraphicsDevice.
Release(disposing);
73 visGraphicsDevice = null;
76 base.Dispose(disposing);
82 #region Windows Form Update
83 protected override void OnInvalidated(InvalidateEventArgs e)
86 base.OnInvalidated(e);
87 Console.WriteLine(
"Call OnInvalidated");
105 #region Windows Form Paint
106 protected override void OnPaint(PaintEventArgs e)
111 Console.WriteLine(
"Call OnPaint");
125 string beginDrawError = BeginDraw();
127 if (
string.IsNullOrEmpty(beginDrawError))
151 if (visGraphicsDevice == null)
153 return Text +
"\n\n" + GetType();
157 string deviceResetError = HandleDeviceReset();
159 if (!
string.IsNullOrEmpty(deviceResetError))
161 return deviceResetError;
169 Viewport viewport =
new Viewport();
174 viewport.Width = ClientSize.Width;
175 viewport.Height = ClientSize.Height;
177 viewport.MinDepth = 0;
178 viewport.MaxDepth = 1;
180 GraphicsDevice.Viewport = viewport;
200 Rectangle sourceRectangle =
new Rectangle(0, 0, ClientSize.Width,
203 GraphicsDevice.Present(sourceRectangle, null, this.Handle);
226 string HandleDeviceReset()
228 bool deviceNeedsReset =
false;
230 switch (GraphicsDevice.GraphicsDeviceStatus)
232 case GraphicsDeviceStatus.Lost:
234 return "Graphics device lost";
236 case GraphicsDeviceStatus.NotReset:
238 deviceNeedsReset =
true;
243 PresentationParameters pp = GraphicsDevice.PresentationParameters;
245 deviceNeedsReset = (ClientSize.Width > pp.BackBufferWidth) ||
246 (ClientSize.Height > pp.BackBufferHeight);
251 if (deviceNeedsReset)
260 return "Graphics device reset failed\n\n" + e;
275 graphics.Clear(Color.CornflowerBlue);
277 using (Brush brush =
new SolidBrush(Color.Black))
279 using (StringFormat format =
new StringFormat())
281 format.Alignment = StringAlignment.Center;
282 format.LineAlignment = StringAlignment.Center;
284 graphics.DrawString(text, Font, brush, ClientRectangle, format);
303 #region Control Properties Events
304 protected override void OnSizeChanged(EventArgs e)
306 base.OnSizeChanged(e);
312 #region Abstract Methods
314 protected abstract void Initialize();
315 protected abstract void LoadContent();
316 protected abstract new void Update();
317 protected abstract void Draw();