public void DefaultDraw(Batcher batcher, Rectangle finalBounds) { var isEmpty = string.IsNullOrEmpty(TextValue); var start = finalBounds.Location.ToVector2() + new Vector2(Padding); batcher.DrawRect(finalBounds, PanelColor); // Ghost or normal if (isEmpty) { batcher.DrawString(LabelFont, GhostValue, start, FontGhostColor); } else { batcher.DrawString(LabelFont, TextValue, start, FontColor); } if (Manager?.GetFocus() == this) { if (caretVisible) { var end = LabelFont.MeasureString(isEmpty ? "." : TextValue); batcher.DrawLine(start.X + end.X, start.Y, start.X + end.X, start.Y + end.Y, FontColor); } } }
public static void DrawBarUp(this Batcher batcher, float x, float bottom, float height, Color color, float thickness) { var t = new Vector2(x, bottom - height); var b = new Vector2(x, bottom); batcher.DrawLine(t, b, color, thickness); }
public static void DrawBarLeft(this Batcher batcher, float y, float right, float width, Color color, float thickness) { var l = new Vector2(right - width, y); var r = new Vector2(right, y); batcher.DrawLine(l, r, color, thickness); }
public static void DrawBarDown(this Batcher batcher, float x, float top, float height, Color color, float thickness) { var t = new Vector2(x, top); var b = new Vector2(x, top + height); batcher.DrawLine(t, b, color, thickness); }
void RenderRects(Batcher batcher, SvgRectangle[] rects) { if (rects == null) { return; } foreach (var rect in rects) { var fixedPts = rect.GetTransformedPoints(); for (var i = 0; i < fixedPts.Length - 1; i++) { batcher.DrawLine(fixedPts[i], fixedPts[i + 1], rect.StrokeColor, rect.StrokeWidth); } batcher.DrawLine(fixedPts[3], fixedPts[0], rect.StrokeColor, rect.StrokeWidth); } }
public override void Render(Batcher batcher, Camera camera) { batcher.DrawPixel(_lastPosition.X, _lastPosition.Y, Color.Yellow, 4); batcher.DrawPixel(Transform.Position.X, Transform.Position.Y, Color.White, 4); batcher.DrawLine(_lastPosition, Transform.Position, Color.White); if (_collisionPosition.X > 0 && _collisionPosition.Y > 0) { batcher.DrawPixel(_collisionPosition.X, _collisionPosition.Y, Color.Red, 10); } }
void RenderLines(Batcher batcher, SvgLine[] lines) { if (lines == null) { return; } foreach (var line in lines) { var fixedPts = line.GetTransformedPoints(); batcher.DrawLine(fixedPts[0], fixedPts[1], line.StrokeColor, line.StrokeWidth); } }
public override void DebugRender(Batcher batcher) { base.DebugRender(batcher); foreach (Connection c in connections.Values) { batcher.DrawLine(Position, Position + Direction8Ext.ToVector2(c.direction) * 50, Color.Chartreuse, 5); } if (roadSystem.truckTargetNode == this) { batcher.DrawHollowRect(new Rectangle((int)Position.X - 25, (int)Position.Y - 25, 50, 50), Color.White, 5); } }
void RenderPolylines(Batcher batcher, SvgPolyline[] polylines) { if (polylines == null) { return; } foreach (var poly in polylines) { var fixedPts = poly.GetTransformedPoints(); for (var i = 0; i < fixedPts.Length - 1; i++) { batcher.DrawLine(fixedPts[i], fixedPts[i + 1], poly.StrokeColor, poly.StrokeWidth); } } }
void RenderPaths(Batcher batcher, SvgPath[] paths) { if (paths == null && _pathBuilder != null) { return; } foreach (var path in paths) { var points = path.GetTransformedDrawingPoints(_pathBuilder, 3); for (var i = 0; i < points.Length - 1; i++) { batcher.DrawLine(points[i], points[i + 1], path.StrokeColor, path.StrokeWidth); batcher.DrawPixel(points[i], Color.Yellow, 3); } } }
public override void DebugRender(Batcher batcher) { base.DebugRender(batcher); var mapRepr = playState.map; if (mapRepr == null) { return; } // draw points for each point on the map graph foreach (var node in mapRepr.sng.nodes) { Vector2 toWorldPos(Point tilePos) => mapRenderer.TiledMap.TileToWorldPosition(tilePos.ToVector2()); batcher.DrawHollowRect(toWorldPos(node.pos), 4f, 4f, Color.GreenYellow, 1f); // draw edges foreach (var adj in node.links) { batcher.DrawLine(toWorldPos(node.pos), toWorldPos(adj.pos), Color.GreenYellow, 1f); } } }
public override void DebugRender(Batcher batcher) { batcher.DrawLine(_particleOne.Position, _particleTwo.Position, Debug.Colors.VerletConstraintEdge); }
static void Main(string[] args) { // Create the window and the graphics device VeldridInit(out var window, out var graphicsDevice); // Create a renderer that implements the OpenWheels.Rendering.IRenderer interface // this guy actually draws everything to the backbuffer var renderer = new VeldridRenderer(graphicsDevice); // Our batcher lets use make calls to render lots of different primitive shapes and text. // When we're done the batcher sends the draw calls to the renderer which will actually do the drawing. // Alternatively to Batcher you can use StringIdBatcher so you can register and set the active texture // and font with a string identifier. var batcher = new Batcher(renderer); var checkerBoardTextureId = batcher.LoadTexture("checkerboard.png"); // OpenWheels defines a sprite as an image that's part of a texture // To create a sprite, we pass a texture and a region of that texture (in pixels) that contains the actual image // let's add a sprite that draws 3/4th of the checkerboard // So if our original texture looks like this: // |## | // |## | // | ##| // | ##| // We'll create a sprite that looks like this: // |## | // |## | // | #| var cbSize = renderer.GetTextureSize(checkerBoardTextureId); var subSpriteRect = new Rectangle(0, 0, (cbSize.Width * 3) / 4, (cbSize.Height * 3) / 4); var checkerBoardSubSprite = new Sprite(checkerBoardTextureId, subSpriteRect); var frame = 0; // We run the game loop here and do our drawing inside of it. VeldridRunLoop(window, graphicsDevice, () => { renderer.Clear(Color.CornflowerBlue); // Start a new batch batcher.Start(); // we set the texture using the texture id we got back when registering the texture // OpenWheels internally only works with sprites // If you set a texture on a batcher it will convert it to a sprite with the region being the // entire texture bounds batcher.SetTexture(checkerBoardTextureId); // The Batcher API is stateful. Anything we render now will use the checkerboard texture. // By default the UV coordinates 0, 0, 1, 1 are use, so our texture is stretched batcher.FillRect(new RectangleF(50, 20, 100, 100), Color.White); batcher.FillRect(new RectangleF(200, 20, 100, 200), Color.White); // Let's draw our subsprite batcher.Sprite = checkerBoardSubSprite; batcher.FillRect(new RectangleF(350, 20, 100, 100), Color.White); // We can only draw 1 texture in a single draw call, but since our subsprite actually uses the same // texture as our full checkerboard the batcher can still combine the calls into a single batch. batcher.SetTexture(checkerBoardTextureId); // Most of the primitives support UV coordinates one way or another. batcher.FillCircle(new Vector2(550, 70), 50, Color.White, .25f); batcher.FillRoundedRect(new RectangleF(650, 20, 100, 100), 15, Color.White); var v1 = new Vector2(50, 280); var v2 = new Vector2(150, 380); batcher.DrawLine(v1, v2, Color.White, 6f); // Note that the texture rotates with the line // This is different from the circle(segment) primitives where we draw a cutout of the active texture // There are a lot of ways to UV-map shapes, but OpenWheels currently picks just one for each shape // we can set a matrix to transform UV coordinates // let's make our texture loop in length while keeping it's aspect ratio and UV across its width. // The sampler should wrap to be able to loop the texture (the default sampler state is LinearClamp) // This state sticks across frames, so we could set it before the render loop as well batcher.SamplerState = SamplerState.LinearWrap; var v3 = new Vector2(200, 280); var v4 = new Vector2(300, 380); const float lineWidth = 10f; // we want our UV aspect ratio to be 1:1, but it's lineWidth:length and we want to use // the coordinate system of the width, so we normalize height to get the right aspect ratio // (note that height is defined as the forward direction of the line) var uvHeight = Vector2.Distance(v3, v4) / lineWidth; batcher.UvTransform = Matrix3x2.CreateScale(1f, uvHeight); batcher.DrawLine(v3, v4, Color.White, lineWidth); // Reset the uv transform batcher.UvTransform = Matrix3x2.Identity; // The color value we can pass to these methods is multiplied with our texture color at each pixel. batcher.FillRect(new RectangleF(350, 280, 100, 100), Color.Red); // Finish the batch and let the renderer draw everything to the back buffer. batcher.Finish(); if (frame < 2) { // Note that the first frame renders in two batches because we change the sampler state // halfway through. // Every subsequent frame render in a single batch because the sampler state stays at LinearClamp Console.WriteLine("Frame " + frame); Console.WriteLine("Vertices: " + batcher.VerticesSubmitted); Console.WriteLine("Indices: " + batcher.IndicesSubmitted); Console.WriteLine("Batches: " + batcher.BatchCount); Console.WriteLine(); frame++; } }); renderer.Dispose(); graphicsDevice.Dispose(); }
public override void DebugRender(Batcher batcher) { base.DebugRender(batcher); batcher.DrawLine(_context.Position, targetPosition, Color.Green, 10); }