forked from MonoGame/MonoGame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWinFormsGamePlatform.cs
138 lines (114 loc) · 3.44 KB
/
WinFormsGamePlatform.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// MonoGame - Copyright (C) The MonoGame Team
// This file is subject to the terms and conditions defined in
// file 'LICENSE.txt', which is part of this source code package.
using System;
using System.Diagnostics;
using System.Drawing;
using Microsoft.Xna.Framework;
using System.Windows.Forms;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
namespace MonoGame.Framework
{
class WinFormsGamePlatform : GamePlatform
{
//internal static string LaunchParameters;
private WinFormsGameWindow _window;
public WinFormsGamePlatform(Game game)
: base(game)
{
_window = new WinFormsGameWindow(this);
Window = _window;
}
public override GameRunBehavior DefaultRunBehavior
{
get { return GameRunBehavior.Synchronous; }
}
protected override void OnIsMouseVisibleChanged()
{
_window.MouseVisibleToggled();
}
public override bool BeforeRun()
{
_window.UpdateWindows();
return base.BeforeRun();
}
public override void BeforeInitialize()
{
base.BeforeInitialize();
var gdm = Game.graphicsDeviceManager;
if (gdm == null)
{
_window.Initialize(GraphicsDeviceManager.DefaultBackBufferWidth, GraphicsDeviceManager.DefaultBackBufferHeight);
}
else
{
var pp = Game.GraphicsDevice.PresentationParameters;
_window.Initialize(pp);
}
}
public override void RunLoop()
{
_window.RunLoop();
}
public override void StartRunLoop()
{
throw new NotSupportedException("The Windows platform does not support asynchronous run loops");
}
public override void Exit()
{
if (_window != null)
_window.Dispose();
_window = null;
Window = null;
}
public override bool BeforeUpdate(GameTime gameTime)
{
return true;
}
public override bool BeforeDraw(GameTime gameTime)
{
return true;
}
public override void EnterFullScreen()
{
}
public override void ExitFullScreen()
{
}
internal override void OnPresentationChanged(PresentationParameters pp)
{
_window.OnPresentationChanged(pp);
}
public override void EndScreenDeviceChange(string screenDeviceName, int clientWidth, int clientHeight)
{
}
public override void BeginScreenDeviceChange(bool willBeFullScreen)
{
}
public override void Log(string message)
{
Debug.WriteLine(message);
}
public override void Present()
{
var device = Game.GraphicsDevice;
if ( device != null )
device.Present();
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (_window != null)
{
_window.Dispose();
_window = null;
Window = null;
}
Microsoft.Xna.Framework.Media.MediaManagerState.CheckShutdown();
}
base.Dispose(disposing);
}
}
}