public void UpdateANode() { 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 fillCmd = primitive.PathFill(Color.Black); Node node = new Node(1); node.Primitive = primitive; { fillCmd.Color = Color.Red; Util.DrawNodeToImage(out var imageRawBytes, node, 110, 110); Util.CheckExpectedImage(imageRawBytes, 110, 110, @"Rendering\images\NodeFacts.Draw.UpdateANode.Black.png"); } { fillCmd.Color = Color.Green; Util.DrawNodeToImage(out var imageRawBytes, node, 110, 110); Util.CheckExpectedImage(imageRawBytes, 110, 110, @"Rendering\images\NodeFacts.Draw.UpdateANode.Green.png"); } { fillCmd.Color = Color.Blue; Util.DrawNodeToImage(out var imageRawBytes, node, 110, 110); Util.CheckExpectedImage(imageRawBytes, 110, 110, @"Rendering\images\NodeFacts.Draw.UpdateANode.Blue.png"); } }
//##################################################################### /// <summary> /// 根据星历表,创建新的PathPrimitive</para> /// </summary> /// <param name="ephemeris">卫星星历数据</param> /// <param name="frame">参考系</param> public static PathPrimitive CreatePathPrimitiveFromEphemeris(DateMotionCollection <Cartesian> ephemeris, ReferenceFrame frame) { try { List <PathPoint> points = new List <PathPoint>(); for (int i = 0; i < ephemeris.Count; i++) { points.Add(new PathPointBuilder(ephemeris.Values[i], ephemeris.Dates[i], Color.Yellow).ToPathPoint()); } PathPrimitive pathPrimitive = new PathPrimitive(); //pathPrimitive.UpdatePolicy = new DurationPathPrimitiveUpdatePolicy(new Duration(0, 60), PathPrimitiveRemoveLocation.RemoveLocationFront); pathPrimitive.ReferenceFrame = frame; //pathPrimitive.AddRangeToFront(points); pathPrimitive.AddRangeToBack(points); pathPrimitive.Width = 3.0F; SceneManager.Animation.Time = ephemeris.Dates[0]; return(pathPrimitive); } catch (Exception ex) { throw new Exception(ex.Message + "\n" + "向3D图中画卫星轨迹出错!"); } }
public void Works() { var primitive = new PathPrimitive(); primitive.PathMoveTo(Point.Zero); primitive.PathLineTo(new Point(0, 10)); primitive.PathLineTo(new Point(10, 10)); primitive.PathLineTo(new Point(10, 0)); Assert.Equal(4, primitive.Path.Count); { Assert.IsType <MoveToCommand>(primitive.Path[0]); var cmd = (MoveToCommand)primitive.Path[0]; Assert.Equal(Point.Zero, cmd.Point); } { var cmd = (LineToCommand)primitive.Path[1]; Assert.Equal(new Point(0, 10), cmd.Point); } { var cmd = (LineToCommand)primitive.Path[2]; Assert.Equal(new Point(10, 10), cmd.Point); } { var cmd = (LineToCommand)primitive.Path[3]; Assert.Equal(new Point(10, 0), cmd.Point); } }
public void ShowHideANode() { 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(); primitive.PathFill(Color.Red); node.Primitive = primitive; { node.ActiveSelf = true; Util.DrawNodeToImage(out var imageRawBytes, node, 110, 110); Util.CheckExpectedImage(imageRawBytes, 110, 110, @"Rendering\images\NodeFacts.Draw.ShowHideANode.Show.png"); } { node.ActiveSelf = false; Util.DrawNodeToImage(out var imageRawBytes, node, 110, 110); Util.CheckExpectedImage(imageRawBytes, 110, 110, @"Rendering\images\NodeFacts.Draw.ShowHideANode.Hide.png"); } }
public void DrawPath(PathPrimitive primitive, Vector offset) { foreach (var command in primitive.Path) { switch (command.Type) { case PathCommandType.PathMoveTo: { var cmd = (MoveToCommand)command; this.PathMoveTo(cmd.Point + offset); break; } case PathCommandType.PathLineTo: { var cmd = (LineToCommand)command; this.PathLineTo(cmd.Point + offset); break; } case PathCommandType.PathCurveTo: { throw new NotImplementedException(); break; } case PathCommandType.PathClosePath: { this.PathClose(); break; } case PathCommandType.PathArc: { var cmd = (ArcCommand)command; this.PathArcFast(cmd.Center + offset, cmd.Radius, cmd.Amin, cmd.Amax); break; } case PathCommandType.Stroke: { var cmd = (StrokeCommand)command; this.PathStroke(cmd.Color, false, cmd.LineWidth); break; } case PathCommandType.Fill: { var cmd = (FillCommand)command; this.PathFill(cmd.Color); break; } default: throw new ArgumentOutOfRangeException(); } } }
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"); }
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"); } }
public void DrawPathPrimitive(Mesh shapeMesh, PathPrimitive pathPrimitive, Vector offset) { shapeMesh.Clear(); shapeMesh.CommandBuffer.Add(DrawCommand.Default); //draw this.SetShapeMesh(shapeMesh); this.DrawPath(pathPrimitive, offset); this.SetShapeMesh(null); }
public void Draw() { var primitive = new PathPrimitive(); primitive.PathMoveTo(Point.Zero); primitive.PathArcFast(new Point(10, 0), 10, 6, 9); primitive.PathStroke(1, Color.Black); Util.DrawPathPrimitive(primitive); }
public void Works() { var primitive = new PathPrimitive(); primitive.PathMoveTo(Point.Zero); Assert.Single(primitive.Path); Assert.IsType <MoveToCommand>(primitive.Path[0]); var cmd = (MoveToCommand)primitive.Path[0]; Assert.Equal(Point.Zero, cmd.Point); }
public void FillAPath() { var primitive = new PathPrimitive(); primitive.PathMoveTo(new Point(10, 10)); primitive.PathLineTo(new Point(10, 80)); primitive.PathLineTo(new Point(80, 80)); primitive.PathClose(); primitive.PathFill(Color.Red); Util.CheckExpectedImage(primitive, 100, 100, @"GraphicsImplementation\Builtin\images\BuiltinPrimitiveRendererFacts.DrawPath.FillAPath.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.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"); }
/// <summary> /// Draw the ephemeris in the Insight3D window. /// </summary> /// <param name="ephemeris">The date, position (and velocity) information of the object being displayed.</param> /// <param name="inertialFrame">The inertial frame to display the graphics in.</param> private void DrawSatellite(DateMotionCollection <Cartesian> ephemeris, ReferenceFrame inertialFrame) { // Clean up the previous run's graphics foreach (Primitive primitive in m_primitivesAddedToScene) { SceneManager.Primitives.Remove(primitive); } m_primitivesAddedToScene.Clear(); if (m_platform != null) { m_display.ServiceProviders.Remove(m_platform); } // Draw the orbit List <PathPoint> points = new List <PathPoint>(); for (int i = 0; i < ephemeris.Count; i++) { points.Add(new PathPointBuilder(ephemeris.Values[i], ephemeris.Dates[i]).ToPathPoint()); } PathPrimitive path = new PathPrimitive { ReferenceFrame = inertialFrame }; path.AddRangeToFront(points); SceneManager.Primitives.Add(path); m_primitivesAddedToScene.Add(path); // Put a marker where the satellite is at a given time LagrangePolynomialApproximation interpolationAlgorithm = new LagrangePolynomialApproximation(); TranslationalMotionInterpolator interpolator = new TranslationalMotionInterpolator(interpolationAlgorithm, 2, ephemeris); m_platform = new Platform { LocationPoint = new PointInterpolator(inertialFrame, interpolator) }; Texture2D texture = SceneManager.Textures.FromUri(@"Data\Markers\Satellite.png"); m_platform.Extensions.Add(new MarkerGraphicsExtension(new MarkerGraphics { Texture = new ConstantGraphicsParameter <Texture2D>(texture) })); m_display.ServiceProviders.Add(m_platform); m_display.ApplyChanges(); // Set the date to the start of the ephemeris SceneManager.Animation.Time = ephemeris.Dates[0]; }
internal static void CheckExpectedImage(PathPrimitive primitive, int width, int height, string expectedImageFilePath) { byte[] imageRawBytes; using (var context = new RenderContextForTest(width, height)) { BuiltinPrimitiveRenderer primitiveRenderer = new BuiltinPrimitiveRenderer(); var mesh = new Mesh(); primitiveRenderer.DrawPathPrimitive(mesh, primitive, Vector.Zero); context.Clear(); context.DrawShapeMesh(mesh); imageRawBytes = context.GetRenderedRawBytes(); } Util.CheckExpectedImage(imageRawBytes, width, height, expectedImageFilePath); }
public void Works() { var primitive = new PathPrimitive(); primitive.PathMoveTo(Point.Zero); primitive.PathArcFast(new Point(10, 0), 10, 3, 6); var cmd = (ArcCommand)primitive.Path[1]; var center = cmd.Center; var amin = cmd.Amin; var amax = cmd.Amax; Assert.Equal(10, center.x, precision: 2); Assert.Equal(0, center.y, precision: 2); Assert.Equal(3, amin); Assert.Equal(6, amax); }
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 DrawANode() { 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(); primitive.PathFill(Color.Black); Node node = new Node(1); node.Primitive = primitive; Util.DrawNodeToImage(out var imageRawBytes, node, 110, 110); Util.CheckExpectedImage(imageRawBytes, 110, 110, @"Rendering\images\NodeFacts.Draw.DrawANode.png"); }
public void UpdateTwoNode() { var nodes = new List <Node>(); FillCommand node0FillCmd, node1FillCmd; { Node node = new Node(0); 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(); node0FillCmd = primitive.PathFill(Color.Green); node.Primitive = primitive; } { Node node = new Node(1); nodes.Add(node); var primitive = new PathPrimitive(); primitive.PathMoveTo(new Point(110, 10)); primitive.PathLineTo(new Point(110, 100)); primitive.PathLineTo(new Point(200, 100)); primitive.PathLineTo(new Point(200, 10)); primitive.PathClose(); node1FillCmd = primitive.PathFill(Color.Orange); node.Primitive = primitive; } { node0FillCmd.Color = Color.Red; node1FillCmd.Color = Color.Blue; Util.DrawNodesToImage(out var imageRawBytes, nodes, 110, 110); Util.CheckExpectedImage(imageRawBytes, 110, 110, @"Rendering\images\NodeFacts.Draw.UpdateTwoNode.Before.png"); } { node0FillCmd.Color = Color.Green; node1FillCmd.Color = Color.Orange; Util.DrawNodesToImage(out var imageRawBytes, nodes, 110, 110); Util.CheckExpectedImage(imageRawBytes, 110, 110, @"Rendering\images\NodeFacts.Draw.UpdateTwoNode.After.png"); } }
internal static void DrawPathPrimitive(PathPrimitive primitive, [CallerMemberName] string memberName = "") { var size = GetPrimitiveSize(primitive, out Point minPoint); using (ImageSurface surface = new ImageSurface(Format.Argb32, (int)size.Width, (int)size.Height)) using (Context context = new Context(surface)) { context.Translate(-minPoint.x, -minPoint.y); Draw(context, primitive); if (!Directory.Exists(OutputPath)) { Directory.CreateDirectory(OutputPath); } string filePath = OutputPath + "\\" + DateTime.UtcNow.ToString("yyyy-MM-dd_HH-mm-ss-fff_") + surface.GetHashCode() + memberName + ".png"; surface.WriteToPng(filePath); Util.OpenImage(filePath); } }
internal static void CheckExpectedImage(PathPrimitive primitive, int width, int height, string expectedImageFilePath) { byte[] imageRawBytes; using (var context = new RenderContextForTest(width, height)) { BuiltinPrimitiveRenderer primitiveRenderer = new BuiltinPrimitiveRenderer(); var mesh = new Mesh(); mesh.CommandBuffer.Add(DrawCommand.Default); primitiveRenderer.DrawPathPrimitive(mesh, primitive, Vector.Zero); context.Clear(); context.DrawShapeMesh(mesh); imageRawBytes = context.GetRenderedRawBytes(); } var image = Util.CreateImage(imageRawBytes, width, height, flip: true); #if DEBUG var expectedImage = Util.LoadImage(expectedImageFilePath); Assert.True(Util.CompareImage(expectedImage, image)); #else Util.SaveImage(image, Util.UnitTestRootDir + expectedImageFilePath); //generate expected image #endif }
private static Size GetPrimitiveSize(PathPrimitive primitive, out Point min) { var minX = 0.0; var minY = 0.0; var maxX = 0.0; var maxY = 0.0; void updateMinMax(Point point) { minX = Math.Min(minX, point.x); minY = Math.Min(minY, point.y); maxX = Math.Max(maxX, point.x); maxY = Math.Max(maxY, point.y); } foreach (var command in primitive.Path) { switch (command.Type) { case PathCommandType.PathMoveTo: { var cmd = (MoveToCommand)command; var point = cmd.Point; updateMinMax(point); break; } case PathCommandType.PathLineTo: { var cmd = (LineToCommand)command; var point = cmd.Point; updateMinMax(point); break; } case PathCommandType.PathCurveTo: { var cmd = (CurveToCommand)command; var c0 = cmd.ControlPoint0; var c1 = cmd.ControlPoint1; var end = cmd.EndPoint; updateMinMax(c0); updateMinMax(c1); updateMinMax(end); break; } case PathCommandType.PathArc: { var cmd = (ArcCommand)command; var c0 = cmd.Center; var v = new Vector(cmd.Radius, cmd.Radius); var minPoint = c0 - v; var maxPoint = c0 + v; updateMinMax(minPoint); updateMinMax(maxPoint); break; } case PathCommandType.PathClosePath: case PathCommandType.Stroke: case PathCommandType.Fill: break; default: throw new ArgumentOutOfRangeException(); } } min = new Point(minX, minY); return(new Size(maxX - minX, maxY - minY)); }
private static void Draw(Context context, PathPrimitive primitive) { foreach (var command in primitive.Path) { switch (command.Type) { case PathCommandType.PathMoveTo: { var cmd = (MoveToCommand)command; context.MoveTo(cmd.Point.ToPointD()); break; } case PathCommandType.PathLineTo: { var cmd = (LineToCommand)command; context.LineTo(cmd.Point.ToPointD()); break; } case PathCommandType.PathCurveTo: { var cmd = (CurveToCommand)command; context.CurveTo(cmd.ControlPoint0.ToPointD(), cmd.ControlPoint1.ToPointD(), cmd.EndPoint.ToPointD()); break; } case PathCommandType.PathArc: { var cmd = (ArcCommand)command; var xc = cmd.Center.x; var yc = cmd.Center.y; var r = cmd.Radius; var angle1 = cmd.Amin * Math.PI / 6; var angle2 = cmd.Amax * Math.PI / 6; context.Arc(xc, yc, r, angle1, angle2); break; } case PathCommandType.PathClosePath: { context.ClosePath(); break; } case PathCommandType.Stroke: { var cmd = (StrokeCommand)command; context.Color = cmd.Color.ToCairoColor(); context.LineWidth = cmd.LineWidth; context.Stroke(); break; } case PathCommandType.Fill: { var cmd = (FillCommand)command; context.Color = cmd.Color.ToCairoColor(); context.Fill(); break; } default: throw new ArgumentOutOfRangeException(); } } }
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 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 }
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 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 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 DrawPathPrimitive(Mesh shapeMesh, PathPrimitive pathPrimitive, Vector offset) { this.SetShapeMesh(shapeMesh); this.DrawPath(pathPrimitive, offset); this.SetShapeMesh(null); }
public void DrawPath(PathPrimitive primitive) => this.DrawPath(primitive, Vector.Zero);