void UpdateOrientation() { int newIndex = ClosestOrientation(cameraTransform.up, -cameraTransform.right); PhoneOrientation o = allOrientations[newIndex]; float dot = dots[newIndex]; if (o != currentOrientation && dot > dotRequiredToSwitch) { currentOrientation = o; currentIndex = newIndex; Debug.Log("New orientation detected: " + currentOrientation); if (managedTransforms.Length > 0) { rotateStartTime = Time.time; startRotation = managedTransforms[0].localRotation; targetRotation = rotations[newIndex]; if (rotationHappening) { // we updated the currently running co-routine, no need to start a new one } else { StartCoroutine(RotateTransforms()); } } } }
public static void IsVisible(this RectangleF position, PhoneOrientation orientation) { if (position.IsEmpty) { throw new ArgumentOutOfRangeException("IsVisible position is Empty"); } var height = 0.0; var width = 0.0; switch (orientation) { case PhoneOrientation.Landscape800By480: height = 480.0; width = 800.0; break; case PhoneOrientation.Portrait480By800: height = 800.0; width = 480.0; break; default: throw new ArgumentException("unknown orientation " + orientation); } if (position.X + position.Width <= 0) { throw new ArgumentOutOfRangeException("bottom", string.Format( "IsVisible position.X ({0}) + position.Width ({1}) <= 0 ", position.X, position.Width)); } if (position.Y + position.Height <= 0) { throw new ArgumentOutOfRangeException("right", string.Format( "IsVisible position.Y ({0}) + position.Height ({1}) <= 0 ", position.Y, position.Height)); } if (position.X >= width) { throw new ArgumentOutOfRangeException("left", string.Format("IsVisible position.X ({0}) > width ({1})", position.X, width)); } if (position.Y >= height) { throw new ArgumentOutOfRangeException("top", string.Format("IsVisible position.Y ({0}) > height ({1})", position.Y, height)); } }
public static Size ScreenSize(this PhoneOrientation orientation) { switch (orientation) { case PhoneOrientation.Landscape800By480: return(new Size(800, 480)); case PhoneOrientation.Portrait480By800: return(new Size(480, 800)); default: throw new ArgumentException("unknown orientation " + orientation); } }
//***************************************************************************************** //***************************************************************************************** // Prototype : protected override void OnOrientationChanged ( // OrientationChangedEventArgs Args ) // Description : Appelé après la modification de la propriété Orientation //***************************************************************************************** /// <summary> /// Appelé après la modification de la propriété Orientation. /// </summary> /// <param name="Args">Arguments d'événement.</param> //----------------------------------------------------------------------------------------- public void OnOrientationChanged(PhoneOrientation Value) { //------------------------------------------------------------------------------------- double ButtonCount = 3; double ScreenWidth = 480; if (Value == PhoneOrientation.Portrait) { //--------------------------------------------------------------------------------- ButtonCount = 3; ScreenWidth = Application.Current.Host.Content.ActualWidth; //--------------------------------------------------------------------------------- } //------------------------------------------------------------------------------------- else { //--------------------------------------------------------------------------------- ButtonCount = 5; //--------------------------------------------------------------------------------- //--------------------------------------------------------------------------------- #if WP80 //--------------------------------------------------------------------------------- ScreenWidth = Application.Current.Host.Content.ActualHeight - DeviceInfos.ApplicationBarHeight; //--------------------------------------------------------------------------------- #endif //--------------------------------------------------------------------------------- //--------------------------------------------------------------------------------- #if WP81 //--------------------------------------------------------------------------------- ScreenWidth = Application.Current.Host.Content.ActualHeight - DeviceInfos.ApplicationBarHeight * 2; //--------------------------------------------------------------------------------- #endif //--------------------------------------------------------------------------------- } //------------------------------------------------------------------------------------- //------------------------------------------------------------------------------------- double ItemWidth = (ScreenWidth - (4 * (ButtonCount + 1))) / ButtonCount; foreach (FrameworkElement Child in this.Layout.Children) { Child.Width = ItemWidth; } //------------------------------------------------------------------------------------- }
public static void IsVisible(this RectangleF position, PhoneOrientation orientation) { if (position.IsEmpty) { throw new ArgumentOutOfRangeException("IsVisible position is Empty"); } var height = 0.0; var width = 0.0; switch (orientation) { case PhoneOrientation.Landscape800By480: height = 480.0; width = 800.0; break; case PhoneOrientation.Portrait480By800: height = 800.0; width = 480.0; break; default: throw new ArgumentException("unknown orientation " + orientation); } if (position.X + position.Width <= 0) throw new ArgumentOutOfRangeException("bottom", string.Format( "IsVisible position.X ({0}) + position.Width ({1}) <= 0 ", position.X, position.Width)); if (position.Y + position.Height <= 0) throw new ArgumentOutOfRangeException("right", string.Format( "IsVisible position.Y ({0}) + position.Height ({1}) <= 0 ", position.Y, position.Height)); if (position.X >= width) throw new ArgumentOutOfRangeException("left", string.Format("IsVisible position.X ({0}) > width ({1})", position.X, width)); if (position.Y >= height) throw new ArgumentOutOfRangeException("top", string.Format("IsVisible position.Y ({0}) > height ({1})", position.Y, height)); }
public static bool IsVisible(this RectangleF position, PhoneOrientation orientation) { if (position.IsEmpty) return false; var height = 0.0; var width = 0.0; switch (orientation) { case PhoneOrientation.Landscape800By480: height = 480.0; width = 800.0; break; case PhoneOrientation.Portrait480By800: height = 800.0; width = 480.0; break; default: throw new ArgumentException("unknown orientation " + orientation); } if (position.X + position.Width <= 0) return false; if (position.Y + position.Height <= 0) return false; if (position.X >= width) return false; if (position.Y >= height) return false; return true; }
public static Point ScreenMiddle(this PhoneOrientation orientation) { var size = orientation.ScreenSize(); return(new Point(size.Width / 2, size.Height / 2)); }