コード例 #1
0
        XElement FromCompositionGeometricClip(CompositionGeometricClip obj)
        {
            return(new XElement(GetCompositionObjectName(obj), GetContents()));

            IEnumerable <XObject> GetContents()
            {
                if (obj.Geometry != null)
                {
                    yield return(new XElement("Geometry", FromCompositionObject(obj.Geometry)));
                }
            }
        }
コード例 #2
0
        CompositionGeometricClip GetCompositionGeometricClip(CompositionGeometricClip obj)
        {
            if (GetExisting(obj, out CompositionGeometricClip result))
            {
                return(result);
            }

            result          = CacheAndInitializeCompositionObject(obj, _c.CreateCompositionGeometricClip());
            result.Geometry = GetCompositionGeometry(obj.Geometry);

            return(result);
        }
コード例 #3
0
        public MessagePinnedLine()
        {
            RegisterPropertyChangedCallback(BorderBrushProperty, OnBorderBrushChanged);

            var compositor = Window.Current.Compositor;

            var visual = compositor.CreateShapeVisual();

            visual.Size = new Vector2(2, 36);

            var back = compositor.CreateRectangleGeometry();

            back.Offset = Vector2.Zero;
            back.Size   = new Vector2(4, 36);

            var backShape = compositor.CreateSpriteShape(back);

            backShape.FillBrush = GetBrush(BorderBrushProperty);

            var fore = compositor.CreateRectangleGeometry();

            fore.Offset = Vector2.Zero;
            fore.Size   = new Vector2(4, 36);
            //fore.CornerRadius = Vector2.One;

            var foreShape = compositor.CreateSpriteShape(fore);

            foreShape.FillBrush = GetBrush(ForegroundProperty);

            var mask      = compositor.CreatePathGeometry(GetMask(1));
            var maskShape = compositor.CreateGeometricClip(mask);

            visual.Shapes.Add(backShape);
            visual.Shapes.Add(foreShape);
            visual.Clip = maskShape;

            _back     = backShape;
            _fore     = foreShape;
            _forePath = fore;
            _mask     = maskShape;
            _maskPath = mask;

            ElementCompositionPreview.SetElementChildVisual(this, visual);
        }
コード例 #4
0
        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);
        }