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 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(); } }
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(); } }
public void DrawTextMesh(TextMesh textMesh) { Win32OpenGLRenderer.DrawTextMesh(this.Renderer.glyphMaterial, textMesh, viewportWidth, viewportHeight); }
public void DrawImageMesh(Mesh imageMesh) { Win32OpenGLRenderer.DrawMesh(this.Renderer.imageMaterial, imageMesh, viewportWidth, viewportHeight); }
public void DrawShapeMesh(Mesh shapeMesh) { Win32OpenGLRenderer.DrawMesh(this.Renderer.shapeMaterial, shapeMesh, viewportWidth, viewportHeight); }