public void ShowWindowWithChildWindow() { Application.InitSysDependencies(); Win32Window windowA = new Win32Window(); windowA.Init((100, 100), (300, 400), WindowTypes.Regular); windowA.Show(); Win32Window windowB = new Win32Window(windowA); windowB.Init((10, 10), (100, 100), WindowTypes.ClientAreaOnly); windowB.Show(); Win32OpenGLRenderer renderer = new Win32OpenGLRenderer(windowA); var meshA = new QuadMesh(new Rect(150, 150, 50, 50), Color.Blue); var meshB = new QuadMesh(new Rect(10, 10, 50, 50), Color.DarkBlue); while (!windowA.Closed) { windowA.MainLoop(() => { renderer.SetRenderingWindow(windowA); renderer.Clear(Color.Rgb(200, 100, 100)); Win32OpenGLRenderer.DrawMesh(OpenGLMaterial.shapeMaterial, meshA, (int)windowA.ClientSize.Width, (int)windowA.ClientSize.Height); renderer.SwapBuffers(); renderer.SetRenderingWindow(windowB); renderer.Clear(Color.Rgb(100, 200, 100)); Win32OpenGLRenderer.DrawMesh(OpenGLMaterial.shapeMaterial, meshB, (int)windowB.ClientSize.Width, (int)windowB.ClientSize.Height); renderer.SwapBuffers(); }); } }
public void StrokeAPath() { 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(); var primitiveRenderer = new BuiltinPrimitiveRenderer(); var brush = new Brush(); brush.LineColor = Color.Red; var mesh = new Mesh(); mesh.CommandBuffer.Add(DrawCommand.Default); primitiveRenderer.SetShapeMesh(mesh); primitiveRenderer.Stroke(primitive, brush, new StrokeStyle()); 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); while (true) { window.MainLoop(() => { renderer.Clear(Color.FrameBg); Win32OpenGLRenderer.DrawMesh(renderer.shapeMaterial, primitiveRenderer.ShapeMesh, (int)window.ClientSize.Width, (int)window.ClientSize.Height); renderer.SwapBuffers(); }); if (Input.Keyboard.Instance.KeyDown(Key.Escape)) { break; } } }
public void DrawImage() { 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); var image = new Image(@"assets\images\logo.png"); var primitive = new ImagePrimitive(); primitive.Image = image; primitive.Offset = new Vector(10, 10); var primitiveRenderer = new BuiltinPrimitiveRenderer(); var brush = new Brush(); brush.FillColor = Color.White; var mesh = new Mesh(); mesh.CommandBuffer.Add(DrawCommand.Default); primitiveRenderer.SetImageMesh(mesh); primitiveRenderer.DrawImage(primitive, brush); while (true) { window.MainLoop(() => { renderer.Clear(Color.FrameBg); Win32OpenGLRenderer.DrawMesh(renderer.imageMaterial, primitiveRenderer.ImageMesh, (int)window.ClientSize.Width, (int)window.ClientSize.Height); renderer.SwapBuffers(); }); if (Input.Keyboard.Instance.KeyDown(Key.Escape)) { break; } } }
public void DrawText() { TextPrimitive primitive = new TextPrimitive(); primitive.Text = "Hello你好こんにちは"; var style = GUIStyle.Default; BuiltinPrimitiveRenderer primitiveRenderer = new BuiltinPrimitiveRenderer(); var textMesh = new TextMesh(); primitiveRenderer.SetTextMesh(textMesh); primitiveRenderer.DrawText(primitive, new Rect(10, 10, 500, 40), style.FontFamily, style.FontSize, style.FontColor, style.FontStyle, style.FontWeight); //render text var window = new Win32Window(); window.Init(new Point(100, 100), new Size(500, 400), WindowTypes.Regular); var renderer = new Win32OpenGLRenderer(); renderer.Init(window.Pointer, window.ClientSize); while (true) { window.MainLoop(() => { renderer.Clear(Color.FrameBg); Win32OpenGLRenderer.DrawTextMesh(renderer.glyphMaterial, primitiveRenderer.TextMesh, (int)window.ClientSize.Width, (int)window.ClientSize.Height); renderer.SwapBuffers(); }); if (Input.Keyboard.Instance.KeyDown(Key.Escape)) { break; } } }
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(); } }
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 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(); } }