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");
            }
Beispiel #2
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");
                }
            }
Beispiel #3
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");
            }
Beispiel #4
0
        public Window(string name, Point position, Size size, WindowFlags Flags)
        {
            Form          form = Form.current;
            GUIContext    g    = form.uiContext;
            WindowManager w    = g.WindowManager;

            this.ID       = name.GetHashCode();
            this.Name     = name;
            this.Active   = this.WasActive = false;
            this.Position = position;
            this.FullSize = size;

            this.Flags = Flags;

            this.AbsoluteVisualList = new List <Visual>();
            this.RenderTree         = new RenderTree(this.ID, position, size);

            this.IDStack.Push(this.ID);
            this.MoveID = this.GetID("#MOVE");

            #region Window nodes

            {
                var windowContainer = new Node(this.GetID("window"), "window");
                this.WindowContainer = windowContainer;

                var style = windowContainer.RuleSet;
                style.BackgroundColor = Color.White;
                style.Border          = (1, 1, 1, 1);
                style.BorderColor     = (Color.Black, Color.Black, Color.Black, Color.Black);
                style.Set(GUIStyleName.BorderTopColor, Color.Blue, GUIState.Active);
                style.Set(GUIStyleName.BorderRightColor, Color.Blue, GUIState.Active);
                style.Set(GUIStyleName.BorderBottomColor, Color.Blue, GUIState.Active);
                style.Set(GUIStyleName.BorderLeftColor, Color.Blue, GUIState.Active);
                style.Set(GUIStyleName.BorderTopColor, Color.Gray, GUIState.Hover);
                style.Set(GUIStyleName.BorderRightColor, Color.Gray, GUIState.Hover);
                style.Set(GUIStyleName.BorderBottomColor, Color.Gray, GUIState.Hover);
                style.Set(GUIStyleName.BorderLeftColor, Color.Gray, GUIState.Hover);
                style.Set(GUIStyleName.BorderTop, 1.0);
                style.Set(GUIStyleName.BorderRight, 1.0);
                style.Set(GUIStyleName.BorderBottom, 1.0);
                style.Set(GUIStyleName.BorderLeft, 1.0);
                style.Set(GUIStyleName.PaddingTop, 5.0);
                style.Set(GUIStyleName.PaddingRight, 10.0);
                style.Set(GUIStyleName.PaddingBottom, 5.0);
                style.Set(GUIStyleName.PaddingLeft, 10.0);
                style.Set(GUIStyleName.WindowBorderColor, Color.Rgb(255, 0, 0), GUIState.Normal);
                style.Set(GUIStyleName.WindowBorderColor, Color.Rgb(0, 0, 255), GUIState.Active);
                style.Set(GUIStyleName.WindowShadowColor, Color.Argb(100, 227, 227, 227));
                style.Set(GUIStyleName.WindowShadowWidth, 15.0);
                style.Set(GUIStyleName.BackgroundColor, Color.White);
                style.Set(GUIStyleName.ResizeGripColor, Color.Argb(75, 102, 102, 102));
                style.Set(GUIStyleName.ResizeGripColor, Color.Argb(150, 102, 102, 102), GUIState.Hover);
                style.Set(GUIStyleName.ResizeGripColor, Color.Argb(225, 102, 102, 102), GUIState.Active);
                style.Set(GUIStyleName.WindowRounding, 20.0);
                style.Set(GUIStyleName.ScrollBarWidth, CurrentOS.IsDesktopPlatform ? 10.0 : 20.0);
                style.Set(GUIStyleName.ScrollBarBackgroundColor, Color.Rgb(240));
                style.Set(GUIStyleName.ScrollBarButtonColor, Color.Rgb(205), GUIState.Normal);
                style.Set(GUIStyleName.ScrollBarButtonColor, Color.Rgb(166), GUIState.Hover);
                style.Set(GUIStyleName.ScrollBarButtonColor, Color.Rgb(96), GUIState.Active);

                windowContainer.AttachLayoutGroup(true);
                windowContainer.UseBoxModel = true;
                var windowStyleOptions = GUILayout.Width(this.FullSize.Width).Height(
                    this.Collapsed ? this.CollapsedHeight : this.FullSize.Height
                    );
                windowContainer.RuleSet.ApplyOptions(windowStyleOptions);

                this.RenderTree.Root.AppendChild(windowContainer);
            }

            //title bar
            {
                var titleBarContainer = new Node(this.GetID("titleBar"), "title bar");
                this.titleBarNode = titleBarContainer;
                titleBarContainer.AttachLayoutGroup(false);
                titleBarContainer.RuleSet.ApplyOptions(GUILayout.ExpandWidth(true).Height(this.TitleBarHeight));
                titleBarContainer.UseBoxModel = true;
                StyleRuleSetBuilder b = new StyleRuleSetBuilder(titleBarContainer);
                b.Padding((top: 8, right: 8, bottom: 8, left: 8))
                .FontColor(Color.Black)
                .FontSize(12)
                .BackgroundColor(Color.White)
                .AlignmentVertical(Alignment.Center)
                .AlignmentHorizontal(Alignment.Start);

                var icon = new Node(this.GetID("icon"), "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(this.GetID("title"), "title");
                var contentSize = title.RuleSet.CalcSize(this.Name, GUIState.Normal);
                title.AttachLayoutEntry(contentSize);
                title.RuleSet.ApplyOptions(GUILayout.Height(20));
                title.UseBoxModel      = false;
                title.Primitive        = new TextPrimitive(this.Name);
                this.titleBarTitleNode = title;

                var closeButton = new Node(this.GetID("close button"), "close button");
                closeButton.AttachLayoutEntry(new Size(20, 20));
                closeButton.RuleSet.ApplyOptions(GUILayout.Width(20).Height(20));
                closeButton.UseBoxModel = false;
                PathPrimitive path = new PathPrimitive();
                path.PathRect(new Rect(0, 0, 20, 20));
                closeButton.Primitive = path;

                titleBarContainer.AppendChild(icon);
                titleBarContainer.AppendChild(title);
                //titleBarContainer.AppendChild(closeButton);
                this.WindowContainer.AppendChild(titleBarContainer);
            }

            //client area
            {
                var node = new Node(this.GetID("client area"), "client area");
                node.AttachLayoutGroup(true);
                node.RuleSet.ApplyOptions(GUILayout.ExpandWidth(true).ExpandHeight(true));
                node.UseBoxModel          = true;
                node.RuleSet.OutlineWidth = 1;
                node.RuleSet.OutlineColor = Color.Red;
                node.RuleSet.refNode      = node;
                this.ClientAreaNode       = node;
                this.WindowContainer.AppendChild(node);
            }

            //resize grip (lasy-initialized)

            this.ShowWindowTitleBar(true);
            this.ShowWindowClientArea(!this.Collapsed);
            #endregion
        }
Beispiel #5
0
            public void DrawAWindow()
            {
                //window
                var windowContainer = new Node("#window");

                windowContainer.AttachLayoutGroup(true);
                windowContainer.RuleSet.ApplyOptions(GUILayout.Width(400));
                windowContainer.UseBoxModel             = true;
                windowContainer.RuleSet.Border          = (1, 1, 1, 1);
                windowContainer.RuleSet.BackgroundColor = Color.White;

                //title bar
                {
                    var titleBarContainer = new Node(1, "#titleBar");
                    titleBarContainer.AttachLayoutGroup(false);
                    titleBarContainer.RuleSet.ApplyOptions(GUILayout.ExpandWidth(true).Height(40));
                    titleBarContainer.UseBoxModel = true;
                    StyleRuleSetBuilder b = new StyleRuleSetBuilder(titleBarContainer);
                    b.Padding((top: 8, right: 8, bottom: 8, left: 8))
                    .FontColor(Color.Black)
                    .FontSize(12)
                    .BackgroundColor(Color.White)
                    .AlignmentVertical(Alignment.Center)
                    .AlignmentHorizontal(Alignment.Start);

                    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");
                    title.AttachLayoutEntry(Size.Zero);
                    title.RuleSet.ApplyOptions(GUILayout.Height(20));
                    title.UseBoxModel = false;
                    title.Primitive   = new TextPrimitive("The Window Title");

                    var closeButton = new Node(4, "#close button");
                    closeButton.AttachLayoutEntry(new Size(20, 20));
                    closeButton.RuleSet.ApplyOptions(GUILayout.Width(20).Height(20));
                    closeButton.UseBoxModel = false;
                    PathPrimitive path = new PathPrimitive();
                    path.PathRect(new Rect(0, 0, 20, 20));
                    closeButton.Primitive = path;

                    titleBarContainer.AppendChild(icon);
                    titleBarContainer.AppendChild(title);
                    titleBarContainer.AppendChild(closeButton);
                    windowContainer.AppendChild(titleBarContainer);
                }

                //client area background
                {
                    var clientArea = new Node("#ClientArea_Background");
                    clientArea.AttachLayoutGroup(true);
                    clientArea.RuleSet.ApplyOptions(GUILayout.ExpandWidth(true).Height(200));
                    windowContainer.AppendChild(clientArea);
                }

                windowContainer.Layout();

                CheckExpectedImage(windowContainer, @"Rendering\images\NodeFacts.Container.DrawAWindow.png");
            }
            public void DrawAWindow()
            {
                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(800, 600), 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);
                }

                //window
                var windowContainer = new Node("#window");

                windowContainer.AttachLayoutGroup(true);
                windowContainer.RuleSet.ApplyOptions(GUILayout.Width(400));
                windowContainer.UseBoxModel             = true;
                windowContainer.RuleSet.Border          = (1, 1, 1, 1);
                windowContainer.RuleSet.BackgroundColor = Color.White;

                //title bar
                {
                    var titleBarContainer = new Node(1, "#titleBar");
                    titleBarContainer.AttachLayoutGroup(false);
                    titleBarContainer.RuleSet.ApplyOptions(GUILayout.ExpandWidth(true).Height(40));
                    titleBarContainer.UseBoxModel = true;
                    StyleRuleSetBuilder b = new StyleRuleSetBuilder(titleBarContainer);
                    b.Padding((top: 8, right: 8, bottom: 8, left: 8))
                    .FontColor(Color.Black)
                    .FontSize(12)
                    .BackgroundColor(Color.White)
                    .AlignmentVertical(Alignment.Center)
                    .AlignmentHorizontal(Alignment.Start);

                    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");
                    title.AttachLayoutEntry(Size.Zero);
                    title.RuleSet.ApplyOptions(GUILayout.Height(20));
                    title.UseBoxModel = false;
                    title.Primitive   = new TextPrimitive("The Window Title");

                    var closeButton = new Node(4, "#close button");
                    closeButton.AttachLayoutEntry(new Size(20, 20));
                    closeButton.RuleSet.ApplyOptions(GUILayout.Width(20).Height(20));
                    closeButton.UseBoxModel = false;
                    PathPrimitive path = new PathPrimitive();
                    path.PathRect(new Rect(0, 0, 20, 20));
                    closeButton.Primitive = path;

                    titleBarContainer.AppendChild(icon);
                    titleBarContainer.AppendChild(title);
                    titleBarContainer.AppendChild(closeButton);
                    windowContainer.AppendChild(titleBarContainer);
                }

                Node clientArea;

                //client area background
                {
                    clientArea = new Node("#ClientArea_Background");
                    clientArea.AttachLayoutGroup(true);
                    clientArea.RuleSet.ApplyOptions(GUILayout.ExpandWidth(true).Height(200));
                    windowContainer.AppendChild(clientArea);
                }

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

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

                        if (Keyboard.Instance.KeyPressed(Key.Space))
                        {
                            clientArea.ActiveSelf = !clientArea.ActiveSelf;
                        }

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