internal static void DrawNodesToImage(out byte[] imageRawBytes, IList <Node> nodes, int width, int height) { MeshBuffer meshBuffer = new MeshBuffer(); MeshList meshList = new MeshList(); IPrimitiveRenderer primitiveRenderer = new BuiltinPrimitiveRenderer(); using (var context = new RenderContextForTest(width, height)) { //This must be called after the context is created, for creating textures when the OpenGL context is built. foreach (var node in nodes) { node.Draw(primitiveRenderer, meshList); } //rebuild mesh buffer meshBuffer.Clear(); meshBuffer.Init(); meshBuffer.Build(meshList); //draw mesh buffer to screen context.Clear(); context.DrawMeshes(meshBuffer); imageRawBytes = context.GetRenderedRawBytes(); } }
internal static void CheckRectangle(Brush brush, Pen pen, Rect rectangle, int width, int height, [CallerMemberName] string methodName = "unknown") { Application.EnableMSAA = false; MeshBuffer meshBuffer = new MeshBuffer(); MeshList meshList = new MeshList(); BuiltinGeometryRenderer renderer = new BuiltinGeometryRenderer(); byte[] bytes; using (var context = new RenderContextForTest(width, height)) { renderer.OnBeforeRead(); renderer.DrawRectangle(brush, pen, rectangle);//This must be called after the RenderContextForTest is created, for uploading textures to GPU via OpenGL. renderer.OnAfterRead(meshList); //rebuild mesh buffer meshBuffer.Clear(); meshBuffer.Init(); meshBuffer.Append(meshList); //draw mesh buffer to screen context.Clear(); context.DrawMeshes(meshBuffer); bytes = context.GetRenderedRawBytes(); } Util.CheckExpectedImage(bytes, width, height, $"{RootDir}{nameof(DrawRectangle)}\\{methodName}.png"); }
internal static void DrawNodeToImage_NewPipeline(out byte[] imageRawBytes, Node node, int width, int height) { Application.EnableMSAA = false; MeshBuffer meshBuffer = new MeshBuffer(); MeshList meshList = new MeshList(); BuiltinGeometryRenderer geometryRenderer = new BuiltinGeometryRenderer(); using (var context = new RenderContextForTest(width, height)) { RenderContext renderContext = new RenderContext(geometryRenderer, meshList); //This must be called after the RenderContextForTest is created, for uploading textures to GPU via OpenGL. node.Render(renderContext); //rebuild mesh buffer meshBuffer.Clear(); meshBuffer.Init(); meshBuffer.Build(meshList); //draw mesh buffer to screen context.Clear(); context.DrawMeshes(meshBuffer); imageRawBytes = context.GetRenderedRawBytes(); } }
public static void CaptureMesh(AbcAPI.aeObject abc, Mesh mesh, Cloth cloth, MeshBuffer dst_buf) { dst_buf.Clear(); dst_buf.indices.LockList(ls => mesh.GetTriangles(ls, 0)); dst_buf.uvs.LockList(ls => mesh.GetUVs(0, ls)); if (cloth == null) { dst_buf.vertices.LockList(ls => mesh.GetVertices(ls)); dst_buf.normals.LockList(ls => mesh.GetNormals(ls)); } else { dst_buf.vertices.Assign(cloth.vertices); dst_buf.normals.Assign(cloth.normals); } var data = new AbcAPI.aePolyMeshData(); data.indices = dst_buf.indices; data.positions = dst_buf.vertices; data.normals = dst_buf.normals; data.uvs = dst_buf.uvs; data.positionCount = dst_buf.vertices.Count; data.indexCount = dst_buf.indices.Count; AbcAPI.aePolyMeshWriteSample(abc, ref data); }
public override void usdiOnUnload() { base.usdiOnUnload(); if (m_asyncRead != null) { m_asyncRead.Wait(); m_asyncRead = null; } m_mesh = default(usdi.Mesh); m_buf.Clear(); }
internal static void DrawNodeTreeToImage(out byte[] imageRawBytes, Node root, int width, int height, Rect clipRect) { if (root == null) { throw new ArgumentNullException(nameof(root)); } MeshBuffer meshBuffer = new MeshBuffer(); MeshList meshList = new MeshList(); BuiltinGeometryRenderer geometryRenderer = new BuiltinGeometryRenderer(); using (var context = new RenderContextForTest(width, height)) { if (root is Node rootNode) { using (var dc = rootNode.RenderOpen()) { dc.DrawBoxModel(rootNode.RuleSet, rootNode.Rect); } } root.Foreach(visual => { if (!(visual is Node node)) { return(true); } using (var dc = node.RenderOpen()) { dc.DrawBoxModel(node.RuleSet, node.Rect); } return(true); }); //This must be called after the context is created, for uploading textures to GPU via OpenGL. root.Render(new RenderContext(geometryRenderer, meshList)); //rebuild mesh buffer meshBuffer.Clear(); meshBuffer.Init(); meshBuffer.Build(meshList); //draw mesh buffer to screen context.Clear(); context.DrawMeshes(meshBuffer); imageRawBytes = context.GetRenderedRawBytes(); } }
public void CreateMesh(float[] field) { mb.Clear(); float[] cube = new float[8]; for (int x = 0; x < size; x++) { for (int y = 0; y < size; y++) { for (int z = 0; z < size; z++) { FillCube(x, y, z, field, cube); MarchCube(x, y, z, cube); } } } }
internal void Render() { GUIContext g = this.uiContext; WindowManager w = g.WindowManager; Debug.Assert(g.Initialized); // Forgot to call NewFrame() if (g.FrameCountEnded != g.FrameCount) { EndFrame(); } g.FrameCountRendered = g.FrameCount; var openGLRenderer = (Win32OpenGLRenderer)renderer; //FIXME TEMP openGLRenderer.Clear(this.BackgroundColor); foreach (var window in w.Windows) { if (window.Active) { window.RenderTree.Foreach(node => { if (!node.ActiveInTree) { return(false); } node.Draw(this.primitiveRenderer); return(true); }); //rebuild mesh buffer MeshBuffer.Clear(); MeshBuffer.Init(); MeshBuffer.Build(); //draw mesh buffer openGLRenderer.DrawMeshes((int)this.ClientSize.Width, (int)this.ClientSize.Height); } } openGLRenderer.SwapBuffers(); }
internal static void DrawNodeTreeToImage(out byte[] imageRawBytes, Node root, int width, int height, Rect clipRect) { MeshBuffer meshBuffer = new MeshBuffer(); MeshList meshList = new MeshList(); var primitiveRenderer = new BuiltinPrimitiveRenderer(); using (var context = new RenderContextForTest(width, height)) { //This must be called after the context is created, for uploading textures to GPU via OpenGL. root.Foreach(n => primitiveRenderer.Draw(n, clipRect, meshList)); //rebuild mesh buffer meshBuffer.Clear(); meshBuffer.Init(); meshBuffer.Build(meshList); //draw mesh buffer to screen context.Clear(); context.DrawMeshes(meshBuffer); imageRawBytes = context.GetRenderedRawBytes(); } }
internal static void DrawDrawingVisualToImage(out byte[] imageRawBytes, int width, int height, DrawingVisual drawingVisual) { //convert geometries inside the drawingVisual's content to meshes stored in a MeshList with a BuiltinGeometryRenderer MeshList meshList = new MeshList(); using BuiltinGeometryRenderer geometryRenderer = new BuiltinGeometryRenderer(); RenderContext renderContext = new RenderContext(geometryRenderer, meshList); drawingVisual.RenderContent(renderContext); //merge meshes in the MeshList to a MeshBuffer MeshBuffer meshBuffer = new MeshBuffer(); meshBuffer.Clear(); meshBuffer.Init(); meshBuffer.Build(meshList); //created a mesh IRenderer Application.Init(); var window = Application.PlatformContext.CreateWindow(Point.Zero, new Size(100, 100), WindowTypes.Hidden); var renderer = Application.PlatformContext.CreateRenderer() as Win32OpenGLRenderer;//TEMP HACK Debug.Assert(renderer != null, nameof(renderer) + " != null"); renderer.Init(window.Pointer, window.ClientSize); //clear the canvas and draw mesh in the MeshBuffer with the mesh renderer renderer.Clear(Color.White); renderer.StartDrawMeshToImage(width, height); imageRawBytes = renderer.DrawMeshToImage(width, height, meshBuffer.ShapeMesh, OpenGLMaterial.shapeMaterial); renderer.EndDrawMeshToImage(); //clear native resources: window and IRenderer renderer.ShutDown(); window.Close(); }
public void Capture(Mesh mesh, Cloth cloth, MeshBuffer mbuf, AlembicRecorderSettings settings) { if (mesh == null || cloth == null) { mbuf.Clear(); return; } if (remap.Count != mesh.vertexCount) { GenerateRemapIndices(mesh, mbuf); } // capture cloth points and normals vertices.Assign(cloth.vertices); if (numRemappedVertices != vertices.Count) { Debug.LogWarning("numRemappedVertices != vertices.Count"); return; } if (settings.MeshNormals) { normals.Assign(cloth.normals); } else { normals.Clear(); } // apply root bone transform if (rootBone != null) { var mat = Matrix4x4.TRS(rootBone.localPosition, rootBone.localRotation, Vector3.one); NativeMethods.aeApplyMatrixP(vertices, vertices.Count, ref mat); NativeMethods.aeApplyMatrixV(normals, normals.Count, ref mat); } // remap vertices and normals for (int vi = 0; vi < remap.Count; ++vi) { mbuf.points[vi] = vertices[remap[vi]]; } if (normals.Count > 0) { mbuf.normals.ResizeDiscard(remap.Count); for (int vi = 0; vi < remap.Count; ++vi) { mbuf.normals[vi] = normals[remap[vi]]; } } // capture other components if (settings.MeshUV0) { mbuf.uv0.LockList(ls => mesh.GetUVs(0, ls)); } else { mbuf.uv0.Clear(); } if (settings.MeshUV1) { mbuf.uv1.LockList(ls => mesh.GetUVs(1, ls)); } else { mbuf.uv1.Clear(); } if (settings.MeshColors) { mbuf.colors.LockList(ls => mesh.GetColors(ls)); } else { mbuf.colors.Clear(); } }
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() { 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 DrawOneTextNodeAtPosition() { Application.IsRunningInUnitTest = true; Application.InitSysDependencies(); var primitiveRenderer = new BuiltinPrimitiveRenderer(); Node node = new Node(1); var primitive = new TextPrimitive(); primitive.Text = "AAA"; node.Primitive = primitive; node.Draw(primitiveRenderer); node.Rect.X = 100; node.Rect.Y = 30; 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.Escape)) { Application.Quit(); } //update the node 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(); } }
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(); } }
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(); } }
public void ShowAnimateNode() { //FIXME make this test automatable Application.IsRunningInUnitTest = true; Application.InitSysDependencies(); MeshBuffer meshBuffer = new MeshBuffer(); MeshList meshList = new MeshList(); var primitiveRenderer = new BuiltinPrimitiveRenderer(); Node node = new Node(1); node.Primitive = new PathPrimitive(); 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(); var A = new Point(200, 200); var B = new Point(600, 200); var C = new Point(400, 400); while (true) { Time.OnFrameBegin(); Keyboard.Instance.OnFrameBegin(); window.MainLoop(() => { if (Keyboard.Instance.KeyDown(Key.Escape)) { Application.Quit(); } var normal = (Time.time % 1000) / 1000f * 2 - 1; var rad = normal * Math.PI; var A_ = A + 50 * new Vector(Math.Cos(rad) - Math.Sin(rad), Math.Sin(rad) + Math.Cos(rad)); rad += Math.PI * 0.333; var B_ = B + 30 * new Vector(Math.Cos(rad) - Math.Sin(rad), Math.Sin(rad) + Math.Cos(rad)); rad += Math.PI * 0.666; var C_ = C + 70 * new Vector(Math.Cos(rad) - Math.Sin(rad), Math.Sin(rad) + Math.Cos(rad)); var d = node.Primitive as PathPrimitive; d.PathClear(); d.PathMoveTo(A_); d.PathLineTo(B_); d.PathLineTo(C_); d.PathStroke(2, Color.Blue); //update nodes if (node.ActiveInTree)//this is actually always true { node.Draw(primitiveRenderer, meshList); } //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(); } }
private void BuildMesh(MeshBuffer buffer) { MeshFilter meshFilter = GetComponent<MeshFilter>(); Mesh mesh = meshFilter.mesh; if (mesh == null) { mesh = new Mesh(); mesh.MarkDynamic(); } else mesh.Clear(); //get the arrays we have just created and assign them to the new mesh mesh.vertices = buffer.GetVertices(); //mesh.tangents = buffer.GetTangents(); mesh.normals = buffer.GetNormals(); mesh.triangles = buffer.GetTriangles(); //mesh.colors32 = buffer.GetColors32(); mesh.uv = buffer.GetUVs(); //clear our mesh buffer buffer.Clear(); meshFilter.mesh = mesh; }
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(); } }