internal static void MouseOverColorEvent(byte a, byte r, byte g, byte b, Brush brush, bool alpha) { colorAnimation.From = Color.FromArgb(a, r, g, b); colorAnimation.To = !alpha?GetPrefferedColorOver() : GetPrefferedColorOverAlpha(); brush.BeginAnimation(SolidColorBrush.ColorProperty, colorAnimation); }
public static void AnimateImageSourceChange(this Brush background, ImageBrush newImage, Action <ImageBrush> onChangeImage, AnimateImageChangeParams animateImageChangeParams = null) { var animationParameters = animateImageChangeParams ?? new AnimateImageChangeParams(); if (background != null) { var fadeOutAnimation = new DoubleAnimation(0d, animationParameters.FadeTime) { AutoReverse = false }; var fadeInAnimation = new DoubleAnimation(0d, animationParameters.TargetOpacity, animationParameters.FadeTime) { AutoReverse = false }; fadeOutAnimation.Completed += (o, e) => { newImage.Opacity = 0d; onChangeImage(newImage); background.Opacity = animationParameters.TargetOpacity; newImage.BeginAnimation(Brush.OpacityProperty, fadeInAnimation); }; background.BeginAnimation(Brush.OpacityProperty, fadeOutAnimation); } else { newImage.Opacity = animateImageChangeParams.TargetOpacity; onChangeImage(newImage); } }
public static void EndBrushColorAnimation(this Brush brush) { if (!brush.IsSealed) { brush.BeginAnimation(SolidColorBrush.ColorProperty, null); } }
protected override void BeginTransition3D(TransitionPresenter transitionElement, ContentPresenter oldContent, ContentPresenter newContent, Viewport3D viewport) { Brush clone = CreateBrush(oldContent); Size size = transitionElement.RenderSize; MeshGeometry3D leftDoor = CreateMesh(new Point3D(), new Vector3D(size.Width / 2, 0, 0), new Vector3D(0, size.Height, 0), 1, 1, new Rect(0, 0, 0.5, 1)); GeometryModel3D leftDoorGeometry = new GeometryModel3D(); leftDoorGeometry.Geometry = leftDoor; leftDoorGeometry.Material = new DiffuseMaterial(clone); AxisAngleRotation3D leftRotation = new AxisAngleRotation3D(new Vector3D(0, 1, 0), 0); leftDoorGeometry.Transform = new RotateTransform3D(leftRotation); GeometryModel3D rightDoorGeometry = new GeometryModel3D(); MeshGeometry3D rightDoor = CreateMesh(new Point3D(size.Width / 2, 0, 0), new Vector3D(size.Width / 2, 0, 0), new Vector3D(0, size.Height, 0), 1, 1, new Rect(0.5, 0, 0.5, 1)); rightDoorGeometry.Geometry = rightDoor; rightDoorGeometry.Material = new DiffuseMaterial(clone); AxisAngleRotation3D rightRotation = new AxisAngleRotation3D(new Vector3D(0, 1, 0), 0); rightDoorGeometry.Transform = new RotateTransform3D(rightRotation, size.Width, 0, 0); Model3DGroup doors = new Model3DGroup(); doors.Children.Add(leftDoorGeometry); doors.Children.Add(rightDoorGeometry); ModelVisual3D model = new ModelVisual3D(); model.Content = doors; viewport.Children.Add(model); DoubleAnimation da = new DoubleAnimation(90 - 0.5 * FieldOfView, Duration); leftRotation.BeginAnimation(AxisAngleRotation3D.AngleProperty, da); da = new DoubleAnimation(-(90 - 0.5 * FieldOfView), Duration); rightRotation.BeginAnimation(AxisAngleRotation3D.AngleProperty, da); da = new DoubleAnimation(0, Duration); da.Completed += delegate { EndTransition(transitionElement, oldContent, newContent); }; clone.BeginAnimation(Brush.OpacityProperty, da); }
internal static void AltInterfacePreviewMouseOver(Brush foreground, Brush border) { var alpha = AnimationHelper.GetPrefferedColorOver(); ccAnim.From = alpha; ccAnim.To = AnimationHelper.GetPrefferedColorDown(); foreground.BeginAnimation(SolidColorBrush.ColorProperty, ccAnim); AnimationHelper.MouseOverColorEvent(alpha.A, alpha.R, alpha.G, alpha.B, border, true); }
internal static void LightThemeMouseEvent(UIElement uIElement, Brush brush) { var c = (Color)Application.Current.Resources["IconColor"]; uIElement.MouseEnter += delegate { colorAnimation.From = Color.FromRgb(c.R, c.G, c.B); colorAnimation.To = Colors.White; brush.BeginAnimation(SolidColorBrush.ColorProperty, colorAnimation); }; uIElement.MouseLeave += delegate { colorAnimation.From = Colors.White; colorAnimation.To = Color.FromRgb(c.R, c.G, c.B); brush.BeginAnimation(SolidColorBrush.ColorProperty, colorAnimation); }; }
internal static void MouseLeaveColorEvent(byte a, byte r, byte g, byte b, Brush brush, short colortheme) { switch (colortheme) { case 1: default: ccAnim.From = Properties.Settings.Default.Blue; break; case 2: ccAnim.From = Properties.Settings.Default.Pink; break; case 3: ccAnim.From = Properties.Settings.Default.Orange; break; case 4: ccAnim.From = Properties.Settings.Default.Green; break; case 5: ccAnim.From = Properties.Settings.Default.Red; break; case 6: ccAnim.From = Properties.Settings.Default.Teal; break; case 7: ccAnim.From = Properties.Settings.Default.Aqua; break; case 8: ccAnim.From = Properties.Settings.Default.Beige; break; case 9: ccAnim.From = Properties.Settings.Default.Purple; break; case 10: ccAnim.From = Properties.Settings.Default.Cyan; break; case 11: ccAnim.From = Properties.Settings.Default.Magenta; break; case 12: ccAnim.From = Properties.Settings.Default.Grey; break; } ccAnim.To = Color.FromArgb(a, r, g, b); brush.BeginAnimation(SolidColorBrush.ColorProperty, ccAnim); }
public static Brush BeginBrushColorAnimation(this Brush brush, Color color, int seconds = 1) { Brush br = (brush == null)? new SolidColorBrush() : brush.Clone(); //otherwise the default brush is "frozen" and can'SelectedFoldersTable be animated br.BeginAnimation(SolidColorBrush.ColorProperty, new ColorAnimation(color, TimeSpan.FromSeconds(seconds)) { AutoReverse = true, RepeatBehavior = RepeatBehavior.Forever }); return(br); }
private void AnimateOpacity(Brush obj, double toOpacity, double animationTime) { DoubleAnimation animation = new DoubleAnimation(toOpacity, new Duration(TimeSpan.FromMilliseconds(animationTime))) { AccelerationRatio = 0.3, DecelerationRatio = 0.5 }; obj.BeginAnimation(Brush.OpacityProperty, animation); }
public static Extensions.EffectEntity AnimateOpacity(this Extensions.EffectEntity Element, double FromValue, double ToValue, int Duration) { DoubleAnimation Animation = new DoubleAnimation(FromValue, ToValue, new Duration(TimeSpan.FromMilliseconds(Duration)), FillBehavior.Stop); Element.If <DoubleAnimation>(Animation); Brush bElement = Element.Get <SolidColorBrush>("Background"); bElement.BeginAnimation(SolidColorBrush.OpacityProperty, Animation); return(Element); }
internal static void PreviewMouseLeftButtonDownColorEvent(Brush brush, bool alpha) { if (!alpha) { colorAnimation.From = GetPrefferedColorOver(); colorAnimation.To = GetPrefferedColorDown(); } else { colorAnimation.From = GetPrefferedColorOverAlpha(); colorAnimation.To = GetPrefferedColorDownAlpha(); } brush.BeginAnimation(SolidColorBrush.ColorProperty, colorAnimation); }
internal static void AltInterfaceMouseLeave(Brush foreground, Brush background, Brush border) { ccAnim.From = AnimationHelper.GetPrefferedColorOver(); ccAnim.To = (Color)Application.Current.Resources["IconColor"]; foreground.BeginAnimation(SolidColorBrush.ColorProperty, ccAnim); ccAnim2.From = (Color)Application.Current.Resources["AltInterfaceW"]; ccAnim2.To = (Color)Application.Current.Resources["AltInterface"]; background.BeginAnimation(SolidColorBrush.ColorProperty, ccAnim2); AnimationHelper.MouseLeaveColorEvent( borderBrush.Color.A, borderBrush.Color.R, borderBrush.Color.G, borderBrush.Color.B, border, true); }
internal static void MouseEnterColorEvent(byte a, byte r, byte g, byte b, Brush brush, int colortheme) { colorAnimation.From = Color.FromArgb(a, r, g, b); colorAnimation.To = colortheme switch { 2 => Properties.Settings.Default.Pink, 3 => Properties.Settings.Default.Orange, 4 => Properties.Settings.Default.Green, 5 => Properties.Settings.Default.Red, 6 => Properties.Settings.Default.Teal, 7 => Properties.Settings.Default.Aqua, 8 => Properties.Settings.Default.Golden, 9 => Properties.Settings.Default.Purple, 10 => Properties.Settings.Default.Cyan, 11 => Properties.Settings.Default.Magenta, 12 => Properties.Settings.Default.Lime, _ => Properties.Settings.Default.Blue, }; brush.BeginAnimation(SolidColorBrush.ColorProperty, colorAnimation); }
/// <summary> /// Animate a <see cref="Brush"/> of an <see cref="UIElement"/> with a specified time. /// </summary> /// <remarks> /// Note: If the initial <see cref="Brush"/> (from) or the final <see cref="Brush"/> (to) are <see langword="null"/>, no animation will be executed. /// </remarks> /// <param name="uiElement"><see cref="UIElement"/> that contains the <see cref="Brush"/>.</param> /// <param name="brushProperty"><see cref="Brush"/> property to animate.</param> /// <param name="to">New value of the <see cref="Brush"/>.</param> /// <param name="animationTime">Animation time.</param> internal static void AnimateBrush(UIElement uiElement, DependencyProperty brushProperty, Brush to, TimeSpan animationTime) { if (animationTime > TimeSpan.Zero && !uiElement.IsNull(brushProperty) && to != null) { uiElement.SetValue(brushProperty, ((Brush)uiElement.GetValue(brushProperty)).CloneCurrentValue()); //Unfreeze the brush Brush from = (Brush)uiElement.GetValue(brushProperty); if (from is SolidColorBrush sbFrom && to is SolidColorBrush sbTo) { ColorAnimation animation = new ColorAnimation { From = sbFrom.Color, To = sbTo.Color, Duration = new Duration(animationTime) }; from.BeginAnimation(SolidColorBrush.ColorProperty, animation); } else { uiElement.SetValue(brushProperty, to); } }
public void MakeCaret(Color colour, int cycleTime) { TheCanvas = new Canvas() { Visibility = Visibility.Visible }; Content = TheCanvas; CaretBrush = new SolidColorBrush(colour); DoubleAnimation caretAnimation = new DoubleAnimation(); caretAnimation.From = 1.0; caretAnimation.To = 0.0; caretAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(cycleTime / 2)); caretAnimation.AutoReverse = true; caretAnimation.RepeatBehavior = RepeatBehavior.Forever; CaretBrush.BeginAnimation(Brush.OpacityProperty, caretAnimation); Caret = new Line() { StrokeThickness = 1, Stroke = CaretBrush, Visibility = Visibility.Visible, X1 = 0, Y1 = 0, X2 = 0, Y2 = LineHeight }; TheCanvas.Children.Add(Caret); }
public void Dispose() { _faceUpBrush.BeginAnimation(Brush.OpacityProperty, null); _faceDownBrush.BeginAnimation(Brush.OpacityProperty, null); _lightRedBrush.BeginAnimation(Brush.OpacityProperty, null); }
protected override void BeginTransition3D(TransitionElement transitionElement, ContentPresenter oldContent, ContentPresenter newContent, Viewport3D viewport) { int xparticles = 15, yparticles = 15; Size size = transitionElement.RenderSize; if (size.Width > size.Height) { yparticles = (int)(xparticles * size.Height / size.Width); } else { xparticles = (int)(yparticles * size.Width / size.Height); } MeshGeometry3D mesh = CreateMesh(new Point3D(), new Vector3D(size.Width, 0, 0), new Vector3D(0, size.Height, 0), xparticles - 1, yparticles - 1, new Rect(0, 0, 1, 1)); Brush cloneBrush = CreateBrush(oldContent); Material clone = new DiffuseMaterial(cloneBrush); double ustep = size.Width / (xparticles - 1), vstep = size.Height / (yparticles - 1); Point3DCollection points = mesh.Positions; Random rand = new Random(); // add some random movement to the z order for (int i = 0; i < points.Count; i++) { points[i] += 0.1 * ustep * (rand.NextDouble() * 2 - 1) * new Vector3D(0, 0, 1); } Point3DCollection oldPoints = points.Clone(); Vector3D acceleration = new Vector3D(0, 700, 0); //gravity double timeStep = 1.0 / 60.0; DispatcherTimer timer = new DispatcherTimer(); timer.Interval = TimeSpan.FromSeconds(timeStep); bool fading = false; double time = 0; double slideVelocity = size.Width / 2.0; double windScale = 30 * size.Width * size.Height; timer.Tick += delegate { time = time + timeStep; Point mousePos = Mouse.GetPosition(viewport); Point3D mousePos3D = new Point3D(mousePos.X, mousePos.Y, -10); for (int i = 0; i < oldPoints.Count; i++) { Point3D currentPoint = points[i]; Vector3D wind = new Vector3D(0, 0, windScale / (mousePos3D - currentPoint).LengthSquared); Point3D newPoint = currentPoint + (currentPoint - oldPoints[i]) + timeStep * timeStep * (acceleration + wind); if (newPoint.Y > size.Height) { newPoint.Y = size.Height; } oldPoints[i] = newPoint; } //for (int j = 0; j < 5; j++) for (int i = oldPoints.Count - 1; i > 0; i--) { // constrain with point to the left if (i > yparticles) { Constrain(oldPoints, i, i - yparticles, ustep); } // constrain with point to the top if (i % yparticles != 0) { Constrain(oldPoints, i, i - 1, vstep); } } // slide the top row of points to the left for (int i = 0; i < xparticles; i += 1) { oldPoints[i * yparticles] = new Point3D(Math.Max(0, i * ustep - slideVelocity * time * i / (xparticles - 1)), 0, 0); } if (!fading && points[points.Count - yparticles].X < size.Width / 2) { fading = true; DoubleAnimation da = new DoubleAnimation(0, new Duration(TimeSpan.FromSeconds(1.5))); da.Completed += delegate { timer.Stop(); EndTransition(transitionElement, oldContent, newContent); }; cloneBrush.BeginAnimation(Brush.OpacityProperty, da); } // Swap position arrays mesh.Positions = oldPoints; oldPoints = points; points = mesh.Positions; }; timer.Start(); GeometryModel3D geo = new GeometryModel3D(mesh, clone); geo.BackMaterial = clone; ModelVisual3D model = new ModelVisual3D(); model.Content = geo; viewport.Children.Add(model); }
internal static void PreviewMouseLeftButtonDownColorEvent(Brush brush, int colortheme) { switch (colortheme) { case 1: default: colorAnimation.From = Properties.Settings.Default.Blue; colorAnimation.To = Properties.Settings.Default.BlueAlpha; break; case 2: colorAnimation.From = Properties.Settings.Default.Pink; colorAnimation.To = Properties.Settings.Default.PinkAlpha; break; case 3: colorAnimation.From = Properties.Settings.Default.Orange; colorAnimation.To = Properties.Settings.Default.OrangeAlpha; break; case 4: colorAnimation.From = Properties.Settings.Default.Green; colorAnimation.To = Properties.Settings.Default.GreenAlpha; break; case 5: colorAnimation.From = Properties.Settings.Default.Red; colorAnimation.To = Properties.Settings.Default.RedAlpha; break; case 6: colorAnimation.From = Properties.Settings.Default.Teal; colorAnimation.To = Properties.Settings.Default.TealAlpha; break; case 7: colorAnimation.From = Properties.Settings.Default.Aqua; colorAnimation.To = Properties.Settings.Default.AquaAlpha; break; case 8: colorAnimation.From = Properties.Settings.Default.Golden; colorAnimation.To = Properties.Settings.Default.GoldenAlpha; break; case 9: colorAnimation.From = Properties.Settings.Default.Purple; colorAnimation.To = Properties.Settings.Default.PurpleAlpha; break; case 10: colorAnimation.From = Properties.Settings.Default.Cyan; colorAnimation.To = Properties.Settings.Default.CyanAlpha; break; case 11: colorAnimation.From = Properties.Settings.Default.Magenta; colorAnimation.To = Properties.Settings.Default.MagentaAlpha; break; case 12: colorAnimation.From = Properties.Settings.Default.Lime; colorAnimation.To = Properties.Settings.Default.LimeAlpha; break; } brush.BeginAnimation(SolidColorBrush.ColorProperty, colorAnimation); }
//fix MAINWINDOW bug public CardDragAdorner(CardControl anchor, CardControl sourceCard, Vector mousePoint) : base(WindowManager.PlayWindow.Content as UIElement) { SourceCard = sourceCard; bool isCardInverted = anchor.IsOnTableCanvas && (Player.LocalPlayer.InvertedTable ^ anchor.IsInverted); Point cardOrigin; if (isCardInverted) { // If adjorners are f****d up, try sourceCard instead of anchor and vise versa cardOrigin = new Point(anchor.Card.Size.Width, anchor.Card.Size.Height); _mouseOffset = new Vector(anchor.Card.Size.Width - mousePoint.X, anchor.Card.Size.Height - mousePoint.Y); } else { cardOrigin = new Point(); _mouseOffset = mousePoint; } //fix MAINWINDOW bug _basePt = anchor.TranslatePoint(cardOrigin, WindowManager.PlayWindow.Content as UIElement); _faceUp = sourceCard.IsAlwaysUp || sourceCard.Card.FaceUp; _lightRedBrush = Brushes.Red.Clone(); _faceDownBrush = new ImageBrush(sourceCard.Card.GetBitmapImage(false)); var bim = new BitmapImage(); bim.BeginInit(); bim.CacheOption = BitmapCacheOption.OnLoad; bim.UriSource = new Uri(anchor.Card.Size.Front); bim.EndInit(); _faceUpBrush = _faceUp ? new VisualBrush(sourceCard.GetCardVisual()) { Viewbox = new Rect(0, 0, sourceCard.ActualWidth, sourceCard.ActualHeight), ViewboxUnits = BrushMappingMode.Absolute } : (Brush) new ImageBrush(bim); _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); }
internal static void MouseLeaveBgTexColor(Brush brush) { colorAnimation.From = (Color)Application.Current.Resources["BackgroundHoverHighlight"]; colorAnimation.To = Color.FromArgb(0, 0, 0, 0); brush.BeginAnimation(SolidColorBrush.ColorProperty, colorAnimation); }