23 #if SILICONSTUDIO_PLATFORM_WINDOWS_RUNTIME
26 using SiliconStudio.Paradox.Graphics;
27 using SiliconStudio.Core.Mathematics;
28 using Windows.UI.ViewManagement;
29 using Windows.UI.Xaml;
30 using Windows.UI.Xaml.Controls;
31 using Windows.UI.Xaml.Media;
33 namespace SiliconStudio.
Paradox.Games
38 internal class GameWindowWindowsRuntimeSwapChainPanel : GameWindow
42 private SwapChainPanel swapChainPanel;
43 private WindowHandle windowHandle;
44 private int currentWidth;
45 private int currentHeight;
49 #region Public Properties
51 public override bool AllowUserResizing
66 return new Rectangle(0, 0, (
int)(this.swapChainPanel.ActualWidth * swapChainPanel.CompositionScaleX + 0.5f), (
int)(
this.swapChainPanel.ActualHeight * swapChainPanel.CompositionScaleY + 0.5f));
74 return DisplayOrientation.Default;
78 public override bool IsMinimized
86 public override bool IsMouseVisible {
get; set; }
112 public override bool IsBorderLess
125 #region Public Methods and Operators
127 public override void BeginScreenDeviceChange(
bool willBeFullScreen)
131 public override void EndScreenDeviceChange(
int clientWidth,
int clientHeight)
139 internal override bool CanHandle(GameContext windowContext)
141 return windowContext.ContextType == AppContextType.WindowsRuntime;
144 internal override void Initialize(GameContext windowContext)
146 if (windowContext != null)
148 swapChainPanel = windowContext.Control as SwapChainPanel;
149 if (swapChainPanel == null)
151 throw new NotSupportedException(
string.Format(
"Unsupported window context [{0}]. Only SwapChainPanel", windowContext.Control.GetType().FullName));
153 windowHandle =
new WindowHandle(
AppContextType.WindowsRuntime, swapChainPanel);
156 swapChainPanel.SizeChanged += swapChainPanel_SizeChanged;
157 swapChainPanel.CompositionScaleChanged += swapChainPanel_CompositionScaleChanged;
161 void swapChainPanel_CompositionScaleChanged(SwapChainPanel sender,
object args)
163 OnClientSizeChanged(sender,
EventArgs.Empty);
166 private void swapChainPanel_SizeChanged(
object sender, SizeChangedEventArgs e)
168 var bounds = e.NewSize;
172 var effectiveOrientation = bounds.Width > bounds.Height ? ApplicationViewOrientation.Landscape : ApplicationViewOrientation.Portrait;
173 var currentOrientation = ApplicationView.GetForCurrentView().
Orientation;
174 if (effectiveOrientation == currentOrientation
175 && bounds.Width > 0 && bounds.Height > 0 && currentWidth > 0 && currentHeight > 0)
179 panelWidth = bounds.Width;
180 panelHeight = bounds.Height;
181 var panelRatio = panelWidth/panelHeight;
182 var currentRatio = currentWidth/currentHeight;
184 if (panelRatio < currentRatio)
186 panelWidth = bounds.Width;
187 panelHeight = (int)(currentHeight*bounds.Width/currentWidth);
191 panelHeight = bounds.Height;
192 panelWidth = (int)(currentWidth*bounds.Height/currentHeight);
195 if (swapChainPanel.Width != panelWidth || swapChainPanel.Height != panelHeight)
198 swapChainPanel.HorizontalAlignment = HorizontalAlignment.Center;
199 swapChainPanel.VerticalAlignment = VerticalAlignment.Center;
201 swapChainPanel.Width = panelWidth;
202 swapChainPanel.Height = panelHeight;
206 OnClientSizeChanged(sender,
EventArgs.Empty);
209 internal override void Resize(
int width,
int height)
211 currentWidth = width;
212 currentHeight = height;
215 internal override void Run()
221 CompositionTarget.Rendering += CompositionTarget_Rendering;
224 void CompositionTarget_Rendering(
object sender,
object e)
229 protected internal override void SetSupportedOrientations(
DisplayOrientation orientations)
234 protected override void SetTitle(
string title)
239 protected override void Destroy()
241 CompositionTarget.Rendering -= CompositionTarget_Rendering;
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
Android.Widget.Orientation Orientation