Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
GameWindowiOS.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 #if SILICONSTUDIO_PLATFORM_IOS
4 using System;
5 using System.Diagnostics;
6 using System.Drawing;
7 using OpenTK.Platform.iPhoneOS;
8 using SiliconStudio.Paradox.Graphics;
10 
11 namespace SiliconStudio.Paradox.Games
12 {
13  /// <summary>
14  /// An abstract window.
15  /// </summary>
16  internal class GameWindowiOS : GameWindow
17  {
18  private bool hasBeenInitialized;
19  private iPhoneOSGameView gameForm;
20  private WindowHandle nativeWindow;
21 
22  public override WindowHandle NativeWindow
23  {
24  get
25  {
26  return nativeWindow;
27  }
28  }
29 
30  public override void BeginScreenDeviceChange(bool willBeFullScreen)
31  {
32 
33  }
34 
35  public override void EndScreenDeviceChange(int clientWidth, int clientHeight)
36  {
37 
38  }
39 
40  protected internal override void SetSupportedOrientations(DisplayOrientation orientations)
41  {
42  // Desktop doesn't have orientation (unless on Windows 8?)
43  }
44 
45  internal override bool CanHandle(GameContext gameContext)
46  {
47  return gameContext.ContextType == AppContextType.iOS;
48  }
49 
50  internal override void Initialize(GameContext gameContext)
51  {
52  GameContext = gameContext;
53 
54  gameForm = gameContext.GameView;
55  nativeWindow = new WindowHandle(AppContextType.iOS, gameForm);
56 
57  gameForm.Load += gameForm_Load;
58  gameForm.Unload += gameForm_Unload;
59  gameForm.RenderFrame += gameForm_RenderFrame;
60 
61  gameForm.ContextRenderingApi = MonoTouch.OpenGLES.EAGLRenderingAPI.OpenGLES2;
62  gameForm.LayerColorFormat = MonoTouch.OpenGLES.EAGLColorFormat.RGBA8;
63  //gameForm.LayerRetainsBacking = false;
64 
65  // Setup the initial size of the window
66  var width = gameContext.RequestedWidth;
67  if (width == 0)
68  {
69  width = (int)(gameForm.Size.Width * gameForm.ContentScaleFactor);
70  }
71 
72  var height = gameContext.RequestedHeight;
73  if (height == 0)
74  {
75  height = (int)(gameForm.Size.Height * gameForm.ContentScaleFactor);
76  }
77 
78  gameForm.Size = new Size(width, height);
79 
80  //gameForm.Resize += OnClientSizeChanged;
81  }
82 
83  void gameForm_Load(object sender, EventArgs e)
84  {
85  hasBeenInitialized = false;
86  }
87 
88  void gameForm_Unload(object sender, EventArgs e)
89  {
90  if (hasBeenInitialized)
91  {
92  OnPause();
93  hasBeenInitialized = false;
94  }
95  }
96 
97  void gameForm_RenderFrame(object sender, OpenTK.FrameEventArgs e)
98  {
99  if (InitCallback != null)
100  {
101  InitCallback();
102  InitCallback = null;
103  }
104 
105  RunCallback();
106 
107  if (!hasBeenInitialized)
108  {
109  OnResume();
110  hasBeenInitialized = true;
111  }
112  }
113 
114  internal override void Run()
115  {
116  Debug.Assert(InitCallback != null);
117  Debug.Assert(RunCallback != null);
118 
119  if (gameForm.GraphicsContext != null)
120  {
121  throw new NotImplementedException("Only supports not yet initialized iPhoneOSGameView.");
122  }
123 
124  var view = gameForm as IAnimatedGameView;
125  if (view != null)
126  {
127  view.StartAnimating();
128  }
129  else
130  {
131  gameForm.Run();
132  }
133  }
134 
135  /// <summary>
136  /// Gets or sets a value indicating whether this <see cref="GameWindow" /> is visible.
137  /// </summary>
138  /// <value><c>true</c> if visible; otherwise, <c>false</c>.</value>
139  public override bool Visible
140  {
141  get
142  {
143  return gameForm.Visible;
144  }
145  set
146  {
147  gameForm.Visible = value;
148  }
149  }
150 
151  protected override void SetTitle(string title)
152  {
153  gameForm.Title = title;
154  }
155 
156  internal override void Resize(int width, int height)
157  {
158  gameForm.Size = new Size(width, height);
159  }
160 
161  public override bool IsBorderLess
162  {
163  get
164  {
165  return true;
166  }
167  set
168  {
169  }
170  }
171 
172  public override bool AllowUserResizing
173  {
174  get
175  {
176  return true;
177  }
178  set
179  {
180  }
181  }
182 
183  public override Rectangle ClientBounds
184  {
185  get
186  {
187  return new Rectangle(0, 0, (int)(gameForm.Size.Width * gameForm.ContentScaleFactor), (int)(gameForm.Size.Height * gameForm.ContentScaleFactor));
188  }
189  }
190 
191  public override DisplayOrientation CurrentOrientation
192  {
193  get
194  {
195  return DisplayOrientation.Default;
196  }
197  }
198 
199  public override bool IsMinimized
200  {
201  get
202  {
203  return gameForm.WindowState == OpenTK.WindowState.Minimized;
204  }
205  }
206 
207  public override bool IsMouseVisible
208  {
209  get { return false; }
210  set {}
211  }
212 
213  protected override void Destroy()
214  {
215  if (gameForm != null)
216  {
217  GraphicsDevice.UnbindGraphicsContext(gameForm.GraphicsContext);
218 
219  var view = gameForm as IAnimatedGameView;
220  if (view != null)
221  {
222  view.StopAnimating();
223  gameForm.Close();
224  }
225  else
226  {
227  gameForm.Close();
228  gameForm.Dispose();
229  }
230 
231  gameForm = null;
232  }
233 
234  base.Destroy();
235  }
236  }
237 }
238 #endif
AppContextType
Type of a GameContext.
HRESULT Resize(_In_ const Image &srcImage, _In_ size_t width, _In_ size_t height, _In_ DWORD filter, _Out_ ScratchImage &image)
ComponentBase.Destroy() event.
DisplayOrientation
Describes the orientation of the display.
System.Windows.Shapes.Rectangle Rectangle
Definition: ColorPicker.cs:16