Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
GameWindow.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 //
4 // Copyright (c) 2010-2013 SharpDX - Alexandre Mutel
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining a copy
7 // of this software and associated documentation files (the "Software"), to deal
8 // in the Software without restriction, including without limitation the rights
9 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 // copies of the Software, and to permit persons to whom the Software is
11 // furnished to do so, subject to the following conditions:
12 //
13 // The above copyright notice and this permission notice shall be included in
14 // all copies or substantial portions of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 // THE SOFTWARE.
23 
24 using System;
25 
26 using SiliconStudio.Paradox.Graphics;
27 using SiliconStudio.Core;
28 using SiliconStudio.Core.Mathematics;
29 
30 namespace SiliconStudio.Paradox.Games
31 {
32  /// <summary>
33  /// An abstract window.
34  /// </summary>
35  public abstract class GameWindow : ComponentBase
36  {
37  #region Fields
38 
39  private string title;
40 
41  internal GameContext GameContext;
42 
43  #endregion
44 
45  #region Public Events
46 
47  /// <summary>
48  /// Indicate if the window is currently activated.
49  /// </summary>
50  public bool IsActivated;
51 
52  /// <summary>
53  /// Occurs when this window is activated.
54  /// </summary>
55  public event EventHandler<EventArgs> Activated;
56 
57  /// <summary>
58  /// Occurs, when device client size is changed.
59  /// </summary>
60  public event EventHandler<EventArgs> ClientSizeChanged;
61 
62  /// <summary>
63  /// Occurs when this window is deactivated.
64  /// </summary>
65  public event EventHandler<EventArgs> Deactivated;
66 
67  /// <summary>
68  /// Occurs, when device orientation is changed.
69  /// </summary>
70  public event EventHandler<EventArgs> OrientationChanged;
71 
72  #endregion
73 
74  #region Public Properties
75 
76  /// <summary>
77  /// Gets or sets, user possibility to resize this window.
78  /// </summary>
79  public abstract bool AllowUserResizing { get; set; }
80 
81  /// <summary>
82  /// Gets the client bounds.
83  /// </summary>
84  /// <value>The client bounds.</value>
85  public abstract Rectangle ClientBounds { get; }
86 
87  /// <summary>
88  /// Gets the current orientation.
89  /// </summary>
90  /// <value>The current orientation.</value>
91  public abstract DisplayOrientation CurrentOrientation { get; }
92 
93  /// <summary>
94  /// Gets a value indicating whether this instance is minimized.
95  /// </summary>
96  /// <value><c>true</c> if this instance is minimized; otherwise, <c>false</c>.</value>
97  public abstract bool IsMinimized { get; }
98 
99  /// <summary>
100  /// Gets or sets a value indicating whether the mouse pointer is visible over this window.
101  /// </summary>
102  /// <value><c>true</c> if this instance is mouse visible; otherwise, <c>false</c>.</value>
103  public abstract bool IsMouseVisible { get; set; }
104 
105  /// <summary>
106  /// Gets the native window.
107  /// </summary>
108  /// <value>The native window.</value>
109  public abstract WindowHandle NativeWindow { get; }
110 
111  /// <summary>
112  /// Gets or sets a value indicating whether this <see cref="GameWindow" /> is visible.
113  /// </summary>
114  /// <value><c>true</c> if visible; otherwise, <c>false</c>.</value>
115  public abstract bool Visible { get; set; }
116 
117  /// <summary>
118  /// Gets or sets the position of the window on the screen.
119  /// </summary>
120  public virtual Int2 Position { get; set; }
121 
122  /// <summary>
123  /// Gets or sets a value indicating whether this window has a border
124  /// </summary>
125  /// <value><c>true</c> if this window has a border; otherwise, <c>false</c>.</value>
126  public abstract bool IsBorderLess { get; set; }
127 
128  /// <summary>
129  /// Gets or sets the title of the window.
130  /// </summary>
131  public string Title
132  {
133  get
134  {
135  return title;
136  }
137 
138  set
139  {
140  if (value == null)
141  {
142  throw new ArgumentNullException("value");
143  }
144 
145  if (title != value)
146  {
147  title = value;
148  SetTitle(title);
149  }
150  }
151  }
152 
153  #endregion
154 
155  #region Public Methods and Operators
156 
157  public abstract void BeginScreenDeviceChange(bool willBeFullScreen);
158 
159  public void EndScreenDeviceChange()
160  {
161  EndScreenDeviceChange(ClientBounds.Width, ClientBounds.Height);
162  }
163 
164  public abstract void EndScreenDeviceChange(int clientWidth, int clientHeight);
165 
166  #endregion
167 
168  #region Methods
169 
170  /// <summary>
171  /// Initializes the GameWindow with the specified window context.
172  /// </summary>
173  /// <param name="gameContext">The window context.</param>
174  internal abstract bool CanHandle(GameContext gameContext);
175 
176  internal abstract void Initialize(GameContext gameContext);
177 
178  internal bool Exiting;
179 
180  internal Action InitCallback;
181 
182  internal Action RunCallback;
183 
184  internal Action ExitCallback;
185 
186  internal abstract void Run();
187 
188  internal abstract void Resize(int width, int height);
189 
190  internal IServiceRegistry Services { get; set; }
191 
192  protected internal abstract void SetSupportedOrientations(DisplayOrientation orientations);
193 
194  protected void OnActivated(object source, EventArgs e)
195  {
196  IsActivated = true;
197 
198  EventHandler<EventArgs> handler = Activated;
199  if (handler != null)
200  {
201  handler(source, e);
202  }
203  }
204 
205  protected void OnClientSizeChanged(object source, EventArgs e)
206  {
207  EventHandler<EventArgs> handler = ClientSizeChanged;
208  if (handler != null)
209  {
210  handler(this, e);
211  }
212  }
213 
214  protected void OnDeactivated(object source, EventArgs e)
215  {
216  IsActivated = false;
217 
218  EventHandler<EventArgs> handler = Deactivated;
219  if (handler != null)
220  {
221  handler(source, e);
222  }
223  }
224 
225  protected void OnOrientationChanged(object source, EventArgs e)
226  {
227  EventHandler<EventArgs> handler = OrientationChanged;
228  if (handler != null)
229  {
230  handler(this, e);
231  }
232  }
233 
234  protected abstract void SetTitle(string title);
235 
236  #endregion
237 
238  internal void OnPause()
239  {
240  OnDeactivated(this, EventArgs.Empty);
241  }
242 
243  internal void OnResume()
244  {
245  OnActivated(this, EventArgs.Empty);
246  }
247  }
248 }
HRESULT Resize(_In_ const Image &srcImage, _In_ size_t width, _In_ size_t height, _In_ DWORD filter, _Out_ ScratchImage &image)
EventHandler< EventArgs > Deactivated
Occurs when this window is deactivated.
Definition: GameWindow.cs:65
bool IsActivated
Indicate if the window is currently activated.
Definition: GameWindow.cs:50
A platform specific window handle.
void OnOrientationChanged(object source, EventArgs e)
Definition: GameWindow.cs:225
A service registry is a IServiceProvider that provides methods to register and unregister services...
DisplayOrientation
Describes the orientation of the display.
Base class for a framework component.
void OnActivated(object source, EventArgs e)
Definition: GameWindow.cs:194
EventHandler< EventArgs > OrientationChanged
Occurs, when device orientation is changed.
Definition: GameWindow.cs:70
Represents a three dimensional mathematical vector.
Definition: Int2.cs:41
Contains context used to render the game (Control for WinForm, a DrawingSurface for WP8...
Definition: GameContext.cs:31
EventHandler< EventArgs > Activated
Occurs when this window is activated.
Definition: GameWindow.cs:55
EventHandler< EventArgs > ClientSizeChanged
Occurs, when device client size is changed.
Definition: GameWindow.cs:60
Structure using the same layout than System.Drawing.Rectangle
Definition: Rectangle.cs:35
void OnClientSizeChanged(object source, EventArgs e)
Definition: GameWindow.cs:205
void OnDeactivated(object source, EventArgs e)
Definition: GameWindow.cs:214