diff --git a/OpenRA.Mods.Common/Graphics/CircleAnnotationRenderable.cs b/OpenRA.Mods.Common/Graphics/CircleAnnotationRenderable.cs new file mode 100644 index 0000000000..fa30c35f5a --- /dev/null +++ b/OpenRA.Mods.Common/Graphics/CircleAnnotationRenderable.cs @@ -0,0 +1,75 @@ +#region Copyright & License Information +/* + * Copyright 2007-2019 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. For more + * information, see COPYING. + */ +#endregion + +using OpenRA.Graphics; +using OpenRA.Primitives; + +namespace OpenRA.Mods.Common.Graphics +{ + public struct CircleAnnotationRenderable : IRenderable, IFinalizedRenderable + { + const int CircleSegments = 32; + static readonly WVec[] FacingOffsets = Exts.MakeArray(CircleSegments, i => new WVec(1024, 0, 0).Rotate(WRot.FromFacing(i * 256 / CircleSegments))); + + readonly WPos centerPosition; + readonly WDist radius; + readonly int width; + readonly Color color; + readonly bool filled; + + public CircleAnnotationRenderable(WPos centerPosition, WDist radius, int width, Color color, bool filled = false) + { + this.centerPosition = centerPosition; + this.radius = radius; + this.width = width; + this.color = color; + this.filled = filled; + } + + public WPos Pos { get { return centerPosition; } } + public PaletteReference Palette { get { return null; } } + public int ZOffset { get { return 0; } } + public bool IsDecoration { get { return true; } } + + public IRenderable WithPalette(PaletteReference newPalette) { return new CircleAnnotationRenderable(centerPosition, radius, width, color, filled); } + public IRenderable WithZOffset(int newOffset) { return new CircleAnnotationRenderable(centerPosition, radius, width, color, filled); } + public IRenderable OffsetBy(WVec vec) { return new CircleAnnotationRenderable(centerPosition + vec, radius, width, color, filled); } + public IRenderable AsDecoration() { return this; } + + public IFinalizedRenderable PrepareRender(WorldRenderer wr) { return this; } + public void Render(WorldRenderer wr) + { + var wcr = Game.Renderer.WorldRgbaColorRenderer; + if (filled) + { + var offset = new WVec(radius.Length, radius.Length, 0); + var tl = wr.Screen3DPosition(centerPosition - offset); + var br = wr.Screen3DPosition(centerPosition + offset); + + wcr.FillEllipse(tl, br, color); + } + else + { + var r = radius.Length; + var a = wr.Screen3DPosition(centerPosition + r * FacingOffsets[CircleSegments - 1] / 1024); + for (var i = 0; i < CircleSegments; i++) + { + var b = wr.Screen3DPosition(centerPosition + r * FacingOffsets[i] / 1024); + wcr.DrawLine(a, b, width / wr.Viewport.Zoom, color); + a = b; + } + } + } + + public void RenderDebugGeometry(WorldRenderer wr) { } + public Rectangle ScreenBounds(WorldRenderer wr) { return Rectangle.Empty; } + } +} diff --git a/OpenRA.Mods.Common/Graphics/LineAnnotationRenderable.cs b/OpenRA.Mods.Common/Graphics/LineAnnotationRenderable.cs new file mode 100644 index 0000000000..f97296e8ee --- /dev/null +++ b/OpenRA.Mods.Common/Graphics/LineAnnotationRenderable.cs @@ -0,0 +1,61 @@ +#region Copyright & License Information +/* + * Copyright 2007-2019 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. For more + * information, see COPYING. + */ +#endregion + +using OpenRA.Graphics; +using OpenRA.Primitives; + +namespace OpenRA.Mods.Common.Graphics +{ + public struct LineAnnotationRenderable : IRenderable, IFinalizedRenderable + { + readonly WPos start; + readonly WPos end; + readonly float width; + readonly Color startColor; + readonly Color endColor; + + public LineAnnotationRenderable(WPos start, WPos end, float width, Color color) + { + this.start = start; + this.end = end; + this.width = width; + startColor = endColor = color; + } + + public LineAnnotationRenderable(WPos start, WPos end, float width, Color startColor, Color endColor) + { + this.start = start; + this.end = end; + this.width = width; + this.startColor = startColor; + this.endColor = endColor; + } + + public WPos Pos { get { return start; } } + public PaletteReference Palette { get { return null; } } + public int ZOffset { get { return 0; } } + public bool IsDecoration { get { return true; } } + + public IRenderable WithPalette(PaletteReference newPalette) { return new LineAnnotationRenderable(start, end, width, startColor, endColor); } + public IRenderable WithZOffset(int newOffset) { return new LineAnnotationRenderable(start, end, width, startColor, endColor); } + public IRenderable OffsetBy(WVec vec) { return new LineAnnotationRenderable(start + vec, end + vec, width, startColor, endColor); } + public IRenderable AsDecoration() { return this; } + + public IFinalizedRenderable PrepareRender(WorldRenderer wr) { return this; } + public void Render(WorldRenderer wr) + { + Game.Renderer.WorldRgbaColorRenderer.DrawLine(wr.Screen3DPosition(start), wr.Screen3DPosition(end), width / wr.Viewport.Zoom, startColor, endColor); + } + + public void RenderDebugGeometry(WorldRenderer wr) { } + public Rectangle ScreenBounds(WorldRenderer wr) { return Rectangle.Empty; } + } +} diff --git a/OpenRA.Mods.Common/Graphics/PolygonAnnotationRenderable.cs b/OpenRA.Mods.Common/Graphics/PolygonAnnotationRenderable.cs new file mode 100644 index 0000000000..62e24ab00e --- /dev/null +++ b/OpenRA.Mods.Common/Graphics/PolygonAnnotationRenderable.cs @@ -0,0 +1,53 @@ +#region Copyright & License Information +/* + * Copyright 2007-2019 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. For more + * information, see COPYING. + */ +#endregion + +using System.Linq; +using OpenRA.Graphics; +using OpenRA.Primitives; + +namespace OpenRA.Mods.Common.Graphics +{ + public struct PolygonAnnotationRenderable : IRenderable, IFinalizedRenderable + { + readonly WPos[] vertices; + readonly WPos effectivePos; + readonly int width; + readonly Color color; + + public PolygonAnnotationRenderable(WPos[] vertices, WPos effectivePos, int width, Color color) + { + this.vertices = vertices; + this.effectivePos = effectivePos; + this.width = width; + this.color = color; + } + + public WPos Pos { get { return effectivePos; } } + public PaletteReference Palette { get { return null; } } + public int ZOffset { get { return 0; } } + public bool IsDecoration { get { return true; } } + + public IRenderable WithPalette(PaletteReference newPalette) { return new PolygonAnnotationRenderable(vertices, effectivePos, width, color); } + public IRenderable WithZOffset(int newOffset) { return new PolygonAnnotationRenderable(vertices, effectivePos, width, color); } + public IRenderable OffsetBy(WVec vec) { return new PolygonAnnotationRenderable(vertices.Select(v => v + vec).ToArray(), effectivePos + vec, width, color); } + public IRenderable AsDecoration() { return this; } + + public IFinalizedRenderable PrepareRender(WorldRenderer wr) { return this; } + public void Render(WorldRenderer wr) + { + var verts = vertices.Select(wr.Screen3DPosition).ToArray(); + Game.Renderer.WorldRgbaColorRenderer.DrawPolygon(verts, width / wr.Viewport.Zoom, color); + } + + public void RenderDebugGeometry(WorldRenderer wr) { } + public Rectangle ScreenBounds(WorldRenderer wr) { return Rectangle.Empty; } + } +}