Fix map preview aspect ratio

This commit is contained in:
Paul Chote
2010-04-04 17:42:34 +12:00
committed by Bob
parent 2885b25ec7
commit a0ad3d76b3
2 changed files with 22 additions and 9 deletions

View File

@@ -20,6 +20,7 @@
using System.Collections.Generic;
using System.Drawing;
using System;
namespace OpenRA.FileFormats
{
@@ -58,5 +59,15 @@ namespace OpenRA.FileFormats
);
}
public Rectangle PreviewBounds(Rectangle container)
{
float scale = Math.Min(container.Width*1.0f/Width,container.Height*1.0f/Height);
var size = Math.Max(Width, Height);
var dw = (int)(scale*(size - Width)) / 2;
var dh = (int)(scale*(size - Height)) / 2;
return new Rectangle(container.X + dw, container.Y + dh, (int)(Width*scale), (int)(Height*scale));
}
}
}