protected override void OnSizeAllocated(double width, double height) { var oldWidth = _width; const double sizenotallocated = -1; base.OnSizeAllocated(width, height); if (Equals(_width, width) && Equals(_height, height)) { return; } _width = width; _height = height; // ignore if the previous height was size unallocated if (Equals(oldWidth, sizenotallocated)) { return; } // Has the device been rotated ? if (!Equals(width, oldWidth)) { OnOrientationChanged.Invoke(this, new PageOrientationEventArgs((width < height) ? PageOrientation.Vertical : PageOrientation.Horizontal)); } }
private void ForceNewOrientation(ScreenOrientation orientation) { // Swap resolution Width and Height if changing from Portrait to Landscape or vice versa if ((orientation == ScreenOrientation.Portrait || orientation == ScreenOrientation.PortraitUpsideDown) && IsRenderingLandscape || (orientation == ScreenOrientation.LandscapeLeft || orientation == ScreenOrientation.LandscapeRight) && !IsRenderingLandscape) { var temp = m_CurrentHeight; m_CurrentHeight = m_CurrentWidth; m_CurrentWidth = temp; OnResolutionChanged?.Invoke(m_CurrentWidth, m_CurrentHeight); } m_RenderedOrientation = orientation; OnOrientationChanged?.Invoke(m_AutoRotation); CalculateInsets(); // We only change the resolution if we never set the resolution by calling Screen.SetResolution(). if (!m_WasResolutionSet) { CalculateResolutionWithInsets(out int tempWidth, out int tempHeight); SetResolution(tempWidth, tempHeight); } CalculateSafeAreaAndCutouts(); }
protected override void OnSizeAllocated(double width, double height) { var oldWidth = this.width; const double sizeNotAllocated = -1; base.OnSizeAllocated(width, height); if (Equals(this.width, width) && Equals(this.height, height)) { return; } this.width = width; this.height = height; if (Equals(oldWidth, sizeNotAllocated)) { return; } // Has the device been rotated ? if (!Equals(width, oldWidth)) { OnOrientationChanged.Invoke(this, new PageOrientationEventArgs((width < height) ? PageOrientation.Vertical : PageOrientation.Horizontal)); } }
public void OnSizeAllocated(double width, double height) { double oldWidth = _Width; if (Equals(_Width, width) && Equals(_Height, height)) { return; } _Width = width; _Height = height; // ignore if the previous height was size unallocated if (Equals(oldWidth, SIZE_NOT_ALLOCATED)) { return; } // Has the device been rotated ? if (Equals(width, oldWidth)) { return; } Orientation = (width < height) ? DisplayOrientation.Portrait : DisplayOrientation.Landscape; OnOrientationChanged?.Invoke(this, new PageOrientationEventArgs(Orientation)); }
private void Rotate(Quaternion rotation) { if (m_AutoRotation) { var newOrientation = SimulatorUtilities.RotationToScreenOrientation(rotation); if (m_Screen.orientations.ContainsKey(newOrientation) && m_AllowedAutoRotation[newOrientation]) { ForceNewOrientation(newOrientation); } OnOrientationChanged?.Invoke(m_AutoRotation); } }
private void OnScreenMetricsChanged(object sender, DisplayInfoChangedEventArgs e) { DisplayInfo metrics = e.DisplayInfo; if (!Orientation.Equals(DisplayOrientation.Unknown) && Orientation != metrics.Orientation) { Orientation = metrics.Orientation; OnOrientationChanged.Invoke(this, new PageOrientationEventArgs((Orientation == DisplayOrientation.Portrait) ? PageOrientation.Vertical : PageOrientation.Horizontal, this)); } else { Orientation = metrics.Orientation; } }
private void ForceNewOrientation(ScreenOrientation orientation) { // Swap resolution Width and Height if changing from Portrait to Landscape or vice versa if ((orientation == ScreenOrientation.Portrait || orientation == ScreenOrientation.PortraitUpsideDown) && IsRenderingLandscape || (orientation == ScreenOrientation.LandscapeLeft || orientation == ScreenOrientation.LandscapeRight) && !IsRenderingLandscape) { var temp = m_CurrentHeight; m_CurrentHeight = m_CurrentWidth; m_CurrentWidth = temp; OnResolutionChanged?.Invoke(m_CurrentWidth, m_CurrentHeight); } m_RenderedOrientation = orientation; OnOrientationChanged?.Invoke(m_AutoRotation); CalculateInsets(); CalculateSafeAreaAndCutouts(); }
private void ApplyAutoRotation() { if (!m_AutoRotation) { return; } if (m_DeviceOrientation != m_RenderedOrientation && m_SupportedOrientations.ContainsKey(m_DeviceOrientation) && m_AllowedAutoRotation[m_DeviceOrientation]) { ForceNewOrientation(m_DeviceOrientation); } else { OnOrientationChanged?.Invoke(m_AutoRotation); } }
private void Rotate(Quaternion rotation) { if (!m_AutoRotation) { return; } var newOrientation = SimulatorUtilities.RotationToScreenOrientation(rotation); if (newOrientation != m_RenderedOrientation && m_SupportedOrientations.ContainsKey(newOrientation) && m_AllowedAutoRotation[newOrientation]) { ForceNewOrientation(newOrientation); } else { OnOrientationChanged?.Invoke(m_AutoRotation); } }
protected override void OnSizeAllocated(double width, double height) { base.OnSizeAllocated(width, height); if (firstPageLoad) { DisplayInfo screenMetrics = new DisplayInfo(); if (screenMetrics.Rotation == DisplayRotation.Rotation0 || screenMetrics.Rotation == DisplayRotation.Rotation180 || screenMetrics.Rotation == DisplayRotation.Unknown) { Orientation = DisplayOrientation.Portrait; } else { Orientation = DisplayOrientation.Landscape; } OnOrientationChanged.Invoke(this, new PageOrientationEventArgs((Orientation == DisplayOrientation.Portrait) ? PageOrientation.Vertical : PageOrientation.Horizontal, this)); firstPageLoad = false; } }
private void DeviceOrientationChange(DisplayOrientation orientation) { DeviceOrientantion = orientation; OnOrientationChanged.Invoke(this, new PageOrientationEventArgs(orientation)); }
public void ApplyChanges() { var updateSafeArea = false; var orientationEvent = false; var resolutionEvent = false; var fullScreenEvent = false; var screenSpaceSafeAreaEvent = false; var insetsEvent = false; if (m_RequestedOrientation != m_RenderedOrientation) { if (m_RequestedOrientation.IsLandscape() != m_RenderedOrientation.IsLandscape()) { // Swap resolution Width and Height if changing from Portrait to Landscape or vice versa if (m_WasResolutionSet) { (m_RequestedHeight, m_RequestedWidth) = (m_RequestedWidth, m_RequestedHeight); } else { m_RequestDefaultResolution = true; } } m_RenderedOrientation = m_RequestedOrientation; orientationEvent = true; m_RequestInsetUpdate = true; updateSafeArea = true; } if (m_RequestedFullScreen != m_IsFullScreen) { m_IsFullScreen = m_RequestedFullScreen; m_RequestInsetUpdate = true; // We only change the resolution if we never set the resolution by calling Screen.SetResolution(). if (!m_WasResolutionSet) { m_RequestDefaultResolution = true; } updateSafeArea = true; fullScreenEvent = true; } if (m_RequestInsetUpdate) { CalculateInsets(); insetsEvent = true; } if ((m_RequestedWidth != m_CurrentWidth || m_RequestedHeight != m_CurrentHeight) && m_WasResolutionSet) { m_CurrentWidth = m_RequestedWidth; m_CurrentHeight = m_RequestedHeight; updateSafeArea = true; resolutionEvent = true; } else if (m_RequestDefaultResolution) { CalculateResolutionWithInsets(); updateSafeArea = true; resolutionEvent = true; } if (updateSafeArea) { CalculateSafeAreaAndCutouts(); screenSpaceSafeAreaEvent = true; } if (orientationEvent) { OnOrientationChanged?.Invoke(); } if (resolutionEvent) { OnResolutionChanged?.Invoke(m_CurrentWidth, m_CurrentHeight); } if (fullScreenEvent) { OnFullScreenChanged?.Invoke(m_IsFullScreen); } if (screenSpaceSafeAreaEvent) { OnScreenSpaceSafeAreaChanged?.Invoke(ScreenSpaceSafeArea); } if (insetsEvent) { OnInsetsChanged?.Invoke(Insets); } m_RequestDefaultResolution = false; m_RequestedOrientation = m_RenderedOrientation; m_RequestedHeight = m_CurrentHeight; m_RequestedWidth = m_CurrentWidth; m_RequestInsetUpdate = false; }