Ejemplo n.º 1
0
            public void Works()
            {
                var primitive = new PathPrimitive();

                primitive.PathMoveTo(Point.Zero);
                primitive.PathLineTo(new Point(0, 10));
                primitive.PathLineTo(new Point(10, 10));
                primitive.PathLineTo(new Point(10, 0));

                Assert.Equal(4, primitive.Path.Count);
                {
                    Assert.IsType <MoveToCommand>(primitive.Path[0]);
                    var cmd = (MoveToCommand)primitive.Path[0];
                    Assert.Equal(Point.Zero, cmd.Point);
                }
                {
                    var cmd = (LineToCommand)primitive.Path[1];
                    Assert.Equal(new Point(0, 10), cmd.Point);
                }
                {
                    var cmd = (LineToCommand)primitive.Path[2];
                    Assert.Equal(new Point(10, 10), cmd.Point);
                }
                {
                    var cmd = (LineToCommand)primitive.Path[3];
                    Assert.Equal(new Point(10, 0), cmd.Point);
                }
            }
Ejemplo n.º 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");
                }
            }
Ejemplo n.º 3
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");
                }
            }
            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");
            }
Ejemplo n.º 5
0
        public void StrokeAPath()
        {
            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 primitiveRenderer = new BuiltinPrimitiveRenderer();
            var brush             = new Brush();

            brush.LineColor = Color.Red;

            var mesh = new Mesh();

            mesh.CommandBuffer.Add(DrawCommand.Default);
            primitiveRenderer.SetShapeMesh(mesh);

            primitiveRenderer.Stroke(primitive, brush, new StrokeStyle());

            var window = new Win32Window();

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

            var renderer = new Win32OpenGLRenderer();

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

            while (true)
            {
                window.MainLoop(() =>
                {
                    renderer.Clear(Color.FrameBg);
                    Win32OpenGLRenderer.DrawMesh(renderer.shapeMaterial, primitiveRenderer.ShapeMesh,
                                                 (int)window.ClientSize.Width, (int)window.ClientSize.Height);
                    renderer.SwapBuffers();
                });
                if (Input.Keyboard.Instance.KeyDown(Key.Escape))
                {
                    break;
                }
            }
        }
Ejemplo n.º 6
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");
            }
Ejemplo n.º 7
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");
                }
            }
Ejemplo n.º 8
0
            public void ShowHideANode()
            {
                Application.IsRunningInUnitTest = true;
                Application.InitSysDependencies();

                var primitiveRenderer = new BuiltinPrimitiveRenderer();
                var nodes             = new List <Node>();
                {
                    Node node = new Node(1);
                    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();

                    node.Primitive       = primitive;
                    node.IsFill          = true;
                    node.Brush           = new Brush();
                    node.Brush.FillColor = Color.Red;

                    node.Draw(primitiveRenderer);
                }
                var theNode = nodes[0];

                var window = new Win32Window();

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

                var renderer = new Win32OpenGLRenderer();

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

                window.Show();

                while (true)
                {
                    Time.OnFrameBegin();
                    Keyboard.Instance.OnFrameBegin();
                    window.MainLoop(() =>
                    {
                        if (Keyboard.Instance.KeyPressed(Key.Space))
                        {
                            theNode.ActiveSelf = !theNode.ActiveSelf;
                            Log.Msg("Key.Space Pressed. theNode becomes " + (theNode.ActiveSelf ? "visible" : "invisible"));
                        }

                        if (Keyboard.Instance.KeyDown(Key.Escape))
                        {
                            Application.Quit();
                        }

                        //update nodes
                        foreach (var node in nodes)
                        {
                            if (node.ActiveInTree)
                            {
                                node.Draw(primitiveRenderer);
                            }
                        }

                        //rebuild mesh buffer
                        MeshBuffer.Clear();
                        MeshBuffer.Init();
                        MeshBuffer.Build();

                        //draw mesh buffer to screen
                        renderer.Clear(Color.FrameBg);
                        renderer.DrawMeshes((int)window.ClientSize.Width, (int)window.ClientSize.Height);
                        renderer.SwapBuffers();
                    });

                    if (Application.RequestQuit)
                    {
                        break;
                    }

                    Keyboard.Instance.OnFrameEnd();
                    Time.OnFrameEnd();
                }
            }
Ejemplo n.º 9
0
            public void UpdateANode()
            {
                Application.IsRunningInUnitTest = true;
                Application.InitSysDependencies();

                var primitiveRenderer = new BuiltinPrimitiveRenderer();

                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();

                node.Primitive = primitive;
                node.IsFill    = true;
                node.Brush     = new Brush();

                node.Draw(primitiveRenderer);

                var window = new Win32Window();

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

                var renderer = new Win32OpenGLRenderer();

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

                window.Show();

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

                    window.MainLoop(() =>
                    {
                        if (Keyboard.Instance.KeyDown(Key.D1))
                        {
                            node.Brush.FillColor = Color.Red;
                        }
                        if (Keyboard.Instance.KeyDown(Key.D2))
                        {
                            node.Brush.FillColor = Color.Green;
                        }
                        if (Keyboard.Instance.KeyDown(Key.D3))
                        {
                            node.Brush.FillColor = Color.Blue;
                        }

                        if (Keyboard.Instance.KeyDown(Key.Escape))
                        {
                            Application.Quit();
                        }

                        //update nodes
                        if (node.ActiveInTree)//this is actually always true
                        {
                            node.Draw(primitiveRenderer);
                        }

                        //rebuild mesh buffer
                        MeshBuffer.Clear();
                        MeshBuffer.Init();
                        MeshBuffer.Build();

                        //draw mesh buffer to screen
                        renderer.Clear(Color.FrameBg);
                        renderer.DrawMeshes((int)window.ClientSize.Width, (int)window.ClientSize.Height);
                        renderer.SwapBuffers();
                    });

                    if (Application.RequestQuit)
                    {
                        break;
                    }

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