private void StartUndoSquishAnimation() { // Build animation to undo squish // _unsquishAnimation = new Storyboard(); DoubleAnimation scaleAnimation = new DoubleAnimation(); _unsquishAnimationTranslation = new DoubleAnimation(); Storyboard.SetTarget(scaleAnimation, _rootTransform); Storyboard.SetTarget(_unsquishAnimationTranslation, _rootTransform); Storyboard.SetTargetProperty(scaleAnimation, new PropertyPath(CompositeTransform.ScaleXProperty)); Storyboard.SetTargetProperty(_unsquishAnimationTranslation, new PropertyPath(CompositeTransform.TranslateXProperty)); scaleAnimation.From = _rootTransform.ScaleX; _unsquishAnimationTranslation.From = _rootTransform.TranslateX; scaleAnimation.To = 1.0; _unsquishAnimationTranslation.To = _dragState.UnsquishTranslationAnimationTarget; scaleAnimation.Duration = new TimeSpan(0, 0, 0, 0, UnsquishAnimationMilliseconds); _unsquishAnimationTranslation.Duration = scaleAnimation.Duration; _unsquishAnimation.Children.Add(scaleAnimation); _unsquishAnimation.Children.Add(_unsquishAnimationTranslation); _unsquishAnimation.FillBehavior = FillBehavior.Stop; _unsquishAnimation.Completed += UnsquishAnimationComplete; _state = FlipperState.UnsquishAnimating; _unsquishAnimation.Begin(); // Go ahead and set the values we're animating to their final values so when the storyboard ends, these will take effect // _rootTransform.ScaleX = scaleAnimation.To.Value; _rootTransform.TranslateX = _unsquishAnimationTranslation.To.Value; }
private void HandleSquishingWhileDragging(double newTranslation) { double translationOfLastItem = -1 * (ItemsSource.Count - 1) * (_size.Value.Width + ItemGutter); double squishDistance = 0; if (newTranslation > 0) { // We're squishing the first item // squishDistance = newTranslation; _dragState.UnsquishTranslationAnimationTarget = 0; _rootCanvas.RenderTransformOrigin = new Point(0, 0); } else if (newTranslation < translationOfLastItem) { // We're squishing the last item // squishDistance = translationOfLastItem - newTranslation; _dragState.UnsquishTranslationAnimationTarget = translationOfLastItem; _rootCanvas.RenderTransformOrigin = new Point(1, 0); } double squishScale = 1.0 - (squishDistance / MaxDraggingSquishDistance) * (1 - MinDraggingSquishScale); // Apply the squish // _rootTransform.ScaleX = squishScale; // Update our state // _state = squishScale == 1.0 ? FlipperState.Dragging : FlipperState.DraggingAndSquishing; }
private void DragStartedEventHandler() { _state = FlipperState.Dragging; _dragState.LastDragUpdateTime = DateTime.Now; _dragState.DragStartingMediaStripOffset = _rootTransform.TranslateX; _dragState.NetDragDistanceSincleLastDragStagnation = 0.0; _dragState.IsDraggingFirstElement = SelectedIndex == 0; _dragState.IsDraggingLastElement = SelectedIndex == ItemsSource.Count - 1; _dragState.GotDragDelta = false; }
private void AnimateToElement(int elementIndex, TimeSpan animationDuration) { double animationEndingValue = -1 * elementIndex * (_size.Value.Width + ItemGutter); ConstructDragInertiaAnimation(animationEndingValue, animationDuration); _state = FlipperState.InertiaAnimating; _dragInertiaAnimation.Begin(); SelectedIndex = elementIndex; }
private void UnsquishAnimationComplete(object sender, EventArgs e) { if (_state == FlipperState.UnsquishAnimating) { _state = FlipperState.Initialized; } _rootTransform.TranslateX = _unsquishAnimationTranslation.To.Value; _unsquishAnimation.Stop(); _unsquishAnimation = null; _unsquishAnimationTranslation = null; }
private void StartDragInertiaAnimation() { TimeSpan lastDragTimeDelta = DateTime.Now - _dragState.LastDragUpdateTime; // Build animation to finish the drag // int elementIndexDelta = CalculateDragInertiaAnimationEndingValue(); TimeSpan animationDuration = CalculateDragInertiaAnimationDuration(lastDragTimeDelta); AnimateToElement(SelectedIndex + elementIndexDelta, animationDuration); _state = FlipperState.InertiaAnimating; }
private void CompleteDragInertiaAnimation() { if (_dragInertiaAnimation != null) { if (_state == FlipperState.InertiaAnimating) { _state = FlipperState.Initialized; } _rootTransform.TranslateX = _dragInertiaAnimationTranslation.To.Value; _dragInertiaAnimation.Stop(); _dragInertiaAnimation = null; _dragInertiaAnimationTranslation = null; } }
protected override void OnManipulationDelta(ManipulationDeltaEventArgs e) { base.OnManipulationDelta(e); if (e.PinchManipulation == null) { bool isZoomed = SelectedIndex >= 0 && _containers[_displayedContainerIndex].IsZoomedIn; if (!isZoomed && _state == FlipperState.Initialized && ItemsSource.Count > 0) { _state = FlipperState.Dragging; DragStartedEventHandler(); } if (_state == FlipperState.Dragging || _state == FlipperState.DraggingAndSquishing) { _dragState.GotDragDelta = true; ProcessDragDelta(e.DeltaManipulation.Translation.X, e.DeltaManipulation.Translation.Y); } } }
private void InitializeIfReady() { if (_state != FlipperState.Uninitialized || _size == null || _rootCanvas == null || ItemTemplate == null || ItemsSource == null) { return; } for (int i = 0; i < VirtualPoolSize; i++) { FrameworkElement root = (FrameworkElement)ItemTemplate.LoadContent(); root.Visibility = Visibility.Collapsed; _containers[i] = new ContentFlipperContent(root, _size.Value); _rootCanvas.Children.Add(root); } _state = FlipperState.Initialized; ResetGeometry(); UpdateVirtualizedItemPositions(); UpdateViewport(); }
/// <summary> /// Allows the game component to perform any initialization it needs to before starting /// to run. This is where it can query for any required services and load content. /// </summary> public override void Initialize() { // TODO: Add your initialization code here flipperTexture = playScene.game1.Content.Load <Texture2D>(flipperTextureName); flipperState = FlipperState.STOP; OK = true; flipperPtTheta = new float[flipperPoints.Count()]; flipperPtRadius = new float[flipperPoints.Count()]; flipperAngle = flipperRestAngle; for (int i = 0; i < flipperPoints.Count(); i++) { flipperPtTheta[i] = (float)Math.Atan2((flipperPoints[i].Y - flipperPivot.Y), (flipperPoints[i].X - flipperPivot.X)); flipperPtRadius[i] = (flipperPoints[i] - flipperPivot).Length(); flipperPoints[i].X = flipperPivot.X + flipperPtRadius[i] * (float)Math.Cos(flipperPtTheta[i] - flipperAngle); flipperPoints[i].Y = flipperPivot.Y + flipperPtRadius[i] * (float)Math.Sin(flipperPtTheta[i] - flipperAngle); } flipperAngularSpeed = 0.09f; flipperAngularSpeed = (float)Math.PI / 25; flipperBounceFactor = 0.9f; flipperLength = flipperPtRadius[1]; base.Initialize(); }
protected override void OnManipulationDelta(ManipulationDeltaEventArgs e) { base.OnManipulationDelta(e); if (e.PinchManipulation == null) { bool isZoomed = SelectedIndex >= 0 && _containers[_displayedContainerIndex].IsZoomedIn; if (!isZoomed && _state == FlipperState.Initialized && ItemsSource.Count > 0) { _state = FlipperState.Dragging; DragStartedEventHandler(); } if (_state == FlipperState.Dragging || _state == FlipperState.DraggingAndSquishing) { _dragState.GotDragDelta = true; ProcessDragDelta(e.DeltaManipulation.Translation.X, e.DeltaManipulation.Translation.Y); } } }
private void DragStartedEventHandler() { _state = FlipperState.Dragging; _dragState.LastDragUpdateTime = DateTime.Now; _dragState.DragStartingMediaStripOffset = _rootTransform.TranslateX; _dragState.NetDragDistanceSincleLastDragStagnation = 0.0; _dragState.IsDraggingFirstElement = SelectedIndex == 0; _dragState.IsDraggingLastElement = SelectedIndex == ItemsSource.Count - 1; _dragState.GotDragDelta = false; }
private void CompleteDragInertiaAnimation() { if (_dragInertiaAnimation != null) { if (_state == FlipperState.InertiaAnimating) { _state = FlipperState.Initialized; } _rootTransform.TranslateX = _dragInertiaAnimationTranslation.To.Value; _dragInertiaAnimation.Stop(); _dragInertiaAnimation = null; _dragInertiaAnimationTranslation = null; } }
private void InitializeIfReady() { if (_state != FlipperState.Uninitialized || _size == null || _rootCanvas == null || ItemTemplate == null || ItemsSource == null) { return; } for (int i = 0; i < VirtualPoolSize; i++) { FrameworkElement root = (FrameworkElement)ItemTemplate.LoadContent(); root.Visibility = Visibility.Collapsed; _containers[i] = new ContentFlipperContent(root, _size.Value); _rootCanvas.Children.Add(root); } _state = FlipperState.Initialized; ResetGeometry(); UpdateVirtualizedItemPositions(); UpdateViewport(); }
private void HandleSquishingWhileDragging(double newTranslation) { double translationOfLastItem = -1 * (ItemsSource.Count - 1) * (_size.Value.Width + ItemGutter); double squishDistance = 0; if (newTranslation > 0) { // We're squishing the first item // squishDistance = newTranslation; _dragState.UnsquishTranslationAnimationTarget = 0; _rootCanvas.RenderTransformOrigin = new Point(0, 0); } else if (newTranslation < translationOfLastItem) { // We're squishing the last item // squishDistance = translationOfLastItem - newTranslation; _dragState.UnsquishTranslationAnimationTarget = translationOfLastItem; _rootCanvas.RenderTransformOrigin = new Point(1, 0); } double squishScale = 1.0 - (squishDistance / MaxDraggingSquishDistance) * (1 - MinDraggingSquishScale); // Apply the squish // _rootTransform.ScaleX = squishScale; // Update our state // _state = squishScale == 1.0 ? FlipperState.Dragging : FlipperState.DraggingAndSquishing; }
private void StartDragInertiaAnimation() { TimeSpan lastDragTimeDelta = DateTime.Now - _dragState.LastDragUpdateTime; // Build animation to finish the drag // int elementIndexDelta = CalculateDragInertiaAnimationEndingValue(); TimeSpan animationDuration = CalculateDragInertiaAnimationDuration(lastDragTimeDelta); AnimateToElement(SelectedIndex + elementIndexDelta, animationDuration); _state = FlipperState.InertiaAnimating; }
private void StartUndoSquishAnimation() { // Build animation to undo squish // _unsquishAnimation = new Storyboard(); DoubleAnimation scaleAnimation = new DoubleAnimation(); _unsquishAnimationTranslation = new DoubleAnimation(); Storyboard.SetTarget(scaleAnimation, _rootTransform); Storyboard.SetTarget(_unsquishAnimationTranslation, _rootTransform); Storyboard.SetTargetProperty(scaleAnimation, new PropertyPath(CompositeTransform.ScaleXProperty)); Storyboard.SetTargetProperty(_unsquishAnimationTranslation, new PropertyPath(CompositeTransform.TranslateXProperty)); scaleAnimation.From = _rootTransform.ScaleX; _unsquishAnimationTranslation.From = _rootTransform.TranslateX; scaleAnimation.To = 1.0; _unsquishAnimationTranslation.To = _dragState.UnsquishTranslationAnimationTarget; scaleAnimation.Duration = new TimeSpan(0, 0, 0, 0, UnsquishAnimationMilliseconds); _unsquishAnimationTranslation.Duration = scaleAnimation.Duration; _unsquishAnimation.Children.Add(scaleAnimation); _unsquishAnimation.Children.Add(_unsquishAnimationTranslation); _unsquishAnimation.FillBehavior = FillBehavior.Stop; _unsquishAnimation.Completed += UnsquishAnimationComplete; _state = FlipperState.UnsquishAnimating; _unsquishAnimation.Begin(); // Go ahead and set the values we're animating to their final values so when the storyboard ends, these will take effect // _rootTransform.ScaleX = scaleAnimation.To.Value; _rootTransform.TranslateX = _unsquishAnimationTranslation.To.Value; }
private void UnsquishAnimationComplete(object sender, EventArgs e) { if (_state == FlipperState.UnsquishAnimating) { _state = FlipperState.Initialized; } _rootTransform.TranslateX = _unsquishAnimationTranslation.To.Value; _unsquishAnimation.Stop(); _unsquishAnimation = null; _unsquishAnimationTranslation = null; }
/// <summary> /// Allows the game component to perform any initialization it needs to before starting /// to run. This is where it can query for any required services and load content. /// </summary> public override void Initialize() { // TODO: Add your initialization code here flipperTexture = playScene.game1.Content.Load<Texture2D>(flipperTextureName); flipperState = FlipperState.STOP; OK = true; flipperPtTheta = new float[flipperPoints.Count()]; flipperPtRadius = new float[flipperPoints.Count()]; flipperAngle = flipperRestAngle; for (int i = 0; i < flipperPoints.Count(); i++) { flipperPtTheta[i] = (float)Math.Atan2((flipperPoints[i].Y - flipperPivot.Y), (flipperPoints[i].X - flipperPivot.X)); flipperPtRadius[i] = (flipperPoints[i] - flipperPivot).Length(); flipperPoints[i].X = flipperPivot.X + flipperPtRadius[i] * (float)Math.Cos(flipperPtTheta[i] - flipperAngle); flipperPoints[i].Y = flipperPivot.Y + flipperPtRadius[i] * (float)Math.Sin(flipperPtTheta[i] - flipperAngle); } flipperAngularSpeed = 0.09f; flipperAngularSpeed = (float)Math.PI / 25; flipperBounceFactor = 0.9f; flipperLength = flipperPtRadius[1]; base.Initialize(); }
private void AnimateToElement(int elementIndex, TimeSpan animationDuration) { double animationEndingValue = -1 * elementIndex * (_size.Value.Width + ItemGutter); ConstructDragInertiaAnimation(animationEndingValue, animationDuration); _state = FlipperState.InertiaAnimating; _dragInertiaAnimation.Begin(); SelectedIndex = elementIndex; }