示例#1
0
        private void OnRendering(object sender, EventArgs eventArgs)
        {
            double dampening        = Dampening;
            double attractionFactor = Attraction * .01;
            double variation        = Variation;

            bool hasChanges = false;

            for (int i = 0; i < InternalChildren.Count; i++)
            {
                ItemAnimationData animationData = GetAnimationData(Children[i]);
                if (animationData != null)
                {
                    attractionFactor *= 1 + (variation * animationData.RandomSeed - .5);
                    Vector currentVelocity = animationData.LocationVelocity;

                    Point  newLocation;
                    Vector newVelocity;

                    Vector diff = animationData.Offset;
                    if (diff.Length > MinimumValueDelta || currentVelocity.Length > MinimumValueDelta)
                    {
                        newVelocity  = currentVelocity * (1 - dampening);
                        newVelocity += diff * attractionFactor;
                        if (currentVelocity.Length > TerminalVelocity)
                        {
                            newVelocity *= TerminalVelocity / currentVelocity.Length;
                        }

                        newLocation = animationData.Current + newVelocity;
                        hasChanges  = true;
                    }
                    else
                    {
                        newLocation = animationData.Target;
                        newVelocity = new Vector();
                    }

                    animationData.Current          = newLocation;
                    animationData.LocationVelocity = newVelocity;

                    Vector transformVector = animationData.Current - animationData.Target;
                    animationData.Transform.X = transformVector.X;
                    animationData.Transform.Y = transformVector.Y;
                }
            }

            // Stop listening if no changes for all elements
            if (!hasChanges)
            {
                renderingListener.StopListening();
            }
        }
示例#2
0
        private void OnRendering(object sender, EventArgs e)
        {
            ActiveTilePanel panel = Child as ActiveTilePanel;

            if (panel == null)
            {
                return;
            }
            if (!ReferenceEquals(tilePanel, panel))
            {
                tilePanel = panel;
                tilePanel.RenderTransform = traslateTransform;
            }

            int actualTargetIndex = Math.Max(0, Math.Min(tilePanel.Children.Count - 1, TargetIndex));

            double targetPercentOffset = -actualTargetIndex / (double)tilePanel.Children.Count;

            targetPercentOffset = targetPercentOffset.IsNaNValue() ? 0 : targetPercentOffset;

            bool stopListening = !Animate(targetPercentOffset);

            double targetPixelOffset = percentOffset * (RenderSize.Width * tilePanel.Children.Count);

            traslateTransform.X = targetPixelOffset;

            if (stopListening)
            {
                listener.StopListening();
            }
        }