public MainPage() { InitializeComponent(); Compositor = Window.Current.Compositor; //Set Background color. GradientBrush = Compositor.CreateLinearGradientBrush(); GradientBrush.StartPoint = new Vector2(0.5f, 0); GradientBrush.EndPoint = new Vector2(0.5f, 1); TopGradientStop = Compositor.CreateColorGradientStop(0, Color.FromArgb(255, 0, 0, 0)); BottomGradientStop = Compositor.CreateColorGradientStop(0.352f, Color.FromArgb(255, 51, 27, 59)); GradientBrush.ColorStops.Add(BottomGradientStop); GradientBrush.ColorStops.Add(TopGradientStop); BackgroundVisual = Compositor.CreateSpriteVisual(); BackgroundVisual.Brush = GradientBrush; ElementCompositionPreview.SetElementChildVisual(Gradient, BackgroundVisual); BuldRef = Bulb; BuldEffectRef = BuldLight; ScreenEffectRef = ScreenEffect; BaseUri = base.BaseUri; Gradient.SizeChanged += (s, e) => { if (e.NewSize == e.PreviousSize) { return; } BackgroundVisual.Size = e.NewSize.ToVector2(); GradientBrush.CenterPoint = BackgroundVisual.Size / 2; }; }
private void StartOffsetAnimation(CompositionColorGradientStop gradientOffset, float offset) { var offsetAnimation = _compositor.CreateScalarKeyFrameAnimation(); offsetAnimation.Duration = TimeSpan.FromSeconds(1); offsetAnimation.InsertKeyFrame(1.0f, offset); gradientOffset.StartAnimation(nameof(CompositionColorGradientStop.Offset), offsetAnimation); }
private void StartColorAnimation(CompositionColorGradientStop gradientOffset, Color color) { var colorAnimation = _compositor.CreateColorKeyFrameAnimation(); colorAnimation.Duration = TimeSpan.FromSeconds(2); colorAnimation.Direction = Windows.UI.Composition.AnimationDirection.Alternate; colorAnimation.InsertKeyFrame(1.0f, color); gradientOffset.StartAnimation(nameof(CompositionColorGradientStop.Color), colorAnimation); }
private void AnimateLinearGradientstopOffset(CompositionColorGradientStop stop, TimeSpan duration, float offsetAdjustment) { var animateStop = _compositor.CreateScalarKeyFrameAnimation(); animateStop.InsertKeyFrame(0, stop.Offset); animateStop.InsertKeyFrame(0.5f, stop.Offset + offsetAdjustment); animateStop.InsertKeyFrame(1, stop.Offset); animateStop.IterationBehavior = AnimationIterationBehavior.Forever; animateStop.Duration = duration; stop.StartAnimation(nameof(stop.Offset), animateStop); }
private void InitLGBAnimation(CompositionColorGradientStop stop, int duration, float offsetAdjustment) { ScalarKeyFrameAnimation animateStop = _compositor.CreateScalarKeyFrameAnimation(); animateStop.InsertKeyFrame(0.0f, stop.Offset); animateStop.InsertKeyFrame(0.5f, stop.Offset + offsetAdjustment); animateStop.InsertKeyFrame(1.0f, stop.Offset); animateStop.IterationBehavior = AnimationIterationBehavior.Forever; animateStop.Duration = TimeSpan.FromSeconds(duration); stop.StartAnimation(nameof(stop.Offset), animateStop); }
public Gradients() : base() { InitializeComponent(); _compositor = Window.Current.Compositor; _gradientBrush = _compositor.CreateLinearGradientBrush(); _gradientBrush.StartPoint = Vector2.Zero; _gradientBrush.EndPoint = new Vector2(1.0f); _relaxGradientStop = _compositor.CreateColorGradientStop(); _relaxGradientStop.Offset = 0.5f; _relaxGradientStop.Color = Blue; _focusGradientStop = _compositor.CreateColorGradientStop(); _focusGradientStop.Offset = 0.5f; _focusGradientStop.Color = Red; _gradientBrush.ColorStops.Add(_relaxGradientStop); _gradientBrush.ColorStops.Add(_focusGradientStop); _backgroundVisual = _compositor.CreateSpriteVisual(); _backgroundVisual.Brush = _gradientBrush; ElementCompositionPreview.SetElementChildVisual(Gradient, _backgroundVisual); Loaded += async(s, e) => { await Task.Delay(2000); UpdateGradients(); MiddleText.Visibility = Visibility.Collapsed; await Task.Delay(2000); UpdateText(); }; Gradient.SizeChanged += (s, e) => { if (e.NewSize == e.PreviousSize) { return; } _backgroundVisual.Size = e.NewSize.ToVector2(); _gradientBrush.CenterPoint = _backgroundVisual.Size / 2; }; ViewModel.IsInPomodoroChanged += (s, e) => { UpdateGradients(); UpdateText(); }; }
private void AnimateBrushStop1(CompositionColorGradientStop target, CompositionColorGradientStop target1) { if (target.Color == Colors.DeepPink) { target.StartAnimation(nameof(target.Color), _colorAnimGradientStop1); target1.StartAnimation(nameof(target1.Color), _colorAnimGradientStop2); } else if (target.Color == Colors.Teal) { target.StartAnimation(nameof(target.Color), _changeb1stop1); target1.StartAnimation(nameof(target1.Color), _changeb1stop2); } }
private void pointerPressedChangeColors(CompositionColorGradientStop target, CompositionColorGradientStop target1) { if (target.Color == Colors.DeepPink || target.Color == Colors.Honeydew) { target.StartAnimation(nameof(target.Color), _changeb1stop1); target1.StartAnimation(nameof(target1.Color), _changeb1stop2); } else if (target.Color == Colors.LightSkyBlue || target.Color == Colors.Teal) { target1.StartAnimation(nameof(target1.Color), _colorAnimGradientStop1); target.StartAnimation(nameof(target.Color), _colorAnimGradientStop2); } }
private void ChangeBrushBack(CompositionColorGradientStop target, CompositionColorGradientStop target1) { if (target.Color == Colors.Honeydew) { target1.StartAnimation(nameof(target1.Color), _colorAnimGradientStop1); target.StartAnimation(nameof(target.Color), _colorAnimGradientStop2); } else if (target.Color == Colors.LightSkyBlue) { target1.StartAnimation(nameof(target1.Color), _changeb1stop1); target.StartAnimation(nameof(target.Color), _changeb1stop2); } }
protected override CompositionBrush CreateBrush() { _compositor = Window.Current.Compositor; _foregroundBrush = _compositor.CreateLinearGradientBrush(); _foregroundBrush.StartPoint = Vector2.Zero; _foregroundBrush.EndPoint = new Vector2(1.0f); _bottomRightGradientStop = _compositor.CreateColorGradientStop(); _bottomRightGradientStop.Offset = 0.5f; _bottomRightGradientStop.Color = Green; _topLeftradientStop = _compositor.CreateColorGradientStop(); _topLeftradientStop.Offset = 0.5f; _topLeftradientStop.Color = Blue; _foregroundBrush.ColorStops.Add(_bottomRightGradientStop); _foregroundBrush.ColorStops.Add(_topLeftradientStop); _backgroundBrush = _compositor.CreateLinearGradientBrush(); _backgroundBrush.StartPoint = new Vector2(1.0f, 0); _backgroundBrush.EndPoint = new Vector2(0, 1.0f); _topRightGradientStop = _compositor.CreateColorGradientStop(); _topRightGradientStop.Offset = 0.25f; _topRightGradientStop.Color = Black; _bottomLeftGradientStop = _compositor.CreateColorGradientStop(); _bottomLeftGradientStop.Offset = 1.0f; _bottomLeftGradientStop.Color = Black; _backgroundBrush.ColorStops.Add(_topRightGradientStop); _backgroundBrush.ColorStops.Add(_bottomLeftGradientStop); var graphicsEffect = new BlendEffect() { Mode = BlendEffectMode.Screen, Foreground = new CompositionEffectSourceParameter("Main"), Background = new CompositionEffectSourceParameter("Tint"), }; var effectFactory = _compositor.CreateEffectFactory(graphicsEffect); _brush = effectFactory.CreateBrush(); _brush.SetSourceParameter("Main", _foregroundBrush); _brush.SetSourceParameter("Tint", _backgroundBrush); return(_brush); }
private SpriteVisual GetRadialGradientVisualWithAnimation(Vector2 size, Vector2 gradientOrigin, Vector2 ellipseCenter, Vector2 ellipseRadius) { // Create radial gradient brush. var gradientBrush = _compositor.CreateRadialGradientBrush(); gradientBrush.GradientOriginOffset = gradientOrigin; gradientBrush.EllipseCenter = ellipseCenter; gradientBrush.EllipseRadius = ellipseRadius; // Add the color stops. The first color stop needs a name so you can refer to it later. CompositionColorGradientStop ColorStop1 = _compositor.CreateColorGradientStop(0, Colors.Blue); gradientBrush.ColorStops.Add(ColorStop1); gradientBrush.ColorStops.Add(_compositor.CreateColorGradientStop(1, Colors.LightBlue)); gradientBrush.ColorStops.Add(_compositor.CreateColorGradientStop(1, Colors.Navy)); gradientBrush.ColorStops.Add(_compositor.CreateColorGradientStop(1, Colors.White)); // Set up animation for ColorStop1's color. var colorAnimation = _compositor.CreateColorKeyFrameAnimation(); colorAnimation.InsertKeyFrame(0.0f, Colors.Blue); colorAnimation.InsertKeyFrame(0.5f, Colors.LightBlue); colorAnimation.InsertKeyFrame(0.75f, Colors.Navy); colorAnimation.InsertKeyFrame(1.0f, Colors.Blue); colorAnimation.Duration = TimeSpan.FromSeconds(5); colorAnimation.IterationBehavior = AnimationIterationBehavior.Forever; ColorStop1.StartAnimation("Color", colorAnimation); // SpriteVisual to be painted with gradated content. var gradientVisual = _compositor.CreateSpriteVisual(); gradientVisual.Size = size; // Set brush on the SpriteVisual. gradientVisual.Brush = gradientBrush; return(gradientVisual); }
// Main circle private void CreateTopCircleButton() { CompositionRoundedRectangleGeometry circleGeometry = compositor.CreateRoundedRectangleGeometry(); circleGeometry.Size = new Vector2(40, 40); circleGeometry.CornerRadius = new Vector2(20, 20); CompositionSpriteShape compositionSpriteShape = compositor.CreateSpriteShape(circleGeometry); circleGradientBrush = compositor.CreateRadialGradientBrush(); // Color animation ColorStop1 = compositor.CreateColorGradientStop(1, Colors.White); circleGradientBrush.ColorStops.Add(ColorStop1); color1Animation = compositor.CreateColorKeyFrameAnimation(); color1Animation.Duration = TimeSpan.FromSeconds(0.5); color1Animation.InsertKeyFrame(1.0f, Color.FromArgb(255, 247, 211, 156)); color1Animation.InsertKeyFrame(0.0f, Colors.White); color2Animation = compositor.CreateColorKeyFrameAnimation(); color2Animation.Duration = TimeSpan.FromSeconds(0.5); color2Animation.InsertKeyFrame(1.0f, Colors.White); color2Animation.InsertKeyFrame(0.0f, Color.FromArgb(255, 247, 211, 156)); compositionSpriteShape.FillBrush = circleGradientBrush; compositionSpriteShape.Offset = new Vector2(5, 5); shapeVisualCircle = compositor.CreateShapeVisual(); shapeVisualCircle.Size = new Vector2(50, 50); shapeVisualCircle.Shapes.Add(compositionSpriteShape); shapeVisualCircle.Offset = new Vector3(sliderMargins.X, 0, 0); // Return animation _leftoffsetAnimation = compositor.CreateVector3KeyFrameAnimation(); _leftoffsetAnimation.InsertKeyFrame(1.0f, new Vector3(0 + sliderMargins.X, 0, 0)); _leftoffsetAnimation.Duration = TimeSpan.FromSeconds(0.2f); _rightoffsetAnimation = compositor.CreateVector3KeyFrameAnimation(); _rightoffsetAnimation.InsertKeyFrame(1.0f, new Vector3(100 - sliderMargins.Y, 0, 0)); _rightoffsetAnimation.Duration = TimeSpan.FromSeconds(0.2f); }
// Stop 0 CompositionColorGradientStop GradientStop_0_AlmostCornflowerBlue_FF60BCEB() { return(_gradientStop_0_AlmostCornflowerBlue_FF60BCEB = _c.CreateColorGradientStop(0F, Color.FromArgb(0xFF, 0x60, 0xBC, 0xEB))); }
// Stop 1 CompositionColorGradientStop GradientStop_1_AlmostSteelBlue_FF306FC4() { return(_gradientStop_1_AlmostSteelBlue_FF306FC4 = _c.CreateColorGradientStop(1F, Color.FromArgb(0xFF, 0x30, 0x6F, 0xC4))); }
private Visual CreateRectangleElement(Vector2 size) { var element = _compositor.CreateContainerVisual(); element.Size = new Vector2(0.0f, 0.0f); element.Offset = new Vector3(0.0f, 0.0f, 0.0f); // Create radial gradient brush. CompositionRadialGradientBrush RGBrush = _compositor.CreateRadialGradientBrush(); // Create the color stops by defining the offset and color. CompositionColorGradientStop ColorStop1 = _compositor.CreateColorGradientStop(); ColorStop1.Offset = 0; ColorStop1.Color = Colors.Blue; CompositionColorGradientStop ColorStop2 = _compositor.CreateColorGradientStop(); ColorStop2.Offset = 0.75f; ColorStop2.Color = Colors.LightBlue; CompositionColorGradientStop ColorStop3 = _compositor.CreateColorGradientStop(); ColorStop3.Offset = 1.5f; ColorStop3.Color = Colors.Navy; RGBrush.ColorStops.Add(ColorStop1); RGBrush.ColorStops.Add(ColorStop2); RGBrush.ColorStops.Add(ColorStop3); // Set up animation for ColorStop1's color. var colorAnimation = _compositor.CreateColorKeyFrameAnimation(); colorAnimation.InsertKeyFrame(0.0f, Colors.Blue); colorAnimation.InsertKeyFrame(0.25f, Colors.LightBlue); colorAnimation.InsertKeyFrame(0.5f, Colors.Navy); colorAnimation.InsertKeyFrame(0.75f, Colors.LightBlue); colorAnimation.InsertKeyFrame(1.0f, Colors.Blue); colorAnimation.Duration = TimeSpan.FromSeconds(8); colorAnimation.IterationBehavior = AnimationIterationBehavior.Forever; ColorStop1.StartAnimation("Color", colorAnimation); //Create Shadow var visual0 = _compositor.CreateSpriteVisual(); visual0.Size = new Vector2(size.X + 2, size.Y + 2); //Create drop shadow DropShadow shadow = _compositor.CreateDropShadow(); shadow.BlurRadius = 5; shadow.Offset = new Vector3(0, 0, 0); shadow.Color = Colors.DarkGray; //Associate shadow to visual visual0.Shadow = shadow; element.Children.InsertAtBottom(visual0); //Create Rounded Rectangle var roundedRect = _compositor.CreateRoundedRectangleGeometry(); roundedRect.Size = new Vector2(size.X, size.Y); roundedRect.CornerRadius = new Vector2(7, 7); var rectShape = _compositor.CreateSpriteShape(roundedRect); rectShape.FillBrush = RGBrush; rectShape.Offset = new Vector2(0f, 0f); var visual = _compositor.CreateShapeVisual(); visual.Size = new Vector2(size.X, size.Y); visual.Shapes.Add(rectShape); element.Children.InsertAtTop(visual); element.Opacity = 0.8f; element.Size = visual.Size; return(element); }
private void Page_Loaded(object sender, RoutedEventArgs e) { // create the compositor _compositor = ElementCompositionPreview.GetElementVisual(this).Compositor; // create what captures the pointer position _hoverPositionPropertySet = ElementCompositionPreview.GetPointerPositionPropertySet(r2); // create the two visuals _vis = _compositor.CreateSpriteVisual(); _pulseVis = _compositor.CreateSpriteVisual(); // create the main brush with warm colors _mainBrush = _compositor.CreateRadialGradientBrush(); _mainBrush.EllipseCenter = new Vector2(.5f, .5f); _mainBrush.EllipseRadius = new Vector2(.5f, .5f); _MBGradientStop1 = _compositor.CreateColorGradientStop(); _MBGradientStop1.Offset = 0; _MBGradientStop1.Color = _warmColor1; _MBGradientStop2 = _compositor.CreateColorGradientStop(); _MBGradientStop2.Offset = .1f; _MBGradientStop2.Color = _warmColor2; _MBGradientStop3 = _compositor.CreateColorGradientStop(); _MBGradientStop3.Offset = 1; _MBGradientStop3.Color = _warmColor3; _mainBrush.ColorStops.Add(_MBGradientStop1); _mainBrush.ColorStops.Add(_MBGradientStop2); _mainBrush.ColorStops.Add(_MBGradientStop3); // create the brush for the pulse visual _pulseBrush = _compositor.CreateRadialGradientBrush(); _pulseBrush.EllipseCenter = new Vector2(.5f, .5f); _pulseBrush.EllipseRadius = new Vector2(.5f, .5f); _PBGradientStop1 = _compositor.CreateColorGradientStop(); _PBGradientStop1.Offset = 0; _PBGradientStop1.Color = _innerPulseColor; _PBGradientStop2 = _compositor.CreateColorGradientStop(); _PBGradientStop2.Offset = 1; _PBGradientStop2.Color = _innerPulseColor; _pulseBrush.ColorStops.Add(_PBGradientStop1); _pulseBrush.ColorStops.Add(_PBGradientStop2); // finish setting properties of the first visual _vis.Size = new Vector2(300, 300); _vis.Offset = new Vector3(((float)r2.ActualWidth / 2), ((float)r2.ActualHeight / 2), 0); _vis.AnchorPoint = new Vector2(.5f, .5f); _vis.Brush = _mainBrush; // finish setting properties of the pulsing visual _pulseVis.Size = new Vector2(500, 500); _pulseVis.Offset = new Vector3(((float)r1.ActualWidth / 2), ((float)r1.ActualHeight / 2), 0); _pulseVis.AnchorPoint = new Vector2(.5f, .5f); _pulseVis.Brush = _pulseBrush; // create the clip that makes the visuals circular CompositionGeometricClip gClip = _compositor.CreateGeometricClip(); CompositionEllipseGeometry circle = _compositor.CreateEllipseGeometry(); circle.Radius = new Vector2(_vis.Size.X / 2, _vis.Size.Y / 2); circle.Center = new Vector2(_vis.Size.X / 2, _vis.Size.Y / 2); gClip.Geometry = circle; _vis.Clip = gClip; CompositionGeometricClip gClip2 = _compositor.CreateGeometricClip(); CompositionEllipseGeometry circle2 = _compositor.CreateEllipseGeometry(); circle2.Radius = new Vector2(_pulseVis.Size.X / 2, _pulseVis.Size.Y / 2); circle2.Center = new Vector2(_pulseVis.Size.X / 2, _pulseVis.Size.Y / 2); gClip2.Geometry = circle2; _pulseVis.Clip = gClip2; // set the pointer my_pointer = new Vector3(((float)r1.ActualWidth / 2), ((float)r1.ActualHeight / 2), 0); // set the visuals in the tree ElementCompositionPreview.SetElementChildVisual(r2, _vis); ElementCompositionPreview.SetElementChildVisual(r1, _pulseVis); // ellipse center follows mouse _ellipseCenterAnim = _compositor.CreateExpressionAnimation("Vector2(p.Position.X / 500.0f, p.Position.Y / 500.0f)"); _ellipseCenterAnim.SetReferenceParameter("p", _hoverPositionPropertySet); _mainBrush.StartAnimation("EllipseCenter", _ellipseCenterAnim); // second stop is animated for "pulsing" effect within the first visual that runs constantly _offsetAnim = _compositor.CreateScalarKeyFrameAnimation(); _offsetAnim.InsertKeyFrame(0, 0); _offsetAnim.InsertKeyFrame(1f, 1f); _offsetAnim.Duration = TimeSpan.FromSeconds(2); _offsetAnim.IterationCount = 50; _MBGradientStop2.StartAnimation("Offset", _offsetAnim); // set up the animation for the backing pulse visual // animate the color _pulseColorAnim = _compositor.CreateColorKeyFrameAnimation(); _pulseColorAnim.InsertKeyFrame(0, _innerPulseColor); _pulseColorAnim.InsertKeyFrame(.99f, _outerPulseColor); _pulseColorAnim.InsertKeyFrame(1, _innerPulseColor); _pulseColorAnim.Duration = TimeSpan.FromSeconds(1); _pulseColorAnim.IterationBehavior = AnimationIterationBehavior.Forever; _PBGradientStop1.StartAnimation("Color", _pulseColorAnim); // animate offset of first stop _pulseStop1OffsetAnim = _compositor.CreateScalarKeyFrameAnimation(); _pulseStop1OffsetAnim.InsertKeyFrame(0, 0); _pulseStop1OffsetAnim.InsertKeyFrame(1f, 1f); _pulseStop1OffsetAnim.Duration = TimeSpan.FromSeconds(1); _pulseStop1OffsetAnim.IterationBehavior = AnimationIterationBehavior.Forever; _PBGradientStop1.StartAnimation("Offset", _pulseStop1OffsetAnim); // animate offset of second stop _pulseStop2OffsetAnim = _compositor.CreateScalarKeyFrameAnimation(); _pulseStop2OffsetAnim.InsertKeyFrame(0, 0); _pulseStop2OffsetAnim.InsertKeyFrame(1f, 1f); _pulseStop2OffsetAnim.Duration = TimeSpan.FromSeconds(1); _pulseStop2OffsetAnim.IterationBehavior = AnimationIterationBehavior.Forever; _pulseStop2OffsetAnim.DelayTime = TimeSpan.FromSeconds(.25f); _PBGradientStop2.StartAnimation("Offset", _pulseStop2OffsetAnim); _pulseScaleAnim = _compositor.CreateVector3KeyFrameAnimation(); _pulseScaleAnim.InsertKeyFrame(0, Vector3.Zero); _pulseScaleAnim.InsertKeyFrame(1, Vector3.One); _pulseScaleAnim.Duration = TimeSpan.FromSeconds(1); _pulseScaleAnim.IterationBehavior = AnimationIterationBehavior.Forever; _pulseVis.StartAnimation("Scale", _pulseScaleAnim); }
public GradientsWithBlend() : base() { InitializeComponent(); _compositor = Window.Current.Compositor; _foregroundBrush = _compositor.CreateLinearGradientBrush(); _foregroundBrush.StartPoint = Vector2.Zero; _foregroundBrush.EndPoint = new Vector2(1.0f); _bottomRightGradientStop = _compositor.CreateColorGradientStop(); _bottomRightGradientStop.Offset = 0.5f; _bottomRightGradientStop.Color = Green; _topLeftradientStop = _compositor.CreateColorGradientStop(); _topLeftradientStop.Offset = 0.5f; _topLeftradientStop.Color = Blue; _foregroundBrush.ColorStops.Add(_bottomRightGradientStop); _foregroundBrush.ColorStops.Add(_topLeftradientStop); _backgroundBrush = _compositor.CreateLinearGradientBrush(); _backgroundBrush.StartPoint = new Vector2(1.0f, 0); _backgroundBrush.EndPoint = new Vector2(0, 1.0f); _topRightGradientStop = _compositor.CreateColorGradientStop(); _topRightGradientStop.Offset = 0.25f; _topRightGradientStop.Color = Black; _bottomLeftGradientStop = _compositor.CreateColorGradientStop(); _bottomLeftGradientStop.Offset = 1.0f; _bottomLeftGradientStop.Color = Black; _backgroundBrush.ColorStops.Add(_topRightGradientStop); _backgroundBrush.ColorStops.Add(_bottomLeftGradientStop); var graphicsEffect = new BlendEffect() { Mode = BlendEffectMode.Screen, Foreground = new CompositionEffectSourceParameter("Main"), Background = new CompositionEffectSourceParameter("Tint"), }; var effectFactory = _compositor.CreateEffectFactory(graphicsEffect); var brush = effectFactory.CreateBrush(); brush.SetSourceParameter("Main", _foregroundBrush); brush.SetSourceParameter("Tint", _backgroundBrush); _backgroundVisual = _compositor.CreateSpriteVisual(); _backgroundVisual.Brush = brush; ElementCompositionPreview.SetElementChildVisual(Gradient, _backgroundVisual); //var leftToRightAnimation = _compositor.CreateScalarKeyFrameAnimation(); //leftToRightAnimation.Duration = TimeSpan.FromSeconds(2); //leftToRightAnimation.DelayTime = TimeSpan.FromSeconds(1); //leftToRightAnimation.InsertKeyFrame(1.0f, 1.0f); //_bottomRightGradientStop.StartAnimation(nameof(_bottomRightGradientStop.Offset), leftToRightAnimation); Loaded += async(s, e) => { await Task.Delay(2000); UpdateGradients(); MiddleText.Visibility = Visibility.Collapsed; await Task.Delay(2000); UpdateText(); ButtonRoot.Visibility = Visibility.Visible; }; Gradient.SizeChanged += (s, e) => { if (e.NewSize == e.PreviousSize) { return; } _backgroundVisual.Size = e.NewSize.ToVector2(); _foregroundBrush.CenterPoint = _backgroundVisual.Size / 2; _backgroundBrush.CenterPoint = _backgroundVisual.Size / 2; }; ViewModel.IsInPomodoroChanged += (s, e) => { UpdateGradients(); UpdateText(); }; }
public GlowPanel2() : base() { this.DefaultStyleKey = typeof(GlowPanel2); _compositor = ElementCompositionPreview.GetElementVisual(this).Compositor; _maskBrush = _compositor.CreateMaskBrush(); Visual.Brush = _maskBrush; _foregroundBrush = _compositor.CreateLinearGradientBrush(); _foregroundBrush.StartPoint = Vector2.Zero; _foregroundBrush.EndPoint = new Vector2(1.0f); _bottomRightGradientStop = _compositor.CreateColorGradientStop(); _bottomRightGradientStop.Offset = 0.5f; _bottomRightGradientStop.Color = Green; _topLeftradientStop = _compositor.CreateColorGradientStop(); _topLeftradientStop.Offset = 0.5f; _topLeftradientStop.Color = Blue; _foregroundBrush.ColorStops.Add(_bottomRightGradientStop); _foregroundBrush.ColorStops.Add(_topLeftradientStop); _backgroundBrush = _compositor.CreateLinearGradientBrush(); _backgroundBrush.StartPoint = new Vector2(1.0f, 0); _backgroundBrush.EndPoint = new Vector2(0, 1.0f); _topRightGradientStop = _compositor.CreateColorGradientStop(); _topRightGradientStop.Offset = 0.25f; _topRightGradientStop.Color = Black; _bottomLeftGradientStop = _compositor.CreateColorGradientStop(); _bottomLeftGradientStop.Offset = 1.0f; _bottomLeftGradientStop.Color = Black; _backgroundBrush.ColorStops.Add(_topRightGradientStop); _backgroundBrush.ColorStops.Add(_bottomLeftGradientStop); var graphicsEffect = new BlendEffect() { Mode = BlendEffectMode.Screen, Foreground = new CompositionEffectSourceParameter("Main"), Background = new CompositionEffectSourceParameter("Tint"), }; var effectFactory = _compositor.CreateEffectFactory(graphicsEffect); var brush = effectFactory.CreateBrush(); brush.SetSourceParameter("Main", _foregroundBrush); brush.SetSourceParameter("Tint", _backgroundBrush); // GaussianBlurEffect blurEffect = new GaussianBlurEffect() // { // Name = "Blur", // BlurAmount = 1.0f, // BorderMode = EffectBorderMode.Hard, // Source = new CompositionEffectSourceParameter("source"); //}; //CompositionEffectFactory blurEffectFactory = _compositor.CreateEffectFactory(blurEffect); //CompositionEffectBrush _backdropBrush = blurEffectFactory.CreateBrush(); //// Create a BackdropBrush and bind it to the EffectSourceParameter source //_backdropBrush.SetSourceParameter("source", _compositor.CreateBackdropBrush()); _maskBrush.Source = brush; Loaded += async(s, e) => { UpdateGradients(); await Task.Delay(2000); }; }
// Stop 0 CompositionColorGradientStop GradientStop_0_AlmostMediumAquamarine_FF61C8B8() { return(_gradientStop_0_AlmostMediumAquamarine_FF61C8B8 = _c.CreateColorGradientStop(0F, Color.FromArgb(0xFF, 0x61, 0xC8, 0xB8))); }
// Stop 1 CompositionColorGradientStop GradientStop_1_AlmostCadetBlue_FF479D8E() { return(_gradientStop_1_AlmostCadetBlue_FF479D8E = _c.CreateColorGradientStop(1F, Color.FromArgb(0xFF, 0x47, 0x9D, 0x8E))); }
private void Page_Loaded(object sender, RoutedEventArgs e) { _compositor = ElementCompositionPreview.GetElementVisual(this).Compositor; // Update Rectangle widths to match text width Rectangle1.Width = TextBlock1.ActualWidth; Rectangle2.Width = TextBlock2.ActualWidth; Rectangle3.Width = TextBlock3.ActualWidth; Rectangle4.Width = TextBlock4.ActualWidth; // Create the four visuals that will be used to hold the LinearGradient brush _vis1 = _compositor.CreateSpriteVisual(); _vis2 = _compositor.CreateSpriteVisual(); _vis3 = _compositor.CreateSpriteVisual(); _vis4 = _compositor.CreateSpriteVisual(); // Create the linearGradient brush and set the first set of colors to the gradientStops of the Brush _linearGradientBrush = _compositor.CreateLinearGradientBrush(); _gradientStop1 = _compositor.CreateColorGradientStop(); _gradientStop1.Offset = 0; _gradientStop1.Color = warmColor1; _gradientStop2 = _compositor.CreateColorGradientStop(); _gradientStop2.Offset = 1; _gradientStop2.Color = warmColor2; _linearGradientBrush.ColorStops.Add(_gradientStop1); _linearGradientBrush.ColorStops.Add(_gradientStop2); // Paint visuals with brushes and set their locations _vis1.Brush = _linearGradientBrush; _vis1.Scale = new Vector3(0, 1, 0); _vis1.Size = new Vector2((float)Rectangle1.ActualWidth, (float)Rectangle1.ActualHeight); _vis2.Brush = _linearGradientBrush; _vis2.Scale = new Vector3(0, 1, 0); _vis2.Size = new Vector2((float)Rectangle2.ActualWidth, (float)Rectangle2.ActualHeight); _vis3.Brush = _linearGradientBrush; _vis3.Scale = new Vector3(0, 1, 0); _vis3.Size = new Vector2((float)Rectangle3.ActualWidth, (float)Rectangle3.ActualHeight); _vis4.Brush = _linearGradientBrush; _vis4.Scale = new Vector3(0, 1, 0); _vis4.Size = new Vector2((float)Rectangle4.ActualWidth, (float)Rectangle4.ActualHeight); // Parent visuals to XAML rectangles ElementCompositionPreview.SetElementChildVisual(Rectangle1, _vis1); ElementCompositionPreview.SetElementChildVisual(Rectangle2, _vis2); ElementCompositionPreview.SetElementChildVisual(Rectangle3, _vis3); ElementCompositionPreview.SetElementChildVisual(Rectangle4, _vis4); //create the scale & offset animation Vector3KeyFrameAnimation offsetAnim_r1 = _compositor.CreateVector3KeyFrameAnimation(); offsetAnim_r1.InsertKeyFrame(1, new Vector3((float)Rectangle1.ActualWidth, (float)Rectangle1.ActualHeight, 0)); offsetAnim_r1.Duration = TimeSpan.FromSeconds(6); // Instantiate animation //TODO update to animate gradient stops instaed of scale _scaleAnim = _compositor.CreateVector3KeyFrameAnimation(); _scaleAnim.InsertKeyFrame(0, new Vector3(0, 1, 0)); _scaleAnim.InsertKeyFrame(.5f, new Vector3(1, 1, 0)); _scaleAnim.InsertKeyFrame(1, new Vector3(0, 1, 0)); _scaleAnim.Duration = TimeSpan.FromSeconds(2); // animation of color stops _colorAnimGradientStop1 = _compositor.CreateColorKeyFrameAnimation(); _colorAnimGradientStop1.InsertKeyFrame(.5f, Colors.Honeydew); _colorAnimGradientStop1.Duration = TimeSpan.FromSeconds(4); _colorAnimGradientStop2 = _compositor.CreateColorKeyFrameAnimation(); _colorAnimGradientStop2.InsertKeyFrame(.5f, Colors.DeepPink); _colorAnimGradientStop2.Duration = TimeSpan.FromSeconds(4); _offsetAnim = _compositor.CreateScalarKeyFrameAnimation(); _offsetAnim.Duration = TimeSpan.FromSeconds(1); // when the buttons of text are pressed, the brush will change colors. Below is the set up for animation _changeb1stop1 = _compositor.CreateColorKeyFrameAnimation(); _changeb1stop1.InsertKeyFrame(.5f, Colors.LightSkyBlue); _changeb1stop1.Duration = TimeSpan.FromSeconds(2); _changeb1stop2 = _compositor.CreateColorKeyFrameAnimation(); _changeb1stop2.InsertKeyFrame(.5f, Colors.Teal); _changeb1stop2.Duration = TimeSpan.FromSeconds(2); }