Example #1
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;
                using (var dc = icon.RenderOpen())
                {
                    dc.DrawImage(@"assets\images\logo.png", icon.Rect);
                }

                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;
                using (var dc = title.RenderOpen())
                {
                    var glyphRun = new GlyphRun(title.Rect.Location, "title", title.RuleSet.FontFamily,
                                                title.RuleSet.FontSize);
                    dc.DrawGlyphRun(new Brush(title.RuleSet.FontColor), glyphRun);
                }

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

                closeButton.AttachLayoutEntry(new Size(20, 20));
                closeButton.UseBoxModel = false;
                using (var dc = closeButton.RenderOpen())
                {
                    dc.DrawRectangle(new Brush(Color.Black), null, new Rect(0, 0, 20, 20));
                }

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

                container.Layout();

                CheckExpectedImage(container, @"Rendering\images\NodeFacts.Container.DrawAndLayoutContainerWithElements.png");
            }
Example #2
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.Geometry    = new ImageGeometry(@"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.Geometry    = new TextGeometry("title");

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

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

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

                closeButton.Geometry = path;

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

                container.Layout();

                CheckExpectedImage(container, @"Rendering\images\NodeFacts.Container.DrawAndLayoutContainerWithElements.png");
            }
Example #3
0
            public void DrawAndLayoutEmptyContainer()
            {
                Node node = new Node(1, "container");

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

                b.Border(1)
                .BorderColor(Color.Black)
                .Border((top: 1, right: 2, bottom: 1, left: 2));
                node.Layout();

                CheckExpectedImage(node, @"Rendering\images\NodeFacts.Container.DrawAndLayoutEmptyContainer.png");
            }
            public void DrawAndLayoutEmptyContainer()
            {
                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 node = null;

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

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

                        if (node == null)
                        {
                            node = new Node(1, "container");
                            node.AttachLayoutGroup(true);
                            node.RuleSet.ApplyOptions(GUILayout.Width(300).Height(40));
                            node.UseBoxModel      = true;
                            StyleRuleSetBuilder b = new StyleRuleSetBuilder(node);
                            b.Border(1)
                            .BorderColor(Color.Black)
                            .Padding((top: 1, right: 2, bottom: 1, left: 2))
                            .BackgroundColor(Color.Silver);
                        }

                        {
                            DrawNode(node, meshList);
                            node.Foreach(n => DrawNode(n, meshList));
                            node.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();
                }
            }
            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();
                }
            }