3 #if SILICONSTUDIO_PLATFORM_WINDOWS_DESKTOP && SILICONSTUDIO_PARADOX_GRAPHICS_API_OPENGL
5 using System.Diagnostics;
6 using System.Threading;
7 using System.Windows.Forms;
9 using SiliconStudio.Core.Mathematics;
10 using SiliconStudio.Paradox.Graphics;
12 namespace SiliconStudio.
Paradox.Games
17 internal class GameWindowOpenTK : GameWindow
19 private bool isMouseVisible;
21 private bool isMouseCurrentlyHidden;
23 private OpenTK.GameWindow gameForm;
24 private WindowHandle nativeWindow;
26 internal GameWindowOpenTK()
38 public override Int2 Position
45 return new Int2(gameForm.X, gameForm.Y);
55 base.Position = value;
59 public override void BeginScreenDeviceChange(
bool willBeFullScreen)
64 public override void EndScreenDeviceChange(
int clientWidth,
int clientHeight)
69 protected internal override void SetSupportedOrientations(
DisplayOrientation orientations)
74 internal override bool CanHandle(GameContext gameContext)
76 return gameContext.ContextType == AppContextType.DesktopOpenTK;
79 internal override void Initialize(GameContext gameContext)
81 this.GameContext = gameContext;
83 gameForm = (OpenTK.GameWindow)gameContext.Control;
84 nativeWindow =
new WindowHandle(
AppContextType.DesktopOpenTK, gameForm);
87 var width = gameContext.RequestedWidth;
90 width = gameForm.Width;
93 var height = gameContext.RequestedHeight;
96 height = gameForm.Height;
99 gameForm.ClientSize =
new System.Drawing.Size(width, height);
101 gameForm.MouseEnter += GameWindowForm_MouseEnter;
102 gameForm.MouseLeave += GameWindowForm_MouseLeave;
104 gameForm.Resize += OnClientSizeChanged;
107 internal override void Run()
109 Debug.Assert(InitCallback != null);
110 Debug.Assert(RunCallback != null);
116 gameForm.Visible =
true;
123 gameForm.ProcessEvents();
128 if (gameForm != null)
130 if (OpenTK.Graphics.GraphicsContext.CurrentContext == gameForm.Context)
131 gameForm.Context.MakeCurrent(null);
139 if (ExitCallback != null)
146 private void GameWindowForm_MouseEnter(
object sender,
System.EventArgs e)
148 if (!isMouseVisible && !isMouseCurrentlyHidden)
151 isMouseCurrentlyHidden =
true;
155 private void GameWindowForm_MouseLeave(
object sender,
System.EventArgs e)
157 if (isMouseCurrentlyHidden)
160 isMouseCurrentlyHidden =
false;
164 public override bool IsMouseVisible
168 return isMouseVisible;
172 if (isMouseVisible != value)
174 isMouseVisible = value;
177 if (isMouseCurrentlyHidden)
180 isMouseCurrentlyHidden =
false;
183 else if (!isMouseCurrentlyHidden)
186 isMouseCurrentlyHidden =
true;
200 return gameForm.Visible;
204 gameForm.Visible = value;
208 protected override void SetTitle(
string title)
210 gameForm.Title = title;
213 internal override void Resize(
int width,
int height)
215 gameForm.ClientSize =
new System.Drawing.Size(width, height);
218 public override bool IsBorderLess
229 public override bool AllowUserResizing
244 return new Rectangle(0, 0, gameForm.ClientSize.Width, gameForm.ClientSize.Height);
252 return DisplayOrientation.Default;
256 public override bool IsMinimized
260 return gameForm.WindowState == OpenTK.WindowState.Minimized;
264 protected override void Destroy()
266 if (gameForm != null)
268 gameForm.Context.MakeCurrent(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