예제 #1
0
        private static void RTSkewYAnimation(FrameworkElement Item, DoubleAnimation Ani, Action OnCompleted, SetExtentAnimationTimelineDelegate SetExtentValue)
        {
            SkewTransform Transform = CuxAnimation1.GetRTInstance <SkewTransform>(Item);

            if (Transform != null)
            {
                if (SetExtentValue != null)
                {
                    SetExtentValue(Ani);
                }
                Ani.Completed += new EventHandler(
                    delegate(object sender, EventArgs e)
                {
                    if (!Ani.AutoReverse)
                    {
                        Transform.AngleY = Ani.To.Value;
                        if (OnCompleted != null && Transform.AngleY == Ani.To.Value)
                        {
                            OnCompleted();
                        }
                    }
                    else
                    {
                        if (OnCompleted != null)
                        {
                            OnCompleted();
                        }
                    }
                });
                Transform.BeginAnimation(SkewTransform.AngleYProperty, Ani);
            }
        }
예제 #2
0
        //Skew Animation
        private void skew(Node Snow)
        {
            DoubleAnimation skewA = new DoubleAnimation(0, 180, new TimeSpan(0, 0, 0, 0, 3000));
            DoubleAnimation skewB = new DoubleAnimation(0, 180, new TimeSpan(0, 0, 0, 0, 3000));

            skewA.AutoReverse    = true;
            skewA.RepeatBehavior = RepeatBehavior.Forever;
            TransformGroup tg  = new TransformGroup();
            SkewTransform  xst = new SkewTransform();

            xst.CenterX = 25;
            xst.CenterY = 25;
            SkewTransform yst = new SkewTransform();

            yst.CenterX = 25;
            yst.CenterY = 25;

            tg.Children.Add(xst);
            tg.Children.Add(yst);

            Snow.AllowResize     = false;
            Snow.RenderTransform = tg;
            xst.BeginAnimation(SkewTransform.AngleXProperty, skewA);
            yst.BeginAnimation(SkewTransform.AngleYProperty, skewB);
        }
예제 #3
0
        private void Cloud1_Loaded(object sender, RoutedEventArgs e)
        {
            DoubleAnimation da2 = new DoubleAnimation();
            DoubleAnimation da1 = new DoubleAnimation();

            da1.To = -35;
            da2.To = -5;

            da1.Duration       = new Duration(TimeSpan.FromSeconds(30));
            da1.RepeatBehavior = RepeatBehavior.Forever;
            da2.Duration       = new Duration(TimeSpan.FromSeconds(30));
            da2.RepeatBehavior = RepeatBehavior.Forever;
            SkewTransform rt = new SkewTransform();

            Cloud1.RenderTransform = rt;
            rt.BeginAnimation(SkewTransform.AngleXProperty, da1);
            rt.BeginAnimation(SkewTransform.AngleYProperty, da2);
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            /*
             * var skewGrass = new DoubleAnimation
             * {
             *  From = -15.0f,
             *  To = 0.0f,
             *  Duration = new Duration(TimeSpan.FromMilliseconds(2000)),
             *  //RepeatBehavior = RepeatBehavior.,
             *  //EasingFunction = new BackEase(),
             *  //AutoReverse = true
             * };
             */

            DoubleAnimation skewGrassX;
            DoubleAnimation skewGrassY;
            DoubleAnimation rotate;

            if ((explorerGrid.Tag == null) || (explorerGrid.Tag == "0"))
            {
                skewGrassX       = new DoubleAnimation(-15.0f, 0.0f, new Duration(TimeSpan.FromMilliseconds(2000)));
                skewGrassY       = new DoubleAnimation(-10.0f, 0.0f, new Duration(TimeSpan.FromMilliseconds(2000)));
                rotate           = new DoubleAnimation(17.0f, 0.0f, new Duration(TimeSpan.FromMilliseconds(2000)));
                explorerGrid.Tag = "1";
            }
            else
            {
                skewGrassX       = new DoubleAnimation(-15.0f, new Duration(TimeSpan.FromMilliseconds(2000)));
                skewGrassY       = new DoubleAnimation(-10.0f, new Duration(TimeSpan.FromMilliseconds(2000)));
                rotate           = new DoubleAnimation(17.0f, new Duration(TimeSpan.FromMilliseconds(2000)));
                explorerGrid.Tag = "0";
            }


            SkewTransform   skewTransformX  = new SkewTransform();
            SkewTransform   skewTransformY  = new SkewTransform();
            RotateTransform rotateTransform = new RotateTransform();

            TransformGroup transformGroup = new TransformGroup();

            transformGroup.Children.Add(skewTransformX);
            transformGroup.Children.Add(skewTransformY);
            transformGroup.Children.Add(rotateTransform);

            explorerGrid.LayoutTransform = transformGroup;

            skewTransformX.BeginAnimation(SkewTransform.AngleXProperty, skewGrassX);
            skewTransformY.BeginAnimation(SkewTransform.AngleYProperty, skewGrassY);
            rotateTransform.BeginAnimation(RotateTransform.AngleProperty, rotate);
        }
예제 #5
0
        /// <summary>
        /// Executes when the logo gets clicked
        /// </summary>
        private void OnLogoClick(object sender, RoutedEventArgs e)
        {
            // Updates the rotated times
            this.RotatedLogoTimes++;

            // Checks if the easter-easter-egg got activated
            if (this.RotatedLogoTimes >= 41)
            {
                // Resets the rotated times
                this.RotatedLogoTimes = 0;

                // Creates the transformer
                SkewTransform skew = new SkewTransform();
                // Starts the animation
                this.ButtonLogo.RenderTransform = skew;
                skew.BeginAnimation(
                    SkewTransform.AngleXProperty,
                    new DoubleAnimation(0, 180, new Duration(TimeSpan.FromMilliseconds(2000)))
                    );
            }
            else
            {
                // Creates the transformer
                RotateTransform rt = new RotateTransform();

                // Gets the rotate direction
                bool forward = this.RotatedLogoTimes % 2 == 0;

                // Gets the max amount of rotations
                int max = 360 + 2;

                // Starts the animation
                this.ButtonLogo.RenderTransform = rt;
                rt.BeginAnimation(
                    RotateTransform.AngleProperty,
                    new DoubleAnimation(forward ? max : 0, forward ? 0 : max, new Duration(TimeSpan.FromMilliseconds(200)))
                    );
            }
        }
예제 #6
0
        /// <summary>
        /// Переключатель плоский или наклоный просмотр сетки
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void perspectiveViewImage_Click(object sender, RoutedEventArgs e)
        {
            DoubleAnimation skewGrassX;
            DoubleAnimation skewGrassY;
            DoubleAnimation rotate;

            if ((explorerGrid.Tag == null) || (explorerGrid.Tag.ToString().Equals("1")))
            {
                skewGrassX       = new DoubleAnimation(-15.0f, new Duration(TimeSpan.FromMilliseconds(2000)));
                skewGrassY       = new DoubleAnimation(-10.0f, new Duration(TimeSpan.FromMilliseconds(2000)));
                rotate           = new DoubleAnimation(17.0f, new Duration(TimeSpan.FromMilliseconds(2000)));
                explorerGrid.Tag = "0";
            }
            else
            {
                skewGrassX       = new DoubleAnimation(-15.0f, 0.0f, new Duration(TimeSpan.FromMilliseconds(2000)));
                skewGrassY       = new DoubleAnimation(-10.0f, 0.0f, new Duration(TimeSpan.FromMilliseconds(2000)));
                rotate           = new DoubleAnimation(17.0f, 0.0f, new Duration(TimeSpan.FromMilliseconds(2000)));
                explorerGrid.Tag = "1";
            }

            SkewTransform   skewTransformX  = new SkewTransform();
            SkewTransform   skewTransformY  = new SkewTransform();
            RotateTransform rotateTransform = new RotateTransform();

            TransformGroup transformGroup = new TransformGroup();

            transformGroup.Children.Add(skewTransformX);
            transformGroup.Children.Add(skewTransformY);
            transformGroup.Children.Add(rotateTransform);

            explorerGrid.LayoutTransform = transformGroup;

            skewTransformX.BeginAnimation(SkewTransform.AngleXProperty, skewGrassX);
            skewTransformY.BeginAnimation(SkewTransform.AngleYProperty, skewGrassY);
            rotateTransform.BeginAnimation(RotateTransform.AngleProperty, rotate);
        }
예제 #7
0
        /*
         * 加载所有动画效果
         *
         * @param currElement 当前控件
         *
         * @param currDControl  当前控件数据
         *
         * @param  list 动画列表
         */
        public static void loadAllAnimation(FrameworkElement currElement, DControl currDControl, List <DControlAnimation> list, Cfg cfg)
        {
            double         currOpacity = currDControl.opacity / 100.0;
            TransformGroup group       = (TransformGroup)currElement.RenderTransform;


            // group.Children.Clear();   多次加载动画需要归零
            foreach (DControlAnimation animation in list)
            {
                if (animation.type == 1001)
                {
                    //淡入
                    currElement.RenderTransformOrigin = new Point(0.5, 0.5);
                    currElement.Opacity = 0;
                    IEasingFunction easingFunction = new CubicEase()
                    {
                        EasingMode = EasingMode.EaseIn
                    };
                    DoubleAnimation da = DoubleAnimationUtil.initDoubleAnimation(animation, 0, currOpacity, easingFunction);
                    currElement.BeginAnimation(UIElement.OpacityProperty, da);
                }
                else if (animation.type == 1002)
                {
                    //从左移入
                    currElement.RenderTransformOrigin = new Point(0.5, 0.5);


                    TranslateTransform translateTransform = TransformGroupUtil.GetTranslateTransform(group);
                    DoubleAnimation    da = DoubleAnimationUtil.initDoubleAnimation(animation, -currDControl.left - currDControl.width, 0);
                    translateTransform.BeginAnimation(TranslateTransform.XProperty, da);

                    DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity);
                }
                else if (animation.type == 1003)
                {
                    //从右移入
                    currElement.RenderTransformOrigin = new Point(0.5, 0.5);

                    TranslateTransform translateTransform = TransformGroupUtil.GetTranslateTransform(group);
                    DoubleAnimation    da = DoubleAnimationUtil.initDoubleAnimation(animation, cfg.screenWidth - currDControl.left, 0);
                    translateTransform.BeginAnimation(TranslateTransform.XProperty, da);

                    DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity);
                }
                else if (animation.type == 1004)
                {
                    //从上移入
                    currElement.RenderTransformOrigin = new Point(0.5, 0.5);

                    TranslateTransform translateTransform = TransformGroupUtil.GetTranslateTransform(group);
                    DoubleAnimation    da = DoubleAnimationUtil.initDoubleAnimation(animation, -currDControl.top - currDControl.height, 0);

                    translateTransform.BeginAnimation(TranslateTransform.YProperty, da);

                    DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity);
                }
                else if (animation.type == 1005)
                {
                    //从下移入
                    currElement.RenderTransformOrigin = new Point(0.5, 0.5);

                    TranslateTransform translateTransform = TransformGroupUtil.GetTranslateTransform(group);
                    DoubleAnimation    da = DoubleAnimationUtil.initDoubleAnimation(animation, cfg.screenHeight - currDControl.top, 0);

                    translateTransform.BeginAnimation(TranslateTransform.YProperty, da);

                    DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity);
                }

                else if (animation.type == 1006)
                {
                    //放大
                    currElement.RenderTransformOrigin = new Point(0.5, 0.5);

                    ScaleTransform  scaleTransform = TransformGroupUtil.GetScaleTransform(group);
                    DoubleAnimation da             = DoubleAnimationUtil.initDoubleAnimation(animation, 0.5, 1.0);
                    scaleTransform.BeginAnimation(ScaleTransform.ScaleXProperty, da);
                    scaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, da);


                    DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity);
                }
                else if (animation.type == 1007)
                {
                    //缩小
                    currElement.RenderTransformOrigin = new Point(0.5, 0.5);

                    ScaleTransform  scaleTransform = TransformGroupUtil.GetScaleTransform(group);
                    DoubleAnimation da             = DoubleAnimationUtil.initDoubleAnimation(animation, 1.5, 1.0);
                    scaleTransform.BeginAnimation(ScaleTransform.ScaleXProperty, da);
                    scaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, da);

                    DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity);
                }
                else if (animation.type == 1101)
                {
                    //从左旋转
                    currElement.RenderTransformOrigin = new Point(0.5, 0.5);

                    RotateTransform rotateTransform = TransformGroupUtil.GetRotateTransform(group);
                    DoubleAnimation da = DoubleAnimationUtil.initDoubleAnimation(animation, 180 + currDControl.rotateAngle, 360 + currDControl.rotateAngle);
                    rotateTransform.BeginAnimation(RotateTransform.AngleProperty, da);


                    TranslateTransform translateTransform = TransformGroupUtil.GetTranslateTransform(group);
                    DoubleAnimation    da2 = DoubleAnimationUtil.initDoubleAnimation(animation, -currDControl.width * 1, 0);
                    translateTransform.BeginAnimation(TranslateTransform.XProperty, da2);


                    DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity);
                }
                else if (animation.type == 1102)
                {
                    //从右旋转
                    currElement.RenderTransformOrigin = new Point(0.5, 0.5);

                    RotateTransform rotateTransform = TransformGroupUtil.GetRotateTransform(group);
                    DoubleAnimation da = DoubleAnimationUtil.initDoubleAnimation(animation, 180 + currDControl.rotateAngle, 360 + currDControl.rotateAngle);

                    rotateTransform.BeginAnimation(RotateTransform.AngleProperty, da);


                    TranslateTransform translateTransform = TransformGroupUtil.GetTranslateTransform(group);
                    DoubleAnimation    da2 = DoubleAnimationUtil.initDoubleAnimation(animation, currDControl.width * 1, 0);
                    translateTransform.BeginAnimation(TranslateTransform.XProperty, da2);


                    DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity);
                }
                else if (animation.type == 1103)
                {
                    //从上旋转
                    currElement.RenderTransformOrigin = new Point(0.5, 0.5);

                    RotateTransform rotateTransform = TransformGroupUtil.GetRotateTransform(group);
                    DoubleAnimation da = DoubleAnimationUtil.initDoubleAnimation(animation, 180 + currDControl.rotateAngle, 360 + currDControl.rotateAngle);
                    rotateTransform.BeginAnimation(RotateTransform.AngleProperty, da);


                    TranslateTransform translateTransform = TransformGroupUtil.GetTranslateTransform(group);
                    DoubleAnimation    da2 = DoubleAnimationUtil.initDoubleAnimation(animation, -currDControl.height * 1, 0);
                    translateTransform.BeginAnimation(TranslateTransform.YProperty, da2);


                    DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity);
                }
                else if (animation.type == 1104)
                {
                    //从下旋转
                    currElement.RenderTransformOrigin = new Point(0.5, 0.5);

                    RotateTransform rotateTransform = TransformGroupUtil.GetRotateTransform(group);
                    DoubleAnimation da = DoubleAnimationUtil.initDoubleAnimation(animation, 180 + currDControl.rotateAngle, 360 + currDControl.rotateAngle);
                    rotateTransform.BeginAnimation(RotateTransform.AngleProperty, da);


                    TranslateTransform translateTransform = TransformGroupUtil.GetTranslateTransform(group);
                    DoubleAnimation    da2 = DoubleAnimationUtil.initDoubleAnimation(animation, currDControl.height * 1, 0);
                    translateTransform.BeginAnimation(TranslateTransform.YProperty, da2);


                    DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity);
                }
                else if (animation.type == 1201)
                {
                    //从左弹入
                    currElement.RenderTransformOrigin = new Point(0.5, 0.5);

                    TranslateTransform translateTransform12 = TransformGroupUtil.GetTranslateTransform(group);
                    IEasingFunction    easingFunction       = new BackEase()
                    {
                        EasingMode = EasingMode.EaseInOut
                    };
                    DoubleAnimation da = DoubleAnimationUtil.initDoubleAnimation(animation, -currDControl.left - currDControl.width, 0, easingFunction);
                    translateTransform12.BeginAnimation(TranslateTransform.XProperty, da);


                    DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity);
                }
                else if (animation.type == 1202)
                {
                    //从右弹入
                    currElement.RenderTransformOrigin = new Point(0.5, 0.5);

                    TranslateTransform translateTransform = TransformGroupUtil.GetTranslateTransform(group);
                    IEasingFunction    easingFunction     = new BackEase()
                    {
                        EasingMode = EasingMode.EaseInOut
                    };
                    DoubleAnimation da = DoubleAnimationUtil.initDoubleAnimation(animation, cfg.screenWidth - currDControl.left, 0, easingFunction);
                    translateTransform.BeginAnimation(TranslateTransform.XProperty, da);

                    DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity);
                }
                else if (animation.type == 1203)
                {
                    //从上弹入
                    currElement.RenderTransformOrigin = new Point(0.5, 0.5);

                    TranslateTransform translateTransform = TransformGroupUtil.GetTranslateTransform(group);
                    IEasingFunction    easingFunction     = new BackEase()
                    {
                        EasingMode = EasingMode.EaseInOut
                    };
                    DoubleAnimation da = DoubleAnimationUtil.initDoubleAnimation(animation, -currDControl.top - currDControl.height, 0, easingFunction);

                    translateTransform.BeginAnimation(TranslateTransform.YProperty, da);


                    DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity);
                }
                else if (animation.type == 1204)
                {
                    //从下弹入
                    currElement.RenderTransformOrigin = new Point(0.5, 0.5);

                    TranslateTransform translateTransform = TransformGroupUtil.GetTranslateTransform(group);
                    IEasingFunction    easingFunction     = new BackEase()
                    {
                        EasingMode = EasingMode.EaseInOut
                    };
                    DoubleAnimation da = DoubleAnimationUtil.initDoubleAnimation(animation, cfg.screenHeight - currDControl.top, 0, easingFunction);

                    translateTransform.BeginAnimation(TranslateTransform.YProperty, da);

                    DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity);
                }
                else if (animation.type == 1205)
                {
                    //中心弹入
                    currElement.RenderTransformOrigin = new Point(0.5, 0.5);

                    ScaleTransform  scaleTransform = TransformGroupUtil.GetScaleTransform(group);
                    IEasingFunction easingFunction = new BackEase()
                    {
                        EasingMode = EasingMode.EaseInOut
                    };
                    DoubleAnimation da = DoubleAnimationUtil.initDoubleAnimation(animation, 0.5, 1.0, easingFunction);
                    scaleTransform.BeginAnimation(ScaleTransform.ScaleXProperty, da);
                    scaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, da);


                    DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity);
                }
                else if (animation.type == 1301)
                {
                    //从左斜入
                    currElement.RenderTransformOrigin = new Point(0.5, 0.5);

                    SkewTransform   skewTransform  = TransformGroupUtil.GetSkewTransform(group);
                    IEasingFunction easingFunction = new BackEase()
                    {
                        EasingMode = EasingMode.EaseInOut
                    };
                    DoubleAnimation da = DoubleAnimationUtil.initDoubleAnimation(animation, 140, 180, easingFunction);
                    skewTransform.BeginAnimation(SkewTransform.AngleXProperty, da);


                    TranslateTransform translateTransform = TransformGroupUtil.GetTranslateTransform(group);
                    DoubleAnimation    da1 = DoubleAnimationUtil.initDoubleAnimation(animation, -currDControl.width * 1, 0, easingFunction);
                    translateTransform.BeginAnimation(TranslateTransform.XProperty, da1);


                    DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity);
                }
                else if (animation.type == 1302)
                {
                    //从右斜入
                    currElement.RenderTransformOrigin = new Point(0.5, 0.5);

                    SkewTransform   skewTransform  = TransformGroupUtil.GetSkewTransform(group);
                    IEasingFunction easingFunction = new BackEase()
                    {
                        EasingMode = EasingMode.EaseInOut
                    };
                    DoubleAnimation da = DoubleAnimationUtil.initDoubleAnimation(animation, 40, 0, easingFunction);
                    skewTransform.BeginAnimation(SkewTransform.AngleXProperty, da);


                    TranslateTransform translateTransform = TransformGroupUtil.GetTranslateTransform(group);
                    DoubleAnimation    da1 = DoubleAnimationUtil.initDoubleAnimation(animation, currDControl.width, 0, easingFunction);
                    translateTransform.BeginAnimation(TranslateTransform.XProperty, da1);


                    DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity);
                }
                else if (animation.type == 1303)
                {
                    //从上斜入
                    currElement.RenderTransformOrigin = new Point(0.5, 0.5);

                    ScaleTransform  scaleTransform = TransformGroupUtil.GetScaleTransform(group);
                    DoubleAnimation da             = DoubleAnimationUtil.initDoubleAnimation(animation, 0.1, 1.0);
                    scaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, da);



                    SkewTransform   skewTransform  = TransformGroupUtil.GetSkewTransform(group);
                    IEasingFunction easingFunction = new BackEase()
                    {
                        EasingMode = EasingMode.EaseInOut
                    };
                    DoubleAnimation da1 = DoubleAnimationUtil.initDoubleAnimation(animation, 60, 0, easingFunction);
                    skewTransform.BeginAnimation(SkewTransform.AngleXProperty, da1);


                    TranslateTransform translateTransform = TransformGroupUtil.GetTranslateTransform(group);
                    DoubleAnimation    da2 = DoubleAnimationUtil.initDoubleAnimation(animation, -currDControl.height, 0);
                    translateTransform.BeginAnimation(TranslateTransform.YProperty, da2);

                    DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity);
                }
                else if (animation.type == 1304)
                {
                    //从下斜入
                    currElement.RenderTransformOrigin = new Point(0.5, 0.5);

                    ScaleTransform  scaleTransform = TransformGroupUtil.GetScaleTransform(group);
                    DoubleAnimation da             = DoubleAnimationUtil.initDoubleAnimation(animation, 0.1, 1.0);
                    scaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, da);

                    SkewTransform   skewTransform  = TransformGroupUtil.GetSkewTransform(group);
                    IEasingFunction easingFunction = new BackEase()
                    {
                        EasingMode = EasingMode.EaseInOut
                    };
                    DoubleAnimation da1 = DoubleAnimationUtil.initDoubleAnimation(animation, 60, 0, easingFunction);
                    skewTransform.BeginAnimation(SkewTransform.AngleXProperty, da1);


                    TranslateTransform translateTransform = TransformGroupUtil.GetTranslateTransform(group);
                    DoubleAnimation    da2 = DoubleAnimationUtil.initDoubleAnimation(animation, currDControl.height, 0);
                    translateTransform.BeginAnimation(TranslateTransform.YProperty, da2);


                    DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity);
                }
                else if (animation.type == 1401)
                {
                    //从左绕入

                    currElement.RenderTransformOrigin = new Point(0, 0);
                    RotateTransform rotateTransform = TransformGroupUtil.GetRotateTransform(group);
                    DoubleAnimation da = DoubleAnimationUtil.initDoubleAnimation(animation, 360 + currDControl.rotateAngle, 0 + currDControl.rotateAngle);
                    rotateTransform.BeginAnimation(RotateTransform.AngleProperty, da);


                    ScaleTransform  scaleTransform = TransformGroupUtil.GetScaleTransform(group);
                    DoubleAnimation da1            = DoubleAnimationUtil.initDoubleAnimation(animation, 0, 1.0);
                    scaleTransform.BeginAnimation(ScaleTransform.ScaleXProperty, da1);
                    scaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, da1);

                    DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity);
                }
                else if (animation.type == 1402)
                {
                    //从右绕入

                    currElement.RenderTransformOrigin = new Point(1, 1);
                    RotateTransform rotateTransform = TransformGroupUtil.GetRotateTransform(group);
                    DoubleAnimation da = DoubleAnimationUtil.initDoubleAnimation(animation, 360 + currDControl.rotateAngle, 0 + currDControl.rotateAngle);
                    rotateTransform.BeginAnimation(RotateTransform.AngleProperty, da);


                    ScaleTransform  scaleTransform = TransformGroupUtil.GetScaleTransform(group);
                    DoubleAnimation da1            = DoubleAnimationUtil.initDoubleAnimation(animation, 0, 1.0);
                    scaleTransform.BeginAnimation(ScaleTransform.ScaleXProperty, da1);
                    scaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, da1);


                    DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity);
                }
                else if (animation.type == 1403)
                {
                    //从上绕入


                    currElement.RenderTransformOrigin = new Point(1, 0);
                    RotateTransform rotateTransform = TransformGroupUtil.GetRotateTransform(group);
                    DoubleAnimation da = DoubleAnimationUtil.initDoubleAnimation(animation, 360 + currDControl.rotateAngle, 0 + currDControl.rotateAngle);
                    rotateTransform.BeginAnimation(RotateTransform.AngleProperty, da);

                    ScaleTransform  scaleTransform = TransformGroupUtil.GetScaleTransform(group);
                    DoubleAnimation da1            = DoubleAnimationUtil.initDoubleAnimation(animation, 0, 1.0);
                    scaleTransform.BeginAnimation(ScaleTransform.ScaleXProperty, da1);
                    scaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, da1);

                    DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity);
                }
                else if (animation.type == 1404)
                {
                    //从下绕入

                    currElement.RenderTransformOrigin = new Point(0, 1);
                    RotateTransform rotateTransform = TransformGroupUtil.GetRotateTransform(group);
                    DoubleAnimation da = DoubleAnimationUtil.initDoubleAnimation(animation, 0 + currDControl.rotateAngle, 360 + currDControl.rotateAngle);
                    rotateTransform.BeginAnimation(RotateTransform.AngleProperty, da);


                    ScaleTransform  scaleTransform = TransformGroupUtil.GetScaleTransform(group);
                    DoubleAnimation da1            = DoubleAnimationUtil.initDoubleAnimation(animation, 0, 1.0);
                    scaleTransform.BeginAnimation(ScaleTransform.ScaleXProperty, da1);
                    scaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, da1);


                    DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity);
                }
                else if (animation.type == 1501)
                {
                    //翻开
                    currElement.RenderTransformOrigin = new Point(0.5, 0.5);

                    SkewTransform   skewTransform  = TransformGroupUtil.GetSkewTransform(group);
                    IEasingFunction easingFunction = new BackEase()
                    {
                        EasingMode = EasingMode.EaseInOut, Amplitude = 0.1
                    };
                    DoubleAnimation da = DoubleAnimationUtil.initDoubleAnimation(animation, 10, 0, easingFunction);
                    skewTransform.BeginAnimation(SkewTransform.AngleXProperty, da);


                    ScaleTransform  scaleTransform  = TransformGroupUtil.GetScaleTransform(group);
                    IEasingFunction easingFunction1 = new BackEase()
                    {
                        EasingMode = EasingMode.EaseInOut
                    };
                    DoubleAnimation da1 = DoubleAnimationUtil.initDoubleAnimation(animation, 0.4, 1.0, easingFunction1);
                    scaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, da1);


                    IEasingFunction easingFunction2 = new CubicEase()
                    {
                        EasingMode = EasingMode.EaseIn
                    };
                    DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity, easingFunction2);
                }
                else if (animation.type == 1502)
                {
                    //旋转
                    currElement.RenderTransformOrigin = new Point(0.5, 0.5);

                    RotateTransform rotateTransform = TransformGroupUtil.GetRotateTransform(group);
                    DoubleAnimation da = DoubleAnimationUtil.initDoubleAnimation(animation, 0 + currDControl.rotateAngle, 360 + currDControl.rotateAngle);
                    rotateTransform.BeginAnimation(RotateTransform.AngleProperty, da);

                    IEasingFunction easingFunction2 = new CubicEase()
                    {
                        EasingMode = EasingMode.EaseIn
                    };
                    DoubleAnimationUtil.andBeginOpacityAnimation(currElement, animation, 0, currOpacity, easingFunction2);
                }
                else if (animation.type == 1601)
                {
                    //光晕 来回缩放
                    currElement.RenderTransformOrigin = new Point(0.5, 0.5);

                    double halfSeconds = animation.durationSeconds / 2.0;
                    DoubleAnimationUsingKeyFrames da = new DoubleAnimationUsingKeyFrames();
                    if (animation.playTimes <= 0)
                    {
                        da.RepeatBehavior = RepeatBehavior.Forever;
                    }
                    else
                    {
                        da.RepeatBehavior = new RepeatBehavior(animation.playTimes);
                    }
                    ScaleTransform  scaleTransform = TransformGroupUtil.GetScaleTransform(group);
                    var             keyFrames      = da.KeyFrames;
                    IEasingFunction easingFunction = new CubicEase()
                    {
                        EasingMode = EasingMode.EaseIn
                    };
                    keyFrames.Add(new LinearDoubleKeyFrame(1.0, TimeSpan.FromMilliseconds(0)));
                    keyFrames.Add(new LinearDoubleKeyFrame(0.78, TimeSpan.FromMilliseconds(halfSeconds)));
                    keyFrames.Add(new LinearDoubleKeyFrame(1.0, TimeSpan.FromMilliseconds(animation.durationSeconds)));
                    scaleTransform.BeginAnimation(ScaleTransform.ScaleXProperty, da);
                    scaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, da);
                }
            }
        }
예제 #8
0
        /// <summary>
        /// Overrides the standard ArrangeOverride method from the <see cref="System.Windows.FrameworkElement" /> class.
        /// </summary>
        /// <param name="finalSize">The final area within the parent that this element should use to arrange itself and its children.</param>
        /// <returns>
        /// The actual size used.
        /// </returns>
        protected override Size ArrangeOverride(Size finalSize)
        {
            // If an item was removed don't move resp. animate anything
            if (removedUIElement != null)
            {
                return(finalSize);
            }

            // If a row was added and as a result of this the panel height has changed don't move resp. animate anything
            if (changeOfPanelHeightInProgress)
            {
                changeOfPanelHeightInProgress = false;
                return(finalSize);
            }

            // Set the time stamp at the beginning of the arrangement process
            var startArrangementTimeStamp = DateTime.Now.Ticks;

            // Iterate through all childs in the UIElementCollection
            for (var i = 0; i < Children.Count; i++)
            {
                // Get the current child by it's index
                var child = Children[i];
                if (child == null)
                {
                    continue;
                }

                // Try to find the current child in our internal child collection
                var existingChild = internalChildCollection.FirstOrDefault(item => item.Child.Equals(child));
                if (existingChild == null)
                {
                    // If the current child is not in our internal child collection, then add it to our internal collection
                    internalChildCollection.Add(new UIElementWithMetaData
                    {
                        Child           = child,
                        ChildIndex      = i,
                        IsRecentlyAdded = true
                    });
                }
                else
                {
                    existingChild.IsRecentlyAdded = false;
                }
            }

            // Calculate the width and height of every single Slot
            var slotWidth  = finalSize.Width / ColumnCount;
            var slotHeight = finalSize.Height / RowCount;
            // Calculate the initial horizontal and vertical offset
            var horizontalOffset = slotWidth * (ColumnCount - 1);
            // ReSharper disable once PossibleLossOfFraction
            var verticalOffset = slotHeight * (internalChildCollection.Count / ColumnCount);
            // Determine if the first column is full
            var isFirstColumnFull = (internalChildCollection.Count % ColumnCount).Equals(0);

            // This is our column counter
            var currentColumn = ColumnCount;

            // Here we hold all indexes of childs which are involved in the merge process
            var currentRowMergeIndexes  = new List <int>();
            var previousRowMergeIndexes = new List <int>();

            // Count of row pairs to merge ( 2 rows -> 1 row )
            var countOfRowPairs = 0;

            // Count of deleted childs in curent row pair, so we can skip all childs after ColumnColunt childs were removed
            var countOfDeletedChildsInCurrentRowPair = 0;

            // If a new child was added and the first column is full ...
            if (newChildAdded && isFirstColumnFull)
            {
                // ... iterate through all rows
                for (var i = 0; i < internalChildCollection.Count; i += ColumnCount)
                {
                    var removedChildsInCurrentRow  = 0;
                    var removedChildsInPreviousRow = 0;

                    // Determine the first and last child indexes of the current and previous row
                    var firstChildIndexInCurrentRow  = i - (i % ColumnCount);
                    var lastChildIndexInCurrentRow   = firstChildIndexInCurrentRow + ColumnCount - 1;
                    var firstChildIndexInPreviousRow = firstChildIndexInCurrentRow + ColumnCount;
                    var lastChildIndexInPreviousRow  = lastChildIndexInCurrentRow + ColumnCount;

                    // Count all removed childs in the current row
                    for (var childIndex = firstChildIndexInCurrentRow; childIndex <= lastChildIndexInCurrentRow; childIndex++)
                    {
                        if (childIndex >= internalChildCollection.Count)
                        {
                            continue;
                        }

                        if (internalChildCollection[childIndex].IsRemoved)
                        {
                            removedChildsInCurrentRow++;
                        }
                    }

                    // Count all removed childs in the previous row
                    for (var childIndex = firstChildIndexInPreviousRow; childIndex <= lastChildIndexInPreviousRow; childIndex++)
                    {
                        if (childIndex >= internalChildCollection.Count)
                        {
                            continue;
                        }

                        if (internalChildCollection[childIndex].IsRemoved)
                        {
                            removedChildsInPreviousRow++;
                        }
                    }

                    // If all removed childs in the current row and the previous row are greater or equal to the column count ...
                    if (removedChildsInCurrentRow + removedChildsInPreviousRow >= ColumnCount)
                    {
                        // ... add all child indexes of the current and previous row to our index lists
                        currentRowMergeIndexes.AddRange(Enumerable.Range(firstChildIndexInCurrentRow, ColumnCount));
                        previousRowMergeIndexes.AddRange(Enumerable.Range(firstChildIndexInPreviousRow, ColumnCount));

                        countOfRowPairs++;
                        i += ColumnCount;
                    }
                }

                // Update the initial vertical offset considering the count of row pairs
                if (countOfRowPairs > 0)
                {
                    verticalOffset -= slotHeight * countOfRowPairs;
                }
            }

            // Iterate through all childs in our internal child collection
            for (var i = 0; i < internalChildCollection.Count; i++)
            {
                // Get the current internal child by it's index
                var existingChild = internalChildCollection[i];
                var child         = existingChild.Child;
                if (child == null)
                {
                    continue;
                }

                // Get the current TransformGroup
                var existingTransformGroup = child.RenderTransform as TransformGroup;

                var translateTransform = new TranslateTransform();
                var skewTransform      = new SkewTransform();
                var transformGroup     = new TransformGroup();

                // If there is no current TransformGroup, create a new one ...
                if (existingTransformGroup == null)
                {
                    transformGroup.Children.Add(translateTransform);
                    transformGroup.Children.Add(skewTransform);
                    child.RenderTransform = transformGroup;
                }
                else
                {
                    // ... else retrieve the available Transform objects from the existing TransformGroup
                    translateTransform = existingTransformGroup.Children[0] as TranslateTransform;
                    skewTransform      = existingTransformGroup.Children[1] as SkewTransform;
                }

                // First arrangement of the child on position [0,0] with the size of a single Slot
                // The animation values will overwrite this first position settings
                child.Arrange(new Rect(0, 0, slotWidth, slotHeight));

                // New childs will slide in from outside ...
                var fromHorizontalPosition = -slotWidth;
                var fromVerticalPosition   = 0.0;

                // If the current child wasn't recently added and the initial size change is not in progress ...
                if (!internalChildCollection[i].IsRecentlyAdded && !initialSizeChangeInProgress)
                {
                    // ...  retrieve the current position as the animation start position
                    fromHorizontalPosition = existingChild.CurrentPosition.X;
                    fromVerticalPosition   = existingChild.CurrentPosition.Y;
                }

                // Update the current position data and the animation progress state
                existingChild.CurrentPosition = new Point(horizontalOffset, verticalOffset);
                existingChild.HorizontalAnimationInProgress = true;

                var mergeInProgress            = false;
                var lastChildIndexInCurrentRow = -1;

                if (translateTransform != null)
                {
                    // Animate the vertical position of the current child from the childs current vertical position
                    // to the calculated vertical offset
                    var verticalAnimation = new DoubleAnimation(fromVerticalPosition, verticalOffset, MovementAnimationDuration)
                    {
                        AccelerationRatio = 0.5,
                        DecelerationRatio = 0.3
                    };

                    // If the first column is full ...
                    if (newChildAdded && isFirstColumnFull)
                    {
                        // ... merge corresponding rows, where the cumulated item count is equal to the column count
                        var removedChildsInCurrentRow = 0;
                        // var removedChildsInNextRow = 0;

                        // Determine the first and last child indexes of the current and next row
                        var firstChildIndexInCurrentRow = i - (i % ColumnCount);
                        lastChildIndexInCurrentRow = firstChildIndexInCurrentRow + ColumnCount - 1;
                        // var firstChildIndexInNextRow = firstChildIndexInCurrentRow - ColumnCount;
                        // var lastChildIndexInNextRow = lastChildIndexInCurrentRow - ColumnCount;

                        // Count all removed childs in the current row
                        for (var childIndex = firstChildIndexInCurrentRow; childIndex <= lastChildIndexInCurrentRow; childIndex++)
                        {
                            if (childIndex >= internalChildCollection.Count)
                            {
                                continue;
                            }

                            if (internalChildCollection[childIndex].IsRemoved)
                            {
                                removedChildsInCurrentRow++;
                            }
                        }

                        // Count all removed childs in the next row
                        // for (var childIndex = firstChildIndexInNextRow; childIndex <= lastChildIndexInNextRow; childIndex++)
                        // {
                        // if (childIndex < 0 || childIndex >= internalChildCollection.Count) continue;
                        // if (internalChildCollection[childIndex].IsRemoved) removedChildsInNextRow++;
                        // }

                        // If the current child is located in a row to merge
                        if (currentRowMergeIndexes.Contains(i) || previousRowMergeIndexes.Contains(i))
                        {
                            mergeInProgress = true;

                            // If the child is marked as removed ...
                            if (existingChild.IsRemoved)
                            {
                                // ... update the horizontal offset
                                horizontalOffset += slotWidth;
                                // ... and mark the child for deletion
                                // (only if all deleted childs in the current row pair don't exceed the ColumnCount)
                                if (++countOfDeletedChildsInCurrentRowPair <= ColumnCount)
                                {
                                    existingChild.IsMarkedForDeletion = true;
                                }
                            }

                            // If the child is the first child in the previous row ...
                            if (previousRowMergeIndexes.Contains(i) && i == firstChildIndexInCurrentRow)
                            {
                                // ... update the horizontal offset
                                horizontalOffset -= slotWidth * removedChildsInCurrentRow;
                                // horizontalOffset -= slotWidth * (ColumnCount - removedChildsInPreviousRow);
                            }
                        }
                        else
                        {
                            lastChildIndexInCurrentRow           = -1;
                            countOfDeletedChildsInCurrentRowPair = 0;
                        }

                        // Start the movement of all lines AFTER the sliding movement and the arrangement is finished
                        verticalAnimation.BeginTime = MovementAnimationDuration.TimeSpan + arrangementTimeSpan;

                        // If there are rows to merge ..
                        if (countOfRowPairs > 0)
                        {
                            // ... add the merge animation delay to the vertical animation delay
                            verticalAnimation.BeginTime += MergeAnimationDelay.TimeSpan;
                        }
                    }

                    // Hook the vertical animation completed event, so we can remove the childs which are marked for deletion
                    verticalAnimation.Completed += (os, ea) => verticalAnimation_Completed(child);

                    // Apply the vertical animation ONLY if the vertical position has changed
                    if (!fromVerticalPosition.Equals(verticalOffset))
                    {
                        // !-----------------------------------------------------------------------------------------------------------------
                        Debug.WriteLine("Vertical Movement Item No. {0} from {1} to {2} ", i, fromVerticalPosition, verticalOffset);
                        // !-----------------------------------------------------------------------------------------------------------------
                        translateTransform.BeginAnimation(TranslateTransform.YProperty, verticalAnimation, HandoffBehavior.Compose);
                    }

                    // Animate the horizontal position of the current child from the childs current horizontal position
                    // to the calculated horizontal offset
                    var horizontalAnimation = new DoubleAnimation(fromHorizontalPosition, horizontalOffset, MovementAnimationDuration)
                    {
                        AccelerationRatio = 0.5,
                        DecelerationRatio = 0.3
                    };
                    // Hook the animation completed event, so we can change the "HorizontalAnimationInProgress" flag
                    horizontalAnimation.Completed += (os, ea) => horizontalAnimation_Completed(child);

                    if (internalChildCollection[i].IsRecentlyAdded || existingChild.HorizontalAnimationInProgress == false ||
                        resizeInProgress || mergeInProgress)
                    {
                        // !-----------------------------------------------------------------------------------------------------------------
                        Debug.WriteLine("Horizontal Movement Item No. " + i);
                        Debug.WriteLine("Arrange time span : " + arrangementTimeSpan.TotalMilliseconds);
                        // !-----------------------------------------------------------------------------------------------------------------

                        // Set the beginning of the horizontal animation to the end of the arrangement process
                        // (this will prevent unpredictable animation effects)
                        horizontalAnimation.BeginTime = arrangementTimeSpan;

                        // If a merge is in progress..
                        if (mergeInProgress)
                        {
                            // ... add the merge animation delay to the horizontal animation
                            horizontalAnimation.BeginTime += MergeAnimationDelay.TimeSpan;

                            // If we have the last child of the current merged row reset the horizontal offset to EPSILON
                            if (currentRowMergeIndexes.Contains(i) && i == lastChildIndexInCurrentRow)
                            {
                                horizontalOffset = EPSILON;
                            }
                        }
                        else
                        {
                            // This is neccessary to move the child to it's current horizontal start position
                            var moveToStartPositionAnimation = new DoubleAnimation(fromHorizontalPosition, fromHorizontalPosition, new Duration(new TimeSpan(0)));
                            translateTransform.BeginAnimation(TranslateTransform.XProperty, moveToStartPositionAnimation, HandoffBehavior.Compose);
                        }

                        translateTransform.BeginAnimation(TranslateTransform.XProperty, horizontalAnimation, HandoffBehavior.Compose);
                    }
                }

                existingChild.CurrentPosition = new Point(horizontalOffset, verticalOffset);

                //// If the child is the last child in the current merged row ...
                // if (currentRowMergeIndexes.Contains( i ) && i == lastChildIndexInCurrentRow)
                // // ... update the vertical offset
                // verticalOffset += slotHeight;

                // If the current child is the first in the row, then update the vertical and horizontal offset for the next childs
                // and set the current column to the last column in the row
                if (horizontalOffset <= EPSILON)
                {
                    // If the child is not the last child in a row that is currently merged ...
                    if (!(currentRowMergeIndexes.Contains(i) && i == lastChildIndexInCurrentRow))
                    {
                        verticalOffset -= slotHeight;                         // ... update the vertical offset for the next child
                    }

                    horizontalOffset = slotWidth * (ColumnCount - 1); // Update the horizontal offset for the next child
                    currentColumn    = ColumnCount;                   // Reset our column counter to last column in row
                }
                else
                {
                    // If we have the recently added child ...
                    if (newChildAdded && child.Equals(addedUIElement) && skewTransform != null)
                    {
                        // ... perform an additional skew animation
                        // Calculate the skew angle dependent on the distance to the end of line (base angle = -30°)
                        var skewAngle     = -30.0 * ((double)currentColumn / ColumnCount);
                        var skewAnimation = new DoubleAnimationUsingKeyFrames
                        {
                            Duration  = MovementAnimationDuration,
                            BeginTime = arrangementTimeSpan
                        };
                        var fractionOfMovementAnimationDuration = (MovementAnimationDuration.TimeSpan.Multiply(0.65));

                        skewAnimation.KeyFrames.Add(new LinearDoubleKeyFrame(skewAngle,                                                 // Target value (KeyValue)
                                                                             KeyTime.FromTimeSpan(fractionOfMovementAnimationDuration)) // KeyTime
                                                    );
                        skewAnimation.KeyFrames.Add(new LinearDoubleKeyFrame(0,                                                         // Target value (KeyValue)
                                                                             KeyTime.FromTimeSpan(MovementAnimationDuration.TimeSpan))  // KeyTime
                                                    );

                        skewTransform.BeginAnimation(SkewTransform.AngleXProperty, skewAnimation, HandoffBehavior.Compose);

                        newChildAdded = false;
                    }

                    horizontalOffset -= slotWidth;       // Update the horizontal offset for the next child
                    currentColumn--;                     // Increase our column counter
                }
            }

            // Set the time stamp at the end of the arrangement process
            var endArrangementTimeStamp = DateTime.Now.Ticks;

            // Calculate the time span of the arrangement process
            arrangementTimeSpan = new TimeSpan(endArrangementTimeStamp - startArrangementTimeStamp);

            // Calculate the required rows (with respect to the count of childs marked for deletion)
            var countOfChildsMarkedForDeletion = internalChildCollection.Count(item => item.IsMarkedForDeletion);

            // (Centigrade IW) not used because the calculation is wrong, when the panel is resized to fullscreen
            var requiredRows = (internalChildCollection.Count - countOfChildsMarkedForDeletion) / ColumnCount + 1;

            //If we need more rows ...
            if (requiredRows > RowCount)
            {
                // ... increase the RowCount ...
                RowCount += requiredRows - RowCount;
                // ... and adjust the height of the panel itself
                this.Height = requiredRows * slotHeight;
                changeOfPanelHeightInProgress = true;
            }

            // Fill all the space given
            return(finalSize);
        }