internal static void CheckExpectedImage(ImagePrimitive primitive, int width, int height, Rect rect, StyleRuleSet style, string expectedImageFilePath) { byte[] imageRawBytes; using (var context = new RenderContextForTest(width, height)) { BuiltinPrimitiveRenderer primitiveRenderer = new BuiltinPrimitiveRenderer(); var mesh = new Mesh(); primitiveRenderer.DrawSlicedImagePrimitive(mesh, primitive, rect, style, Vector.Zero); context.Clear(); context.DrawImageMesh(mesh); imageRawBytes = context.GetRenderedRawBytes(); } Util.CheckExpectedImage(imageRawBytes, width, height, expectedImageFilePath); }
public void DrawOneImage() { byte[] imageRawBytes; int width, height; using (var context = new RenderContextForTest(300, 400)) { var styleRuleSet = new StyleRuleSet(); var styleRuleSetBuilder = new StyleRuleSetBuilder(styleRuleSet); styleRuleSetBuilder .BorderImageSource(@"assets\images\button.png") .BorderImageSlice((83, 54, 54, 54)); var primitiveRenderer = new BuiltinPrimitiveRenderer(); //build image and get the image primitive var rule = styleRuleSet.GetRule <string>(GUIStyleName.BorderImageSource); if (rule.primitive == null) { rule.primitive = new ImagePrimitive(rule.Value); } Assert.True(rule.primitive is ImagePrimitive); var primitive = (ImagePrimitive)rule.primitive; var mesh = new Mesh(); mesh.CommandBuffer.Add(DrawCommand.Default); primitiveRenderer.SetImageMesh(mesh); primitiveRenderer.DrawSlicedImage(primitive, new Rect(2, 2, primitive.Image.Width + 50, primitive.Image.Height + 100), styleRuleSet); context.Clear(); context.DrawImageMesh(mesh); imageRawBytes = context.Renderer.GetRawBackBuffer(out width, out height); } var image = Util.CreateImage(imageRawBytes, width, height, flip: true); string expectedImageFilePath = @"GraphicsImplementation\Builtin\images\BuiltinPrimitiveRendererFacts.DrawSlicedImage.DrawOneImage.png"; #if GenerateExpectedImages Util.SaveImage(image, Util.UnitTestRootDir + expectedImageFilePath);//generate expected image #else var expectedImage = Util.LoadImage(expectedImageFilePath); Assert.True(Util.CompareImage(expectedImage, image)); #endif }
public void DrawBoxModelWithImageContent() { byte[] imageRawBytes; int width, height; using (var context = new RenderContextForTest(500, 500)) { var primitive = new ImagePrimitive(@"assets\images\logo.png"); var ruleSet = new StyleRuleSet(); var styleSetBuilder = new StyleRuleSetBuilder(ruleSet); styleSetBuilder .BackgroundColor(Color.White) .Border((top: 1, right: 3, bottom: 1, left: 3)) .BorderColor(Color.LightBlue) .Padding((10, 5, 10, 5)); BuiltinPrimitiveRenderer primitiveRenderer = new BuiltinPrimitiveRenderer(); var mesh = new Mesh(); mesh.CommandBuffer.Add(DrawCommand.Default); primitiveRenderer.SetShapeMesh(mesh); var imageMesh = new Mesh(); imageMesh.CommandBuffer.Add(DrawCommand.Default); primitiveRenderer.SetImageMesh(imageMesh); primitiveRenderer.DrawBoxModel(primitive, new Rect(10, 10, 300, 400), ruleSet); context.Clear(); context.DrawShapeMesh(mesh); context.DrawImageMesh(imageMesh); imageRawBytes = context.Renderer.GetRawBackBuffer(out width, out height); } var image = Util.CreateImage(imageRawBytes, width, height, flip: true); string expectedImageFilePath = @"GraphicsImplementation\Builtin\images\BuiltinPrimitiveRendererFacts.DrawBoxModel.DrawBoxModelWithImageContent.png"; #if GenerateExpectedImages Util.SaveImage(image, Util.UnitTestRootDir + expectedImageFilePath);//generate expected image #else var expectedImage = Util.LoadImage(expectedImageFilePath); Assert.True(Util.CompareImage(expectedImage, image)); #endif }
public void DrawBoxModelWithImageContent() { var primitive = new ImagePrimitive(@"assets\images\logo.png"); var ruleSet = new StyleRuleSet(); var styleSetBuilder = new StyleRuleSetBuilder(ruleSet); styleSetBuilder .BackgroundColor(Color.White) .Border((top: 1, right: 3, bottom: 1, left: 3)) .BorderColor(Color.LightBlue) .Padding((10, 5, 10, 5)); var rect = new Rect(10, 10, 300, 400); const string expectedImageFilePath = @"GraphicsImplementation\Builtin\images\BuiltinPrimitiveRendererFacts.DrawBoxModel.DrawBoxModelWithImageContent.png"; const int width = 500, height = 500; byte[] imageRawBytes; using (var context = new RenderContextForTest(width, height)) { BuiltinPrimitiveRenderer primitiveRenderer = new BuiltinPrimitiveRenderer(); var mesh = new Mesh(); mesh.CommandBuffer.Add(DrawCommand.Default); primitiveRenderer.SetShapeMesh(mesh); var imageMesh = new Mesh(); primitiveRenderer.SetImageMesh(imageMesh); primitiveRenderer.DrawBoxModel(primitive, rect, ruleSet); context.Clear(); context.DrawShapeMesh(mesh); context.DrawImageMesh(imageMesh); imageRawBytes = context.GetRenderedRawBytes(); } Util.CheckExpectedImage(imageRawBytes, width, height, expectedImageFilePath); }
public void DrawOriginalImage() { byte[] imageRawBytes; int width, height; using (var context = new RenderContextForTest(300, 400)) { var primitive = new ImagePrimitive(@"assets\images\logo.png"); primitive.Offset = new Vector(10, 10); var styleRuleSet = new StyleRuleSet(); var styleRuleSetBuilder = new StyleRuleSetBuilder(styleRuleSet); styleRuleSetBuilder.BackgroundColor(Color.White); var primitiveRenderer = new BuiltinPrimitiveRenderer(); var mesh = new Mesh(); mesh.CommandBuffer.Add(DrawCommand.Default); primitiveRenderer.SetImageMesh(mesh); primitiveRenderer.DrawImage(primitive, new Rect(10, 10, primitive.Image.Width, primitive.Image.Height), styleRuleSet); context.Clear(); context.DrawImageMesh(mesh); imageRawBytes = context.Renderer.GetRawBackBuffer(out width, out height); } var image = Util.CreateImage(imageRawBytes, width, height, flip: true); string expectedImageFilePath = @"GraphicsImplementation\Builtin\images\BuiltinPrimitiveRendererFacts.DrawImage.DrawOriginalImage.png"; #if DEBUG var expectedImage = Util.LoadImage(expectedImageFilePath); Assert.True(Util.CompareImage(expectedImage, image)); #else Util.SaveImage(image, Util.UnitTestRootDir + expectedImageFilePath);//generate expected image #endif }