상속: Timeline, IRepositionThemeAnimation
예제 #1
0
        private void AddDice(DiceViewModel newDiceViewModel)
        {
            Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                var storyRollDice = new Storyboard();

                var maxWidth = MainCanvas.ActualWidth;
                var maxHeight = MainCanvas.ActualHeight;

                // Retrieve the center position of the menu, to use as a start point for the animation later.
                var menuCenter = (Menu.VerticalAlignment == VerticalAlignment.Center)
                                    ? new Point(Menu.ActualWidth / 2.0, maxHeight / 2.0)
                                    : new Point(maxWidth / 2.0, maxHeight - (Menu.ActualHeight / 2.0));

                // Create the Dice object.
                var dice = new Dice
                {
                    DataContext = newDiceViewModel
                };

                // Add it to the Canvas.
                MainCanvas.Children.Add(dice);

                // Find a position to place the dice in max 10 loops.
                Rect posRect;
                bool posOk = false;
                short tryCount = 0;

                while (!posOk && tryCount < 10)
                {
                    double newTop;
                    double newLeft;

                    if (Menu.VerticalAlignment == VerticalAlignment.Center)
                    {
                        newTop = (double)RandomHelpers.Next(0, (int)(maxHeight - dice.RealHeight));
                        newLeft = ((newTop > (maxHeight / 2.0) ? newTop - (maxHeight / 2.0) : (maxHeight / 2.0) - newTop - dice.RealHeight) > (Menu.ActualHeight / 2.0)) ? (double)RandomHelpers.Next(0, (int)(maxWidth - dice.RealWidth)) : (double)RandomHelpers.Next((int)Menu.ActualWidth, (int)(maxWidth - dice.RealWidth));
                    }
                    else
                    {
                        newLeft = (double)RandomHelpers.Next(0, (int)(maxWidth - dice.RealWidth));
                        newTop = ((newLeft > (maxWidth / 2.0) ? newLeft - (maxWidth / 2.0) : (maxWidth / 2.0) - newLeft - dice.RealWidth) > (Menu.ActualWidth / 2.0)) ? (double)RandomHelpers.Next(0, (int)(maxHeight - dice.RealHeight)) : (double)RandomHelpers.Next(0, (int)(maxHeight - dice.RealHeight - Menu.ActualHeight));
                    }

                    posRect = new Rect(newLeft, newTop, dice.RealWidth, dice.RealHeight);
                    posOk = true;

                    foreach (var otherDiceRect in diceRects.Values)
                    {
                        var intersection = otherDiceRect;
                        intersection.Intersect(posRect);

                        if (!intersection.IsEmpty)
                        {
                            posOk = false;
                            tryCount++;
                            continue;
                        }
                    }
                }

                // Add the current dice's rect to the list.
                diceRects.Add(newDiceViewModel, posRect);

                Canvas.SetLeft(dice, posRect.X);
                Canvas.SetTop(dice, posRect.Y);

                var repositionAnim = new RepositionThemeAnimation
                {
                    FromHorizontalOffset = (menuCenter.X - (dice.RealWidth / 2.0)) - posRect.X,
                    FromVerticalOffset = (menuCenter.Y - (dice.RealHeight / 2.0)) - posRect.Y,
                    SpeedRatio = 0.2
                };

                Storyboard.SetTarget(repositionAnim, dice);
                storyRollDice.Children.Add(repositionAnim);

                // Run the animaton.
                storyRollDice.Begin();
            });
        }
예제 #2
0
        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            // Create the different dice types... Could be loaded from files later (or part of user settings).
            App.ViewModel.Counters.Add(new DiceCounterViewModel
            {
                Name = "D4",
                Brush = new SolidColorBrush(Colors.Black),
                DiceMax = 4
            });

            App.ViewModel.Counters.Add(new DiceCounterViewModel
            {
                Name = "D6",
                Brush = new SolidColorBrush(ColorHelpers.ColorFromHexString("#2B2B2B")),
                DiceMax = 6
            });

            App.ViewModel.Counters.Add(new DiceCounterViewModel
            {
                Name = "D8",
                Brush = new SolidColorBrush(ColorHelpers.ColorFromHexString("#5C5C5C")),
                DiceMax = 8
            });

            App.ViewModel.Counters.Add(new DiceCounterViewModel
            {
                Name = "D10",
                Brush = new SolidColorBrush(ColorHelpers.ColorFromHexString("#9D1414")),
                DiceMax = 10
            });

            App.ViewModel.Counters.Add(new DiceCounterViewModel
            {
                Name = "D20",
                Brush = new SolidColorBrush(ColorHelpers.ColorFromHexString("#DC0000")),
                DiceMax = 20
            });

            // Entrance animations.
            var menuEntranceAnim = new RepositionThemeAnimation
            {
                SpeedRatio = 0.2
            };

            if (DisplayProperties.CurrentOrientation == DisplayOrientations.Portrait
                || DisplayProperties.CurrentOrientation == DisplayOrientations.PortraitFlipped)
            {
                menuEntranceAnim.FromHorizontalOffset = (this.ActualWidth / 2.0) + (GridMenu.ActualWidth / 2.0);
            }
            else
            {
                menuEntranceAnim.FromVerticalOffset = (this.ActualHeight / 2.0) + (GridMenu.ActualHeight / 2.0);
            }

            Storyboard.SetTarget(menuEntranceAnim, GridMenu);

            var menuOpacityAnim = new DoubleAnimation
            {
                To = 1,
                Duration = new Duration(TimeSpan.FromSeconds(0.2))
            };

            Storyboard.SetTarget(menuOpacityAnim, GridMenu);
            Storyboard.SetTargetProperty(menuOpacityAnim, "Opacity");

            var menuEntranceStory = new Storyboard();

            menuEntranceStory.Children.Add(menuEntranceAnim);
            menuEntranceStory.Children.Add(menuOpacityAnim);

            menuEntranceStory.BeginTime = TimeSpan.FromSeconds(0.5);
            menuEntranceStory.Begin();
        }
예제 #3
0
        private void AppBarOpened(object sender, object e)
        {
            ApplicationViewState currentViewState = ApplicationView.Value;

            if (currentViewState != ApplicationViewState.Snapped)
            {
                if (timelineContainer == null)
                {
                    try
                    {
                        timelineContainer = (Grid)videoMediaElement.ControlPanel.GetDescendantsOfType<Grid>().ElementAt(2);
                    }
                    catch { }
                }

                try
                {
                    ClipDataGrid.Visibility = Windows.UI.Xaml.Visibility.Collapsed;

                    Storyboard sb = new Storyboard();

                    RepositionThemeAnimation repositionTimelineAnimation = new RepositionThemeAnimation();
                    RepositionThemeAnimation repositionBtnAnimation = new RepositionThemeAnimation();
                    FadeOutThemeAnimation fadeOutAnimation = new FadeOutThemeAnimation();
                    FadeOutThemeAnimation fadeOutBtn = new FadeOutThemeAnimation();

                    Storyboard.SetTarget(fadeOutAnimation, ClipDataGrid as DependencyObject);
                    Storyboard.SetTarget(fadeOutBtn, LessBtn as DependencyObject);

                    Storyboard.SetTarget(repositionTimelineAnimation, timelineContainer as DependencyObject);
                    repositionTimelineAnimation.FromVerticalOffset = 204;

                    Storyboard.SetTarget(repositionBtnAnimation, LessBtn as DependencyObject);
                    repositionBtnAnimation.FromVerticalOffset = 204;

                    sb.Children.Add(repositionTimelineAnimation);
                    sb.Children.Add(repositionBtnAnimation);
                    sb.Children.Add(fadeOutAnimation);
                    sb.Children.Add(fadeOutBtn);

                    timelineContainer.Margin = new Thickness(0, 0, 0, 204);

                    sb.Begin();
                }
                catch { }
            }
        }