Files
OpenRA/OpenRA.Mods.Common/Graphics/SelectionBoxAnnotationRenderable.cs
let5sne.win10 9cf6ebb986
Some checks failed
Continuous Integration / Linux (.NET 8.0) (push) Has been cancelled
Continuous Integration / Windows (.NET 8.0) (push) Has been cancelled
Initial commit: OpenRA game engine
Fork from OpenRA/OpenRA with one-click launch script (start-ra.cmd)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-10 21:46:54 +08:00

62 lines
2.2 KiB
C#

#region Copyright & License Information
/*
* Copyright (c) The OpenRA Developers and Contributors
* 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 class SelectionBoxAnnotationRenderable : IRenderable, IFinalizedRenderable
{
readonly Rectangle decorationBounds;
readonly Color color;
public SelectionBoxAnnotationRenderable(Actor actor, Rectangle decorationBounds, Color color)
: this(actor.CenterPosition, decorationBounds, color) { }
public SelectionBoxAnnotationRenderable(WPos pos, Rectangle decorationBounds, Color color)
{
Pos = pos;
this.decorationBounds = decorationBounds;
this.color = color;
}
public WPos Pos { get; }
public int ZOffset => 0;
public bool IsDecoration => true;
public IRenderable WithZOffset(int newOffset) { return this; }
public IRenderable OffsetBy(in WVec vec) { return new SelectionBoxAnnotationRenderable(Pos + vec, decorationBounds, color); }
public IRenderable AsDecoration() { return this; }
public IFinalizedRenderable PrepareRender(WorldRenderer wr) { return this; }
public void Render(WorldRenderer wr)
{
var tl = wr.Viewport.WorldToViewPx(new float2(decorationBounds.Left, decorationBounds.Top)).ToFloat2();
var br = wr.Viewport.WorldToViewPx(new float2(decorationBounds.Right, decorationBounds.Bottom)).ToFloat2();
var tr = new float2(br.X, tl.Y);
var bl = new float2(tl.X, br.Y);
var u = new float2(4, 0);
var v = new float2(0, 4);
var cr = Game.Renderer.RgbaColorRenderer;
cr.DrawLine([tl + u, tl, tl + v], 1, color, true);
cr.DrawLine([tr - u, tr, tr + v], 1, color, true);
cr.DrawLine([br - u, br, br - v], 1, color, true);
cr.DrawLine([bl + u, bl, bl - v], 1, color, true);
}
public void RenderDebugGeometry(WorldRenderer wr) { }
public Rectangle ScreenBounds(WorldRenderer wr) { return Rectangle.Empty; }
}
}