forked from MonoGame/MonoGame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GameWindow.cs
170 lines (137 loc) · 4.9 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
// 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 Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Input.Touch;
using System;
using System.ComponentModel;
namespace Microsoft.Xna.Framework {
public abstract class GameWindow {
#region Properties
[DefaultValue(false)]
public abstract bool AllowUserResizing { get; set; }
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; } }
#if (WINDOWS && !WINRT) || DESKTOPGL
/// <summary>
/// The location of this window on the desktop, eg: global coordinate space
/// which stretches across all screens.
/// </summary>
public abstract Point Position { get; set; }
#endif
public abstract DisplayOrientation CurrentOrientation { get; }
public abstract IntPtr Handle { get; }
public abstract string ScreenDeviceName { get; }
private string _title;
/// <summary>
/// Gets or sets the title of the game window.
/// </summary>
/// <remarks>
/// For Windows 8 and Windows 10 UWP this has no effect. For these platforms the title should be
/// set by using the DisplayName property found in the app manifest file.
/// </remarks>
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 WinDX and WinGL/Linux platforms.
/// </summary>
/// <exception cref="System.NotImplementedException">
/// Thrown when trying to use this property on a platform other than the WinDX and WinGL/Linux platforms.
/// </exception>
public virtual bool IsBorderless
{
get
{
return false;
}
set
{
throw new NotImplementedException();
}
}
internal MouseState MouseState;
internal TouchPanelState TouchPanelState;
protected GameWindow()
{
TouchPanelState = new TouchPanelState(this);
}
#endregion Properties
#region Events
public event EventHandler<EventArgs> ClientSizeChanged;
public event EventHandler<EventArgs> OrientationChanged;
public event EventHandler<EventArgs> ScreenDeviceNameChanged;
#if WINDOWS || WINDOWS_UAP || DESKTOPGL|| ANGLE
/// <summary>
/// Use this event to retrieve text for objects like textbox's.
/// This event is not raised by noncharacter keys.
/// This event also supports key repeat.
/// For more information this event is based off:
/// http://msdn.microsoft.com/en-AU/library/system.windows.forms.control.keypress.aspx
/// </summary>
/// <remarks>
/// This event is only supported on the Windows DirectX, Windows OpenGL and Linux platforms.
/// </remarks>
public event EventHandler<TextInputEventArgs> TextInput;
#endif
#endregion Events
public abstract void BeginScreenDeviceChange (bool willBeFullScreen);
public abstract void EndScreenDeviceChange (
string screenDeviceName, int clientWidth, int clientHeight);
public void EndScreenDeviceChange (string screenDeviceName)
{
EndScreenDeviceChange(screenDeviceName, ClientBounds.Width, ClientBounds.Height);
}
protected void OnActivated ()
{
}
internal void OnClientSizeChanged ()
{
if (ClientSizeChanged != null)
ClientSizeChanged (this, EventArgs.Empty);
}
protected void OnDeactivated ()
{
}
protected void OnOrientationChanged ()
{
if (OrientationChanged != null)
OrientationChanged (this, EventArgs.Empty);
}
protected void OnPaint ()
{
}
protected void OnScreenDeviceNameChanged ()
{
if (ScreenDeviceNameChanged != null)
ScreenDeviceNameChanged (this, EventArgs.Empty);
}
#if WINDOWS || WINDOWS_UAP || DESKTOPGL || ANGLE
protected void OnTextInput(object sender, TextInputEventArgs e)
{
if (TextInput != null)
TextInput(sender, e);
}
#endif
protected internal abstract void SetSupportedOrientations (DisplayOrientation orientations);
protected abstract void SetTitle (string title);
#if DIRECTX && WINDOWS
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
}
}