public Bar(Compositor compositor, float maxBarHeight, float height, float width, string label, double value, CompositionBrush brush = null)
        {
            _compositor = compositor;

            Height = height;
            Width  = width;
            Value  = value;
            Label  = label;

            var barBrush = brush ?? compositor.CreateColorBrush(Colors.Blue);

            // Define shape visual for bar outline.
            var shapeOutlineVisual = _compositor.CreateShapeVisual();

            shapeOutlineVisual.Size = new Vector2(maxBarHeight, maxBarHeight);
            shapeOutlineVisual.RotationAngleInDegrees = -90f;

            // Create geometry and shape for the bar outline.
            _rectOutlineGeometry = _compositor.CreateRectangleGeometry();
            // Reverse width and height since rect will be at a 90* angle.
            _rectOutlineGeometry.Size = new Vector2(Height, Width);
            var barOutlineVisual = _compositor.CreateSpriteShape(_rectOutlineGeometry);

            barOutlineVisual.StrokeThickness = _strokeThickness;
            barOutlineVisual.StrokeBrush     = barBrush;

            shapeOutlineVisual.Shapes.Add(barOutlineVisual);

            // Define shape visual.
            var shapeVisual = _compositor.CreateShapeVisual();

            shapeVisual.Size = new Vector2(maxBarHeight, maxBarHeight);
            shapeVisual.RotationAngleInDegrees = -90f;

            // Create rectangle geometry and shape for the bar.
            _rectGeometry = _compositor.CreateRectangleGeometry();
            // Reverse width and height since rect will be at a 90* angle.
            _rectGeometry.Size = new Vector2(Height, Width);

            var barVisual = _compositor.CreateSpriteShape(_rectGeometry);

            barVisual.FillBrush = barBrush;

            shapeVisual.Shapes.Add(barVisual);

            Root        = shapeVisual;
            OutlineRoot = shapeOutlineVisual;

            // Add implict animation to bar.
            var implicitAnimations = _compositor.CreateImplicitAnimationCollection();

            // Trigger animation when the size property changes.
            implicitAnimations["Size"]              = CreateAnimation();
            _rectGeometry.ImplicitAnimations        = implicitAnimations;
            _rectOutlineGeometry.ImplicitAnimations = implicitAnimations;
        }
        public MessagePinnedLine()
        {
            if (!ApiInfo.CanUseDirectComposition)
            {
                return;
            }

            RegisterPropertyChangedCallback(ForegroundProperty, OnForegroundChanged);
            RegisterPropertyChangedCallback(BackgroundProperty, OnBackgroundChanged);
            RegisterPropertyChangedCallback(BorderBrushProperty, OnBorderBrushChanged);

            var compositor = Window.Current.Compositor;

            var visual = compositor.CreateShapeVisual();

            visual.Clip = compositor.CreateInsetClip(0, 0, 1, 0);
            visual.Size = new Vector2(4, 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.CreateSpriteShape(mask);

            maskShape.FillBrush = GetBrush(BackgroundProperty);
            maskShape.Offset    = new Vector2(-2);

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

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

            ElementCompositionPreview.SetElementChildVisual(this, visual);
        }
示例#3
0
        CompositionRectangleGeometry GetCompositionRectangleGeometry(CompositionRectangleGeometry obj)
        {
            if (GetExisting(obj, out CompositionRectangleGeometry result))
            {
                return(result);
            }

            result = CacheAndInitializeCompositionGeometry(obj, _c.CreateRectangleGeometry());
            if (obj.Offset != null)
            {
                result.Offset = obj.Offset;
            }

            result.Size = obj.Size;
            StartAnimationsAndFreeze(obj, result);
            return(result);
        }
示例#4
0
        public void CreateBar(float maxHeight)
        {
            var strokeThickness = 8;

            // Define shape visual for bar outline.
            shapeOutlineVisual      = compositor.CreateShapeVisual();
            shapeOutlineVisual.Size = new Vector2(maxHeight, maxHeight);
            shapeOutlineVisual.RotationAngleInDegrees = -90f;

            // Create geometry and shape for the bar outline.
            rectOutlineGeometry = compositor.CreateRectangleGeometry();
            // Reverse width and height since rect will be at a 90* angle.
            rectOutlineGeometry.Size = new Vector2(Height, Width);
            var barOutlineVisual = compositor.CreateSpriteShape(rectOutlineGeometry);

            barOutlineVisual.StrokeThickness = (float)strokeThickness;
            barOutlineVisual.StrokeBrush     = Brush;

            shapeOutlineVisual.Shapes.Add(barOutlineVisual);

            // Define shape visual.
            shapeVisual      = compositor.CreateShapeVisual();
            shapeVisual.Size = new Vector2(maxHeight, maxHeight);
            shapeVisual.RotationAngleInDegrees = -90f;

            // Create rectangle geometry and shape for the bar.
            rectGeometry = compositor.CreateRectangleGeometry();
            // Reverse width and height since rect will be at a 90* angle.
            rectGeometry.Size   = new Vector2(Height, Width);
            barVisual           = compositor.CreateSpriteShape(rectGeometry);
            barVisual.FillBrush = Brush;

            shapeVisual.Shapes.Add(barVisual);

            Root        = shapeVisual;
            OutlineRoot = shapeOutlineVisual;

            // Add implict animation to bar.
            var implicitAnimations = compositor.CreateImplicitAnimationCollection();

            // Trigger animation when the size property changes.
            implicitAnimations["Size"]             = CreateAnimation();
            rectGeometry.ImplicitAnimations        = implicitAnimations;
            rectOutlineGeometry.ImplicitAnimations = implicitAnimations;
        }
示例#5
0
        XElement FromCompositionRectangleGeometry(CompositionRectangleGeometry obj)
        {
            return(new XElement(GetCompositionObjectName(obj), GetContents()));

            IEnumerable <XObject> GetContents()
            {
                foreach (var item in GetCompositionGeometryContents(obj))
                {
                    yield return(item);
                }

                if (obj.Offset != null)
                {
                    yield return(FromVector2(nameof(obj.Offset), obj.Offset.Value));
                }

                yield return(FromVector2(nameof(obj.Size), obj.Size));
            }
        }
        public void DrawRectangle(IRectangle rectangle)
        {
            Vector2 size = new Vector2((float)rectangle.Width, (float)rectangle.Height);

            if (rectangle.RadiusX > 0 || rectangle.RadiusY > 0)
            {
                CompositionRoundedRectangleGeometry roundedRectangleGeometry = _compositor.CreateRoundedRectangleGeometry();
                roundedRectangleGeometry.Size         = size;
                roundedRectangleGeometry.CornerRadius = new Vector2((float)rectangle.RadiusX, (float)rectangle.RadiusY);

                DrawShapeGeometry(roundedRectangleGeometry, rectangle);
            }
            else
            {
                CompositionRectangleGeometry rectangleGeometry = _compositor.CreateRectangleGeometry();
                rectangleGeometry.Size = size;

                DrawShapeGeometry(rectangleGeometry, rectangle);
            }
        }
示例#7
0
        public void CreateBar(float maxHeight)
        {
            shapeVisual      = _compositor.CreateShapeVisual();
            shapeVisual.Size = new System.Numerics.Vector2(maxHeight, maxHeight);
            shapeVisual.RotationAngleInDegrees = -90f;

            rectGeometry      = _compositor.CreateRectangleGeometry();
            rectGeometry.Size = new System.Numerics.Vector2(Height, Width); //reverse width and height since rect will be at a 90* angle

            barVisual           = _compositor.CreateSpriteShape(rectGeometry);
            barVisual.FillBrush = Brush;

            shapeVisual.Shapes.Add(barVisual);

            Root = shapeVisual;

            // Add implict animation to bar
            var implicitAnimations = _compositor.CreateImplicitAnimationCollection();

            // Trigger animation when the size property changes.
            implicitAnimations["Size"]      = CreateAnimation();
            rectGeometry.ImplicitAnimations = implicitAnimations;
        }
 internal WrappedRectangleGeometry(CompositionRectangleGeometry wrapped)
     : base(wrapped)
 {
     _wrapped = wrapped;
 }