示例#1
0
        public static void SetBorderBackgroundSlider(ImageBrush image, Border border)
        {
            //Create the fade out animation. 
            DoubleAnimation fadeOutAnimation = new DoubleAnimation(0, TimeSpan.FromMilliseconds(500));
            fadeOutAnimation.AutoReverse = false;

            //wait until the first animation is complete before changing the background, or else it will appear to just "fadeIn" with now fadeout.
            fadeOutAnimation.Completed += delegate(object sender, EventArgs e)
            {
                //once the fadeout is complete set the new back ground and fade back in. 
                //Create a new background brush.
                image.Opacity = 0;

                //Set the grid background to the new brush. 
                border.Background = image;

                //Set the brush...(not the background property) with the animation. 
                DoubleAnimation fadeInAnimation = new DoubleAnimation(1, TimeSpan.FromMilliseconds(1000));
                fadeInAnimation.AutoReverse = false;
                image.BeginAnimation(Brush.OpacityProperty, fadeInAnimation);
            };

            //Fade out..before changing the background.
            var currentBackground = border.Background;
            currentBackground.BeginAnimation(Brush.OpacityProperty, fadeOutAnimation);
        }
示例#2
0
        public CardDragAdorner(CardControl anchor, CardControl sourceCard, Vector mousePoint)
            : base(Application.Current.MainWindow.Content as UIElement)
        {
            SourceCard = sourceCard;
              bool isCardInverted = anchor.IsOnTableCanvas && (Player.LocalPlayer.InvertedTable ^ anchor.IsInverted);
              Point cardOrigin;
              if (isCardInverted)
              {
            var cardDef = Program.Game.Definition.CardDefinition;
            cardOrigin = new Point(cardDef.Width, cardDef.Height);
            mouseOffset = new Vector(cardDef.Width - mousePoint.X, cardDef.Height - mousePoint.Y);
              }
              else
              {
            cardOrigin = new Point();
            mouseOffset = mousePoint;
              }
              basePt = anchor.TranslatePoint(cardOrigin, Application.Current.MainWindow.Content as UIElement);

              _faceUp = sourceCard.IsAlwaysUp ? true : sourceCard.Card.FaceUp;
              lightRedBrush = Brushes.Red.Clone();
              faceDownBrush = new ImageBrush(sourceCard.Card.GetBitmapImage(false));
              faceUpBrush = _faceUp ?
              (Brush)new VisualBrush(sourceCard.GetCardVisual()) { Viewbox = new Rect(0, 0, sourceCard.ActualWidth, sourceCard.ActualHeight), ViewboxUnits = BrushMappingMode.Absolute } :
              (Brush)new ImageBrush(new BitmapImage(new Uri(Program.Game.Definition.CardDefinition.Front)));
              invertTransform = new ScaleTransform() { CenterX = 0.5, CenterY = 0.5 };
              faceUpBrush.RelativeTransform = invertTransform;
              if (faceUpBrush is VisualBrush)
            RenderOptions.SetCachingHint(faceUpBrush, CachingHint.Cache);

              child.BeginInit();
              child.Width = anchor.ActualWidth * CardControl.scaleFactor.Width;
              child.Height = anchor.ActualHeight * CardControl.scaleFactor.Height;
              child.Fill = _faceUp ? faceUpBrush : faceDownBrush;
              child.StrokeThickness = 3;

              var transforms = new TransformGroup();
              child.RenderTransform = transforms;
              rot = sourceCard.Card.Orientation;
              if ((rot & CardOrientation.Rot180) != 0)
              {
            rot180Transform = new RotateTransform(180, child.Width / 2, child.Height / 2);
            transforms.Children.Add(rot180Transform);
              }
              if ((rot & CardOrientation.Rot90) != 0)
              {
            rot90Transform = isCardInverted ?
              new RotateTransform(90, child.Width / 2, child.Width / 2) :
              new RotateTransform(90, child.Width / 2, child.Height - child.Width / 2);
            transforms.Children.Add(rot90Transform);
              }
              translate = new TranslateTransform();
              transforms.Children.Add(translate);

              child.IsHitTestVisible = false;
              child.EndInit();
              AddVisualChild(child);

              DoubleAnimation animation = new DoubleAnimation(0.55, 0.75, new Duration(TimeSpan.FromMilliseconds(500)));
              animation.AutoReverse = true;
              animation.RepeatBehavior = RepeatBehavior.Forever;
              animation.Freeze();

              faceUpBrush.BeginAnimation(Brush.OpacityProperty, animation);
              faceDownBrush.BeginAnimation(Brush.OpacityProperty, animation);
              lightRedBrush.BeginAnimation(Brush.OpacityProperty, animation);
        }