Exemple #1
0
 private static void ThreadSys(Brush bg, Dispatcher dispatcher, Color defaultColor)
 {
     while (ShouldRun)
     {
         while (Changing)
         {
             dispatcher.Invoke(() =>
             {
                 Random random            = new Random();
                 ColorAnimation animation = new ColorAnimation();
                 animation.From           = ((SolidColorBrush)bg).Color;
                 animation.To             = Color.FromRgb((byte)random.Next(0, 255), (byte)random.Next(0, 255),
                                                          (byte)random.Next(0, 255));
                 animation.Duration = new Duration(TimeSpan.FromSeconds(1));
                 bg.BeginAnimation(SolidColorBrush.ColorProperty, animation);
             });
             Thread.Sleep(1000);
         }
         if (!Changing)
         {
             dispatcher.Invoke(() =>
             {
                 // Random random = new Random();
                 ColorAnimation animation = new ColorAnimation();
                 animation.From           = ((SolidColorBrush)bg).Color;
                 animation.To             = defaultColor;
                 animation.Duration       = new Duration(TimeSpan.FromSeconds(1));
                 bg.BeginAnimation(SolidColorBrush.ColorProperty, animation);
             });
         }
     }
 }
        //fix MAINWINDOW bug
        public CardDragAdorner(CardControl anchor, CardControl sourceCard, Vector mousePoint)
            : base(Program.PlayWindow.Content as UIElement)
        {
            SourceCard = sourceCard;
            bool isCardInverted = anchor.IsOnTableCanvas && (Player.LocalPlayer.InvertedTable ^ anchor.IsInverted);
            Point cardOrigin;
            if (isCardInverted)
            {
                CardDef 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;
            }
            //fix MAINWINDOW bug
            _basePt = anchor.TranslatePoint(cardOrigin, Program.PlayWindow.Content as UIElement);

            _faceUp = sourceCard.IsAlwaysUp || sourceCard.Card.FaceUp;
            _lightRedBrush = Brushes.Red.Clone();
            _faceDownBrush = new ImageBrush(sourceCard.Card.GetBitmapImage(false));
            _faceUpBrush = _faceUp
                               ? 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);

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

            _faceUpBrush.BeginAnimation(Brush.OpacityProperty, animation);
            _faceDownBrush.BeginAnimation(Brush.OpacityProperty, animation);
            _lightRedBrush.BeginAnimation(Brush.OpacityProperty, animation);
        }