24 #if SILICONSTUDIO_PLATFORM_WINDOWS_DESKTOP && SILICONSTUDIO_PARADOX_GRAPHICS_API_DIRECT3D
26 using System.Diagnostics;
28 using System.Threading;
29 using System.Windows.Forms;
31 using SiliconStudio.Core.Mathematics;
32 using SiliconStudio.Paradox.Graphics;
33 using SharpDX.Windows;
36 namespace SiliconStudio.
Paradox.Games
41 internal class GameWindowDesktop : GameWindow
43 private bool isMouseVisible;
45 private bool isMouseCurrentlyHidden;
49 private WindowHandle windowHandle;
53 private bool isFullScreenMaximized;
54 private FormBorderStyle savedFormBorderStyle;
55 private bool oldVisible;
56 private bool deviceChangeChangedVisible;
57 private bool? deviceChangeWillBeFullScreen;
59 private bool allowUserResizing;
60 private bool isBorderLess;
62 internal GameWindowDesktop()
74 public override void BeginScreenDeviceChange(
bool willBeFullScreen)
76 if (willBeFullScreen && !isFullScreenMaximized && form != null)
78 savedFormBorderStyle = form.FormBorderStyle;
81 if (willBeFullScreen != isFullScreenMaximized)
83 deviceChangeChangedVisible =
true;
92 deviceChangeChangedVisible =
false;
95 if (!willBeFullScreen && isFullScreenMaximized && form != null)
98 form.FormBorderStyle = savedFormBorderStyle;
101 deviceChangeWillBeFullScreen = willBeFullScreen;
104 public override void EndScreenDeviceChange(
int clientWidth,
int clientHeight)
106 if (!deviceChangeWillBeFullScreen.HasValue)
109 if (deviceChangeWillBeFullScreen.Value)
111 isFullScreenMaximized =
true;
113 else if (isFullScreenMaximized)
119 isFullScreenMaximized =
false;
124 if (deviceChangeChangedVisible)
129 form.ClientSize =
new Size(clientWidth, clientHeight);
133 var gameForm = form as GameForm;
134 if (gameForm != null)
136 gameForm.IsFullScreen = isFullScreenMaximized;
139 deviceChangeWillBeFullScreen = null;
142 protected internal override void SetSupportedOrientations(
DisplayOrientation orientations)
147 internal override bool CanHandle(GameContext gameContext)
149 return gameContext.ContextType == AppContextType.Desktop;
152 internal override void Initialize(GameContext gameContext)
154 this.GameContext = gameContext;
159 var width = gameContext.RequestedWidth;
162 width =
Control is
Form ? GraphicsDeviceManager.DefaultBackBufferWidth : Control.ClientSize.Width;
165 var height = gameContext.RequestedHeight;
168 height =
Control is
Form ? GraphicsDeviceManager.DefaultBackBufferHeight : Control.ClientSize.Height;
173 Control.ClientSize =
new System.Drawing.Size(width, height);
175 Control.MouseEnter += GameWindowForm_MouseEnter;
176 Control.MouseLeave += GameWindowForm_MouseLeave;
179 var gameForm =
Control as GameForm;
180 if (gameForm != null)
184 gameForm.UserResized += OnClientSizeChanged;
188 Control.Resize += OnClientSizeChanged;
192 internal override void Run()
194 Debug.Assert(InitCallback != null);
195 Debug.Assert(RunCallback != null);
200 if (GameContext.IsUserManagingRun)
202 GameContext.RunCallback = RunCallback;
203 GameContext.ExitCallback = ExitCallback;
207 var runCallback =
new WindowsMessageLoop.RenderCallback(RunCallback);
211 WindowsMessageLoop.Run(
Control, () =>
228 if (ExitCallback != null)
236 private void GameWindowForm_MouseEnter(
object sender,
System.EventArgs e)
238 if (!isMouseVisible && !isMouseCurrentlyHidden)
241 isMouseCurrentlyHidden =
true;
245 private void GameWindowForm_MouseLeave(
object sender,
System.EventArgs e)
247 if (isMouseCurrentlyHidden)
250 isMouseCurrentlyHidden =
false;
254 public override bool IsMouseVisible
258 return isMouseVisible;
262 if (isMouseVisible != value)
264 isMouseVisible = value;
267 if (isMouseCurrentlyHidden)
270 isMouseCurrentlyHidden =
false;
273 else if (!isMouseCurrentlyHidden)
276 isMouseCurrentlyHidden =
true;
290 return Control.Visible;
294 Control.Visible = value;
298 public override Int2 Position
303 return base.Position;
305 return new Int2(Control.Location.X, Control.Location.Y);
310 Control.Location =
new Point(value.X, value.Y);
312 base.Position = value;
316 protected override void SetTitle(
string title)
324 internal override void Resize(
int width,
int height)
326 Control.ClientSize =
new Size(width, height);
329 public override bool AllowUserResizing
333 return allowUserResizing;
339 allowUserResizing = value;
345 public override bool IsBorderLess
353 if (isBorderLess != value)
355 isBorderLess = value;
361 private void UpdateFormBorder()
365 form.MaximizeBox = allowUserResizing;
366 form.FormBorderStyle = isFullScreenMaximized || isBorderLess ? FormBorderStyle.None : allowUserResizing ? FormBorderStyle.Sizable : FormBorderStyle.FixedSingle;
368 if (isFullScreenMaximized)
389 return DisplayOrientation.Default;
393 public override bool IsMinimized
399 return form.WindowState == FormWindowState.Minimized;
407 protected override void Destroy()
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.
Structure using the same layout than System.Drawing.Rectangle
System.Windows.Point Point