예제 #1
0
        public PopupMsg(TextBlock msg)
        {
            //Store TextBlock for message display
            this.msg = msg;
            //Register the textblock's name, this is necessary for creating Storyboard using codes instead of XAML
            NameScope.SetNameScope(msg, new NameScope());
            msg.RegisterName("fadetext", msg);

            //Create the fade in & fade out animation
            DoubleAnimationUsingKeyFrames fadeInOutAni = new DoubleAnimationUsingKeyFrames();
            LinearDoubleKeyFrame keyframe = new LinearDoubleKeyFrame();
            keyframe.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(2));
            keyframe.Value = 1;
            fadeInOutAni.KeyFrames.Add(keyframe);
            //keyframe = new LinearDoubleKeyFrame();

            fadeInOutAni.Duration = new Duration(TimeSpan.FromSeconds(4));        
            fadeInOutAni.AutoReverse = true;
            fadeInOutAni.AccelerationRatio = .2;
            fadeInOutAni.DecelerationRatio = .7;

            // Configure the animation to target the message's opacity property
            Storyboard.SetTargetName(fadeInOutAni, "fadetext");
            Storyboard.SetTargetProperty(fadeInOutAni, new PropertyPath(TextBlock.OpacityProperty));

            // Add the fade in & fade out animation to the Storyboard
            Storyboard fadeInOutStoryBoard = new Storyboard();
            fadeInOutStoryBoard.Children.Add(fadeInOutAni);

            // Set event trigger, make this animation played on an event we can control
            msg.IsVisibleChanged += delegate(object sender,  System.Windows.DependencyPropertyChangedEventArgs e)
            {
                if (msg.IsVisible) fadeInOutStoryBoard.Begin(msg);
            };
        }
        private void StartAnimation()
        {
            Storyboard board = new Storyboard();
            var timeline = new DoubleAnimationUsingKeyFrames();
            timeline.RepeatBehavior = RepeatBehavior.Forever;
            Storyboard.SetTarget(timeline, rotateTransform);
            Storyboard.SetTargetProperty(timeline, new PropertyPath("Angle"));
            var frame = new LinearDoubleKeyFrame() { KeyTime = TimeSpan.FromSeconds(1), Value = 360 };
            timeline.KeyFrames.Add(frame);
            board.Children.Add(timeline);

            board.Begin();
        }
예제 #3
0
        private static void FillAnimation(DoubleAnimationUsingKeyFrames animation, TransitionType type, double from, double to, TimeSpan duration, double fps)
        {
            Equation equation = (Equation)Delegate.CreateDelegate(typeof(Equation), typeof(Equations).GetMethod(type.ToString()));

            double total = duration.TotalMilliseconds;
            double step = 1000D / (double)fps;

            // clear animation
            animation.KeyFrames.Clear();

            for (double i = 0; i < total; i += step) {
                LinearDoubleKeyFrame frame = new LinearDoubleKeyFrame();
                frame.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(i));
                frame.Value = equation(i, from, to - from, total);

                animation.KeyFrames.Add(frame);
            }

            // always add exact final key frame
            LinearDoubleKeyFrame finalFrame = new LinearDoubleKeyFrame();
            finalFrame.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(total));
            finalFrame.Value = to;
            animation.KeyFrames.Add(finalFrame);
        }
예제 #4
0
        private void ShowInfoBar()
        {
            bdrInfo.Visibility = Visibility.Visible;

            DoubleAnimation dbaOpacity = new DoubleAnimation(1, durationCommon + durationCommon);

            ScaleTransform scaleTransform = new ScaleTransform();
            bdrInfo.RenderTransform = scaleTransform;

            LinearDoubleKeyFrame dbk01 = new LinearDoubleKeyFrame(1 + 6 / bdrInfo.ActualWidth, TimeSpan.FromMilliseconds(120));
            LinearDoubleKeyFrame dbk02 = new LinearDoubleKeyFrame(1, TimeSpan.FromMilliseconds(200));

            DoubleAnimationUsingKeyFrames dbak = new DoubleAnimationUsingKeyFrames();
            dbak.KeyFrames.Add(dbk01);
            dbak.KeyFrames.Add(dbk02);
            dbak.AccelerationRatio = 0;

            bdrInfo.BeginAnimation(Border.OpacityProperty, dbaOpacity);
            scaleTransform.BeginAnimation(ScaleTransform.ScaleXProperty, dbak);
            scaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, dbak);
        }
예제 #5
0
        /// <summary>
        /// Animates the given 3D object to the front of the stack
        /// </summary>
        /// <param name="visual3D"></param>
        private void AnimateToFront(ModelVisual3D visual3D)
        {
            TranslateTransform3D transform = ((TranslateTransform3D)((Transform3DGroup)visual3D.Transform).Children[1]);

            LinearDoubleKeyFrame key1 = new LinearDoubleKeyFrame(-Width, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(300)));
            LinearDoubleKeyFrame key2 = new LinearDoubleKeyFrame(0, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(300)));
            LinearDoubleKeyFrame key3 = new LinearDoubleKeyFrame(0, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(900)));

            DoubleAnimationUsingKeyFrames doubleAnimX = new DoubleAnimationUsingKeyFrames();
            doubleAnimX.KeyFrames.Add(key1);
            doubleAnimX.KeyFrames.Add(key3);

            DoubleAnimationUsingKeyFrames doubleAnimZ = new DoubleAnimationUsingKeyFrames();
            doubleAnimZ.KeyFrames.Add(key2);
            doubleAnimZ.BeginTime = TimeSpan.FromMilliseconds(300);

            transform.BeginAnimation(TranslateTransform3D.OffsetXProperty, doubleAnimX);
            transform.BeginAnimation(TranslateTransform3D.OffsetZProperty, doubleAnimZ);
        }
예제 #6
0
        private void AnimatePieceToPosition(int piece, Position start, Position end, int phase)
        {
            TimeSpan beginTime = TimeSpan.FromMilliseconds(ThreadedLimakeGame.delayAmount * phase),
                    endTime = TimeSpan.FromMilliseconds(ThreadedLimakeGame.delayAmount * (phase+1));

            PieceControl pieceControl = pieces[piece];

            Point startpoint = GetAbsolutePosition(start);
            Point endpoint = GetAbsolutePosition(end);

            DoubleAnimationUsingKeyFrames leftAnimation, topAnimation;
            if (leftAnimationDict.ContainsKey(piece))
            {
                leftAnimation = leftAnimationDict[piece];
            }
            else
            {
                leftAnimation = new DoubleAnimationUsingKeyFrames();
                leftAnimationDict[piece] = leftAnimation;
                board.Children.Add(leftAnimation);

                Storyboard.SetTarget(leftAnimation, pieceControl);
                Storyboard.SetTargetProperty(leftAnimation, new PropertyPath("(Canvas.Left)"));
            }

            if (topAnimationDict.ContainsKey(piece))
            {
                topAnimation = topAnimationDict[piece];
            }
            else
            {
                topAnimation = new DoubleAnimationUsingKeyFrames();
                topAnimationDict[piece] = topAnimation;
                board.Children.Add(topAnimation);

                Storyboard.SetTarget(topAnimation, pieceControl);
                Storyboard.SetTargetProperty(topAnimation, new PropertyPath("(Canvas.Top)"));
            }

            LinearDoubleKeyFrame leftStart = new LinearDoubleKeyFrame()
            {
                Value = startpoint.X,
                KeyTime = KeyTime.FromTimeSpan(beginTime)
            };
            LinearDoubleKeyFrame leftEnd = new LinearDoubleKeyFrame()
            {
                Value = endpoint.X,
                KeyTime = KeyTime.FromTimeSpan(endTime)
            };
            leftAnimation.KeyFrames.Add(leftStart);
            leftAnimation.KeyFrames.Add(leftEnd);

            LinearDoubleKeyFrame topStart = new LinearDoubleKeyFrame()
            {
                Value = startpoint.Y,
                KeyTime = KeyTime.FromTimeSpan(beginTime)
            };
            LinearDoubleKeyFrame topEnd = new LinearDoubleKeyFrame()
            {
                Value = endpoint.Y,
                KeyTime = KeyTime.FromTimeSpan(endTime)
            };
            topAnimation.KeyFrames.Add(topStart);
            topAnimation.KeyFrames.Add(topEnd);
        }
예제 #7
0
        /// <summary>
        /// Adds an animation corresponding to an specific framework element.
        /// Thus, the storyboard can be composed piece by piece.
        /// </summary>
        /// <param name="element">The framework element.</param>
        /// <param name="leftToRight">
        /// Indicates whether the animation should go 
        /// from left to right or viceversa.
        /// </param>
        /// <param name="storyboard">A reference to the storyboard.</param>
        private static void ComposeStoryboard(FrameworkElement element, bool leftToRight, ref Storyboard storyboard)
        {
            double xPosition = SlideInEffect.GetLineIndex(element) * ProportionalOffset;
            double from = leftToRight ? xPosition : -xPosition;
            TranslateTransform translateTransform = SlideInEffect.GetAttachedTransform(element);
            DoubleAnimationUsingKeyFrames animation = new DoubleAnimationUsingKeyFrames();

            LinearDoubleKeyFrame keyFrame1 = new LinearDoubleKeyFrame();
            keyFrame1.KeyTime = TimeSpan.Zero;
            keyFrame1.Value = from;
            animation.KeyFrames.Add(keyFrame1);

            LinearDoubleKeyFrame keyFrame2 = new LinearDoubleKeyFrame();
            keyFrame2.KeyTime = TimeSpan.FromMilliseconds(BeginTime);
            keyFrame2.Value = from;
            animation.KeyFrames.Add(keyFrame2);

            LinearDoubleKeyFrame keyFrame3 = new LinearDoubleKeyFrame();
            keyFrame3.KeyTime = TimeSpan.FromMilliseconds(BreakTime);
            keyFrame3.Value = from * ExponentialInterpolationWeight;
            animation.KeyFrames.Add(keyFrame3);

            EasingDoubleKeyFrame keyFrame4 = new EasingDoubleKeyFrame();
            keyFrame4.KeyTime = TimeSpan.FromMilliseconds(EndTime);
            keyFrame4.Value = 0.0;

            keyFrame4.EasingFunction = SlideInExponentialEase;
            animation.KeyFrames.Add(keyFrame4);

            Storyboard.SetTarget(animation, translateTransform);
            Storyboard.SetTargetProperty(animation, XPropertyPath);
            storyboard.Children.Add(animation);
        }
예제 #8
0
        private void ShiftBoard(double from, double to)
        {
            DoubleAnimationUsingKeyFrames advanceAnimation = new DoubleAnimationUsingKeyFrames();
            advanceAnimation.Completed +=new EventHandler(advanceAnimation_Completed);
            advanceAnimation.Duration = TimeSpan.FromSeconds(1);
            LinearDoubleKeyFrame linear = new LinearDoubleKeyFrame(from, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0)));
            EasingDoubleKeyFrame easing = new EasingDoubleKeyFrame(to, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(1)), new CircleEase() {EasingMode = EasingMode.EaseInOut });
            advanceAnimation.KeyFrames.Add(linear);
            advanceAnimation.KeyFrames.Add(easing);
            Storyboard.SetTarget(advanceAnimation, BoardContainer);
            Storyboard.SetTargetProperty(advanceAnimation, new PropertyPath("(Canvas.Left)"));

            DoubleAnimationUsingKeyFrames advanceAnimation2 = new DoubleAnimationUsingKeyFrames();
            advanceAnimation2.Duration = TimeSpan.FromSeconds(1);
            LinearDoubleKeyFrame linear2 = new LinearDoubleKeyFrame(from, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0)));
            EasingDoubleKeyFrame easing2 = new EasingDoubleKeyFrame(to, KeyTime.FromTimeSpan(TimeSpan.FromSeconds(1)), new CircleEase() { EasingMode = EasingMode.EaseInOut });
            advanceAnimation2.KeyFrames.Add(linear2);
            advanceAnimation2.KeyFrames.Add(easing2);
            Storyboard.SetTarget(advanceAnimation2, TitleContainer);
            Storyboard.SetTargetProperty(advanceAnimation2, new PropertyPath("(Canvas.Left)"));


            sbAdvance.Children.Clear();
            sbAdvance.Children.Add(advanceAnimation);
            sbAdvance.Children.Add(advanceAnimation2);
            sbAdvance.Begin();
        }
예제 #9
0
        private void StartAnimationHour(DateTime now)
        {
            Storyboard stH = new Storyboard();
            stH.RepeatBehavior = RepeatBehavior.Forever;

            DoubleAnimationUsingKeyFrames daHour = new DoubleAnimationUsingKeyFrames();
            daHour.Duration = new Duration(TimeSpan.FromHours(12));

            LinearDoubleKeyFrame keyHour = new LinearDoubleKeyFrame();
            //keyHour.Value = 360;
            daHour.KeyFrames.Add(keyHour);

            double hour = now.Hour;
            if (hour >= 12)
            {
                hour = hour - 12;
            }
            double angleHour = 360 * ((hour + (double)now.Minute / 60 + (double)now.Second / 3600) / 12);
            keyHour.Value = angleHour + 360;

            RotateTransform rtHour = ((TransformGroup)pathHour.RenderTransform).Children[2] as RotateTransform;
            rtHour.Angle = angleHour;
            this.RegisterName("RtHour", rtHour);
            Storyboard.SetTargetName(daHour, "RtHour");
            Storyboard.SetTargetProperty(daHour, new PropertyPath(RotateTransform.AngleProperty));
            stH.Children.Add(daHour);
            stH.Begin(this);
        }
예제 #10
0
        private void StartAnimationSecond(DateTime now)
        {
            Storyboard stS = new Storyboard();
            stS.RepeatBehavior = RepeatBehavior.Forever;

            DoubleAnimationUsingKeyFrames daSecond = new DoubleAnimationUsingKeyFrames();
            daSecond.Duration = new Duration(TimeSpan.FromMinutes(1));

            LinearDoubleKeyFrame keySecond = new LinearDoubleKeyFrame();
            //keySecond.Value = 360;
            daSecond.KeyFrames.Add(keySecond);

            double second = dtNow.Second;
            double angleSecond = 360 * ((double)now.Second / 60);
            keySecond.Value = angleSecond + 360;

            RotateTransform rtSecond = ((TransformGroup)pathSecond.RenderTransform).Children[2] as RotateTransform;
            rtSecond.Angle = angleSecond;
            this.RegisterName("RtSecond", rtSecond);

            Storyboard.SetTargetName(daSecond, "RtSecond");
            Storyboard.SetTargetProperty(daSecond, new PropertyPath(RotateTransform.AngleProperty));
            stS.Children.Add(daSecond);
            stS.Begin(this);
        }
예제 #11
0
        private void StartAnimationMinute(DateTime now)
        {
            Storyboard stM = new Storyboard();
            stM.RepeatBehavior = RepeatBehavior.Forever;

            DoubleAnimationUsingKeyFrames daMinute = new DoubleAnimationUsingKeyFrames();
            daMinute.Duration = new Duration(TimeSpan.FromHours(1));

            LinearDoubleKeyFrame keyMinute = new LinearDoubleKeyFrame();
            //keyMinute.Value = 360;
            daMinute.KeyFrames.Add(keyMinute);

            double minute = now.Minute;
            double angleMinute = 360 * ((minute + (now.Second / 60)) / 60);
            keyMinute.Value = angleMinute + 360;

            RotateTransform rtMinute = ((TransformGroup)pathMinute.RenderTransform).Children[2] as RotateTransform;
            rtMinute.Angle = angleMinute;
            this.RegisterName("RtMinute", rtMinute);

            Storyboard.SetTargetName(daMinute, "RtMinute");
            Storyboard.SetTargetProperty(daMinute, new PropertyPath(RotateTransform.AngleProperty));
            stM.Children.Add(daMinute);
            stM.Begin(this);
        }
예제 #12
0
        private static void OnTweenChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
        {
            DoubleAnimationUsingKeyFrames animation = o as DoubleAnimationUsingKeyFrames;

            if (animation != null && e.Property != Tween.IsInitializeProperty)
            {

                EquationType type = GetType(animation);
                double from = GetFrom(animation);
                double to = GetTo(animation);

                Equation equation = (Equation)Delegate.CreateDelegate(typeof(Equation), typeof(Equations).GetMethod(type.ToString(), new Type[] { typeof(double[]) }));

                double total = animation.Duration.TimeSpan.TotalMilliseconds;

                bool isInitialize = GetIsInitialize(animation);

                if (!isInitialize)
                {

                    animation.KeyFrames.Clear();

                    for (double i = 0; i < total; i += 50)
                    {
                        LinearDoubleKeyFrame frame = new LinearDoubleKeyFrame();

                        frame.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(i));

                        frame.Value = equation(i, from, to - from, total);

                        animation.KeyFrames.Add(frame);
                    }

                    // add final key frame
                    LinearDoubleKeyFrame finalFrame = new LinearDoubleKeyFrame();
                    finalFrame.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(total));
                    finalFrame.Value = to;
                    animation.KeyFrames.Add(finalFrame);
                }
                else
                {
                    int frameIndex = 0;

                    int countFrame = animation.KeyFrames.Count;

                    for (double i = 0; i < total; i += 50)
                    {
                        if (frameIndex < countFrame)
                        {
                            LinearDoubleKeyFrame frame = (LinearDoubleKeyFrame)animation.KeyFrames[frameIndex];

                            frame.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(i));

                            frame.Value = equation(i, from, to - from, total);

                            frameIndex++;
                        }
                    }

                    // final key frame
                    if (countFrame > 0)
                    {
                        LinearDoubleKeyFrame finalFrame = (LinearDoubleKeyFrame)animation.KeyFrames[animation.KeyFrames.Count - 1];
                        finalFrame.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(total));
                        finalFrame.Value = to;
                    }
                }
            }
        }
        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));
        }
예제 #14
0
        void rect_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            Rectangle rect = (Rectangle)sender;

            int row = (int)rect.Resources["row"];
            int col = (int)rect.Resources["col"];

            currentClickedRow = row;
            currentClickedCol = col;

            if (table.GameTable[row, col] != 0)
            {
                rectArray[row, col].Fill = new SolidColorBrush(Colors.Orange);
                rectArray[row, col].Stroke = new SolidColorBrush(Colors.Red);

                if (table.IsBallSelected)
                {
                    rectArray[(int)table.SelectedPoint.X, (int)table.SelectedPoint.Y].Stroke = new SolidColorBrush(Colors.Green);
                    rectArray[(int)table.SelectedPoint.X, (int)table.SelectedPoint.Y].Fill = new SolidColorBrush(Colors.Gray);
                }

                table.IsBallSelected = true;
                table.SelectedPoint = new Point(row, col);
            }
            else
            {
                if (table.IsBallSelected)
                {
                    Route shortestRoute =  table.calculateRoute(table.SelectedPoint, new Point(row, col));

                    Storyboard sb = new Storyboard();

                    DoubleAnimationUsingKeyFrames verticaldaukf = new DoubleAnimationUsingKeyFrames();
                    LinearDoubleKeyFrame verticalldkf = new LinearDoubleKeyFrame();

                    DoubleAnimationUsingKeyFrames horizontaldaukf = new DoubleAnimationUsingKeyFrames();
                    LinearDoubleKeyFrame horizontalldkf = new LinearDoubleKeyFrame();

                    verticalldkf.KeyTime = TimeSpan.FromSeconds(0);
                    verticalldkf.Value = table.SelectedPoint.X * 53;
                    verticaldaukf.KeyFrames.Add(verticalldkf);

                    horizontalldkf.KeyTime = TimeSpan.FromSeconds(0);
                    horizontalldkf.Value = table.SelectedPoint.Y * 53;
                    horizontaldaukf.KeyFrames.Add(horizontalldkf);

                    sb.Duration = TimeSpan.FromMilliseconds(shortestRoute.Connections.Count * 200);
                    verticaldaukf.Duration = TimeSpan.FromMilliseconds(shortestRoute.Connections.Count * 200);
                    horizontaldaukf.Duration = TimeSpan.FromMilliseconds(shortestRoute.Connections.Count * 200);

                    if (shortestRoute.Connections.Count == 0)
                    {
                        MessageBox.Show("Disabled step, othere balls are in the route.");
                    }
                    else
                    {
                        for (int i = 0; i < shortestRoute.Connections.Count; i++)
                        {
                            Connection conn = shortestRoute.Connections[i];
                            Location f = conn.A;
                            Location t = conn.B;

                            verticalldkf = new LinearDoubleKeyFrame();

                            verticalldkf.KeyTime = TimeSpan.FromMilliseconds((i + 1) * 200);
                            verticalldkf.Value = Int32.Parse(conn.B.Identifier.Split(',')[0]) * 53;
                            verticaldaukf.KeyFrames.Add(verticalldkf);

                            horizontalldkf = new LinearDoubleKeyFrame();

                            horizontalldkf.KeyTime = TimeSpan.FromMilliseconds((i + 1) * 200);
                            horizontalldkf.Value = Int32.Parse(conn.B.Identifier.Split(',')[1]) * 53;
                            horizontaldaukf.KeyFrames.Add(horizontalldkf);
                        }

                        currentBallImg = ballImgList.First(i => i.Margin.Top == (double)(table.SelectedPoint.X * 53) && i.Margin.Left == (double)(table.SelectedPoint.Y * 53));
                        currentBallImg.RenderTransform = new TranslateTransform();
                        Storyboard.SetTarget(verticaldaukf, currentBallImg);
                        Storyboard.SetTarget(horizontaldaukf, currentBallImg);
                        Storyboard.SetTargetProperty(verticaldaukf, new PropertyPath(Canvas.TopProperty));
                        Storyboard.SetTargetProperty(horizontaldaukf, new PropertyPath(Canvas.LeftProperty));

                        sb.Children.Add(verticaldaukf);
                        sb.Children.Add(horizontaldaukf);
                        Thickness thickness = new Thickness();
                        currentBallImg.Margin = thickness;

                        gameCanvas.IsHitTestVisible = false;
                        sb.Begin();
                        sb.Completed += new EventHandler(sb_Completed);

                        currentColor = table.GameTable[(int)table.SelectedPoint.X, (int)table.SelectedPoint.Y];
                        table.GameTable[row, col] = currentColor;
                        table.GameTable[(int)table.SelectedPoint.X, (int)table.SelectedPoint.Y] = 0;

                        table.IsBallSelected = false;
                        rectArray[(int)table.SelectedPoint.X, (int)table.SelectedPoint.Y].Stroke = new SolidColorBrush(Colors.Green);
                        rectArray[(int)table.SelectedPoint.X, (int)table.SelectedPoint.Y].Fill = new SolidColorBrush(Colors.Gray);
                        table.SelectedPoint = new Point(row, col);
                    }
                }
            }
        }
예제 #15
0
 private static DoubleKeyFrame CreateDoubleKeyFrmas(KeyFrames<double> Model)
 {
     DoubleKeyFrame frame = null;
     switch (Model.Type)
     {
         case KeyFramesType.Spline: frame = new SplineDoubleKeyFrame() { KeySpline = Model.Spline }; break;
         case KeyFramesType.Linear: frame = new LinearDoubleKeyFrame(); break;
         case KeyFramesType.Easing: frame = new EasingDoubleKeyFrame() { EasingFunction = Model.EasingFunction }; break;
         case KeyFramesType.Discrete: frame = new DiscreteDoubleKeyFrame(); break;
         default: break;
     }
     frame.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(Model.KeyTime)); 
     frame.Value = Model.Value;
     return frame;
 }
        private static void Grid_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
        {
            var cp = GetCP(sender);

            if (cp == null)
            {
                return;
            }

            MenuItem mi = (sender as MenuItem);

            cp.Item1.Content = mi.Header;

            cp.Item1.Opacity = 0;

            Storyboard sb = new Storyboard();


            double currentangle = normaliseangle((cp.Item3.RenderTransform as RotateTransform).Angle);
            double targetangle = -SimpleCirclePanel.GetDecalAngle(mi);

            targetangle = normaliseangle(targetangle - currentangle) + currentangle;

            double delta = targetangle - currentangle;

            if (delta > 180)
            {
                targetangle = targetangle - 360;
            }
            else if (delta < -180)
            {
                targetangle = targetangle + 360;
            }

            //Console.WriteLine(targetangle);

            DoubleAnimation da0 = new DoubleAnimation(currentangle, targetangle, new Duration(TimeSpan.FromSeconds(0.3)));
            da0.AccelerationRatio = 0.2; da0.DecelerationRatio = 0.2;
            Storyboard.SetTarget(da0, cp.Item3);
            Storyboard.SetTargetProperty(da0, new PropertyPath("(Path.RenderTransform).(RotateTransform.Angle)"));
            sb.Children.Add(da0);

            DoubleAnimationUsingKeyFrames myAnimation = new DoubleAnimationUsingKeyFrames();

            DiscreteDoubleKeyFrame opacityChange1 = new DiscreteDoubleKeyFrame();
            opacityChange1.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0));
            opacityChange1.Value = 0;
            myAnimation.KeyFrames.Add(opacityChange1);

            DiscreteDoubleKeyFrame opacityChange2 = new DiscreteDoubleKeyFrame();
            opacityChange2.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.4));
            opacityChange2.Value = 0;
            myAnimation.KeyFrames.Add(opacityChange2);

            LinearDoubleKeyFrame opacityChange3 = new LinearDoubleKeyFrame();
            opacityChange3.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromSeconds(0.9));
            opacityChange3.Value = 1;
            myAnimation.KeyFrames.Add(opacityChange3);

            Storyboard.SetTarget(myAnimation, cp.Item1);
            Storyboard.SetTargetProperty(myAnimation, new PropertyPath("Opacity"));
            sb.Children.Add(myAnimation);

            sb.Begin();

        }