3 #if SILICONSTUDIO_PLATFORM_ANDROID
5 using System.Diagnostics;
8 using Android.Views.InputMethods;
9 using SiliconStudio.Core;
10 using SiliconStudio.Paradox.Games.Android;
11 using SiliconStudio.Paradox.Graphics;
13 using OpenTK.Platform.Android;
15 namespace SiliconStudio.
Paradox.Games
20 internal class GameWindowAndroid : GameWindow
22 private AndroidParadoxGameView paradoxGameForm;
23 private WindowHandle nativeWindow;
33 public override void BeginScreenDeviceChange(
bool willBeFullScreen)
38 public override void EndScreenDeviceChange(
int clientWidth,
int clientHeight)
43 protected internal override void SetSupportedOrientations(
DisplayOrientation orientations)
48 internal override bool CanHandle(GameContext gameContext)
50 return gameContext.ContextType == AppContextType.Android;
53 internal override void Initialize(GameContext gameContext)
55 GameContext = gameContext;
57 paradoxGameForm = (AndroidParadoxGameView)gameContext.Control;
58 nativeWindow =
new WindowHandle(
AppContextType.Android, paradoxGameForm);
60 paradoxGameForm.Load += gameForm_Resume;
61 paradoxGameForm.OnPause += gameForm_OnPause;
62 paradoxGameForm.Unload += gameForm_Unload;
63 paradoxGameForm.RenderFrame += gameForm_RenderFrame;
66 var width = gameContext.RequestedWidth;
69 width = paradoxGameForm.Width;
72 var height = gameContext.RequestedHeight;
75 height = paradoxGameForm.Height;
79 paradoxGameForm.RequestedBackBufferFormat = gameContext.RequestedBackBufferFormat;
80 paradoxGameForm.RequestedDepthStencilFormat = gameContext.RequestedDepthStencilFormat;
82 paradoxGameForm.Size =
new Size(width, height);
87 void gameForm_Resume(
object sender,
EventArgs e)
90 if (InitCallback != null)
95 paradoxGameForm.Run();
100 void gameForm_OnPause(
object sender,
EventArgs e)
103 var inputMethodManager = (InputMethodManager)PlatformAndroid.Context.GetSystemService(Context.InputMethodService);
104 inputMethodManager.HideSoftInputFromWindow(GameContext.Control.RootView.WindowToken, HideSoftInputFlags.None);
107 void gameForm_Unload(
object sender,
EventArgs e)
112 void gameForm_RenderFrame(
object sender, OpenTK.FrameEventArgs e)
117 internal override void Run()
119 Debug.Assert(InitCallback != null);
120 Debug.Assert(RunCallback != null);
122 if (paradoxGameForm.GraphicsContext != null)
124 throw new NotImplementedException(
"Only supports not yet initialized AndroidGameView.");
136 return paradoxGameForm.Visible;
140 paradoxGameForm.Visible = value;
144 protected override void SetTitle(
string title)
146 paradoxGameForm.Title = title;
149 internal override void Resize(
int width,
int height)
151 paradoxGameForm.Size =
new Size(width, height);
154 public override bool IsBorderLess
165 public override bool AllowUserResizing
180 return new Rectangle(0, 0, paradoxGameForm.Size.Width, paradoxGameForm.Size.Height);
188 return DisplayOrientation.Default;
192 public override bool IsMinimized
196 return paradoxGameForm.WindowState == OpenTK.WindowState.Minimized;
200 public override bool IsMouseVisible
202 get {
return false; }
206 protected override void Destroy()
208 if (paradoxGameForm != null)
210 paradoxGameForm.Load -= gameForm_Resume;
211 paradoxGameForm.OnPause -= gameForm_OnPause;
212 paradoxGameForm.Unload -= gameForm_Unload;
213 paradoxGameForm.RenderFrame -= gameForm_RenderFrame;
215 paradoxGameForm.GraphicsContext.MakeCurrent(null);
216 paradoxGameForm.GraphicsContext.Dispose();
217 ((AndroidWindow)paradoxGameForm.WindowInfo).TerminateDisplay();
219 paradoxGameForm.Holder.RemoveCallback(paradoxGameForm);
220 paradoxGameForm.Dispose();
221 paradoxGameForm = null;
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