Rework multi-resolution sprite handling:

- Sprite.Bounds now refers to rectangles in the source image.
  Use this when copying pixels, etc.
- Sprite.Size now refers to sizes in effective pixel coordinates.
  Use this when rendering.
- Sheet.DPIScale has been removed.
- "Density" term is introduced to refer to the number of artwork
  pixels per effective pixel.
This commit is contained in:
Paul Chote
2020-02-11 21:29:15 +00:00
committed by abcdefg30
parent c0ece00c4b
commit de4a7cecf0
15 changed files with 106 additions and 91 deletions

View File

@@ -47,22 +47,27 @@ namespace OpenRA.Mods.Common.Widgets
public static void FillRectWithSprite(Rectangle r, Sprite s)
{
for (var x = r.Left; x < r.Right; x += (int)s.Size.X)
for (var y = r.Top; y < r.Bottom; y += (int)s.Size.Y)
var scale = s.Size.X / s.Bounds.Width;
for (var x = (float)r.Left; x < r.Right; x += s.Size.X)
{
for (var y = (float)r.Top; y < r.Bottom; y += s.Size.Y)
{
var ss = s;
var left = new int2(r.Right - x, r.Bottom - y);
if (left.X < (int)s.Size.X || left.Y < (int)s.Size.Y)
var dx = r.Right - x;
var dy = r.Bottom - y;
if (dx < s.Size.X || dy < s.Size.Y)
{
var rr = new Rectangle(s.Bounds.Left,
var rr = new Rectangle(
s.Bounds.Left,
s.Bounds.Top,
Math.Min(left.X, (int)s.Size.X),
Math.Min(left.Y, (int)s.Size.Y));
ss = new Sprite(s.Sheet, rr, s.Channel);
Math.Min(s.Bounds.Width, (int)(dx / scale)),
Math.Min(s.Bounds.Height, (int)(dy / scale)));
ss = new Sprite(s.Sheet, rr, s.Channel, scale);
}
DrawRGBA(ss, new float2(x, y));
}
}
}
public static void FillRectWithColor(Rectangle r, Color c)