forked from MonoGame/MonoGame
-
Notifications
You must be signed in to change notification settings - Fork 4
/
GameWindow.cs
284 lines (241 loc) · 9.16 KB
/
GameWindow.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
// MonoGame - Copyright (C) MonoGame Foundation, Inc
// This file is subject to the terms and conditions defined in
// file 'LICENSE.txt', which is part of this source code package.
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Input.Touch;
using System;
using System.ComponentModel;
namespace Microsoft.Xna.Framework
{
/// <summary>
/// The system window used by a <see cref="Game"/>.
/// </summary>
public abstract class GameWindow
{
#region Properties
/// <summary>
/// Indicates if users can resize this <see cref="GameWindow"/>.
/// </summary>
[DefaultValue(false)]
public abstract bool AllowUserResizing { get; set; }
/// <summary>
/// The client rectangle of the <see cref="GameWindow"/>.
/// </summary>
public abstract Rectangle ClientBounds { get; }
internal bool _allowAltF4 = true;
/// <summary>
/// Gets or sets a bool that enables usage of Alt+F4 for window closing on desktop platforms. Value is true by default.
/// </summary>
public virtual bool AllowAltF4 { get { return _allowAltF4; } set { _allowAltF4 = value; } }
/// <summary>
/// The location of this window on the desktop, eg: global coordinate space
/// which stretches across all screens.
///
/// May be zero on platforms where it is not supported.
/// </summary>
public abstract Point Position { get; set; }
/// <summary>
/// The display orientation on a mobile device.
/// </summary>
public abstract DisplayOrientation CurrentOrientation { get; }
/// <summary>
/// The handle to the window used by the backend windowing service.
///
/// For WindowsDX this is the Win32 window handle (HWND).
/// For DesktopGL this is the SDL window handle.
/// </summary>
public abstract IntPtr Handle { get; }
/// <summary>
/// The name of the screen the window is currently on.
/// </summary>
public abstract string ScreenDeviceName { get; }
private string _title;
/// <summary>
/// Gets or sets the title of the game window.
/// </summary>
public string Title {
get { return _title; }
set {
if (_title != value) {
SetTitle(value);
_title = value;
}
}
}
/// <summary>
/// Determines whether the border of the window is visible. Currently only supported on the WindowsDX and DesktopGL platforms.
/// </summary>
/// <exception cref="System.NotImplementedException">
/// Thrown when trying to use this property on a platform other than WinowsDX or DesktopGL.
/// </exception>
public virtual bool IsBorderless
{
get
{
return false;
}
set
{
throw new NotImplementedException();
}
}
internal MouseState MouseState;
internal TouchPanelState TouchPanelState;
/// <summary>
/// Create a <see cref="GameWindow"/>.
/// </summary>
protected GameWindow()
{
TouchPanelState = new TouchPanelState(this);
}
#endregion Properties
#region Events
/// <summary>
/// Raised when the user resized the window or the window switches from fullscreen mode to
/// windowed mode or vice versa.
/// </summary>
public event EventHandler<EventArgs> ClientSizeChanged;
/// <summary>
/// Raised when <see cref="CurrentOrientation"/> changed.
/// </summary>
public event EventHandler<EventArgs> OrientationChanged;
/// <summary>
/// Raised when <see cref="ScreenDeviceName"/> changed.
/// </summary>
public event EventHandler<EventArgs> ScreenDeviceNameChanged;
#if WINDOWS || DESKTOPGL|| ANGLE || NATIVE
/// <summary>
/// Use this event to user text input.
///
/// This event is not raised by noncharacter keys except control characters such as backspace, tab, carriage return and escape.
/// This event also supports key repeat.
/// </summary>
/// <remarks>
/// This event is only supported on desktop platforms.
/// </remarks>
public event EventHandler<TextInputEventArgs> TextInput;
internal bool IsTextInputHandled { get { return TextInput != null; } }
/// <summary>
/// Buffered keyboard KeyDown event.
/// </summary>
public event EventHandler<InputKeyEventArgs> KeyDown;
/// <summary>
/// Buffered keyboard KeyUp event.
/// </summary>
public event EventHandler<InputKeyEventArgs> KeyUp;
#endif
/// <summary>
/// This event is raised when user drops a file into the game window
/// </summary>
/// <remarks>
/// This event is only supported on desktop platforms.
/// </remarks>
public event EventHandler<FileDropEventArgs> FileDrop;
#endregion Events
/// <summary>
/// Called before a game switches from windowed to full screen mode or vice versa.
/// </summary>
/// <param name="willBeFullScreen">Indicates what mode the game will switch to.</param>
public abstract void BeginScreenDeviceChange (bool willBeFullScreen);
/// <summary>
/// Called when a transition from windowed to full screen or vice versa ends, or when
/// the <see cref="Graphics.GraphicsDevice"/> is reset.
/// </summary>
/// <param name="screenDeviceName">Name of the screen to move the window to.</param>
/// <param name="clientWidth">The new width of the client rectangle.</param>
/// <param name="clientHeight">The new height of the client rectangle.</param>
public abstract void EndScreenDeviceChange (
string screenDeviceName, int clientWidth, int clientHeight);
/// <summary>
/// Called when a transition from windowed to full screen or vice versa ends, or when
/// the <see cref="Graphics.GraphicsDevice"/> is reset.
/// </summary>
/// <param name="screenDeviceName">Name of the screen to move the window to.</param>
public void EndScreenDeviceChange (string screenDeviceName)
{
EndScreenDeviceChange(screenDeviceName, ClientBounds.Width, ClientBounds.Height);
}
/// <summary>
/// Called when the window gains focus.
/// </summary>
protected void OnActivated ()
{
}
internal void OnClientSizeChanged ()
{
EventHelpers.Raise(this, ClientSizeChanged, EventArgs.Empty);
}
/// <summary>
/// Called when the window loses focus.
/// </summary>
protected void OnDeactivated ()
{
}
/// <summary>
/// Called when <see cref="CurrentOrientation"/> changed. Raises the <see cref="OnOrientationChanged"/> event.
/// </summary>
protected void OnOrientationChanged ()
{
EventHelpers.Raise(this, OrientationChanged, EventArgs.Empty);
}
/// <summary>
/// Called when the window needs to be painted.
/// </summary>
protected void OnPaint ()
{
}
/// <summary>
/// Called when <see cref="ScreenDeviceName"/> changed. Raises the <see cref="ScreenDeviceNameChanged"/> event.
/// </summary>
protected void OnScreenDeviceNameChanged ()
{
EventHelpers.Raise(this, ScreenDeviceNameChanged, EventArgs.Empty);
}
#if WINDOWS || DESKTOPGL || ANGLE || NATIVE
/// <summary>
/// Called when the window receives text input. Raises the <see cref="TextInput"/> event.
/// </summary>
/// <param name="e">Parameters to the <see cref="TextInput"/> event.</param>
internal void OnTextInput(TextInputEventArgs e)
{
EventHelpers.Raise(this, TextInput, e);
}
internal void OnKeyDown(InputKeyEventArgs e)
{
EventHelpers.Raise(this, KeyDown, e);
}
internal void OnKeyUp(InputKeyEventArgs e)
{
EventHelpers.Raise(this, KeyUp, e);
}
#endif
internal void OnFileDrop(FileDropEventArgs e)
{
EventHelpers.Raise(this, FileDrop, e);
}
/// <summary>
/// Sets the supported display orientations.
/// </summary>
/// <param name="orientations">Supported display orientations</param>
protected internal abstract void SetSupportedOrientations (DisplayOrientation orientations);
/// <summary>
/// Set the title of this window to the given string.
/// </summary>
/// <param name="title">The new title of the window.</param>
protected abstract void SetTitle (string title);
#if DIRECTX && WINDOWS
/// <summary>
/// Create a <see cref="GameWindow"/> based on the given <see cref="Game"/> and a fixed starting size.
/// </summary>
/// <param name="game">The <see cref="Game"/> to create the <see cref="GameWindow"/> for.</param>
/// <param name="width">Initial pixel width to set for the <see cref="GameWindow"/>.</param>
/// <param name="height">Initial pixel height to set for the <see cref="GameWindow"/>.</param>
public static GameWindow Create(Game game, int width, int height)
{
var window = new MonoGame.Framework.WinFormsGameWindow((MonoGame.Framework.WinFormsGamePlatform)game.Platform);
window.Initialize(width, height);
return window;
}
#endif
}
}