From 8ac9477cd9be7edb1abd91d6ca1c2ae3183490ed Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Tue, 22 Jul 2014 22:43:28 +1200 Subject: [PATCH] Add UISpriteRenderable for screen-space decorations. --- OpenRA.Game/Graphics/UISpriteRenderable.cs | 61 ++++++++++++++++++++++ OpenRA.Game/OpenRA.Game.csproj | 1 + 2 files changed, 62 insertions(+) create mode 100644 OpenRA.Game/Graphics/UISpriteRenderable.cs diff --git a/OpenRA.Game/Graphics/UISpriteRenderable.cs b/OpenRA.Game/Graphics/UISpriteRenderable.cs new file mode 100644 index 0000000000..5ff496b023 --- /dev/null +++ b/OpenRA.Game/Graphics/UISpriteRenderable.cs @@ -0,0 +1,61 @@ +#region Copyright & License Information +/* + * Copyright 2007-2014 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. For more information, + * see COPYING. + */ +#endregion + +using System.Collections.Generic; +using System.Drawing; +using System.Linq; + +namespace OpenRA.Graphics +{ + public struct UISpriteRenderable : IRenderable + { + readonly Sprite sprite; + readonly int2 screenPos; + readonly int zOffset; + readonly PaletteReference palette; + readonly float scale; + + public UISpriteRenderable(Sprite sprite, int2 screenPos, int zOffset, PaletteReference palette, float scale) + { + this.sprite = sprite; + this.screenPos = screenPos; + this.zOffset = zOffset; + this.palette = palette; + this.scale = scale; + } + + // Does not exist in the world, so a world positions don't make sense + public WPos Pos { get { return WPos.Zero; } } + public WVec Offset { get { return WVec.Zero; } } + public bool IsDecoration { get { return true; } } + + public float Scale { get { return scale; } } + public PaletteReference Palette { get { return palette; } } + public int ZOffset { get { return zOffset; } } + + public IRenderable WithScale(float newScale) { return new UISpriteRenderable(sprite, screenPos, zOffset, palette, newScale); } + public IRenderable WithPalette(PaletteReference newPalette) { return new UISpriteRenderable(sprite, screenPos, zOffset, newPalette, scale); } + public IRenderable WithZOffset(int newOffset) { return this; } + public IRenderable OffsetBy(WVec vec) { return this; } + public IRenderable AsDecoration() { return this; } + + public void BeforeRender(WorldRenderer wr) {} + public void Render(WorldRenderer wr) + { + Game.Renderer.SpriteRenderer.DrawSprite(sprite, screenPos, palette, sprite.size * scale); + } + + public void RenderDebugGeometry(WorldRenderer wr) + { + var offset = screenPos + sprite.offset; + Game.Renderer.LineRenderer.DrawRect(offset, offset + sprite.size, Color.Red); + } + } +} diff --git a/OpenRA.Game/OpenRA.Game.csproj b/OpenRA.Game/OpenRA.Game.csproj index ca5b6f2429..3ed4d44984 100644 --- a/OpenRA.Game/OpenRA.Game.csproj +++ b/OpenRA.Game/OpenRA.Game.csproj @@ -240,6 +240,7 @@ +