rhythmbullet/RhythmBullet/ContentResolvers/ResolutionContentResolver.cs

111 lines
2.6 KiB
C#
Raw Normal View History

using RhythmBullet.Preferences;
using RhythmBullet.Utilities;
using RhythmBullet.Utilities.ContentSystem;
using RhythmBullet.Utilities.DataTypes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RhythmBullet.ContentResolvers
{
2018-10-30 23:29:54 +00:00
class ResolutionContentResolver : IContentPathModifier
{
int width, height;
bool updated;
Resolution bestResolution;
public int Width
{
get
{
return width;
}
set
{
updated = true;
width = value;
}
}
public int Height
{
get
{
return height;
}
set
{
updated = true;
height = value;
}
}
Resolution[] resolutions = {
new Resolution(1920, 1080),
new Resolution(2560, 1440),
new Resolution(3840, 2160)
};
Resolution ChooseRounded()
{
updated = false;
Resolution best = resolutions[0];
int leastDifference = -1;
int w = Width, h = Height;
if (w > h)
{
for (int i = 0; i < resolutions.Length; i++)
{
int currentDiff = h - resolutions[i].Height;
if (currentDiff < 0)
{
currentDiff = currentDiff * -1;
}
if ((currentDiff < leastDifference) || leastDifference == -1)
{
best = resolutions[i];
leastDifference = currentDiff;
}
}
}
else
{
for (int i = 0; i < resolutions.Length; i++)
{
int currentDiff = w - resolutions[i].Width;
if (currentDiff < 0)
{
currentDiff = currentDiff * -1;
}
if (currentDiff < leastDifference || leastDifference == -1)
{
best = resolutions[i];
leastDifference = currentDiff;
}
}
}
return best;
}
2018-10-30 23:29:54 +00:00
public string Modify(string path)
{
if (updated)
{
bestResolution = ChooseRounded();
}
return bestResolution + "/" + path;
}
}
}