public void DrawABoxModelWithImageContent() { Node node = new Node(1, "imageNode", new Rect(10, 10, 300, 200)); StyleRuleSetBuilder ruleSetBuilder = new StyleRuleSetBuilder(node.RuleSet); ruleSetBuilder .Border((5, 10, 5, 10)) .BorderColor(Color.HotPink) .Padding((4, 2, 4, 2)); node.UseBoxModel = true; var texture = new FakeTexture(); texture.LoadImage(@"assets\images\logo.png"); void Populate(DrawingContext dc, ImGui.OSAbstraction.Graphics.ITexture t, StyleRuleSet rule, Rect r) { dc.DrawBoxModel(t, rule, r); } var context = node.RenderOpen(); Populate(context, texture, node.RuleSet, node.Rect); context.Close(); //write records into ContentChecker var checker = new ContentChecker(); Populate(checker, texture, node.RuleSet, node.Rect); //read records from visual to checker and compare checker.StartCheck(); node.RenderContent(new RenderContext(checker, null)); }
public void DrawABoxModelWithTextContent() { void Populate(DrawingContext dc, string t, StyleRuleSet rule, Rect r) { dc.DrawBoxModel(t, rule, r); } var node = new Node(1, new Rect(10, 10, 300, 60)); 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)); const string text = "啊rABC"; var context = node.RenderOpen(); Populate(context, text, styleRuleSet, node.Rect); context.Close(); //write records into ContentChecker var checker = new ContentChecker(); Populate(checker, text, styleRuleSet, node.Rect); //read records from visual to checker and compare checker.StartCheck(); node.RenderContent(new RenderContext(checker, null)); }
public void GetRectWithPadding() { var group = new Node(1); group.AttachLayoutGroup(true); group.RuleSet.ApplyOptions(GUILayout.Width(800).Height(600)); var node = new Node(2); var contentSize = new Size(200, 300); node.AttachLayoutEntry(contentSize); var builder = new StyleRuleSetBuilder(node.RuleSet); builder.Padding((1, 2, 3, 4)); group.AppendChild(node); group.Layout(); var rect = node.Rect; Assert.Equal(0, rect.X); Assert.Equal(0, rect.Y); Assert.Equal(200 + 2 + 4, rect.Width); Assert.Equal(300 + 1 + 3, rect.Height); }
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"); }
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"); }
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 DrawBoxModelImage() { Node node = new Node(1, "imageNode", new Rect(10, 10, 300, 200)); StyleRuleSetBuilder ruleSetBuilder = new StyleRuleSetBuilder(node.RuleSet); ruleSetBuilder .Border((5, 10, 5, 10)) .BorderColor(Color.HotPink) .Padding((4, 2, 4, 2)); node.UseBoxModel = true; node.Primitive = new ImagePrimitive(@"assets\images\logo.png"); Util.DrawNodeToImage(out var imageRawBytes, node, 400, 300); Util.CheckExpectedImage(imageRawBytes, 400, 300, @"Rendering\images\NodeFacts.Draw.DrawBoxModelImage.png"); }
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 }
public void DrawBoxModelText() { Node node = new Node(1, "textNode", new Rect(10, 10, 90, 40)); StyleRuleSetBuilder ruleSetBuilder = new StyleRuleSetBuilder(node.RuleSet); ruleSetBuilder .Border((5, 10, 5, 10)) .BorderColor(Color.HotPink) .BackgroundColor(Color.Azure) .Padding((4, 2, 4, 2)); node.UseBoxModel = true; var primitive = new TextPrimitive("AAA"); node.Primitive = primitive; Util.DrawNodeToImage(out var imageRawBytes, node, 120, 60); Util.CheckExpectedImage(imageRawBytes, 120, 60, @"Rendering\images\NodeFacts.Draw.DrawBoxModelText.png"); }
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); }
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 }
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 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 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.Geometry = new ImageGeometry(@"assets\images\logo.png"); var title = new Node(3, "#title"); title.AttachLayoutEntry(Size.Zero); title.RuleSet.ApplyOptions(GUILayout.Height(20)); title.UseBoxModel = false; title.Geometry = new TextGeometry("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; PathGeometry path = new PathGeometry(); path.PathRect(new Rect(0, 0, 20, 20)); closeButton.Geometry = 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() { //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; using (var dc = icon.RenderOpen()) { dc.DrawImage(@"assets\images\logo.png", icon.Rect); } var title = new Node(3, "#title"); title.AttachLayoutEntry(Size.Zero); title.RuleSet.ApplyOptions(GUILayout.Height(20)); title.UseBoxModel = false; using (var dc = title.RenderOpen()) { var glyphRun = new GlyphRun(title.Rect.Location, "The Window 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.RuleSet.ApplyOptions(GUILayout.Width(20).Height(20)); closeButton.UseBoxModel = false; using (var dc = closeButton.RenderOpen()) { dc.DrawRectangle(new Brush(Color.Black), null, new Rect(0, 0, 20, 20)); } 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(); } }