add "retro" pixel scaler (chunky pixels style)

This commit is contained in:
Gered 2013-08-24 19:23:02 -04:00
parent 90d4885d71
commit b04f7b52c1
2 changed files with 57 additions and 0 deletions

View file

@ -183,6 +183,7 @@
<Compile Include="BasicGameApp.cs" />
<Compile Include="Graphics\IOrthoPixelScaler.cs" />
<Compile Include="Graphics\NoScaleOrthoPixelScaler.cs" />
<Compile Include="Graphics\RetroOrthoPixelScaler.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
<ItemGroup>

View file

@ -0,0 +1,56 @@
using System;
namespace Blarg.GameFramework.Graphics
{
public class RetroOrthoPixelScaler : IOrthoPixelScaler
{
int _scale = 0;
Rect _scaledViewport;
public void Calculate(Rect viewport)
{
int viewportWidth = viewport.Width;
int viewportHeight = viewport.Height;
// TODO: these might need tweaking, this is fairly arbitrary
if (viewportWidth < 640 || viewportHeight < 480)
_scale = 1;
else if (viewportWidth < 960 || viewportHeight < 720)
_scale = 2;
else if (viewportWidth < 1280 || viewportHeight < 960)
_scale = 3;
else if (viewportWidth < 1920 || viewportHeight < 1080)
_scale = 4;
else
_scale = 5;
// TODO: desktop "retina" / 4K display sizes? 1440p?
_scaledViewport.Left = viewport.Left / _scale;
_scaledViewport.Top = viewport.Top / _scale;
_scaledViewport.Right = viewport.Right / _scale;
_scaledViewport.Bottom = viewport.Bottom / _scale;
}
public int Scale
{
get { return _scale; }
}
public Rect ScaledViewport
{
get { return _scaledViewport; }
}
public int ScaledWidth
{
get { return _scaledViewport.Width; }
}
public int ScaledHeight
{
get { return _scaledViewport.Height; }
}
}
}