public void CreateFlashStoryBoard(TimeSpan interval)
        {
            flashStoryboard = new Storyboard();
            ObjectAnimationUsingKeyFrames animation = new ObjectAnimationUsingKeyFrames();
            Storyboard.SetTarget(animation, image);
            Storyboard.SetTargetProperty(animation, new PropertyPath(Control.VisibilityProperty));

            TimeSpan currentInterval = TimeSpan.FromMilliseconds(0);
            ObjectKeyFrame keyFrameVisible = new DiscreteObjectKeyFrame();
            keyFrameVisible.Value = Visibility.Visible;
            keyFrameVisible.KeyTime = currentInterval;

            animation.KeyFrames.Add(keyFrameVisible);
            currentInterval = currentInterval.Add(interval);

            ObjectKeyFrame keyFrameHidden = new DiscreteObjectKeyFrame();
            keyFrameHidden.Value = Visibility.Hidden;
            keyFrameHidden.KeyTime = currentInterval;

            animation.KeyFrames.Add(keyFrameHidden);
            currentInterval = currentInterval.Add(interval);

            flashStoryboard.RepeatBehavior = RepeatBehavior.Forever;
            flashStoryboard.AutoReverse = true;
            flashStoryboard.Children.Add(animation);
        }
        public void AnimateImage(IEnumerable<string> imageNames, TimeSpan interval)
        {
            var storyboard = new Storyboard
            {
                RepeatBehavior = RepeatBehavior.Forever
            };

            var animation = new ObjectAnimationUsingKeyFrames();
            Storyboard.SetTarget(animation, this);
            Storyboard.SetTargetProperty(animation, new PropertyPath("Background"));

            var currentInterval = TimeSpan.FromMilliseconds(0);
            foreach (var imageName in imageNames)
            {
                var keyFrame = new DiscreteObjectKeyFrame
                {
                    Value = CreateImageFromAssets(imageName),
                    KeyTime = currentInterval
                };
                animation.KeyFrames.Add(keyFrame);
                currentInterval = currentInterval.Add(interval);
            }

            storyboard.Children.Add(animation);

            storyboard.Begin();
        }
Пример #3
0
        public void StartFlapping(TimeSpan interval)
        {
            List<string> imageNames = new List<string>() {
            "Bee animation 1.png", "Bee animation 2.png", "Bee animation 3.png", "Bee animation 4.png"
        };

            Storyboard storyboard = new Storyboard();
            ObjectAnimationUsingKeyFrames animation = new ObjectAnimationUsingKeyFrames();
            Storyboard.SetTarget(animation, image);
            Storyboard.SetTargetProperty(animation, new PropertyPath("Source"));

            TimeSpan currentInteval = TimeSpan.FromMilliseconds(0);
            foreach (string imageName in imageNames)
            {
                ObjectKeyFrame keyFrame = new DiscreteObjectKeyFrame();
                keyFrame.Value = CreateImageFromAssets(imageName);
                keyFrame.KeyTime = currentInteval;
                animation.KeyFrames.Add(keyFrame);
                currentInteval = currentInteval.Add(interval);
            }

            storyboard.RepeatBehavior = RepeatBehavior.Forever;
            storyboard.AutoReverse = true;
            storyboard.Children.Add(animation);
            storyboard.Begin();
        }
Пример #4
0
 private static ObjectKeyFrame CreateColorKeyFrmas(KeyFrames<Object> Model)
 {
     ObjectKeyFrame frame = null;
     switch (Model.Type)
     {
         case KeyFramesType.Spline: break;
         case KeyFramesType.Linear: break;
         case KeyFramesType.Easing: break;
         case KeyFramesType.Discrete: frame = new DiscreteObjectKeyFrame(); break;
         default: break;
     }
     frame.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(Model.KeyTime));
     frame.Value = Model.Value;
     return frame;
 }
Пример #5
0
        public void StartAnimation(IEnumerable<string> imageNames, TimeSpan interval)
        {
            Storyboard storyboard = new Storyboard();
            ObjectAnimationUsingKeyFrames animation = new ObjectAnimationUsingKeyFrames();
            Storyboard.SetTarget(animation, image);
            Storyboard.SetTargetProperty(animation, new PropertyPath(Image.SourceProperty));

            TimeSpan currentInterval = TimeSpan.FromMilliseconds(0);
            foreach (string imageName in imageNames)
            {
                ObjectKeyFrame keyFrame = new DiscreteObjectKeyFrame();
                keyFrame.Value = CreateImageFromAssets(imageName);
                keyFrame.KeyTime = currentInterval;
                animation.KeyFrames.Add(keyFrame);
                currentInterval = currentInterval.Add(interval);
            }

            storyboard.RepeatBehavior = RepeatBehavior.Forever;
            storyboard.AutoReverse = true;
            storyboard.Children.Add(animation);
            storyboard.Begin();
        }
Пример #6
0
        protected override Storyboard CreateStoryboard(FrameworkElement target)
        {
            Storyboard storyboard = new Storyboard();
            ObjectAnimationUsingKeyFrames animation = new ObjectAnimationUsingKeyFrames();
            Debugger.Log(1,"",animation.KeyFrames.ToString());
            DiscreteObjectKeyFrame keyFrame =  new DiscreteObjectKeyFrame();
            KeyTime keyTime = KeyTime.FromTimeSpan(new TimeSpan(0));
            keyFrame.KeyTime = keyTime;
            keyFrame.Value=Visibility.Visible;

            DiscreteObjectKeyFrame keyFrame2 = new DiscreteObjectKeyFrame();
            KeyTime keyTime2 = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(250));
            keyFrame2.KeyTime = keyTime2;
            keyFrame2.Value=Visibility.Collapsed;

            animation.KeyFrames.Add(keyFrame);
            animation.KeyFrames.Add(keyFrame2);
            animation.SpeedRatio = Speed;
            storyboard.Children.Add(animation);
            Storyboard.SetTarget(animation, target);
            Storyboard.SetTargetProperty(animation, new PropertyPath(Image.VisibilityProperty));
            return storyboard;
        }
        public static void ShowHidePrincipal(Window window, string target, EventHandler OnComplete, Visibility visibility)
        {
            int seconds = 1;
            Storyboard storyboard = new Storyboard();
            TimeSpan time = new TimeSpan(0, 0, seconds);

            DoubleAnimation animationFade = new DoubleAnimation(
                visibility == Visibility.Hidden ? 0 : 1,
                new Duration(time));
            Storyboard.SetTargetName(animationFade, target);
            Storyboard.SetTargetProperty(animationFade, new PropertyPath(Frame.OpacityProperty));

            ObjectAnimationUsingKeyFrames animationHide = new ObjectAnimationUsingKeyFrames();
            ObjectKeyFrame hideFrame = new DiscreteObjectKeyFrame(visibility, KeyTime.FromTimeSpan(time));
            animationHide.KeyFrames.Add(hideFrame);
            Storyboard.SetTargetName(animationHide, target);
            Storyboard.SetTargetProperty(animationHide, new PropertyPath(Frame.VisibilityProperty));

            storyboard.Children.Add(animationFade);
            storyboard.Children.Add(animationHide);
            storyboard.Completed += OnComplete;
            
            storyboard.Begin(window);
        }
        public Task StopAsync()
        {
            TaskCompletionSource<object> tcs = new TaskCompletionSource<object>();

            if (_Running != true)
            {
                tcs.SetResult(null);
                return tcs.Task;
            }

            Storyboard SB = new Storyboard();

            _Running = false;

            double cangle = RotateTransform.Angle;

            int Nb = (int)Math.Round((360 - cangle) / 45) + 1;

            DoubleAnimationUsingKeyFrames dauk = new DoubleAnimationUsingKeyFrames();
            for (int i = 0; i < 17; i++)
            {
                DiscreteDoubleKeyFrame first = new DiscreteDoubleKeyFrame(cangle + 45 * i, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(i * Frequency)));
                dauk.KeyFrames.Add(first);
            }
            Storyboard.SetTarget(dauk, VB);
            Storyboard.SetTargetProperty(dauk, new PropertyPath("(RenderTransform).(RotateTransform.Angle)"));
            SB.Children.Add(dauk);

            for (int i = 0; i < 8; i++)
            {
                ObjectAnimationUsingKeyFrames oauk = new ObjectAnimationUsingKeyFrames();

                oauk.RepeatBehavior = new RepeatBehavior(1);

                DiscreteObjectKeyFrame first = new DiscreteObjectKeyFrame(Visibility.Visible, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(Frequency * Nb)));
                oauk.KeyFrames.Add(first);
                DiscreteObjectKeyFrame first_1 = new DiscreteObjectKeyFrame(Visibility.Collapsed, KeyTime.FromTimeSpan(TimeSpan.FromSeconds((i + Nb) * Frequency)));
                oauk.KeyFrames.Add(first_1);
                DiscreteObjectKeyFrame second = new DiscreteObjectKeyFrame(Visibility.Collapsed, KeyTime.FromTimeSpan(TimeSpan.FromSeconds((i + Nb) * Frequency)));
                oauk.KeyFrames.Add(second);

                Storyboard.SetTarget(oauk, this.FindName(string.Format("E{0}", i)) as DependencyObject);
                Storyboard.SetTargetProperty(oauk, new PropertyPath("Visibility"));

                SB.Children.Add(oauk);
            }

            _SB.Stop();
           
            EventHandler handler = null;
            handler = delegate
            {
                SB.Completed -= handler;
                tcs.SetResult(null);
            };
            SB.Completed += handler;
            SB.Begin();

            return tcs.Task;
        }
        private void Root_Loaded(object sender, RoutedEventArgs e)
        {
            _SB = new Storyboard();

            DoubleAnimationUsingKeyFrames dauk = new DoubleAnimationUsingKeyFrames();
            dauk.RepeatBehavior = RepeatBehavior.Forever;
            for (int i = 0; i < 9; i++)
            {
                DiscreteDoubleKeyFrame first = new DiscreteDoubleKeyFrame(45 * i, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(i * Frequency)));
                dauk.KeyFrames.Add(first);
            }
            Storyboard.SetTarget(dauk, VB);
            Storyboard.SetTargetProperty(dauk, new PropertyPath("(RenderTransform).(RotateTransform.Angle)"));
            _SB.Children.Add(dauk);



            for (int i = 1; i < 8; i++)
            {
                ObjectAnimationUsingKeyFrames oauk = new ObjectAnimationUsingKeyFrames();

                oauk.RepeatBehavior = new RepeatBehavior(1);

                DiscreteObjectKeyFrame first = new DiscreteObjectKeyFrame(Visibility.Collapsed, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0)));
                oauk.KeyFrames.Add(first);
                DiscreteObjectKeyFrame first_1 = new DiscreteObjectKeyFrame(Visibility.Collapsed, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(i * Frequency)));
                oauk.KeyFrames.Add(first_1);
                DiscreteObjectKeyFrame second = new DiscreteObjectKeyFrame(Visibility.Visible, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(i * Frequency)));
                oauk.KeyFrames.Add(second);

                Storyboard.SetTarget(oauk, this.FindName(string.Format("E{0}", i)) as DependencyObject);
                Storyboard.SetTargetProperty(oauk, new PropertyPath("Visibility"));

                _SB.Children.Add(oauk);
            }

            Start();
        }
Пример #10
0
        /// <summary>
        /// Adding of animations for each TourEvent during loading of tourDict --> tourStoryboard
        /// </summary>
        /// <param name="tourParallelTL"></param>
        /// <param name="tourEvent"></param>
        /// <param name="timerCount"></param>
        public void addAnim(TourParallelTL tourParallelTL, TourEvent tourEvent, double timerCount)
        {
            switch (tourEvent.type)
            {
                case TourEvent.Type.fadeInMedia:
                    FadeInMediaEvent fadeInMediaEvent = (FadeInMediaEvent)tourEvent;

                    // used to use MSI points, but now using screen points -- see artwork mode documentation in Google Doc
                    Point mediaPoint = new Point();
                    mediaPoint.X = fadeInMediaEvent.fadeInMediaToScreenPointX;
                    mediaPoint.Y = fadeInMediaEvent.fadeInMediaToScreenPointY;

                    double initialScale = fadeInMediaEvent.absoluteScale;

                    DockableItem fadeInMediaItem = fadeInMediaEvent.media;
                    fadeInMediaItem.ApplyAnimationClock(DockableItem.CenterProperty, null);
                    fadeInMediaItem.Center = mediaPoint;
                    fadeInMediaItem.Width = fadeInMediaItem.image.Source.Width * initialScale;
                    fadeInMediaItem.Height = fadeInMediaItem.image.Source.Height * initialScale;
                    fadeInMediaItem.Orientation = 0;

                    DoubleAnimation fadeInMediaWidth = new DoubleAnimation(fadeInMediaItem.Width, fadeInMediaItem.Width, new Duration(TimeSpan.FromSeconds(0.0)));
                    Storyboard.SetTarget(fadeInMediaWidth, fadeInMediaItem);
                    Storyboard.SetTargetProperty(fadeInMediaWidth, new PropertyPath(DockableItem.WidthProperty));
                    fadeInMediaWidth.BeginTime = TimeSpan.FromSeconds(timerCount);
                    tourParallelTL.Children.Add(fadeInMediaWidth);

                    DoubleAnimation fadeInMediaHeight = new DoubleAnimation(fadeInMediaItem.Height, fadeInMediaItem.Height, new Duration(TimeSpan.FromSeconds(0.0)));
                    Storyboard.SetTarget(fadeInMediaHeight, fadeInMediaItem);
                    Storyboard.SetTargetProperty(fadeInMediaHeight, new PropertyPath(DockableItem.HeightProperty));
                    fadeInMediaHeight.BeginTime = TimeSpan.FromSeconds(timerCount);
                    tourParallelTL.Children.Add(fadeInMediaHeight);

                    PointAnimation fadeInMediaCenter = new PointAnimation(fadeInMediaItem.Center, fadeInMediaItem.Center, new Duration(TimeSpan.FromSeconds(0.0)));
                    Storyboard.SetTarget(fadeInMediaCenter, fadeInMediaItem);
                    Storyboard.SetTargetProperty(fadeInMediaCenter, new PropertyPath(DockableItem.CenterProperty));
                    fadeInMediaCenter.BeginTime = TimeSpan.FromSeconds(timerCount);
                    tourParallelTL.Children.Add(fadeInMediaCenter);

                    ObjectAnimationUsingKeyFrames fadeInMediaAnim_vis = new ObjectAnimationUsingKeyFrames();
                    fadeInMediaAnim_vis.Duration = new TimeSpan(0, 0, 0);
                    DiscreteObjectKeyFrame fadeInMediaAnim_vis_kf1 = new DiscreteObjectKeyFrame(Visibility.Visible, new TimeSpan(0, 0, 0));
                    fadeInMediaAnim_vis.KeyFrames.Add(fadeInMediaAnim_vis_kf1);
                    Storyboard.SetTarget(fadeInMediaAnim_vis, fadeInMediaItem);
                    Storyboard.SetTargetProperty(fadeInMediaAnim_vis, new PropertyPath(DockableItem.VisibilityProperty));
                    fadeInMediaAnim_vis.BeginTime = TimeSpan.FromSeconds(timerCount);
                    tourParallelTL.Children.Add(fadeInMediaAnim_vis);

                    DoubleAnimation fadeInMediaAnim = new DoubleAnimation(0.0, 1.0, new Duration(TimeSpan.FromSeconds(fadeInMediaEvent.duration)));
                    Storyboard.SetTarget(fadeInMediaAnim, fadeInMediaItem);
                    Storyboard.SetTargetProperty(fadeInMediaAnim, new PropertyPath(DockableItem.OpacityProperty));
                    fadeInMediaAnim.BeginTime = TimeSpan.FromSeconds(timerCount);
                    tourParallelTL.Children.Add(fadeInMediaAnim);

                    break;

                case TourEvent.Type.fadeOutMedia:
                    FadeOutMediaEvent fadeOutMediaEvent = (FadeOutMediaEvent)tourEvent;

                    DockableItem fadeOutMediaItem = fadeOutMediaEvent.media;
                    fadeOutMediaItem.ApplyAnimationClock(DockableItem.CenterProperty, null);
                    DoubleAnimation fadeOutMediaAnim = new DoubleAnimation(1.0, 0.0, new Duration(TimeSpan.FromSeconds(fadeOutMediaEvent.duration)));
                    Storyboard.SetTarget(fadeOutMediaAnim, fadeOutMediaItem);
                    Storyboard.SetTargetProperty(fadeOutMediaAnim, new PropertyPath(DockableItem.OpacityProperty));
                    fadeOutMediaAnim.BeginTime = TimeSpan.FromSeconds(timerCount);
                    tourParallelTL.Children.Add(fadeOutMediaAnim);

                    ObjectAnimationUsingKeyFrames fadeOutMediaAnim_vis = new ObjectAnimationUsingKeyFrames();
                    fadeOutMediaAnim_vis.Duration = new TimeSpan(0, 0, 0);
                    DiscreteObjectKeyFrame fadeOutMediaAnim_vis_kf1 = new DiscreteObjectKeyFrame(Visibility.Hidden, new TimeSpan(0, 0, 0));
                    fadeOutMediaAnim_vis.KeyFrames.Add(fadeOutMediaAnim_vis_kf1);
                    Storyboard.SetTarget(fadeOutMediaAnim_vis, fadeOutMediaItem);
                    Storyboard.SetTargetProperty(fadeOutMediaAnim_vis, new PropertyPath(DockableItem.VisibilityProperty));
                    fadeOutMediaAnim_vis.BeginTime = TimeSpan.FromSeconds(timerCount + fadeOutMediaEvent.duration);
                    tourParallelTL.Children.Add(fadeOutMediaAnim_vis);

                    break;
                case TourEvent.Type.zoomMedia:
                    ZoomMediaEvent zoomMediaEvent = (ZoomMediaEvent)tourEvent;

                    DockableItem zoomMediaItem = zoomMediaEvent.media;
                    zoomMediaItem.ApplyAnimationClock(DockableItem.CenterProperty, null);
                    double targetMediaScale = zoomMediaEvent.absoluteScale;

                    DoubleAnimation zoomWidth = new DoubleAnimation(zoomMediaItem.image.Source.Width * targetMediaScale, new Duration(TimeSpan.FromSeconds(zoomMediaEvent.duration)));
                    Storyboard.SetTarget(zoomWidth, zoomMediaItem);
                    Storyboard.SetTargetProperty(zoomWidth, new PropertyPath(DockableItem.WidthProperty));
                    zoomWidth.BeginTime = TimeSpan.FromSeconds(timerCount);
                    tourParallelTL.Children.Add(zoomWidth);

                    DoubleAnimation zoomHeight = new DoubleAnimation(zoomMediaItem.image.Source.Height * targetMediaScale, new Duration(TimeSpan.FromSeconds(zoomMediaEvent.duration)));
                    Storyboard.SetTarget(zoomHeight, zoomMediaItem);
                    Storyboard.SetTargetProperty(zoomHeight, new PropertyPath(DockableItem.HeightProperty));
                    zoomHeight.BeginTime = TimeSpan.FromSeconds(timerCount);
                    tourParallelTL.Children.Add(zoomHeight);

                    // used to use MSI points, but now using screen points -- see artwork mode documentation in Google Doc
                    Point zoomEndPoint = new Point();
                    zoomEndPoint.X = zoomMediaEvent.zoomMediaToScreenPointX;
                    zoomEndPoint.Y = zoomMediaEvent.zoomMediaToScreenPointY;

                    PointAnimation zoomMediaPan = new PointAnimation(zoomEndPoint, new Duration(TimeSpan.FromSeconds(zoomMediaEvent.duration)), FillBehavior.HoldEnd);
                    Storyboard.SetTarget(zoomMediaPan, zoomMediaItem);
                    Storyboard.SetTargetProperty(zoomMediaPan, new PropertyPath(DockableItem.CenterProperty));
                    zoomMediaPan.BeginTime = TimeSpan.FromSeconds(timerCount);
                    tourParallelTL.Children.Add(zoomMediaPan);

                    break;
                case TourEvent.Type.zoomMSI:
                    ZoomMSIEvent zoomMSIEvent = (ZoomMSIEvent)tourEvent;

                    double targetMSIScale = zoomMSIEvent.absoluteScale;

                    Point zoomToMSIPoint = new Point(zoomMSIEvent.zoomToMSIPointX, zoomMSIEvent.zoomToMSIPointY);

                    // new
                    ZoomableCanvas zoomMSI_canvas = zoomMSIEvent.msi.GetZoomableCanvas;
                    targetMSIScale = zoomMSIEvent.msi.ClampTargetScale(targetMSIScale);

                    Point targetOffset = new Point(zoomToMSIPoint.X, zoomToMSIPoint.Y);

                    PointAnimation zoomMSI_pan = new PointAnimation(targetOffset, new Duration(TimeSpan.FromSeconds(zoomMSIEvent.duration)));
                    Storyboard.SetTarget(zoomMSI_pan, zoomMSI_canvas);
                    Storyboard.SetTargetProperty(zoomMSI_pan, new PropertyPath(ZoomableCanvas.OffsetProperty));
                    zoomMSI_pan.BeginTime = TimeSpan.FromSeconds(timerCount);
                    tourParallelTL.Children.Add(zoomMSI_pan);

                    DoubleAnimation zoomMSI_scale = new DoubleAnimation(targetMSIScale, new Duration(TimeSpan.FromSeconds(zoomMSIEvent.duration)));
                    zoomMSI_scale.CurrentStateInvalidated += new EventHandler(ZoomMSI_scale_CurrentStateInvalidated);
                    Storyboard.SetTarget(zoomMSI_scale, zoomMSI_canvas);
                    Storyboard.SetTargetProperty(zoomMSI_scale, new PropertyPath(ZoomableCanvas.ScaleProperty));
                    zoomMSI_scale.BeginTime = TimeSpan.FromSeconds(timerCount);
                    tourParallelTL.Children.Add(zoomMSI_scale);

                    break;
                case TourEvent.Type.fadeInPath:
                    FadeInPathEvent fadeInPathEvent = (FadeInPathEvent)tourEvent;

                    // used to use MSI points, but now using screen points -- see artwork mode documentation in Google Doc

                    SurfaceInkCanvas fadeInPathItem = fadeInPathEvent.inkCanvas;
                    fadeInPathItem.Opacity = 0.0;

                    ObjectAnimationUsingKeyFrames fadeInPathAnim_vis = new ObjectAnimationUsingKeyFrames();
                    fadeInPathAnim_vis.Duration = new TimeSpan(0, 0, 0);
                    DiscreteObjectKeyFrame fadeInPathAnim_vis_kf1 = new DiscreteObjectKeyFrame(Visibility.Visible, new TimeSpan(0, 0, 0));
                    fadeInPathAnim_vis.KeyFrames.Add(fadeInPathAnim_vis_kf1);
                    Storyboard.SetTarget(fadeInPathAnim_vis, fadeInPathItem);
                    Storyboard.SetTargetProperty(fadeInPathAnim_vis, new PropertyPath(DockableItem.VisibilityProperty));
                    fadeInPathAnim_vis.BeginTime = TimeSpan.FromSeconds(timerCount);
                    tourParallelTL.Children.Add(fadeInPathAnim_vis);
                    fadeInPathAnim_vis.FillBehavior = FillBehavior.Stop;

                    DoubleAnimation fadeInPathAnim = new DoubleAnimation(0.0, 1.0, new Duration(TimeSpan.FromSeconds(fadeInPathEvent.duration)));
                    Storyboard.SetTarget(fadeInPathAnim, fadeInPathItem);
                    Storyboard.SetTargetProperty(fadeInPathAnim, new PropertyPath(DockableItem.OpacityProperty));
                    fadeInPathAnim.BeginTime = TimeSpan.FromSeconds(timerCount);
                    tourParallelTL.Children.Add(fadeInPathAnim);
                    //fadeInPathAnim.FillBehavior = FillBehavior.Stop;

                    break;
                case TourEvent.Type.fadeOutPath:
                    FadeOutPathEvent fadeOutPathEvent = (FadeOutPathEvent)tourEvent;

                    SurfaceInkCanvas fadeOutPathItem = fadeOutPathEvent.inkCanvas;
                    DoubleAnimation fadeOutPathAnim = new DoubleAnimation(1.0, 0.0, new Duration(TimeSpan.FromSeconds(fadeOutPathEvent.duration)));
                    Storyboard.SetTarget(fadeOutPathAnim, fadeOutPathItem);
                    Storyboard.SetTargetProperty(fadeOutPathAnim, new PropertyPath(DockableItem.OpacityProperty));
                    fadeOutPathAnim.BeginTime = TimeSpan.FromSeconds(timerCount);
                    tourParallelTL.Children.Add(fadeOutPathAnim);

                    ObjectAnimationUsingKeyFrames fadeOutPathAnim_vis = new ObjectAnimationUsingKeyFrames();
                    fadeOutPathAnim_vis.Duration = new TimeSpan(0, 0, 0);
                    DiscreteObjectKeyFrame fadeOutPathAnim_vis_kf1 = new DiscreteObjectKeyFrame(Visibility.Hidden, new TimeSpan(0, 0, 0));
                    fadeOutPathAnim_vis.KeyFrames.Add(fadeOutPathAnim_vis_kf1);
                    Storyboard.SetTarget(fadeOutPathAnim_vis, fadeOutPathItem);
                    Storyboard.SetTargetProperty(fadeOutPathAnim_vis, new PropertyPath(DockableItem.VisibilityProperty));
                    fadeOutPathAnim_vis.BeginTime = TimeSpan.FromSeconds(timerCount + fadeOutPathEvent.duration);
                    tourParallelTL.Children.Add(fadeOutPathAnim_vis);

                    break;

                case TourEvent.Type.fadeInHighlight:

                    FadeInHighlightEvent fadeInHighlightEvent = (FadeInHighlightEvent)tourEvent;

                    // used to use MSI points, but now using screen points -- see artwork mode documentation in Google Doc

                    SurfaceInkCanvas fadeInHighlightItem = fadeInHighlightEvent.inkCanvas;
                    fadeInHighlightItem.Opacity = 0.0;

                    ObjectAnimationUsingKeyFrames fadeInHighlightAnim_vis = new ObjectAnimationUsingKeyFrames();
                    fadeInHighlightAnim_vis.Duration = new TimeSpan(0, 0, 0);
                    DiscreteObjectKeyFrame fadeInHighlightAnim_vis_kf1 = new DiscreteObjectKeyFrame(Visibility.Visible, new TimeSpan(0, 0, 0));
                    fadeInHighlightAnim_vis.KeyFrames.Add(fadeInHighlightAnim_vis_kf1);
                    Storyboard.SetTarget(fadeInHighlightAnim_vis, fadeInHighlightItem);
                    Storyboard.SetTargetProperty(fadeInHighlightAnim_vis, new PropertyPath(DockableItem.VisibilityProperty));
                    fadeInHighlightAnim_vis.BeginTime = TimeSpan.FromSeconds(timerCount);
                    tourParallelTL.Children.Add(fadeInHighlightAnim_vis);
                    fadeInHighlightAnim_vis.FillBehavior = FillBehavior.Stop;

                    DoubleAnimation fadeInHighlightAnim = new DoubleAnimation(0.0, fadeInHighlightEvent.opacity, new Duration(TimeSpan.FromSeconds(fadeInHighlightEvent.duration)));
                    Storyboard.SetTarget(fadeInHighlightAnim, fadeInHighlightItem);
                    Storyboard.SetTargetProperty(fadeInHighlightAnim, new PropertyPath(DockableItem.OpacityProperty));
                    fadeInHighlightAnim.BeginTime = TimeSpan.FromSeconds(timerCount);
                    tourParallelTL.Children.Add(fadeInHighlightAnim);

                    break;
                case TourEvent.Type.fadeOutHighlight:
                    FadeOutHighlightEvent fadeOutHighlightEvent = (FadeOutHighlightEvent)tourEvent;

                    SurfaceInkCanvas fadeOutHighlightItem = fadeOutHighlightEvent.inkCanvas;
                    DoubleAnimation fadeOutHighlightAnim = new DoubleAnimation(fadeOutHighlightEvent.opacity, 0.0, new Duration(TimeSpan.FromSeconds(fadeOutHighlightEvent.duration)));
                    Storyboard.SetTarget(fadeOutHighlightAnim, fadeOutHighlightItem);
                    Storyboard.SetTargetProperty(fadeOutHighlightAnim, new PropertyPath(DockableItem.OpacityProperty));
                    fadeOutHighlightAnim.BeginTime = TimeSpan.FromSeconds(timerCount);
                    tourParallelTL.Children.Add(fadeOutHighlightAnim);

                    ObjectAnimationUsingKeyFrames fadeOutHighlightAnim_vis = new ObjectAnimationUsingKeyFrames();
                    fadeOutHighlightAnim_vis.Duration = new TimeSpan(0, 0, 0);
                    DiscreteObjectKeyFrame fadeOutHighlightAnim_vis_kf1 = new DiscreteObjectKeyFrame(Visibility.Hidden, new TimeSpan(0, 0, 0));
                    fadeOutHighlightAnim_vis.KeyFrames.Add(fadeOutHighlightAnim_vis_kf1);
                    Storyboard.SetTarget(fadeOutHighlightAnim_vis, fadeOutHighlightItem);
                    Storyboard.SetTargetProperty(fadeOutHighlightAnim_vis, new PropertyPath(DockableItem.VisibilityProperty));
                    fadeOutHighlightAnim_vis.BeginTime = TimeSpan.FromSeconds(timerCount + fadeOutHighlightEvent.duration);
                    tourParallelTL.Children.Add(fadeOutHighlightAnim_vis);

                    break;
                default:
                    break;
            }
        }
        public void OpenData(string filename, int number)
        {
            // JSON読み込み
            var wc = new WebClient();
            wc.OpenReadCompleted += (_s, _e) =>
            {
                if (_e.Error == null)
                {
                    // JSONファイルをMediaクラスのインスタンスに逆シリアル化
                    var ser = new DataContractJsonSerializer(typeof(MediaData.Media));
                    try
                    {
                        MediaData.media.Add((MediaData.Media)ser.ReadObject(_e.Result));
                        debugTextBox.Text = string.Empty;
                    }
                    catch
                    {
                        debugTextBox.Text = "JSONファイルの記述に誤りがあります.:" + filename;
                        return;
                    }

                    // 動画ソースへ
                    var movieSet = new MediaData.MovieSet();
                    movieSet.viewList = new Dictionary<string, AdaptMediaPlayer.Controls.MediaPlayer>();
                    movieSet.playerPosition = number;

                    for (var urlPos = 0; urlPos < MediaData.media[MediaData.media.Count - 1].video.Count; urlPos++)
                    {
                        var player = new Controls.MediaPlayer();

                        player.sb = new Storyboard
                        {
                            Duration = TimeSpan.FromMinutes(30) // 時間は適当
                        };

                        // Mediaとひも付け
                        player.media = MediaData.media[MediaData.media.Count - 1];

                        player.movie.Source = new Uri(MediaData.baseUri, player.media.video[urlPos].url);
                        player.title.Text = player.media.title;
                        player.movie_index = MediaData.media.Count - 1;
                        player.Margin = new Thickness(8, 8, 0, 0);
                        Canvas.SetLeft(player, 340 * number);
                        Canvas.SetTop(player, 0);

                        // JSONからアニメーションを生成
                        // rectangle編
                        foreach (var value in player.media.video[0].rectangle) // 決め打ち
                        {
                            // 四角を作る
                            var rect = new Rectangle
                            {
                                Height = value.height[0],
                                Width = value.width[0],
                                Stroke = new SolidColorBrush(TransColor(value.color)),
                                StrokeThickness = 2,
                                Visibility = Visibility.Collapsed
                            };
                            Canvas.SetLeft(rect, value.left[0]);
                            Canvas.SetTop(rect, value.top[0]);

                            player.anime.Children.Add(rect);

                            // アニメの定義
                            var anim = new ObjectAnimationUsingKeyFrames();

                            // 四角を出す
                            var frame1 = new DiscreteObjectKeyFrame();
                            frame1.KeyTime = TimeSpan.Zero;
                            frame1.Value = Visibility.Visible;

                            // 四角を消す
                            var frame2 = new DiscreteObjectKeyFrame();
                            frame2.KeyTime = TimeSpan.Parse(value.time[value.time.Count - 1]) - TimeSpan.Parse(value.time[0]);
                            frame2.Value = Visibility.Collapsed;

                            anim.KeyFrames.Add(frame1);
                            anim.KeyFrames.Add(frame2);

                            anim.BeginTime = TimeSpan.Parse(value.time[0]);

                            // Storyboardの定義
                            player.sb.Children.Add(anim);
                            Storyboard.SetTarget(anim, rect);
                            Storyboard.SetTargetProperty(anim, new PropertyPath(VisibilityProperty));

                            // 長方形の変形・移動を設定する
                            if (value.height.Count >= 2)
                            {
                                var animeHeight = new DoubleAnimationUsingKeyFrames();
                                var animeWidth = new DoubleAnimationUsingKeyFrames();
                                var animeLeft = new DoubleAnimationUsingKeyFrames();
                                var animeTop = new DoubleAnimationUsingKeyFrames();

                                for (var i = 1; i < value.time.Count; i++)
                                {
                                    // 四角の変形 : Height
                                    var animeHeightKeyFrame = new LinearDoubleKeyFrame
                                    {
                                        KeyTime = TimeSpan.Parse(value.time[i]),
                                        Value = value.height[i]
                                    };
                                    animeHeight.KeyFrames.Add(animeHeightKeyFrame);

                                    // 四角の変形 : Width
                                    var animeWidthKeyFrame = new LinearDoubleKeyFrame
                                    {
                                        KeyTime = TimeSpan.Parse(value.time[i]),
                                        Value = value.width[i]
                                    };
                                    animeWidth.KeyFrames.Add(animeWidthKeyFrame);

                                    // 四角の移動 : Left
                                    var animeLeftKeyFrame = new LinearDoubleKeyFrame
                                    {
                                        KeyTime = TimeSpan.Parse(value.time[i]),
                                        Value = value.left[i]
                                    };
                                    animeLeft.KeyFrames.Add(animeLeftKeyFrame);

                                    // 四角の移動 : Top
                                    var animeTopKeyFrame = new LinearDoubleKeyFrame
                                    {
                                        KeyTime = TimeSpan.Parse(value.time[i]),
                                        Value = value.top[i]
                                    };
                                    animeTop.KeyFrames.Add(animeTopKeyFrame);
                                }
                                player.sb.Children.Add(animeHeight);
                                Storyboard.SetTarget(animeHeight, rect);
                                Storyboard.SetTargetProperty(animeHeight, new PropertyPath(Rectangle.HeightProperty));

                                player.sb.Children.Add(animeWidth);
                                Storyboard.SetTarget(animeWidth, rect);
                                Storyboard.SetTargetProperty(animeWidth, new PropertyPath(Rectangle.WidthProperty));

                                player.sb.Children.Add(animeLeft);
                                Storyboard.SetTarget(animeLeft, rect);
                                Storyboard.SetTargetProperty(animeLeft, new PropertyPath(Canvas.LeftProperty));

                                player.sb.Children.Add(animeTop);
                                Storyboard.SetTarget(animeTop, rect);
                                Storyboard.SetTargetProperty(animeTop, new PropertyPath(Canvas.TopProperty));
                            }
                        }

                        // text編
                        foreach (var value in player.media.video[0].text) // 決め打ち
                        {
                            // テキストを作る
                            var str = new TextBlock
                            {
                                Text = value.text,
                                FontSize = 18,
                                Foreground = new SolidColorBrush(TransColor(value.color)),
                                Visibility = Visibility.Collapsed
                            };
                            Canvas.SetLeft(str, value.left[0]);
                            Canvas.SetTop(str, value.top[0]);

                            player.anime.Children.Add(str);

                            // アニメの定義
                            var anim = new ObjectAnimationUsingKeyFrames();

                            // テキストを出す
                            var frame1 = new DiscreteObjectKeyFrame();
                            frame1.KeyTime = TimeSpan.Zero;
                            frame1.Value = Visibility.Visible;

                            // テキストを消す
                            var frame2 = new DiscreteObjectKeyFrame();
                            frame2.KeyTime = TimeSpan.Parse(value.time[1]) - TimeSpan.Parse(value.time[0]);
                            frame2.Value = Visibility.Collapsed;

                            anim.KeyFrames.Add(frame1);
                            anim.KeyFrames.Add(frame2);

                            anim.BeginTime = TimeSpan.Parse(value.time[0]);

                            // Storyboardの定義
                            player.sb.Children.Add(anim);
                            Storyboard.SetTarget(anim, str);
                            Storyboard.SetTargetProperty(anim, new PropertyPath(VisibilityProperty));
                        }

                        // プレイヤーを追加
                        playerArea.Children.Add(player);

                        // 最初に表示するプレイヤーを決定
                        movieSet.viewList.Add(player.media.video[urlPos].viewpoint, player);
                        if (urlPos == 0)
                        {
                            movieSet.currentPlayer = player;
                        }
                        else
                        {
                            player.Visibility = Visibility.Collapsed;
                        }
                    }
                    MediaData.movieList.Add(movieSet);

                    // カメラ切替ボタン生成
                    if (MediaData.media.Count == 1)
                    {
                        foreach (var value in MediaData.media[0].video) // 決め打ち
                        {
                            var buttonChange = new Button
                            {
                                Content = value.viewpoint,
                                FontSize = 18,
                                Width = 80
                            };
                            Canvas.SetTop(buttonChange, 35 * MediaData.media[0].video.IndexOf(value)); // 決め打ち
                            buttonChange.Click += new RoutedEventHandler(ChangeCamera);
                            ChangeCameraArea.Children.Add(buttonChange);

                            var buttonEx = new Button
                            {
                                Content = value.viewpoint,
                                FontSize = 18,
                                Width = 80
                            };
                            Canvas.SetTop(buttonEx, 35 * (MediaData.media[0].video.IndexOf(value) + 1)); // 決め打ち
                            buttonEx.Click += new RoutedEventHandler(ExCamera);
                            ExCamaraArea.Children.Add(buttonEx);
                        }
                    }

                    // JSON変更ボタン
                    var openJsonButton = new Image
                    {
                        Source = new BitmapImage(new Uri("../image/Open.png", UriKind.Relative)),
                        Height = 24,
                        Width = 24,
                        Margin = new Thickness(8, 8, 0, 0),
                        Tag = movieSet.playerPosition
                    };
                    Canvas.SetLeft(openJsonButton, 288 + 340 * movieSet.playerPosition);
                    openJsonButton.MouseLeftButtonDown += new MouseButtonEventHandler(OpenJsonFile);
                    openFileButtonArea.Children.Add(openJsonButton);
                }
                else
                {
                    // エラー処理
                    debugTextBox.Text = _e.Error.ToString();
                }
            };
            wc.OpenReadAsync(new Uri(MediaData.baseUri, filename));
        }
Пример #12
0
        /// <summary>
        /// Adds the slide from left animation.
        /// </summary>
        /// <param name="showStoryboard">The show storyboard.</param>
        /// <param name="popupView">The popup view.</param>
        public static void AddSlideFromLeftAnimation(Storyboard showStoryboard, PopupView popupView)
        {
            //Defining Animation Attributes
            var slideFromLeftAnimation = new DoubleAnimation
            {
                To = 0,
                BeginTime = TimeSpan.Zero,
                Duration = TimeSpan.Parse("00:00:01", CultureInfo.InvariantCulture),
                EasingFunction = new ElasticEase { Oscillations = 2, Springiness = 10 },
                AutoReverse = false
            };

            var adjustBackMarginAnimation = new ObjectAnimationUsingKeyFrames();
            var keyFrame = new DiscreteObjectKeyFrame { KeyTime = TimeSpan.Zero, Value = new Thickness(0, 0, 44, 0) };
            adjustBackMarginAnimation.KeyFrames.Add(keyFrame);
            Storyboard.SetTargetProperty(adjustBackMarginAnimation, new PropertyPath("(FrameworkElement.Margin)"));

            var backBody = popupView.GetChildrenByType<Control>(c => c.Name == "BackBody").FirstOrDefault();

            if (backBody != null)
                Storyboard.SetTarget(adjustBackMarginAnimation, backBody);

            var adjustMarginAnimation = new ObjectAnimationUsingKeyFrames();
            keyFrame = new DiscreteObjectKeyFrame { KeyTime = TimeSpan.Zero, Value = new Thickness(0, 0, 44, 0) };

            adjustMarginAnimation.KeyFrames.Add(keyFrame);
            Storyboard.SetTargetProperty(adjustMarginAnimation, new PropertyPath("(FrameworkElement.Margin)"));

            var borderBody = popupView.GetChildrenByType<Border>(c => c.Name == "BorderBody").FirstOrDefault();
            if (borderBody != null)
                Storyboard.SetTarget(adjustMarginAnimation, borderBody);

            var adjustDetailsButtonAnimation = new ObjectAnimationUsingKeyFrames();
            keyFrame = new DiscreteObjectKeyFrame { KeyTime = TimeSpan.Zero, Value = new Thickness(0, 0, 44, 0) };

            adjustDetailsButtonAnimation.KeyFrames.Add(keyFrame);
            Storyboard.SetTargetProperty(adjustDetailsButtonAnimation, new PropertyPath("(FrameworkElement.Margin)"));
            var detailsButton = popupView.GetChildrenByType<StackPanel>(c => c.Name == "DetailsButton").FirstOrDefault();
            if (detailsButton != null)
                Storyboard.SetTarget(adjustDetailsButtonAnimation, detailsButton);

            var adjustBackButtonAnimation = new ObjectAnimationUsingKeyFrames();
            keyFrame = new DiscreteObjectKeyFrame { KeyTime = TimeSpan.Zero, Value = new Thickness(0, 0, 44, 0) };

            adjustBackButtonAnimation.KeyFrames.Add(keyFrame);
            Storyboard.SetTargetProperty(adjustBackButtonAnimation, new PropertyPath("(FrameworkElement.Margin)"));
            var backButton = popupView.GetChildrenByType<HyperlinkButton>(c => c.Name == "BackButton").FirstOrDefault();
            if (backButton != null)
                Storyboard.SetTarget(adjustBackButtonAnimation, backButton);

            Storyboard.SetTarget(slideFromLeftAnimation, popupView);
            Storyboard.SetTargetProperty(slideFromLeftAnimation, new PropertyPath("(FrameworkElement.RenderTransform).(CompositeTransform.TranslateX)"));

            if (showStoryboard == null)
                return;

            showStoryboard.Children.Add(slideFromLeftAnimation);
            showStoryboard.Children.Add(adjustBackMarginAnimation);
            showStoryboard.Children.Add(adjustMarginAnimation);
            showStoryboard.Children.Add(adjustDetailsButtonAnimation);
            showStoryboard.Children.Add(adjustBackButtonAnimation);
        }
        private static Storyboard CreateStoryboard(
            FrameworkElement target,
            DependencyProperty animatingDependencyProperty,
            string propertyPath,
            ref object toValue,
            TimeSpan durationTimeSpan,
            IEasingFunction easingFunction)
        {
            object fromValue = target.GetValue(animatingDependencyProperty);

            double fromDoubleValue;
            double toDoubleValue;

            DateTime fromDateTime;
            DateTime toDateTime;

            Storyboard storyBoard = new Storyboard();
            Storyboard.SetTarget(storyBoard, target);
            Storyboard.SetTargetProperty(storyBoard, new PropertyPath(propertyPath));

            if ((fromValue != null && toValue != null))
            {
                if (ValueHelper.TryConvert(fromValue, out fromDoubleValue) && ValueHelper.TryConvert(toValue, out toDoubleValue))
                {
                    DoubleAnimation doubleAnimation = new DoubleAnimation();
#if SILVERLIGHT
                    doubleAnimation.EasingFunction = easingFunction;
#endif
                    doubleAnimation.Duration = durationTimeSpan;
                    doubleAnimation.To = ValueHelper.ToDouble(toValue);
                    toValue = doubleAnimation.To;

                    storyBoard.Children.Add(doubleAnimation);
                }
                else if (ValueHelper.TryConvert(fromValue, out fromDateTime) && ValueHelper.TryConvert(toValue, out toDateTime))
                {
                    ObjectAnimationUsingKeyFrames keyFrameAnimation = new ObjectAnimationUsingKeyFrames();
                    keyFrameAnimation.Duration = durationTimeSpan;

                    long intervals = (long)(durationTimeSpan.TotalSeconds * KeyFramesPerSecond);
                    if (intervals < 2L)
                    {
                        intervals = 2L;
                    }

                    IEnumerable<TimeSpan> timeSpanIntervals =
                        ValueHelper.GetTimeSpanIntervalsInclusive(durationTimeSpan, intervals);

                    IEnumerable<DateTime> dateTimeIntervals =
                        ValueHelper.GetDateTimesBetweenInclusive(fromDateTime, toDateTime, intervals);

                    IEnumerable<DiscreteObjectKeyFrame> keyFrames =
                        EnumerableFunctions.Zip(
                            dateTimeIntervals,
                            timeSpanIntervals,
                            (dateTime, timeSpan) => new DiscreteObjectKeyFrame() { Value = dateTime, KeyTime = timeSpan });

                    foreach (DiscreteObjectKeyFrame keyFrame in keyFrames)
                    {
                        keyFrameAnimation.KeyFrames.Add(keyFrame);
                        toValue = keyFrame.Value;
                    }

                    storyBoard.Children.Add(keyFrameAnimation);
                }
            }

            if (storyBoard.Children.Count == 0)
            {
                ObjectAnimationUsingKeyFrames keyFrameAnimation = new ObjectAnimationUsingKeyFrames();
                DiscreteObjectKeyFrame endFrame = new DiscreteObjectKeyFrame() { Value = toValue, KeyTime = new TimeSpan(0, 0, 0) };
                keyFrameAnimation.KeyFrames.Add(endFrame);

                storyBoard.Children.Add(keyFrameAnimation);
            }

           return storyBoard;
        }
 private static Storyboard CreateStoryboard(this DependencyObject target, DependencyProperty animatingDependencyProperty, string propertyPath, string propertyKey, ref object toValue, TimeSpan durationTimeSpan, IEasingFunction easingFunction)
 {
     object obj = target.GetValue(animatingDependencyProperty);
     Storyboard storyboard = new Storyboard();
     Storyboard.SetTarget((DependencyObject)storyboard, target);
     Storyboard.SetTargetProperty((DependencyObject)storyboard, new PropertyPath(propertyPath, new object[0]));
     if (obj != null && toValue != null)
     {
         double doubleValue1;
         double doubleValue2;
         if (ValueHelper.TryConvert(obj, out doubleValue1) && ValueHelper.TryConvert(toValue, out doubleValue2))
         {
             DoubleAnimation doubleAnimation = new DoubleAnimation();
             doubleAnimation.Duration = (Duration)durationTimeSpan;
             doubleAnimation.To = new double?(ValueHelper.ToDouble(toValue));
             toValue = (object)doubleAnimation.To;
             storyboard.Children.Add((Timeline)doubleAnimation);
         }
         else
         {
             DateTime dateTimeValue1;
             DateTime dateTimeValue2;
             if (ValueHelper.TryConvert(obj, out dateTimeValue1) && ValueHelper.TryConvert(toValue, out dateTimeValue2))
             {
                 ObjectAnimationUsingKeyFrames animationUsingKeyFrames = new ObjectAnimationUsingKeyFrames();
                 animationUsingKeyFrames.Duration = (Duration)durationTimeSpan;
                 long count = (long)(durationTimeSpan.TotalSeconds * 20.0);
                 if (count < 2L)
                     count = 2L;
                 IEnumerable<TimeSpan> intervalsInclusive = ValueHelper.GetTimeSpanIntervalsInclusive(durationTimeSpan, count);
                 foreach (DiscreteObjectKeyFrame discreteObjectKeyFrame in Enumerable.Zip<DateTime, TimeSpan, DiscreteObjectKeyFrame>(ValueHelper.GetDateTimesBetweenInclusive(dateTimeValue1, dateTimeValue2, count), intervalsInclusive, (Func<DateTime, TimeSpan, DiscreteObjectKeyFrame>)((dateTime, timeSpan) =>
                {
                    return new DiscreteObjectKeyFrame()
                    {
                        Value = (object)dateTime,
                        KeyTime = (KeyTime)timeSpan
                    };
                })))
                 {
                     animationUsingKeyFrames.KeyFrames.Add((ObjectKeyFrame)discreteObjectKeyFrame);
                     toValue = discreteObjectKeyFrame.Value;
                 }
                 storyboard.Children.Add((Timeline)animationUsingKeyFrames);
             }
         }
     }
     if (storyboard.Children.Count == 0)
     {
         ObjectAnimationUsingKeyFrames animationUsingKeyFrames = new ObjectAnimationUsingKeyFrames();
         DiscreteObjectKeyFrame discreteObjectKeyFrame1 = new DiscreteObjectKeyFrame();
         discreteObjectKeyFrame1.Value = toValue;
         discreteObjectKeyFrame1.KeyTime = (KeyTime)new TimeSpan(0, 0, 0);
         DiscreteObjectKeyFrame discreteObjectKeyFrame2 = discreteObjectKeyFrame1;
         animationUsingKeyFrames.KeyFrames.Add((ObjectKeyFrame)discreteObjectKeyFrame2);
         storyboard.Children.Add((Timeline)animationUsingKeyFrames);
     }
     return storyboard;
 }
Пример #15
0
        /// <summary>
        /// Reveals data points using a storyboard.
        /// </summary>
        /// <param name="dataPoints">The data points to change the state of.
        /// </param>
        /// <param name="dataPointCount">The number of data points in the sequence.</param>
        /// <param name="newState">The state to change to.</param>
        private void StaggeredStateChange(IEnumerable<DataPoint> dataPoints, int dataPointCount, DataPointState newState)
        {
            if (PlotArea == null || dataPointCount == 0)
            {
                return;
            }

            string guid = Guid.NewGuid().ToString();
            Storyboard stateChangeStoryBoard = new Storyboard();
            stateChangeStoryBoard.Completed +=
                (sender, args) =>
                {
                    PlotArea.Resources.Remove(guid);
                };

            dataPoints.ForEachWithIndex((dataPoint, count) =>
            {
                // Create an Animation
                ObjectAnimationUsingKeyFrames objectAnimationUsingKeyFrames = new ObjectAnimationUsingKeyFrames();
                Storyboard.SetTarget(objectAnimationUsingKeyFrames, dataPoint);
                Storyboard.SetTargetProperty(objectAnimationUsingKeyFrames, new PropertyPath("State"));

                // Create a key frame
                DiscreteObjectKeyFrame discreteObjectKeyFrame = new DiscreteObjectKeyFrame();
                discreteObjectKeyFrame.Value = newState;

                // Create the specified animation type
                switch (AnimationSequence)
                {
                    case AnimationSequence.Simultaneous:
                        discreteObjectKeyFrame.KeyTime = TimeSpan.Zero;
                        break;
                    case AnimationSequence.FirstToLast:
                        discreteObjectKeyFrame.KeyTime = TimeSpan.FromMilliseconds(1000 * ((double)count / dataPointCount));
                        break;
                    case AnimationSequence.LastToFirst:
                        discreteObjectKeyFrame.KeyTime = TimeSpan.FromMilliseconds(1000 * ((double)(dataPointCount - count - 1) / dataPointCount));
                        break;
                }

                // Add the Animation to the Storyboard
                objectAnimationUsingKeyFrames.KeyFrames.Add(discreteObjectKeyFrame);
                stateChangeStoryBoard.Children.Add(objectAnimationUsingKeyFrames);
            });

            _storyBoardQueue.Enqueue(stateChangeStoryBoard);
        }
        private static ObjectAnimationUsingKeyFrames CreateAnimation(IList<ImageSource> imageFrames)
        {
            // Initialize the animation for this object.
            var result = new ObjectAnimationUsingKeyFrames
            {
                Duration = s_animationDuration,
            };

            // Creates the frames for the animation.
            var frameDuration = FullDuration / s_lightFrames.Value.Count;
            int framePoint = 0;
            var keyFrames = new ObjectKeyFrameCollection();
            foreach (var frame in imageFrames)
            {
                var keyFrame = new DiscreteObjectKeyFrame
                {
                    KeyTime = new TimeSpan(0, 0, 0, 0, framePoint),
                    Value = frame,
                };
                keyFrames.Add(keyFrame);

                framePoint += frameDuration;
            }
            result.KeyFrames = keyFrames;

            return result;
        }
Пример #17
0
        private static ObjectAnimationUsingKeyFrames CreateVisibilityAnimation(Duration duration, UIElement element, bool show)
        {
            var _One = new DiscreteObjectKeyFrame { KeyTime = new TimeSpan(0), Value = (show ? Visibility.Collapsed : Visibility.Visible) };
            var _Two = new DiscreteObjectKeyFrame { KeyTime = new TimeSpan(duration.TimeSpan.Ticks / 2), Value = (show ? Visibility.Visible : Visibility.Collapsed) };

            var _Animation = new ObjectAnimationUsingKeyFrames { BeginTime = new TimeSpan(0) };
            _Animation.KeyFrames.Add(_One);
            _Animation.KeyFrames.Add(_Two);
            Storyboard.SetTargetProperty(_Animation, new PropertyPath("Visibility"));
            Storyboard.SetTarget(_Animation, element);
            return _Animation;
        }
Пример #18
0
        /// <summary>
        /// Marginを指定してコントロールの位置変更およびフェードアウトアニメーションを実行する
        /// (このメソッドは捕球アニメーションで使用しようとしたがうまく動作しないため未使用)
        /// </summary>
        /// <param name="toMargin">変更位置</param>
        /// <param name="control">対象コントロール</param>
        /// <param name="duration">アニメーション時間</param>
        /// <param name="fadeOut">フェードアウトするか</param>
        public static void MoveControlByMargin(Thickness toMargin, FrameworkElement control, TimeSpan duration, bool fadeOut)
        {
            // マージンを変更するアニメーションの作成
            ObjectAnimationUsingKeyFrames animation = new ObjectAnimationUsingKeyFrames();
            animation.Duration = duration;

            // アニメーション開始時点のマージン設定
            DiscreteObjectKeyFrame key1 = new DiscreteObjectKeyFrame();
            key1.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(0));
            key1.Value = control.Margin;

            // アニメーション終了時点のマージン設定
            DiscreteObjectKeyFrame key2 = new DiscreteObjectKeyFrame();
            key2.KeyTime = KeyTime.FromTimeSpan(duration);
            key2.Value = toMargin;

            // アニメーションを定義したキーフレームを登録
            animation.KeyFrames.Add(key1);
            animation.KeyFrames.Add(key2);

            // アニメーションに依存プロパティを関連付ける
            Storyboard.SetTarget(animation, control);
            Storyboard.SetTargetProperty(animation, new PropertyPath(FrameworkElement.MarginProperty));

            // ストーリーボードの作成
            Storyboard storyboard = new Storyboard();
            storyboard.Duration = duration;
            storyboard.Children.Add(animation);

            // フェードアウトのアニメーション作成
            if (fadeOut)
            {
                DoubleAnimation fadeOutAnimation = new DoubleAnimation();
                fadeOutAnimation.From = 1;
                fadeOutAnimation.To = 0;
                fadeOutAnimation.BeginTime = TimeSpan.Zero;
                fadeOutAnimation.Duration = duration;
                // アニメーションに依存プロパティを関連付ける
                // (ストーリーボード完了後、元のOpacityに戻る)
                Storyboard.SetTarget(fadeOutAnimation, control);
                Storyboard.SetTargetProperty(fadeOutAnimation, new PropertyPath(FrameworkElement.OpacityProperty));
                storyboard.Children.Add(fadeOutAnimation);
            }

            // アニメーション開始
            storyboard.Begin();
        }
Пример #19
0
        /// <summary>
        /// Marginを指定してコントロールの位置変更のアニメーションを実行する
        /// </summary>
        /// <param name="toMargin">変更位置</param>
        /// <param name="control">対象コントロール</param>
        /// <param name="duration">アニメーション時間</param>
        public static void MoveControlByMargin(Thickness toMargin, FrameworkElement control, TimeSpan duration)
        {
            // マージンを変更するアニメーションの作成
            ObjectAnimationUsingKeyFrames animation = new ObjectAnimationUsingKeyFrames();
            animation.Duration = duration;

            // アニメーション開始時点のマージン設定
            DiscreteObjectKeyFrame key1 = new DiscreteObjectKeyFrame();
            key1.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(0));
            key1.Value = control.Margin;

            // アニメーション終了時点のマージン設定
            DiscreteObjectKeyFrame key2 = new DiscreteObjectKeyFrame();
            key2.KeyTime = KeyTime.FromTimeSpan(duration);
            key2.Value = toMargin;

            // アニメーションを定義したキーフレームを登録
            animation.KeyFrames.Add(key1);
            animation.KeyFrames.Add(key2);

            // アニメーションに依存プロパティを関連付ける
            Storyboard.SetTarget(animation, control);
            Storyboard.SetTargetProperty(animation, new PropertyPath(FrameworkElement.MarginProperty));

            // ストーリーボードの作成
            Storyboard storyboard = new Storyboard();
            storyboard.Duration = duration;
            storyboard.Children.Add(animation);

            // アニメーション開始
            storyboard.Begin();
        }
        private void Flash()
        {
            Storyboard storyBoard = new Storyboard();

            MainCanvas.Children.Clear();
            MainCanvas.Background = ColorHelper.GetBrushFromString(_message.BackgroundColor);

            Grid g = new Grid();
            g.Width = 800;
            g.Height = 480;
            g.ColumnDefinitions.Add(new ColumnDefinition());
            g.RowDefinitions.Add(new RowDefinition());
            MainCanvas.Children.Add(g);

            string text = _message.Text;

            string[] words = text.Split(' ');
            for (var i = 0; i <= words.Length - 1; i++)
            {
                TextBlock tb = getTextBlock();
                tb.Text = words[i];
                tb.FontSize = getFontSize();
                tb.Foreground = ColorHelper.GetBrushFromString(_message.ForegroundColor);
                while (tb.ActualWidth > 800)
                {
                    tb.FontSize -= 1;
                    System.Diagnostics.Debug.WriteLine("FontSize: " + tb.FontSize);
                }
                tb.VerticalAlignment = System.Windows.VerticalAlignment.Center;
                tb.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
                tb.Visibility = System.Windows.Visibility.Collapsed;

                g.Children.Add(tb);

                double seconds = ((MAX_SPEED - _message.Speed) + 1) * SPEED_INTERVAL;

                double startingTime = ((i * 2) + 1) * seconds;

                ObjectAnimationUsingKeyFrames animation = new ObjectAnimationUsingKeyFrames();

                DiscreteObjectKeyFrame visibleKeyFrame = new DiscreteObjectKeyFrame();
                visibleKeyFrame.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(startingTime));
                visibleKeyFrame.Value = Visibility.Visible;
                animation.KeyFrames.Add(visibleKeyFrame);

                DiscreteObjectKeyFrame collapsedKeyFrame = new DiscreteObjectKeyFrame();
                collapsedKeyFrame.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(startingTime + seconds));
                collapsedKeyFrame.Value = Visibility.Collapsed;
                animation.KeyFrames.Add(collapsedKeyFrame);

                Storyboard.SetTarget(animation, tb);
                Storyboard.SetTargetProperty(animation, new PropertyPath("(UIElement.Visibility)"));

                storyBoard.Children.Add(animation);

            }

            if (storyBoard.Children.Count > 0)
            {
                storyBoard.RepeatBehavior = RepeatBehavior.Forever;
                storyBoard.Begin();
            }
        }
Пример #21
0
        //private void invalidateButton()
        //{
        //    foreach (Button key in keyList)
        //    {
        //        key.IsEnabled = false;
        //    }
        //}

        //private void validateButton()
        //{
        //    foreach (Button key in keyList)
        //    {
        //        key.IsEnabled = true;
        //    }
        //}


        private void keyClick(object sender, RoutedEventArgs e)
        {
            string ans = "";
            string nextQuestion = "";
            Button keyButton = null;
            if (sender is Button)
            {
                keyButton = (Button)sender;
                ans = keyButton.Name;
            }

            DiscreteObjectKeyFrame setImageFrame = new DiscreteObjectKeyFrame();
            DiscreteObjectKeyFrame clearImageFrame = new DiscreteObjectKeyFrame();
            DiscreteObjectKeyFrame setQuestionFrame = new DiscreteObjectKeyFrame();
            setImageFrame.KeyTime = new TimeSpan(0, 0, 0, 0);
            clearImageFrame.KeyTime = new TimeSpan(0, 0, 0, 0, 700);
            clearImageFrame.Value = clearImage;
            setQuestionFrame.KeyTime = new TimeSpan(0, 0, 0, 0, 700);

            nextQuestion = game.IsCorrect(ans);
            if (nextQuestion == "false")
            {
                setImageFrame.Value = falseImage;
                mainWindow.setStatus("False.");
                setQuestionFrame.Value = qTextBox.Text;
                missCount++;
            }
            else if (nextQuestion == "end")
            {
                Page p = new ResultPage(mainWindow.StopTimer(),missCount);
                mainWindow.setStatus("Finish!");
                NavigationService.Navigate(p);
            }
            else
            {
                setImageFrame.Value = correctImage;
                //rightOrWrongImage.Source = correctImage;
                mainWindow.setStatus("Correct.");
                this.qTextBox.Text = nextQuestion;
                //setQuestionFrame.Value = nextQuestion;
            }
            ObjectAnimationUsingKeyFrames rightOrWrongAnimation = new ObjectAnimationUsingKeyFrames();
            rightOrWrongAnimation.BeginTime = new TimeSpan(0,0,0,0);
            rightOrWrongAnimation.KeyFrames.Add(setImageFrame);
            rightOrWrongAnimation.KeyFrames.Add(clearImageFrame);

            ObjectAnimationUsingKeyFrames questionAnimation = new ObjectAnimationUsingKeyFrames();
            questionAnimation.BeginTime = new TimeSpan(0, 0, 0, 0);
            questionAnimation.KeyFrames.Add(setQuestionFrame);

            Storyboard gameStoryboard = new Storyboard();
            gameStoryboard.Children.Add(rightOrWrongAnimation);
            Storyboard.SetTargetName(rightOrWrongAnimation, rightOrWrongImage.Name);
            Storyboard.SetTargetProperty(rightOrWrongAnimation, new PropertyPath(Image.SourceProperty));

            //gameStoryboard.Children.Add(questionAnimation);
            //Storyboard.SetTargetName(questionAnimation, qTextBox.Name);
            //Storyboard.SetTargetProperty(questionAnimation,new PropertyPath(TextBlock.TextProperty));

            gameStoryboard.Begin(this);
        }
Пример #22
0
        /// <summary>
        /// Uses ObjectAnimatioNUsingKeyFrames and a StoryBoard to animated to expansion
        /// of the specificed ColumnDefinition or RowDefinition.
        /// </summary>
        /// <param name="definition">The RowDefinition or ColumnDefintition that will be expanded.</param>
        private void AnimateExpand(object definition)
        {
            double increment;
                double currentValue;

                // Setup the animation and StoryBoard
                ObjectAnimationUsingKeyFrames gridLengthAnimation = new ObjectAnimationUsingKeyFrames();
                Storyboard sb = new Storyboard();

                // Add the animation to the StoryBoard
                sb.Children.Add(gridLengthAnimation);

                if (_gridCollapseDirection == GridCollapseDirection.Rows)
                {
                    // Specify the target RowDefinition and property (Height) that will be altered by the animation.
                    RowDefinition rowDefinition = (RowDefinition)definition;
                    Storyboard.SetTarget(gridLengthAnimation, rowDefinition);
                    Storyboard.SetTargetProperty(gridLengthAnimation, new PropertyPath("Height"));

                    increment = _savedActualValue / 5;
                    currentValue = rowDefinition.ActualHeight;
                }
                else
                {
                    // Specify the target ColumnDefinition and property (Width) that will be altered by the animation.
                    ColumnDefinition colDefinition = (ColumnDefinition)definition;
                    Storyboard.SetTarget(gridLengthAnimation, colDefinition);
                    Storyboard.SetTargetProperty(gridLengthAnimation, new PropertyPath("Width"));

                    increment = _savedActualValue / 5;
                    currentValue = colDefinition.ActualWidth;
                }

                // Create frames to incrementally expand the target.
                DiscreteObjectKeyFrame keyFrame1 = new DiscreteObjectKeyFrame();
                keyFrame1.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(.1));
                currentValue = currentValue + increment;
                keyFrame1.Value = new GridLength(currentValue);
                gridLengthAnimation.KeyFrames.Add(keyFrame1);

                DiscreteObjectKeyFrame keyFrame2 = new DiscreteObjectKeyFrame();
                keyFrame2.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(.2));
                currentValue = currentValue + increment;
                keyFrame2.Value = new GridLength(currentValue);
                gridLengthAnimation.KeyFrames.Add(keyFrame2);

                DiscreteObjectKeyFrame keyFrame3 = new DiscreteObjectKeyFrame();
                keyFrame3.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(.3));
                currentValue = currentValue + increment;
                keyFrame3.Value = new GridLength(currentValue);
                gridLengthAnimation.KeyFrames.Add(keyFrame3);

                DiscreteObjectKeyFrame keyFrame4 = new DiscreteObjectKeyFrame();
                keyFrame4.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(.4));
                currentValue = currentValue + increment;
                keyFrame4.Value = new GridLength(currentValue);
                gridLengthAnimation.KeyFrames.Add(keyFrame4);

                DiscreteObjectKeyFrame keyFrame5 = new DiscreteObjectKeyFrame();
                keyFrame5.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(.5));
                keyFrame5.Value = _savedGridLength;
                gridLengthAnimation.KeyFrames.Add(keyFrame5);

                // Start the StoryBoard.
                sb.Begin();
        }
        /// <summary>
        /// 初始化报警帧动画
        /// </summary>
        private void InitAlertAnimation()
        {
            sbAlert = new Storyboard();
            sbAlert.RepeatBehavior = RepeatBehavior.Forever;
            this.RegisterName("spAlert", StackPanelAlert);

            ObjectAnimationUsingKeyFrames oaKeyFrames = new ObjectAnimationUsingKeyFrames();

            DiscreteObjectKeyFrame doKey0 = new DiscreteObjectKeyFrame();
            doKey0.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0));
            doKey0.Value = Visibility.Visible;

            DiscreteObjectKeyFrame doKey1 = new DiscreteObjectKeyFrame();
            doKey1.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.5));
            doKey1.Value = Visibility.Hidden;

            DiscreteObjectKeyFrame doKey2 = new DiscreteObjectKeyFrame();
            doKey2.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(1));
            doKey2.Value = Visibility.Visible;

            oaKeyFrames.KeyFrames.Add(doKey0);
            oaKeyFrames.KeyFrames.Add(doKey1);
            oaKeyFrames.KeyFrames.Add(doKey2);

            Storyboard.SetTargetName(oaKeyFrames, "spAlert");
            Storyboard.SetTargetProperty(oaKeyFrames, new PropertyPath(VisibilityProperty));

            sbAlert.Children.Add(oaKeyFrames);
        }
Пример #24
0
        /// <summary>
        /// Adds the flip from top animation.
        /// </summary>
        /// <param name="showStoryboard">The show storyboard.</param>
        /// <param name="popupView">The popup view.</param>
        public static void AddFlipFromTopAnimation(Storyboard showStoryboard, PopupView popupView)
        {
            var slideFromTopAnimation = new DoubleAnimation
            {
                From = -90,
                To = 0,
                BeginTime = TimeSpan.Zero,
                Duration = TimeSpan.Parse("00:00:0.75", CultureInfo.InvariantCulture),
                EasingFunction = new BounceEase() { EasingMode = EasingMode.EaseOut },
                AutoReverse = false
            };

            var adjustBackMarginAnimation = new ObjectAnimationUsingKeyFrames();
            var keyFrame = new DiscreteObjectKeyFrame { KeyTime = TimeSpan.Zero, Value = new Thickness(0, 44, 0, 0) };
            adjustBackMarginAnimation.KeyFrames.Add(keyFrame);
            Storyboard.SetTargetProperty(adjustBackMarginAnimation, new PropertyPath("(FrameworkElement.Margin)"));

            var backBody = popupView.GetChildrenByType<Control>(c => c.Name == "BackBody").FirstOrDefault();

            if (backBody != null)
                Storyboard.SetTarget(adjustBackMarginAnimation, backBody);

            var centerOfRotationAnimationX = new DoubleAnimation { Duration = TimeSpan.Parse("0", CultureInfo.InvariantCulture), To = 0, };
            var centerOfRotationAnimationY = new DoubleAnimation { Duration = TimeSpan.Parse("0", CultureInfo.InvariantCulture), To = 0, };

            var layoutRoot = FindTopLevelPanel(popupView);

            Storyboard.SetTarget(slideFromTopAnimation, layoutRoot);
            Storyboard.SetTarget(centerOfRotationAnimationX, layoutRoot);
            Storyboard.SetTarget(centerOfRotationAnimationY, layoutRoot);
            Storyboard.SetTargetProperty(centerOfRotationAnimationX, new PropertyPath("(UIElement.Projection).(PlaneProjection.CenterOfRotationX)"));
            Storyboard.SetTargetProperty(centerOfRotationAnimationY, new PropertyPath("(UIElement.Projection).(PlaneProjection.CenterOfRotationY)"));
            Storyboard.SetTargetProperty(slideFromTopAnimation, new PropertyPath("(UIElement.Projection).(PlaneProjection.RotationX)"));

            if (showStoryboard == null)
                return;

            showStoryboard.Children.Add(slideFromTopAnimation);
            showStoryboard.Children.Add(centerOfRotationAnimationX);
            showStoryboard.Children.Add(centerOfRotationAnimationY);
            showStoryboard.Children.Add(adjustBackMarginAnimation);
        }