From a112ced10977a1fb899c8b8a5618d2060afdabc4 Mon Sep 17 00:00:00 2001 From: Scott W Harden Date: Sat, 5 Feb 2022 11:51:50 -0500 Subject: [PATCH] GraphicsTester: add ScaleCanvas scenario Add a new abstract scenario to demonstrate Canvas.Scale() with distinct X and Y scales. This test currently demonstrates a bug described by #302 where only the X scale is respected when drawing paths. --- .../Scenarios/ScaleCanvas.cs | 37 +++++++++++++++++++ .../Scenarios/ScenarioList.cs | 1 + 2 files changed, 38 insertions(+) create mode 100644 samples/GraphicsTester.Portable/Scenarios/ScaleCanvas.cs diff --git a/samples/GraphicsTester.Portable/Scenarios/ScaleCanvas.cs b/samples/GraphicsTester.Portable/Scenarios/ScaleCanvas.cs new file mode 100644 index 0000000..1ca4838 --- /dev/null +++ b/samples/GraphicsTester.Portable/Scenarios/ScaleCanvas.cs @@ -0,0 +1,37 @@ +using Microsoft.Maui.Graphics; +using System; +using System.Collections.Generic; +using System.Text; + +namespace GraphicsTester.Scenarios +{ + internal class ScaleCanvas : AbstractScenario + { + public ScaleCanvas() : base(720, 1024) + { + } + + public override void Draw(ICanvas canvas) + { + DrawTestShapesOnScaledCanvas(canvas, 1, 1, Colors.Black); + DrawTestShapesOnScaledCanvas(canvas, 2, 2, Colors.Magenta); + DrawTestShapesOnScaledCanvas(canvas, 2, 1, Colors.Green); + DrawTestShapesOnScaledCanvas(canvas, 1, 2, Colors.Orange); + } + + private void DrawTestShapesOnScaledCanvas(ICanvas canvas, float xScale, float yScale, Color color) + { + PathF path = new(100, 100); + path.AddArc(100, 100, 200, 200, 0, 180, true); + path.LineTo(150, 100); + path.Close(); + + canvas.SaveState(); + canvas.Scale(xScale, yScale); + canvas.StrokeColor = color; + canvas.StrokeSize = 2; + canvas.DrawPath(path); + canvas.RestoreState(); + } + } +} diff --git a/samples/GraphicsTester.Portable/Scenarios/ScenarioList.cs b/samples/GraphicsTester.Portable/Scenarios/ScenarioList.cs index a06481d..983f7da 100644 --- a/samples/GraphicsTester.Portable/Scenarios/ScenarioList.cs +++ b/samples/GraphicsTester.Portable/Scenarios/ScenarioList.cs @@ -61,6 +61,7 @@ namespace GraphicsTester.Scenarios new ClipRect(), new SubtractFromClip(), new DimensionTest(), + new ScaleCanvas(), }; }