Пример #1
0
            public void ShowHideANode()
            {
                Node node      = new Node(1);
                var  primitive = new PathPrimitive();

                primitive.PathMoveTo(new Point(10, 10));
                primitive.PathLineTo(new Point(10, 100));
                primitive.PathLineTo(new Point(100, 100));
                primitive.PathLineTo(new Point(100, 10));
                primitive.PathClose();
                primitive.PathFill(Color.Red);
                node.Primitive = primitive;

                {
                    node.ActiveSelf = true;
                    Util.DrawNodeToImage(out var imageRawBytes, node, 110, 110);
                    Util.CheckExpectedImage(imageRawBytes, 110, 110, @"Rendering\images\NodeFacts.Draw.ShowHideANode.Show.png");
                }

                {
                    node.ActiveSelf = false;
                    Util.DrawNodeToImage(out var imageRawBytes, node, 110, 110);
                    Util.CheckExpectedImage(imageRawBytes, 110, 110, @"Rendering\images\NodeFacts.Draw.ShowHideANode.Hide.png");
                }
            }
Пример #2
0
            public void UpdateANode()
            {
                var primitive = new PathPrimitive();

                primitive.PathMoveTo(new Point(10, 10));
                primitive.PathLineTo(new Point(10, 100));
                primitive.PathLineTo(new Point(100, 100));
                primitive.PathLineTo(new Point(100, 10));
                primitive.PathClose();
                var fillCmd = primitive.PathFill(Color.Black);

                Node node = new Node(1);

                node.Primitive = primitive;

                {
                    fillCmd.Color = Color.Red;
                    Util.DrawNodeToImage(out var imageRawBytes, node, 110, 110);
                    Util.CheckExpectedImage(imageRawBytes, 110, 110, @"Rendering\images\NodeFacts.Draw.UpdateANode.Black.png");
                }
                {
                    fillCmd.Color = Color.Green;
                    Util.DrawNodeToImage(out var imageRawBytes, node, 110, 110);
                    Util.CheckExpectedImage(imageRawBytes, 110, 110, @"Rendering\images\NodeFacts.Draw.UpdateANode.Green.png");
                }
                {
                    fillCmd.Color = Color.Blue;
                    Util.DrawNodeToImage(out var imageRawBytes, node, 110, 110);
                    Util.CheckExpectedImage(imageRawBytes, 110, 110, @"Rendering\images\NodeFacts.Draw.UpdateANode.Blue.png");
                }
            }
            public void FillARect()
            {
                var primitive = new PathPrimitive();

                primitive.PathRect(new Rect(10, 10, 80, 60));
                primitive.PathFill(Color.Red);

                Util.CheckExpectedImage(primitive, 100, 100, @"GraphicsImplementation\Builtin\images\BuiltinPrimitiveRendererFacts.DrawPath.FillARect.png");
            }
Пример #4
0
            public void DrawOverlappedRectangles()
            {
                var box0 = new List <Node>();
                {
                    {
                        Node node = new Node(0);
                        box0.Add(node);
                        var primitive = new PathPrimitive();
                        primitive.PathRect(new Point(10, 10), new Point(100, 100));
                        primitive.PathFill(Color.Orange);
                        node.Primitive = primitive;
                    }
                    {
                        Node node = new Node(1);
                        box0.Add(node);
                        var primitive = new PathPrimitive();
                        primitive.PathRect(new Point(9, 9), new Point(101, 101));
                        primitive.PathStroke(2, Color.Black);
                        node.Primitive = primitive;
                    }
                }
                var box1 = new List <Node>();
                {
                    {
                        Node node = new Node(3);
                        box1.Add(node);
                        var primitive = new PathPrimitive();
                        primitive.PathRect(new Point(50, 50), new Point(140, 140));
                        primitive.PathFill(Color.LightBlue);
                        node.Primitive = primitive;
                    }
                    {
                        Node node = new Node(4);
                        box1.Add(node);
                        var primitive = new PathPrimitive();
                        primitive.PathRect(new Point(49, 49), new Point(141, 141));
                        primitive.PathStroke(2, Color.Red);
                        node.Primitive = primitive;
                    }
                }

                {
                    var box0Foreground = new List <Node>();
                    box0Foreground.AddRange(box0);
                    box0Foreground.AddRange(box1);
                    Util.DrawNodesToImage(out var imageRawBytes, box0Foreground, 150, 150);
                    Util.CheckExpectedImage(imageRawBytes, 150, 150, @"Rendering\images\NodeFacts.Draw.DrawOverlappedRectangles.Before.png");
                }
                {
                    var box1Foreground = new List <Node>();
                    box1Foreground.AddRange(box1);
                    box1Foreground.AddRange(box0);
                    Util.DrawNodesToImage(out var imageRawBytes, box1Foreground, 150, 150);
                    Util.CheckExpectedImage(imageRawBytes, 150, 150, @"Rendering\images\NodeFacts.Draw.DrawOverlappedRectangles.After.png");
                }
            }
            public void FillAPath()
            {
                var primitive = new PathPrimitive();

                primitive.PathMoveTo(new Point(10, 10));
                primitive.PathLineTo(new Point(10, 80));
                primitive.PathLineTo(new Point(80, 80));
                primitive.PathClose();
                primitive.PathFill(Color.Red);

                Util.CheckExpectedImage(primitive, 100, 100, @"GraphicsImplementation\Builtin\images\BuiltinPrimitiveRendererFacts.DrawPath.FillAPath.png");
            }
Пример #6
0
            public void DrawAndLayoutContainerWithElements()
            {
                var container = new Node(1, "container");

                container.AttachLayoutGroup(false);
                container.RuleSet.ApplyOptions(GUILayout.Width(300).Height(40));
                container.UseBoxModel = true;
                StyleRuleSetBuilder b = new StyleRuleSetBuilder(container);

                b.Border(1)
                .BorderColor(Color.Black)
                .Padding((top: 4, right: 3, bottom: 4, left: 3))
                .AlignmentVertical(Alignment.Center)
                .AlignmentHorizontal(Alignment.Center);

                var icon = new Node(2, "icon");

                icon.AttachLayoutEntry(new Size(20, 20));
                icon.RuleSet.ApplyOptions(GUILayout.Width(20).Height(20));
                icon.UseBoxModel = false;
                icon.Primitive   = new ImagePrimitive(@"assets\images\logo.png");

                var title         = new Node(3, "title");
                var titleTextSize = GUIStyle.Default.CalcSize("title", GUIState.Normal);//TODO consider this

                title.AttachLayoutEntry(titleTextSize);
                title.RuleSet.ApplyOptions(GUILayout.Height(20).ExpandWidth(true));
                title.UseBoxModel = false;
                title.Primitive   = new TextPrimitive("title");

                var closeButton = new Node(4, "close button");

                closeButton.AttachLayoutEntry(new Size(20, 20));
                closeButton.UseBoxModel = false;
                PathPrimitive path = new PathPrimitive();

                path.PathRect(new Rect(0, 0, 20, 20));
                path.PathFill(Color.Black);

                closeButton.Primitive = path;

                container.AppendChild(icon);
                container.AppendChild(title);
                container.AppendChild(closeButton);

                container.Layout();

                CheckExpectedImage(container, @"Rendering\images\NodeFacts.Container.DrawAndLayoutContainerWithElements.png");
            }
Пример #7
0
            public void DrawANode()
            {
                var primitive = new PathPrimitive();

                primitive.PathMoveTo(new Point(10, 10));
                primitive.PathLineTo(new Point(10, 100));
                primitive.PathLineTo(new Point(100, 100));
                primitive.PathLineTo(new Point(100, 10));
                primitive.PathClose();
                primitive.PathFill(Color.Black);

                Node node = new Node(1);

                node.Primitive = primitive;

                Util.DrawNodeToImage(out var imageRawBytes, node, 110, 110);
                Util.CheckExpectedImage(imageRawBytes, 110, 110, @"Rendering\images\NodeFacts.Draw.DrawANode.png");
            }
Пример #8
0
            public void UpdateTwoNode()
            {
                var         nodes = new List <Node>();
                FillCommand node0FillCmd, node1FillCmd;
                {
                    Node node = new Node(0);
                    nodes.Add(node);
                    var primitive = new PathPrimitive();
                    primitive.PathMoveTo(new Point(10, 10));
                    primitive.PathLineTo(new Point(10, 100));
                    primitive.PathLineTo(new Point(100, 100));
                    primitive.PathLineTo(new Point(100, 10));
                    primitive.PathClose();
                    node0FillCmd   = primitive.PathFill(Color.Green);
                    node.Primitive = primitive;
                }
                {
                    Node node = new Node(1);
                    nodes.Add(node);
                    var primitive = new PathPrimitive();
                    primitive.PathMoveTo(new Point(110, 10));
                    primitive.PathLineTo(new Point(110, 100));
                    primitive.PathLineTo(new Point(200, 100));
                    primitive.PathLineTo(new Point(200, 10));
                    primitive.PathClose();
                    node1FillCmd = primitive.PathFill(Color.Orange);

                    node.Primitive = primitive;
                }

                {
                    node0FillCmd.Color = Color.Red;
                    node1FillCmd.Color = Color.Blue;
                    Util.DrawNodesToImage(out var imageRawBytes, nodes, 110, 110);
                    Util.CheckExpectedImage(imageRawBytes, 110, 110, @"Rendering\images\NodeFacts.Draw.UpdateTwoNode.Before.png");
                }

                {
                    node0FillCmd.Color = Color.Green;
                    node1FillCmd.Color = Color.Orange;
                    Util.DrawNodesToImage(out var imageRawBytes, nodes, 110, 110);
                    Util.CheckExpectedImage(imageRawBytes, 110, 110, @"Rendering\images\NodeFacts.Draw.UpdateTwoNode.After.png");
                }
            }
Пример #9
0
            public void DrawAndLayoutContainerWithElements()
            {
                Application.IsRunningInUnitTest = true;
                Application.InitSysDependencies();

                var primitiveRenderer = new BuiltinPrimitiveRenderer();

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

                var window = new Win32Window();

                window.Init(new Point(100, 100), new Size(400, 400), WindowTypes.Regular);

                var renderer = new Win32OpenGLRenderer();

                renderer.Init(window.Pointer, window.ClientSize);

                window.Show();

                bool DrawNode(Node n, MeshList list)
                {
                    if (!n.ActiveInTree)
                    {
                        return(false);
                    }

                    n.Draw(primitiveRenderer, list);
                    return(true);
                }

                Node container = null;
                Node icon;
                Node title;
                Node closeButton;

                while (true)
                {
                    Time.OnFrameBegin();
                    Keyboard.Instance.OnFrameBegin();

                    window.MainLoop(() =>
                    {
                        if (Keyboard.Instance.KeyDown(Key.Escape))
                        {
                            Application.Quit();
                        }

                        if (container == null)
                        {
                            container = new Node(1, "container");
                            container.AttachLayoutGroup(false);
                            container.RuleSet.ApplyOptions(GUILayout.Width(300).Height(40));
                            container.UseBoxModel = true;
                            StyleRuleSetBuilder b = new StyleRuleSetBuilder(container);
                            b.Border(1)
                            .BorderColor(Color.Black)
                            .Padding((top: 4, right: 3, bottom: 4, left: 3))
                            .BackgroundColor(Color.Silver)
                            .AlignmentVertical(Alignment.Center)
                            .AlignmentHorizontal(Alignment.Center);

                            icon = new Node(2, "icon");
                            icon.AttachLayoutEntry(new Size(20, 20));
                            icon.RuleSet.ApplyOptions(GUILayout.Width(20).Height(20));
                            icon.UseBoxModel = false;
                            icon.Primitive   = new ImagePrimitive(@"assets\images\logo.png");

                            title             = new Node(3, "title");
                            var titleTextSize = GUIStyle.Default.CalcSize("title", GUIState.Normal);//TODO consider this
                            title.AttachLayoutEntry(titleTextSize);
                            title.RuleSet.ApplyOptions(GUILayout.Height(20).ExpandWidth(true));
                            title.UseBoxModel = false;
                            title.Primitive   = new TextPrimitive("title");

                            closeButton = new Node(4, "close button");
                            closeButton.AttachLayoutEntry(new Size(20, 20));
                            closeButton.UseBoxModel = false;
                            PathPrimitive path      = new PathPrimitive();
                            path.PathRect(new Rect(0, 0, 20, 20));
                            path.PathFill(Color.Black);
                            //path.PathClear();

                            //path.PathMoveTo((0, 0));
                            //path.PathLineTo((20,20));
                            //path.PathStroke(1, Color.Black);
                            //path.PathClear();
                            //
                            //path.PathMoveTo((0, 20));
                            //path.PathLineTo((20,0));
                            //path.PathStroke(1, Color.Black);
                            //path.PathClear();

                            closeButton.Primitive = path;

                            container.AppendChild(icon);
                            container.AppendChild(title);
                            container.AppendChild(closeButton);
                        }

                        {
                            DrawNode(container, meshList);
                            container.Foreach(n => DrawNode(n, meshList));
                            container.Layout();
                        }

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

                        //draw mesh buffer to screen
                        renderer.Clear(Color.FrameBg);
                        renderer.DrawMeshes((int)window.ClientSize.Width, (int)window.ClientSize.Height,
                                            (shapeMesh: meshBuffer.ShapeMesh, imageMesh: meshBuffer.ImageMesh, meshBuffer.TextMesh));
                        renderer.SwapBuffers();
                    });

                    if (Application.RequestQuit)
                    {
                        break;
                    }

                    Keyboard.Instance.OnFrameEnd();
                    Time.OnFrameEnd();
                }
            }