コード例 #1
0
ファイル: Renderer.cs プロジェクト: N500/Win2D
 void DrawContactPoints(CanvasDrawingSession ds)
 {
     foreach (var entry in currentPointsInContact)
     {
         ds.DrawCircle(entry.Value.ToVector2(), 20, Colors.Red);
     }
 }
コード例 #2
0
        public override void DrawMe(CanvasDrawingSession session, MG.Vector2 originScreenCoordinates, float pixelsPerMeter)
        {
            var circlePosition = _body.WorldCenter * pixelsPerMeter + originScreenCoordinates;
            var circleRadius   = _radius * pixelsPerMeter;

            session.DrawCircle(circlePosition.X, circlePosition.Y, circleRadius, Colors.Green);
        }
コード例 #3
0
        private void led_Draw(Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasDrawEventArgs args)
        {
            led.Width  = ActualHeight;
            led.Height = ActualHeight;

            using (CanvasDrawingSession canvas = args.DrawingSession)
            {
                // Calculate the centre of the led
                Vector2 centrePoint = new Vector2();

                centrePoint.X = (float)(led.ActualWidth / 2);
                centrePoint.Y = (float)(led.ActualHeight / 2);

                // Calculate the radius of the LED
                float ledRadius = (float)(ActualHeight / 2.0f);

                // Draw the LED
                if (LedOn)
                {
                    canvas.FillCircle(centrePoint, ledRadius, OnColor);
                }
                else
                {
                    canvas.FillCircle(centrePoint, ledRadius, OffColor);
                }

                // Draw the Border of the LED
                float borderRadius = (float)(ledRadius - (BorderWidth / 2));

                canvas.DrawCircle(centrePoint, borderRadius, BorderColor, (float)BorderWidth);
            }
        }
コード例 #4
0
ファイル: LayersExample.xaml.cs プロジェクト: N500/Win2D
            public void Draw(CanvasDrawingSession ds, float alpha = 1)
            {
                // Create a drop shadow by drawing a black circle with an offset position.
                const float dropShadowOffset = 4;

                ds.FillCircle(Position + new Vector2(dropShadowOffset), Radius, AdjustAlpha(Colors.Black, alpha));

                // Draw a white X.
                const float crossWidth = 3;
                float       crossSize  = Radius * 0.8f;

                Vector2 cross1 = new Vector2(crossSize, crossSize);
                Vector2 cross2 = new Vector2(crossSize, -crossSize);

                ds.DrawLine(Position - cross1, Position + cross1, AdjustAlpha(Colors.White, alpha), crossWidth);
                ds.DrawLine(Position - cross2, Position + cross2, AdjustAlpha(Colors.White, alpha), crossWidth);

                // Fill the circle with its unique color.
                ds.FillCircle(Position, Radius, AdjustAlpha(color, alpha));

                // White border around it.
                ds.DrawCircle(Position, Radius, AdjustAlpha(Colors.White, alpha));

                // Text label.
                ds.DrawText(label, Position, AdjustAlpha(Colors.White, alpha), textFormat);
            }
コード例 #5
0
        private void DrawClickedRipple(CanvasDrawingSession ds)
        {
            Easings.ParamTween(ref ImgR_c, ImgR_t, 0.75f, 0.25f);
            Easings.ParamTween(ref ImgRi_c, ImgRi_t, 0.75f, 0.25f);
            Easings.ParamTween(ref RingR_c, RingR_t, 0.875f, 0.125f);
            Easings.ParamTween(ref RingRi_c, RingRi_t, 0.875f, 0.125f);
            float RingW = (RingR_c - RingRi_c);
            float RingR = RingRi_c + 0.5f * RingW;

            float ImgRW_c = (ImgR_c - ImgRi_c);
            float ImgRR_c = ImgRi_c + 0.5f * ImgRW_c;

            ICanvasBrush RBrush = 0 < RingR ? RingBrush : CoverBrush;

            ds.DrawCircle(PCenter, RingR, RBrush, RingW);
            ds.DrawCircle(PCenter, ImgRR_c, CoverBrush, ImgRW_c);
        }
コード例 #6
0
 private void DrawClusters(CanvasDrawingSession drawingSession)
 {
     foreach (var cluster in _clustersPoints)
     {
         drawingSession.FillCircle(cluster.Position, 6, cluster.Color);
         drawingSession.DrawCircle(cluster.Position.X, cluster.Position.Y, 8, Colors.Black, 4);
     }
 }
コード例 #7
0
ファイル: ExpandButton.cs プロジェクト: Win10Mindapp/Mindmap
        private void RenderCircle(CanvasDrawingSession session)
        {
#if DRAW_OUTLINE
            session.DrawRectangle(renderBounds.ToRect(), Colors.Orange);
#endif
            session.FillCircle(renderCenter, renderRadius, Colors.White);

            session.DrawCircle(renderCenter, renderRadius, Colors.DarkGray);
        }
コード例 #8
0
        public override void Draw(CanvasDrawingSession session)
        {
            if (false == IsVisible)
            {
                return;
            }

            session.DrawCircle(Position.ToVector2(), 2.0f, drawBrush);
        }
コード例 #9
0
        private void DrawHighlightPoint(CanvasDrawingSession session)
        {
            if (!_drawHighlightPoint)
            {
                return;
            }
            float size = GetPointHighlightSize();

            session.DrawCircle((float)Points[_highlightPointIndex].X, (float)Points[_highlightPointIndex].Y, MapController.Instance.PointSize * 2f, Colors.LawnGreen, size);
        }
コード例 #10
0
 public override void Draw(ICanvasResourceCreator creator, CanvasDrawingSession ds)
 {
     if (IsFill)
     {
         ds.FillCircle(CenterPoint, Radius, PenAttribute.GetBrush(creator));
     }
     else
     {
         ds.DrawCircle(CenterPoint, Radius, PenAttribute.GetBrush(creator), PenAttribute.StrokeWidth, StrokeStyle);
     }
 }
コード例 #11
0
        public void RenderDots(Vector2[] dots)
        {
            var counter = 0;

            foreach (var dot in dots)
            {
                session.DrawCircle(dot, 3, Colors.White);
                session.DrawText(counter.ToString(), dot, Colors.OrangeRed);
                counter++;
            }
        }
コード例 #12
0
        private void DrawCircle(CanvasControl sender, CanvasDrawingSession ds)
        {
            var width  = (float)sender.ActualWidth;
            var height = (float)sender.ActualHeight;
            var stroke = this.defaultStroke;
            var radius = Math.Min(width, height) / 2 - stroke;
            var center = new Vector2(width / 2, height / 2);

            ds.FillCircle(center, radius, ForegroundColor);
            ds.DrawCircle(center, radius, GlowColor, stroke);
        }
コード例 #13
0
        private void DrawSpline(CanvasControl sender, CanvasDrawingSession ds,
                                Vector2 startPoint, Vector2 controlPoint1, Vector2 controlPoint2, Vector2 endPoint,
                                Color color)
        {
            var strokeThickness = 2f;

            // Draw the spline
            using (var pathBuilder = new CanvasPathBuilder(sender))
            {
                pathBuilder.BeginFigure(startPoint);
                pathBuilder.AddCubicBezier(controlPoint1, controlPoint2, endPoint);
                pathBuilder.EndFigure(CanvasFigureLoop.Open);

                var geometry = CanvasGeometry.CreatePath(pathBuilder);
                ds.DrawGeometry(geometry, Vector2.Zero, color, strokeThickness);
            }

            // Draw Control Points
            if (_showControlPoints)
            {
                var strokeStyle = new CanvasStrokeStyle()
                {
                    DashStyle = CanvasDashStyle.Dot
                };
                ds.DrawLine(startPoint, controlPoint1, color, strokeThickness, strokeStyle);
                var rect1 = new Rect(controlPoint1.X - 3, controlPoint1.Y - 3, 6, 6);
                ds.FillRectangle(rect1, Colors.Beige);
                ds.DrawRectangle(rect1, color, strokeThickness);

                ds.DrawLine(endPoint, controlPoint2, color, strokeThickness, strokeStyle);
                var rect2 = new Rect(controlPoint2.X - 3, controlPoint2.Y - 3, 6, 6);
                ds.FillRectangle(rect2, Colors.Beige);
                ds.DrawRectangle(rect2, color, strokeThickness);
            }

            // Draw EndPoints
            ds.DrawCircle(startPoint, 5, color, strokeThickness);
            ds.FillCircle(startPoint, 5, Colors.Beige);
            ds.DrawCircle(endPoint, 5, color, strokeThickness);
            ds.FillCircle(endPoint, 5, Colors.Beige);
        }
コード例 #14
0
        /// <summary> Override <see cref="PaletteBase.Draw"/>. </summary>
        public override void Draw(CanvasControl sender, CanvasDrawingSession ds, HSV hsv, Vector2 Center, float squareHalfWidth, float squareHalfHeight)
        {
            //Palette
            Rect rect = new Rect(Center.X - squareHalfWidth, Center.Y - squareHalfHeight, squareHalfWidth * 2, squareHalfHeight * 2);

            ds.FillRoundedRectangle(rect, 4, 4, new CanvasLinearGradientBrush(sender, Windows.UI.Colors.White, HSV.HSVtoRGB(hsv.H))
            {
                StartPoint = new Vector2(Center.X - squareHalfWidth, Center.Y), EndPoint = new Vector2(Center.X + squareHalfWidth, Center.Y)
            });
            ds.FillRoundedRectangle(rect, 4, 4, new CanvasLinearGradientBrush(sender, Windows.UI.Colors.Transparent, Windows.UI.Colors.Black)
            {
                StartPoint = new Vector2(Center.X, Center.Y - squareHalfHeight), EndPoint = new Vector2(Center.X, Center.Y + squareHalfHeight)
            });
            ds.DrawRoundedRectangle(rect, 4, 4, Windows.UI.Colors.Gray);

            //Thumb
            float px = ((float)hsv.S - 50) * squareHalfWidth / 50 + Center.X;
            float py = (50 - (float)hsv.V) * squareHalfHeight / 50 + Center.Y;

            ds.DrawCircle(px, py, 9, Windows.UI.Colors.Black, 5);
            ds.DrawCircle(px, py, 9, Windows.UI.Colors.White, 3);
        }
コード例 #15
0
ファイル: PaletteHue.cs プロジェクト: ysdy44/FanKit-UWP
        public override void Draw(CanvasControl CanvasControl, CanvasDrawingSession ds, HSL HSL, Vector2 Center, float SquareHalfWidth, float SquareHalfHeight)
        {
            //Palette
            Rect rect = new Rect(Center.X - SquareHalfWidth, Center.Y - SquareHalfHeight, SquareHalfWidth * 2, SquareHalfHeight * 2);

            ds.FillRoundedRectangle(rect, 4, 4, new CanvasLinearGradientBrush(CanvasControl, Windows.UI.Colors.White, HSL.HSLtoRGB(HSL.H))
            {
                StartPoint = new Vector2(Center.X - SquareHalfWidth, Center.Y), EndPoint = new Vector2(Center.X + SquareHalfWidth, Center.Y)
            });
            ds.FillRoundedRectangle(rect, 4, 4, new CanvasLinearGradientBrush(CanvasControl, Windows.UI.Colors.Transparent, Windows.UI.Colors.Black)
            {
                StartPoint = new Vector2(Center.X, Center.Y - SquareHalfHeight), EndPoint = new Vector2(Center.X, Center.Y + SquareHalfHeight)
            });
            ds.DrawRoundedRectangle(rect, 4, 4, Windows.UI.Colors.Gray);

            //Thumb
            float px = ((float)HSL.S - 50) * SquareHalfWidth / 50 + Center.X;
            float py = (50 - (float)HSL.L) * SquareHalfHeight / 50 + Center.Y;

            ds.DrawCircle(px, py, 8, Windows.UI.Colors.Black, 4);
            ds.DrawCircle(px, py, 8, Windows.UI.Colors.White, 2);
        }
コード例 #16
0
ファイル: Finish.cs プロジェクト: Mailosz/RysiuRysuje
        public void Draw(CanvasDrawingSession ds)
        {
            var temp = ds.Transform;

            ds.Transform = Matrix3x2.CreateRotation(Rotate, Center) * ds.Transform;

            ds.DrawCircle(Center, Radius, Colors.LimeGreen, 5, new CanvasStrokeStyle()
            {
                CustomDashStyle = new[] { 2f, 2f }
            });

            ds.Transform = temp;
        }
コード例 #17
0
 private void canvas1_CreateResources(Microsoft.Graphics.Canvas.UI.Xaml.CanvasAnimatedControl sender, Microsoft.Graphics.Canvas.UI.CanvasCreateResourcesEventArgs args)
 {
     cl = new CanvasCommandList(sender);
     using (CanvasDrawingSession clds = cl.CreateDrawingSession())
     {
         clds.DrawText("Demo", new Vector2((float)Frame.Height / 2, (float)Frame.Width / 2), Colors.Red);
         for (int i = 0; i < 100; i++)
         {
             clds.DrawText("Hello, World!", RndPosition(), Color.FromArgb(255, RndByte(), RndByte(), RndByte()));
             clds.DrawCircle(RndPosition(), RndRadius(), Color.FromArgb(255, RndByte(), RndByte(), RndByte()));
         }
     }
 }
コード例 #18
0
        protected override void DoDraw(CanvasDrawingSession ds)
        {
            ds.DrawText(
                Activation.ToString("#0.####"),
                Location, Colors.Red,
                new CanvasTextFormat()
            {
                HorizontalAlignment = CanvasHorizontalAlignment.Center,
                VerticalAlignment   = CanvasVerticalAlignment.Center,
                FontSize            = Radius / 2
            });

            ds.DrawCircle(Location, Radius, Colors.Black);
        }
コード例 #19
0
        private void DrawCursor(CanvasRenderTarget target, Dot dot)
        {
            float offsetX = _currentPaperInfo.OffsetX * _scale * Pixel2DotScaleFactor;
            float offsetY = _currentPaperInfo.OffsetY * _scale * Pixel2DotScaleFactor;

            using (CanvasDrawingSession drawSession = target.CreateDrawingSession())
            {
                float x = (dot.X * _scale) - (offsetX);
                float y = (dot.Y * _scale) - (offsetY);

                drawSession.DrawCircle(x, y, 3, Colors.Red, 1);
            }

            drawableCanvas.Invalidate();
        }
コード例 #20
0
ファイル: Circle.cs プロジェクト: davetz/ModelGraph2
        internal override void Draw(CanvasControl cc, CanvasDrawingSession ds, float scale, Vector2 center, FlipState flip)
        {
            var color = GetColor(Coloring.Normal);

            var(cp, r1, r2) = GetCenterRadius(center, scale);

            if (FillStroke == Fill_Stroke.Filled)
            {
                ds.FillCircle(cp, r1, color);
            }
            else
            {
                ds.DrawCircle(cp, r1, color, StrokeWidth, StrokeStyle());
            }
        }
コード例 #21
0
ファイル: ShapesExample.xaml.cs プロジェクト: chenbk85/Win2D
        private void DrawCircles(CanvasControl sender, CanvasDrawingSession ds)
        {
            float width  = (float)sender.ActualWidth;
            float height = (float)sender.ActualHeight;

            float endpointMargin = Math.Min(width, height) / 8;
            float controlMarginX = endpointMargin * 4;
            float controlMarginY = endpointMargin * 2;

            for (int i = 0; i < 25; i++)
            {
                Vector2[] bez = new Vector2[4];
                int       n   = (i * 24) + 9 - (i / 2);

                for (int k = 0; k < 3; k++)
                {
                    int j = 4 - (2 * k);
                    bez[k].X = (0 + (((n >> (j + 1)) & 1) * (width - controlMarginX)));
                    bez[k].Y = (0 + (((n >> j) & 1) * (height - controlMarginY)));
                }
                bez[3].X = width - endpointMargin; // Collect the ends in the lower right
                bez[3].Y = height - endpointMargin;

                const int   nSteps = 80;
                const float tStep  = 1.0f / nSteps;
                float       t      = 0;
                for (int step = 0; step < nSteps; step++)
                {
                    float s           = 1 - t;
                    float ss          = s * s;
                    float sss         = ss * s;
                    float tt          = t * t;
                    float ttt         = tt * t;
                    float x           = (sss * bez[0].X) + (3 * ss * t * bez[1].X) + (3 * s * tt * bez[2].X) + (ttt * bez[3].X);
                    float y           = (sss * bez[0].Y) + (3 * ss * t * bez[1].Y) + (3 * s * tt * bez[2].Y) + (ttt * bez[3].Y);
                    float radius      = ttt * endpointMargin;
                    float strokeWidth = (0.5f - Math.Abs(ss - 0.5f)) * 10;

                    ds.DrawCircle(x, y, radius, GradientColor(t), strokeWidth);
                    t += tStep;
                }
            }
        }
コード例 #22
0
        private void DrawIdleRipple(CanvasDrawingSession ds)
        {
            Easings.ParamTween(ref ImgR_c, ImgR_t, 0.80f, 0.20f);
            Easings.ParamTween(ref RingR_c, RingR_t, 0.75f, 0.25f);
            Easings.ParamTween(ref TextR_c, TextR_t, 0.80f, 0.20f);

            // TextBrush Color
            TextBrush.Color = Easings.ParamTween(TextBrush.Color, TextBrush_t, 0.80f, 0.20f);

            float RingW = (RingR_c - ImgR_c);
            float RingR = ImgR_c + 0.5f * RingW;

            // +2 to fill in the edge between the image and the ring
            ds.DrawCircle(PCenter, RingR, RingBrush, RingW + 2);

            TextRenderer.PrepareDraw(ds, TextR_c, TextRotation += TextSpeed);
            TextLayout.DrawToTextRenderer(TextRenderer, PCenter);

            ds.FillCircle(PCenter, ImgR_c, CoverBrush);
        }
コード例 #23
0
        //CanvasControl raises Draw whenever your app needs to draw or redraw its content.
        private void canvas_Draw(Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl sender, Microsoft.Graphics.Canvas.UI.Xaml.CanvasDrawEventArgs args)
        {
            CanvasCommandList cl = new CanvasCommandList(sender);

            using (CanvasDrawingSession clds = cl.CreateDrawingSession())
            {
                for (int i = 0; i < 100; i++)
                {
                    clds.DrawText("Hello, World!", RndPosition(), Color.FromArgb(255, RndByte(), RndByte(), RndByte()));
                    clds.DrawCircle(RndPosition(), RndRadius(), Color.FromArgb(255, RndByte(), RndByte(), RndByte()));
                    clds.DrawLine(RndPosition(), RndPosition(), Color.FromArgb(255, RndByte(), RndByte(), RndByte()));
                }
            }

            GaussianBlurEffect blur1 = new GaussianBlurEffect();

            blur1.Source     = cl;
            blur1.BlurAmount = 10.0f;
            args.DrawingSession.DrawImage(blur1);
        }
コード例 #24
0
ファイル: InkExample.xaml.cs プロジェクト: mjeanrichard/Win2D
        private void DrawDryInk_LinesMethod(CanvasDrawingSession ds, IReadOnlyList <InkStroke> strokes)
        {
            //
            // This shows off the fact that apps can use the custom drying path
            // to render dry ink using Win2D, and not necessarily
            // rely on the built-in rendering in CanvasDrawingSession.DrawInk.
            //
            foreach (var stroke in strokes)
            {
                var color = stroke.DrawingAttributes.Color;

                var inkPoints = stroke.GetInkPoints().Select(point => point.Position.ToVector2()).ToList();

                for (int i = 1; i < inkPoints.Count; i++)
                {
                    ds.DrawLine(inkPoints[i - 1], inkPoints[i], color);
                    ds.DrawCircle(inkPoints[i], 3, color);
                }
            }
        }
コード例 #25
0
        private void canvas_CreateResources(CanvasAnimatedControl sender, CanvasCreateResourcesEventArgs args)
        {
            CanvasCommandList cl = new CanvasCommandList(sender);

            using (CanvasDrawingSession clds = cl.CreateDrawingSession())
            {
                for (int i = 0; i < 100; i++)
                {
                    clds.DrawText("Hello, World!", RndPosition(), Color.FromArgb(255, RndByte(), RndByte(), RndByte()));
                    clds.DrawCircle(RndPosition(), RndRadius(), Color.FromArgb(255, RndByte(), RndByte(), RndByte()));
                    clds.DrawLine(RndPosition(), RndPosition(), Color.FromArgb(255, RndByte(), RndByte(), RndByte()));
                }
            }

            blur = new GaussianBlurEffect()
            {
                Source     = cl,
                BlurAmount = 10.0f
            };
        }
コード例 #26
0
ファイル: Dancer.cs プロジェクト: bradchristie/TaminationsWin
        public void draw(CanvasDrawingSession ds)
        {
            //  Draw the head
            ds.FillCircle(Vector.Create(0.5, 0), 0.33f, drawColor);
            //  Draw the body
            //  Draw the body outline
            var c = showNumber == DancerNumbers.OFF || gender == Gender.PHANTOM ? fillColor : fillColor.veryBright();

            switch (gender)
            {
            case Gender.BOY:
                ds.FillRectangle(-0.5f, -0.5f, 1, 1, c);
                ds.DrawRectangle(-0.5f, -0.5f, 1, 1, drawColor, 0.1f);
                break;

            case Gender.GIRL:
                ds.FillCircle(Vector.Create(0, 0), 0.5f, c);
                ds.DrawCircle(Vector.Create(0, 0), 0.5f, drawColor, 0.1f);
                break;

            default: // phantom
                ds.FillRoundedRectangle(-0.5f, -0.5f, 1, 1, 0.3f, 0.3f, c);
                ds.DrawRoundedRectangle(-0.5f, -0.5f, 1, 1, 0.3f, 0.3f, drawColor, 0.1f);
                break;
            }
            //  Draw number if on
            if (showNumber != DancerNumbers.OFF)
            {
                //  The dancer is rotated relative to the display, but of course
                //  the dancer number should not be rotated.
                //  So the number needs to be transformed back
                var angle  = Math.Atan2(ds.Transform.M21, ds.Transform.M22);
                var txtext = Matrix.CreateScale(1, -1) * Matrix.CreateRotation(-angle + Math.PI); // * Matrix.CreateScale(1, -1);
                ds.Transform = txtext * ds.Transform;
                var font = new CanvasTextFormat();
                font.FontSize            = 0.8f;
                font.VerticalAlignment   = CanvasVerticalAlignment.Center;
                font.HorizontalAlignment = CanvasHorizontalAlignment.Center;
                ds.DrawText(showNumber == DancerNumbers.COUPLES ? number_couple : number, 0f, 0f, Colors.Black, font);
            }
        }
コード例 #27
0
        private void DrawHex(CanvasDrawingSession drawingSession, Hex hex, Camera camera)
        {
            if (hex.Passable)
            {
                drawingSession.DrawLine(hex.Corners[0] - camera.Offset, hex.Corners[1] - camera.Offset, Colors.Black);
                drawingSession.DrawLine(hex.Corners[1] - camera.Offset, hex.Corners[2] - camera.Offset, Colors.Black);
                drawingSession.DrawLine(hex.Corners[2] - camera.Offset, hex.Corners[3] - camera.Offset, Colors.Black);
                drawingSession.DrawLine(hex.Corners[3] - camera.Offset, hex.Corners[4] - camera.Offset, Colors.Black);
                drawingSession.DrawLine(hex.Corners[4] - camera.Offset, hex.Corners[5] - camera.Offset, Colors.Black);
                drawingSession.DrawLine(hex.Corners[5] - camera.Offset, hex.Corners[0] - camera.Offset, Colors.Black);

                var centerPoint = hex.Center - camera.Offset;

                var rect = new Rect(centerPoint.ToPoint(), centerPoint.ToPoint());
                for (int i = 0; i < 6; i++)
                {
                    rect.Union((hex.Corners[i] - camera.Offset).ToPoint());
                }

                rect.Y      = Math.Floor(rect.Y) - 2.0d;
                rect.Height = Math.Ceiling(rect.Height) + 4.0d;
                drawingSession.DrawImage(_tileImage, rect);

                drawingSession.DrawCircle(centerPoint, 3, hex.IsSelected ? Colors.Blue : Colors.Gold);
                CanvasTextFormat format = new CanvasTextFormat {
                    FontSize = 20.0f, WordWrapping = CanvasWordWrapping.NoWrap
                };
                CanvasTextLayout textLayout = new CanvasTextLayout(drawingSession, hex.Coordinate.ToString(), format, 0.0f, 0.0f);
                drawingSession.DrawTextLayout(textLayout, centerPoint.X - (float)textLayout.DrawBounds.Width / 2.0f, centerPoint.Y, Colors.Black);

                if (hex.Pawn != null)
                {
                    drawingSession.FillRectangle(new Rect((centerPoint - new Vector2(25, 25)).ToPoint(), new Size(50, 50)), hex.Pawn.Selected ? Colors.HotPink : Colors.Red);
                }
            }
            else
            {
                HighlightHex(hex, drawingSession, Colors.DarkGray);
            }
        }
コード例 #28
0
        //CreateResources is an event that is fired only when Win2D determines you need to recreate your visual resources, such as when the page is loaded.
        private void canvas_CreateResources(Microsoft.Graphics.Canvas.UI.Xaml.CanvasAnimatedControl sender, Microsoft.Graphics.Canvas.UI.CanvasCreateResourcesEventArgs args)
        {
            CanvasCommandList cl = new CanvasCommandList(sender);

            using (CanvasDrawingSession clds = cl.CreateDrawingSession())
            {
                for (int i = 0; i < 100; i++)
                {
                    clds.DrawText("Hello, World!", RndPosition(), Color.FromArgb(255, RndByte(), RndByte(), RndByte()));
                    clds.DrawCircle(RndPosition(), RndRadius(), Color.FromArgb(255, RndByte(), RndByte(), RndByte()));
                    clds.DrawLine(RndPosition(), RndPosition(), Color.FromArgb(255, RndByte(), RndByte(), RndByte()));
                }
            }

            blur = new GaussianBlurEffect()
            {
                Source     = cl,
                BlurAmount = 10.0f
            };

            System.Diagnostics.Debug.WriteLine("Create" + ">>>" + j++);
        }
コード例 #29
0
        protected void DrawOuterCircle(CanvasControl sender, CanvasDrawEventArgs args)
        {
            var ds = args.DrawingSession;

            Color edgeColor = this.GaugeColor;

            if (IsLowAlarmEnabled && (Value <= LowAlarmValue) && IsOnline)
            {
                edgeColor = LowAlarmColor;
            }
            else if (IsLowWarningEnabled && (Value <= LowWarningValue) && IsOnline)
            {
                edgeColor = LowWarningColor;
            }
            else if (IsHighAlarmEnabled && (Value >= HighAlarmValue) && IsOnline)
            {
                edgeColor = HighAlarmColor;
            }
            else if (IsHighWarningEnabled && (Value >= HighWarningValue) && IsOnline)
            {
                edgeColor = HighWarningColor;
            }

            CanvasCommandList cl = new CanvasCommandList(sender);

            using (CanvasDrawingSession clds = cl.CreateDrawingSession())
            {
                clds.DrawCircle(Center, OuterCircleRadius, edgeColor, outerCircleThickness);
            }

            GaussianBlurEffect blur = new GaussianBlurEffect();

            blur.Source     = cl;
            blur.BlurAmount = 3.0f;
            args.DrawingSession.DrawImage(blur);
        }
コード例 #30
0
ファイル: MainPage.xaml.cs プロジェクト: truongascii/Win2D
        void DrawStuff(CanvasDrawingSession ds)
        {
            int horizontalLimit = (int)m_canvasControl.ActualWidth;
            int verticalLimit   = (int)m_canvasControl.ActualHeight;

            DrawnContentType drawnContentType = (DrawnContentType)m_drawnContentTypeCombo.SelectedValue;

            ds.Clear(NextRandomColor());

            Vector2 point;
            float   radiusX;
            float   radiusY;

            Random random = new Random();

            m_canvasSwapChainPanel.Visibility = Windows.UI.Xaml.Visibility.Collapsed;

            switch (drawnContentType)
            {
            case DrawnContentType.Clear_Only:
                break;

            case DrawnContentType.Bitmap:
                if (m_bitmap_tiger != null)
                {
                    ds.DrawImage(m_bitmap_tiger, NextRandomPoint(horizontalLimit, verticalLimit).ToVector2());
                }
                else
                {
                    DrawNoBitmapErrorMessage(ds, horizontalLimit / 2, verticalLimit / 2);
                }
                break;

            case DrawnContentType.Rectangle_Filled:
                Point bound0 = NextRandomPoint(horizontalLimit, verticalLimit);
                Point bound1 = NextRandomPoint(horizontalLimit, verticalLimit);

                m_linearGradientBrush.StartPoint = bound0.ToVector2();
                m_linearGradientBrush.EndPoint   = bound1.ToVector2();

                ds.FillRectangle(
                    new Rect(bound0, bound1),
                    m_linearGradientBrush);

                break;

            case DrawnContentType.Ellipse_Fill:
                NextRandomEllipse(horizontalLimit, verticalLimit, out point, out radiusX, out radiusY);
                ds.FillEllipse(
                    point, radiusX, radiusY,
                    NextRandomColor());
                break;

            case DrawnContentType.Circle_Fill:
                ds.FillCircle(
                    NextRandomPoint(horizontalLimit, verticalLimit).ToVector2(),
                    100,
                    NextRandomColor());
                break;

            case DrawnContentType.Text:
                var p     = NextRandomPoint(horizontalLimit, verticalLimit);
                var x     = (float)p.X;
                var y     = (float)p.Y;
                var color = NextRandomColor();
                ds.DrawLine(new Vector2(x, 0), new Vector2(x, verticalLimit), color);
                ds.DrawLine(new Vector2(0, y), new Vector2(horizontalLimit, y), color);
                ds.DrawText(
                    "Centered",
                    p.ToVector2(),
                    color,
                    new CanvasTextFormat()
                {
                    FontSize           = 18,
                    VerticalAlignment  = CanvasVerticalAlignment.Center,
                    ParagraphAlignment = ParagraphAlignment.Center
                });

                var r = NextRandomRect(horizontalLimit, verticalLimit);
                ds.DrawRectangle(r, color);
                ds.DrawText(
                    m_quiteLongText,
                    r,
                    NextRandomColor(),
                    new CanvasTextFormat()
                {
                    FontFamily         = "Comic Sans MS",
                    FontSize           = 18,
                    ParagraphAlignment = ParagraphAlignment.Justify,
                    Options            = CanvasDrawTextOptions.Clip
                });
                break;

            case DrawnContentType.ImageBrush:
                if (m_bitmap_tiger != null)
                {
                    m_imageBrush.Image   = m_bitmap_tiger;
                    m_imageBrush.ExtendX = (CanvasEdgeBehavior)(m_random.Next(3));
                    m_imageBrush.ExtendY = (CanvasEdgeBehavior)(m_random.Next(3));
                    ds.FillRectangle(new Rect(0, 0, horizontalLimit, verticalLimit), m_imageBrush);
                }
                else
                {
                    DrawNoBitmapErrorMessage(ds, horizontalLimit / 2, verticalLimit / 2);
                }
                break;

            case DrawnContentType.OffscreenTarget:
                m_imageBrush.Image   = m_offscreenTarget;
                m_imageBrush.ExtendX = (CanvasEdgeBehavior)(m_random.Next(3));
                m_imageBrush.ExtendY = (CanvasEdgeBehavior)(m_random.Next(3));
                ds.FillRectangle(new Rect(0, 0, horizontalLimit, verticalLimit), m_imageBrush);
                break;

            case DrawnContentType.Gradients:
                Vector2 center = NextRandomPoint(horizontalLimit, verticalLimit).ToVector2();
                m_radialGradientBrush.Center = center;
                float radius = m_random.Next(horizontalLimit / 2);
                m_radialGradientBrush.OriginOffset = new Vector2(radius, radius);
                m_radialGradientBrush.RadiusX      = radius;
                m_radialGradientBrush.RadiusY      = radius;
                ds.FillCircle(center, radius, m_radialGradientBrush);

                Vector2 line0 = NextRandomPoint(horizontalLimit, verticalLimit).ToVector2();
                Vector2 line1 = NextRandomPoint(horizontalLimit, verticalLimit).ToVector2();
                m_linearGradientBrush.StartPoint = line0;
                m_linearGradientBrush.EndPoint   = line1;
                float thickness = m_random.Next(horizontalLimit / 2);
                ds.DrawLine(line0, line1, m_linearGradientBrush, thickness);
                break;

            case DrawnContentType.AlternateBitmapLoading:
                if (m_bitmap_colorGrids != null)
                {
                    Matrix3x2 scale = Matrix3x2.CreateScale(20);

                    ds.Transform = scale;
                    ds.DrawImage(m_bitmap_colorGrids[0]);

                    ds.Transform = scale * Matrix3x2.CreateTranslation(200, 0);
                    ds.DrawImage(m_bitmap_colorGrids[1]);

                    ds.Transform = scale * Matrix3x2.CreateTranslation(0, 200);
                    ds.DrawImage(m_bitmap_colorGrids[2]);
                }
                else
                {
                    DrawNoBitmapErrorMessage(ds, horizontalLimit / 2, verticalLimit / 2);
                }
                break;

            case DrawnContentType.SwapChainPanel:
                m_canvasSwapChainPanel.Visibility = Windows.UI.Xaml.Visibility.Visible;

                float swapChainWidth  = horizontalLimit * ((float)random.NextDouble() / 2 + 0.5f);
                float swapChainHeight = verticalLimit * ((float)random.NextDouble() / 2 + 0.5f);

                if (m_swapChain == null)
                {
                    m_swapChain = new CanvasSwapChain(ds, swapChainWidth, swapChainHeight);
                    m_canvasSwapChainPanel.SwapChain = m_swapChain;
                }
                else
                {
                    m_swapChain.ResizeBuffers(swapChainWidth, swapChainHeight);
                }

                using (CanvasDrawingSession panelDS = m_swapChain.CreateDrawingSession(NextRandomColor()))
                {
                    panelDS.DrawCircle(swapChainWidth / 2.0f, swapChainHeight / 2.0f, 100.0f, NextRandomColor(), 20.0f);
                }
                m_swapChain.Present();
                break;

            case DrawnContentType.Test_Scene0_Default:
                GeometryTestScene0.DrawGeometryTestScene(ds, TestSceneRenderingType.Default);
                break;

            case DrawnContentType.Test_Scene0_Wireframe:
                GeometryTestScene0.DrawGeometryTestScene(ds, TestSceneRenderingType.Wireframe);
                break;

            case DrawnContentType.Test_Scene1_Default:
                GeometryTestScene1.DrawGeometryTestScene(ds, TestSceneRenderingType.Default);
                break;

            case DrawnContentType.Test_Scene1_Randomized:
                GeometryTestScene1.DrawGeometryTestScene(ds, TestSceneRenderingType.Randomized);
                break;

            case DrawnContentType.Test_Scene1_Wireframe:
                GeometryTestScene1.DrawGeometryTestScene(ds, TestSceneRenderingType.Wireframe);
                break;

            default:
                System.Diagnostics.Debug.Assert(false);     // Unexpected
                break;
            }
        }