-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Make sure wrapper and platform DrawingContext have the same transform after Flush * Add some tests * Update Avalonia.RenderTests.WpfCompare.csproj * Remove comments * Use test font
- Loading branch information
Showing
8 changed files
with
171 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
tests/Avalonia.RenderTests/CrossTests/Media/DrawingContextTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 } | ||
|
||
); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Binary file added
BIN
+793 Bytes
...Files/CrossTests/Media/DrawingContext/Transform_Should_Work_As_Expected.wpf.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.23 KB
tests/TestFiles/Skia/Media/DrawingContext/Should_Render_LinesAndText.expected.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.