Browse Source
* Make sure wrapper and platform DrawingContext have the same transform after Flush * Add some tests * Update Avalonia.RenderTests.WpfCompare.csproj * Remove comments * Use test fontpull/17021/head
committed by
GitHub
8 changed files with 171 additions and 3 deletions
@ -0,0 +1,51 @@ |
|||
using Avalonia.Media; |
|||
using CrossUI; |
|||
|
|||
#if AVALONIA_SKIA
|
|||
namespace Avalonia.Skia.RenderTests.CrossTests; |
|||
#elif AVALONIA_D2D
|
|||
namespace Avalonia.Direct2D1.RenderTests.CrossTests; |
|||
#else
|
|||
namespace Avalonia.RenderTests.WpfCompare.CrossTests; |
|||
#endif
|
|||
|
|||
|
|||
public class DrawingContextTests : CrossTestBase |
|||
{ |
|||
public DrawingContextTests() : base("Media/DrawingContext") |
|||
{ |
|||
} |
|||
|
|||
[CrossFact] |
|||
public void Transform_Should_Work_As_Expected() |
|||
{ |
|||
RenderAndCompare( |
|||
|
|||
new CrossFuncControl(ctx => |
|||
{ |
|||
ctx.PushTransform(Matrix.CreateTranslation(100, 100)); |
|||
ctx.DrawLine(new CrossPen { Brush = new CrossSolidColorBrush(Colors.Red), Thickness = 1 }, |
|||
new Point(0, 0), new Point(100, 0)); |
|||
ctx.Pop(); |
|||
|
|||
ctx.PushTransform(Matrix.CreateTranslation(200, 100)); |
|||
ctx.DrawLine(new CrossPen { Brush = new CrossSolidColorBrush(Colors.Orange), Thickness = 1 }, |
|||
new Point(0, 0), new Point(0, 100)); |
|||
ctx.Pop(); |
|||
|
|||
ctx.PushTransform(Matrix.CreateTranslation(200, 200)); |
|||
ctx.DrawLine( |
|||
new CrossPen { Brush = new CrossSolidColorBrush(Colors.Yellow), Thickness = 1 }, |
|||
new Point(0, 0), new Point(-100, 0)); |
|||
ctx.Pop(); |
|||
|
|||
ctx.PushTransform(Matrix.CreateTranslation(100, 200)); |
|||
ctx.DrawLine(new CrossPen { Brush = new CrossSolidColorBrush(Colors.Green), Thickness = 1 }, |
|||
new Point(0, 0), new Point(0, -100)); |
|||
ctx.Pop(); |
|||
}) { Width = 300, Height = 300 } |
|||
|
|||
); |
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,69 @@ |
|||
using System.Globalization; |
|||
using System.Threading.Tasks; |
|||
using Avalonia.Controls; |
|||
using Avalonia.Media; |
|||
using Xunit; |
|||
#pragma warning disable CS0649
|
|||
|
|||
#if AVALONIA_SKIA
|
|||
namespace Avalonia.Skia.RenderTests; |
|||
|
|||
public class DrawingContextTests : TestBase |
|||
{ |
|||
public DrawingContextTests() : base(@"Media\DrawingContext") |
|||
{ |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Should_Render_LinesAndText() |
|||
{ |
|||
var target = new Border |
|||
{ |
|||
Width = 300, |
|||
Height = 300, |
|||
Background = Brushes.White, |
|||
Child = new RenderControl() |
|||
}; |
|||
|
|||
await RenderToFile(target); |
|||
CompareImages(skipImmediate: true); |
|||
} |
|||
|
|||
internal class RenderControl : Control |
|||
{ |
|||
private static readonly Typeface s_typeface = new Typeface(TestFontFamily); |
|||
|
|||
public override void Render(DrawingContext context) |
|||
{ |
|||
var pen = new Pen(Brushes.LightGray, 10); |
|||
RenderLine1(context, pen); |
|||
RenderLine2(context, pen); |
|||
RenderLine3(context, pen); |
|||
RenderLine4(context, pen); |
|||
|
|||
RenderLine1(context, new Pen(Brushes.Red)); |
|||
RenderAText(context, new Point(50, 20)); |
|||
RenderLine2(context, new Pen(Brushes.Orange)); |
|||
RenderAText(context, new Point(50, -50)); |
|||
RenderLine3(context, new Pen(Brushes.Yellow)); |
|||
RenderAText(context, new Point(0, 0)); |
|||
RenderLine4(context, new Pen(Brushes.Green)); |
|||
} |
|||
|
|||
private static void RenderLine1(DrawingContext context, IPen pen) => context.DrawLine(pen, new Point(100, 100), new Point(200, 100)); |
|||
private static void RenderLine2(DrawingContext context, IPen pen) => context.DrawLine(pen, new Point(200, 100), new Point(200, 200)); |
|||
private static void RenderLine3(DrawingContext context, IPen pen) => context.DrawLine(pen, new Point(200, 200), new Point(100, 200)); |
|||
private static void RenderLine4(DrawingContext context, IPen pen) => context.DrawLine(pen, new Point(100, 200), new Point(100, 100)); |
|||
|
|||
private static void RenderAText(DrawingContext context, Point point) |
|||
{ |
|||
using (context.PushOpacity(0.7)) |
|||
{ |
|||
context.DrawText( |
|||
new FormattedText("any text to render", CultureInfo.CurrentCulture, FlowDirection.LeftToRight, |
|||
s_typeface, 12, Brushes.Black), point); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
#endif
|
|||
|
After Width: | Height: | Size: 793 B |
|
After Width: | Height: | Size: 2.2 KiB |
Loading…
Reference in new issue