public void ResetScreen() { double oldZoom = Zoom; Vector oldOffset = Offset; Zoom = 1; CenterView(); AnimationTimeline anim = new DoubleAnimation { From = oldZoom, To = Zoom, Duration = TimeSpan.FromMilliseconds(150), FillBehavior = FillBehavior.Stop }; BeginAnimation(ZoomProperty, anim); anim = new VectorAnimation { From = oldOffset, To = Offset, Duration = TimeSpan.FromMilliseconds(150), FillBehavior = FillBehavior.Stop }; BeginAnimation(OffsetProperty, anim); }
protected void RefitScreen() { var cards = Program.GameEngine.Table.Cards; if (cards.Count > 0) { Rect newBounds = Rect.Empty; foreach (var c in cards) { var cardRect = new Rect(c.X, c.Y, c.RealWidth, c.RealHeight); if (newBounds.IsEmpty) { newBounds = cardRect; } else { newBounds.Union(cardRect); } } if (Player.LocalPlayer.InvertedTable) { newBounds.X = -newBounds.Right; newBounds.Y = -newBounds.Bottom; } double newZoom = Math.Min( (Program.GameEngine.Table.Definition.Width + 2 * _stretchMargins.Width) / newBounds.Width, (Program.GameEngine.Table.Definition.Height + 2 * _stretchMargins.Height) / newBounds.Height); var newOffset = new Vector( -_stretchMargins.Width - newBounds.X * newZoom, -_stretchMargins.Height - newBounds.Y * newZoom); double oldZoom = Zoom; Vector oldOffset = Offset; Zoom = newZoom; Offset = newOffset; AnimationTimeline anim = new DoubleAnimation { From = oldZoom, To = newZoom, Duration = TimeSpan.FromMilliseconds(150), FillBehavior = FillBehavior.Stop }; BeginAnimation(ZoomProperty, anim); anim = new VectorAnimation { From = oldOffset, To = newOffset, Duration = TimeSpan.FromMilliseconds(150), FillBehavior = FillBehavior.Stop }; BeginAnimation(OffsetProperty, anim); } }
public CameraTrackingSwitcher() { MarkerTracker = new ArMarkerCamTracker(); VrTracker = new DelayedVrCamTracker(); OptitrackTracker = new OptitrackCamTracker(); CurrentMode = TrackingMode.Optitrack; _positionAnimation = new VectorAnimation(SwitchTransitionSpeed); _rotationAnimation = new QuaternionAnimation(SwitchTransitionSpeed); _positionAnimation.Finished += AnimationFinished; _rotationAnimation.Finished += AnimationFinished; }
public static AnimationClock AnimateElementVector(DependencyObject element, DependencyProperty property, Vector targetValue, double fromTime, double toTime, IEasingFunction ease = null) { if (!(element is IAnimatable)) { throw new InvalidOperationException("Element must be IAnimatable."); } StopAnimation(element, property); if (ease == null) { ease = new CircleEase(); } Vector initialValue = (Vector)element.GetValue(property); VectorAnimation anim = new VectorAnimation(initialValue, targetValue, new Duration(TimeSpan.FromSeconds(toTime - fromTime))); anim.EasingFunction = ease; //VectorAnimationUsingKeyFrames anim = new VectorAnimationUsingKeyFrames(); //anim.KeyFrames.Add(new SplineVectorKeyFrame(initialValue, // KeyTime.FromTimeSpan(TimeSpan.FromSeconds(fromTime)))); //anim.KeyFrames.Add(new SplineVectorKeyFrame(targetValue, // KeyTime.FromTimeSpan(TimeSpan.FromSeconds(toTime)) // , new KeySpline(0.0, 0, 0.05, 1)) // ); if (fromTime > 0.0) { return(AnimateElementDelayHelper(element, property, anim, fromTime)); } else { return(AnimateElementHelper(element, property, anim)); } }
protected void BringCardIntoView(Card card) { // Get the current target viewport (bypass animations in progress) GeneralTransform transform = TransformToDescendant(cardsView); Rect visibleBounds = transform.TransformBounds(new Rect(0, 0, ActualWidth, ActualHeight)); var cardRect = new Rect(card.X, card.Y, Program.GameEngine.Definition.CardWidth, Program.GameEngine.Definition.CardHeight); if (visibleBounds.Contains(cardRect)) { return; // okay, already completely into view } // Compute the new table bounds Rect newBounds = visibleBounds; if (cardRect.Left < visibleBounds.Left) { newBounds.X = cardRect.Left; } newBounds.Width = Math.Max(visibleBounds.Right, cardRect.Right) - newBounds.Left; if (cardRect.Top < visibleBounds.Top) { newBounds.Y = cardRect.Top; } newBounds.Height = Math.Max(visibleBounds.Bottom, cardRect.Bottom) - newBounds.Top; if (Player.LocalPlayer.InvertedTable) { // Transform the viewport so that it will fit correctly after the invert transform is applied newBounds.X = -newBounds.Right; newBounds.Y = -newBounds.Bottom; } // Compute the zoom and offset corresponding to the new view double newZoom = Math.Min( (Program.GameEngine.Table.Definition.Width + 2 * _stretchMargins.Width) / newBounds.Width, (Program.GameEngine.Table.Definition.Height + 2 * _stretchMargins.Height) / newBounds.Height); var newOffset = new Vector( -_stretchMargins.Width - newBounds.X * newZoom, -_stretchMargins.Height - newBounds.Y * newZoom); // Combine new values with the current ones // (bypassing animations, e.g. when moving several cards outside the bounds at the same time var realZoom = (double)GetAnimationBaseValue(ZoomProperty); //var realOffset = (Vector)GetAnimationBaseValue(OffsetProperty); if (newZoom > realZoom) { newZoom = realZoom; } //if (newOffset.X < realOffset.X) newOffset.X = realOffset.X; //if (newOffset.Y < realOffset.Y) newOffset.Y = realOffset.Y; double oldZoom = Zoom; Vector oldOffset = Offset; Zoom = newZoom; Offset = newOffset; // Animate the table with the result AnimationTimeline anim = new DoubleAnimation { From = oldZoom, To = newZoom, Duration = TimeSpan.FromMilliseconds(150), FillBehavior = FillBehavior.Stop }; BeginAnimation(ZoomProperty, anim); anim = new VectorAnimation { From = oldOffset, To = newOffset, Duration = TimeSpan.FromMilliseconds(150), FillBehavior = FillBehavior.Stop }; BeginAnimation(OffsetProperty, anim); // Note: the new visibleBounds may end up bigger than newBounds, // because the window aspect ratio may be different }
public OffsetAnimationActuator(IScrollableUIElement scrollableUIElement, VectorAnimation animation) { _scrollableUIElement = scrollableUIElement; _doubleAnimation = animation ?? throw new ArgumentNullException(nameof(animation)); }