Add logic for game image stretching in Hooks#draw

Cache stretched dimensions and image

Fix rendering hint not being set until you resize window
This commit is contained in:
Lotto
2018-03-03 00:41:21 +01:00
parent 22f931a438
commit 4e198b6e0e
2 changed files with 70 additions and 13 deletions

View File

@@ -43,6 +43,12 @@ public abstract class StretchedFixedModeMixin implements RSClient
@Inject
private static boolean stretchedKeepAspectRatio;
@Inject
private static Dimension cachedStretchedDimensions;
@Inject
private static Dimension lastCanvasDimensions;
@Inject
@Override
public boolean isStretchedEnabled()
@@ -76,6 +82,7 @@ public abstract class StretchedFixedModeMixin implements RSClient
public void setStretchedKeepAspectRatio(boolean state)
{
stretchedKeepAspectRatio = state;
cachedStretchedDimensions = null;
}
@Inject
@@ -84,23 +91,29 @@ public abstract class StretchedFixedModeMixin implements RSClient
{
Canvas canvas = getCanvas();
int newWidth = canvas.getWidth();
int newHeight = canvas.getHeight();
int width = canvas.getWidth();
int height = canvas.getHeight();
if (stretchedKeepAspectRatio)
if (cachedStretchedDimensions == null || width != lastCanvasDimensions.width || height != lastCanvasDimensions.height)
{
int tempNewWidth = (int) (newHeight * Constants.GAME_FIXED_ASPECT_RATIO);
if (stretchedKeepAspectRatio)
{
int tempNewWidth = (int) (height * Constants.GAME_FIXED_ASPECT_RATIO);
if (tempNewWidth > canvas.getWidth())
{
newHeight = (int) (newWidth / Constants.GAME_FIXED_ASPECT_RATIO);
}
else
{
newWidth = tempNewWidth;
if (tempNewWidth > canvas.getWidth())
{
height = (int) (width / Constants.GAME_FIXED_ASPECT_RATIO);
}
else
{
width = tempNewWidth;
}
}
cachedStretchedDimensions = new Dimension(width, height);
lastCanvasDimensions = new Dimension(width, height);
}
return new Dimension(newWidth, newHeight);
return cachedStretchedDimensions;
}
}