Files
OpenRA/OpenRA.Mods.Common/Graphics/SelectionBoxRenderable.cs
reaperrr be290cfabd Split Actor.Bounds into RenderBounds and SelectableBounds
Additionally, internally renamed VisualBounds to SelectionOverlayBounds to avoid confusion with RenderBounds.

This step was necessary to prevent actors with selectable area smaller than their graphics to be removed too early from ScreenMap even though part of the graphics should still be visible.
RA cruisers were a prime example, but to a lesser extent several other actors were affected as well.

This separation also serves as preparation to determine the final RenderBounds from multiple source bounds later, to fix the remaining ScreenMap issues (building 'bibs', aircraft shadows).
2017-11-21 01:00:09 +02:00

67 lines
2.4 KiB
C#

#region Copyright & License Information
/*
* Copyright 2007-2017 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.Drawing;
using OpenRA.Graphics;
namespace OpenRA.Mods.Common.Graphics
{
public struct SelectionBoxRenderable : IRenderable, IFinalizedRenderable
{
readonly WPos pos;
readonly Rectangle visualBounds;
readonly Color color;
public SelectionBoxRenderable(Actor actor, Color color)
: this(actor.CenterPosition, actor.SelectionOverlayBounds, color) { }
public SelectionBoxRenderable(WPos pos, Rectangle visualBounds, Color color)
{
this.pos = pos;
this.visualBounds = visualBounds;
this.color = color;
}
public WPos Pos { get { return pos; } }
public PaletteReference Palette { get { return null; } }
public int ZOffset { get { return 0; } }
public bool IsDecoration { get { return true; } }
public IRenderable WithPalette(PaletteReference newPalette) { return this; }
public IRenderable WithZOffset(int newOffset) { return this; }
public IRenderable OffsetBy(WVec vec) { return new SelectionBoxRenderable(pos + vec, visualBounds, color); }
public IRenderable AsDecoration() { return this; }
public IFinalizedRenderable PrepareRender(WorldRenderer wr) { return this; }
public void Render(WorldRenderer wr)
{
var iz = 1 / wr.Viewport.Zoom;
var screenPos = wr.Screen3DPxPosition(pos);
var tl = screenPos + new float2(visualBounds.Left, visualBounds.Top);
var br = screenPos + new float2(visualBounds.Right, visualBounds.Bottom);
var tr = new float3(br.X, tl.Y, screenPos.Z);
var bl = new float3(tl.X, br.Y, screenPos.Z);
var u = new float2(4 * iz, 0);
var v = new float2(0, 4 * iz);
var wcr = Game.Renderer.WorldRgbaColorRenderer;
wcr.DrawLine(new[] { tl + u, tl, tl + v }, iz, color, true);
wcr.DrawLine(new[] { tr - u, tr, tr + v }, iz, color, true);
wcr.DrawLine(new[] { br - u, br, br - v }, iz, color, true);
wcr.DrawLine(new[] { bl + u, bl, bl - v }, iz, color, true);
}
public void RenderDebugGeometry(WorldRenderer wr) { }
public Rectangle ScreenBounds(WorldRenderer wr) { return Rectangle.Empty; }
}
}