Ejemplo n.º 1
0
            internal static void CheckRectangle(Brush brush, Pen pen, Rect rectangle,
                                                int width, int height,
                                                [CallerMemberName] string methodName = "unknown")
            {
                Application.EnableMSAA = false;

                MeshBuffer meshBuffer            = new MeshBuffer();
                MeshList   meshList              = new MeshList();
                BuiltinGeometryRenderer renderer = new BuiltinGeometryRenderer();

                byte[] bytes;

                using (var context = new RenderContextForTest(width, height))
                {
                    renderer.OnBeforeRead();
                    renderer.DrawRectangle(brush, pen, rectangle);//This must be called after the RenderContextForTest is created, for uploading textures to GPU via OpenGL.
                    renderer.OnAfterRead(meshList);

                    //rebuild mesh buffer
                    meshBuffer.Clear();
                    meshBuffer.Init();
                    meshBuffer.Append(meshList);

                    //draw mesh buffer to screen
                    context.Clear();
                    context.DrawMeshes(meshBuffer);

                    bytes = context.GetRenderedRawBytes();
                }

                Util.CheckExpectedImage(bytes, width, height, $"{RootDir}{nameof(DrawRectangle)}\\{methodName}.png");
            }
Ejemplo n.º 2
0
            internal static void CheckExpectedImage(TextPrimitive primitive, int width, int height, Rect contentRect, string expectedImageFilePath)
            {
                byte[] imageRawBytes;
                using (var context = new RenderContextForTest(width, height))
                {
                    BuiltinPrimitiveRenderer primitiveRenderer = new BuiltinPrimitiveRenderer();
                    var textMesh = new TextMesh();
                    primitiveRenderer.DrawTextPrimitive(textMesh, primitive, contentRect, new StyleRuleSet(), Vector.Zero);

                    context.Clear();
                    context.DrawTextMesh(textMesh);

                    imageRawBytes = context.GetRenderedRawBytes();
                }
                Util.CheckExpectedImage(imageRawBytes, width, height, expectedImageFilePath);
            }
Ejemplo n.º 3
0
            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 DrawBoxModelWithTextContent()
            {
                byte[] imageRawBytes;
                int    width, height;

                using (var context = new RenderContextForTest(400, 100))
                {
                    TextPrimitive textPrimitive       = new TextPrimitive("Hello你好こんにちは");
                    var           styleRuleSet        = new StyleRuleSet();
                    var           styleRuleSetBuilder = new StyleRuleSetBuilder(styleRuleSet);
                    styleRuleSetBuilder
                    .BackgroundColor(Color.White)
                    .Border((1, 3, 1, 3))
                    .BorderColor(Color.Black)
                    .Padding((10, 5, 10, 5))
                    .FontSize(24)
                    .FontColor(Color.Black);

                    BuiltinPrimitiveRenderer primitiveRenderer = new BuiltinPrimitiveRenderer();
                    var mesh = new Mesh();
                    mesh.CommandBuffer.Add(DrawCommand.Default);
                    primitiveRenderer.SetShapeMesh(mesh);
                    var textMesh = new TextMesh();
                    primitiveRenderer.SetTextMesh(textMesh);
                    primitiveRenderer.DrawBoxModel(textPrimitive, new Rect(10, 10, 350, 60), styleRuleSet);

                    context.Clear();
                    context.DrawShapeMesh(mesh);
                    context.DrawTextMesh(textMesh);

                    imageRawBytes = context.Renderer.GetRawBackBuffer(out width, out height);
                }

                var    image = Util.CreateImage(imageRawBytes, width, height, flip: true);
                string expectedImageFilePath =
                    @"GraphicsImplementation\Builtin\images\BuiltinPrimitiveRendererFacts.DrawBoxModel.DrawBoxModelWithTextContent.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
            }
Ejemplo n.º 7
0
            public void DrawBoxModelWithTextContent()
            {
                TextPrimitive textPrimitive       = new TextPrimitive("Hello你好こんにちは");
                var           styleRuleSet        = new StyleRuleSet();
                var           styleRuleSetBuilder = new StyleRuleSetBuilder(styleRuleSet);

                styleRuleSetBuilder
                .BackgroundColor(Color.White)
                .Border((1, 3, 1, 3))
                .BorderColor(Color.Black)
                .Padding((10, 5, 10, 5))
                .FontSize(24)
                .FontColor(Color.Black);
                var rect = new Rect(10, 10, 350, 60);

                const string expectedImageFilePath =
                    @"GraphicsImplementation\Builtin\images\BuiltinPrimitiveRendererFacts.DrawBoxModel.DrawBoxModelWithTextContent.png";
                const int width = 400, height = 100;

                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 textMesh = new TextMesh();
                    primitiveRenderer.SetTextMesh(textMesh);
                    var imageMesh = new Mesh();
                    primitiveRenderer.SetImageMesh(imageMesh);
                    primitiveRenderer.DrawBoxModel(textPrimitive, rect, styleRuleSet);

                    context.Clear();
                    context.DrawShapeMesh(mesh);
                    context.DrawTextMesh(textMesh);

                    imageRawBytes = context.GetRenderedRawBytes();
                }

                Util.CheckExpectedImage(imageRawBytes, width, height, expectedImageFilePath);
            }
Ejemplo n.º 8
0
            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
            }