stretchedfixedmode: add resizable interface scaling

This commit is contained in:
Lotto
2018-10-21 17:56:22 +02:00
parent 2ba20c1859
commit 7cf3e3401a
13 changed files with 285 additions and 65 deletions

View File

@@ -68,6 +68,7 @@ import net.runelite.api.WorldType;
import net.runelite.api.coords.LocalPoint;
import net.runelite.api.coords.WorldPoint;
import net.runelite.api.events.BoostedLevelChanged;
import net.runelite.api.events.CanvasSizeChanged;
import net.runelite.api.events.ChatMessage;
import net.runelite.api.events.ClanChanged;
import net.runelite.api.events.DraggingWidgetChanged;
@@ -155,6 +156,9 @@ public abstract class RSClientMixin implements RSClient
@Inject
private static RSItem lastItemDespawn;
@Inject
private static boolean oldIsResized;
@Inject
@Override
public Callbacks getCallbacks()
@@ -968,9 +972,16 @@ public abstract class RSClientMixin implements RSClient
public static void resizeChanged(int idx)
{
//maybe couple with varbitChanged. resizeable may not be a varbit but it would fit with the other client settings.
ResizeableChanged resizeableChanged = new ResizeableChanged();
resizeableChanged.setResized(client.isResized());
client.getCallbacks().post(resizeableChanged);
boolean isResized = client.isResized();
if (oldIsResized != isResized)
{
ResizeableChanged resizeableChanged = new ResizeableChanged();
resizeableChanged.setResized(isResized);
client.getCallbacks().post(resizeableChanged);
oldIsResized = isResized;
}
}
@FieldHook("clanMemberManager")
@@ -980,6 +991,20 @@ public abstract class RSClientMixin implements RSClient
client.getCallbacks().post(new ClanChanged(client.getClanMemberManager() != null));
}
@FieldHook("canvasWidth")
@Inject
public static void canvasWidthChanged(int idx)
{
client.getCallbacks().post(new CanvasSizeChanged());
}
@FieldHook("canvasHeight")
@Inject
public static void canvasHeightChanged(int idx)
{
client.getCallbacks().post(new CanvasSizeChanged());
}
@Inject
@Override
public boolean hasHintArrow()

View File

@@ -67,7 +67,7 @@ public abstract class RSGameCanvasMixin extends Canvas implements RSGameCanvas
@Override
public void setSize(int width, int height)
{
if (!client.isResized() && client.isStretchedEnabled())
if (client.isStretchedEnabled())
{
super.setSize(client.getStretchedDimensions().width, client.getStretchedDimensions().height);
}
@@ -81,7 +81,7 @@ public abstract class RSGameCanvasMixin extends Canvas implements RSGameCanvas
@Override
public void setLocation(int x, int y)
{
if (!client.isResized() && client.isStretchedEnabled())
if (client.isStretchedEnabled())
{
super.setLocation((getParent().getWidth() - client.getStretchedDimensions().width) / 2, 0);
}

View File

@@ -0,0 +1,58 @@
/*
* Copyright (c) 2018, Lotto <https://github.com/devLotto>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.mixins;
import java.awt.Dimension;
import net.runelite.api.mixins.Copy;
import net.runelite.api.mixins.Mixin;
import net.runelite.api.mixins.Replace;
import net.runelite.api.mixins.Shadow;
import net.runelite.rs.api.RSClient;
import net.runelite.rs.api.RSGameEngine;
@Mixin(RSGameEngine.class)
public abstract class StretchedFixedModeMaxSizeMixin implements RSGameEngine
{
@Shadow("clientInstance")
private static RSClient client;
@Copy("setMaxCanvasSize")
abstract void rs$setMaxCanvasSize(int width, int height);
@Replace("setMaxCanvasSize")
public void setMaxCanvasSize(int width, int height)
{
if (client.isStretchedEnabled() && client.isResized())
{
Dimension realDimensions = client.getRealDimensions();
rs$setMaxCanvasSize(realDimensions.width, realDimensions.height);
}
else
{
rs$setMaxCanvasSize(width, height);
}
}
}

View File

@@ -24,7 +24,8 @@
*/
package net.runelite.mixins;
import java.awt.Canvas;
import com.google.common.primitives.Ints;
import java.awt.Container;
import java.awt.Dimension;
import net.runelite.api.Constants;
import net.runelite.api.mixins.Inject;
@@ -46,11 +47,14 @@ public abstract class StretchedFixedModeMixin implements RSClient
@Inject
private static boolean stretchedKeepAspectRatio;
@Inject
private static double scalingFactor;
@Inject
private static Dimension cachedStretchedDimensions;
@Inject
private static Dimension lastCanvasDimensions;
private static Dimension cachedRealDimensions;
@Inject
@Override
@@ -85,7 +89,6 @@ public abstract class StretchedFixedModeMixin implements RSClient
public void setStretchedIntegerScaling(boolean state)
{
stretchedIntegerScaling = state;
cachedStretchedDimensions = null;
}
@Inject
@@ -93,62 +96,127 @@ public abstract class StretchedFixedModeMixin implements RSClient
public void setStretchedKeepAspectRatio(boolean state)
{
stretchedKeepAspectRatio = state;
cachedStretchedDimensions = null;
}
@Inject
@Override
public void setScalingFactor(int factor)
{
factor = Ints.constrainToRange(factor, 0, 100);
scalingFactor = (100 - factor) / 100D;
}
@Inject
@Override
public Dimension getRealDimensions()
{
if (isStretchedEnabled() && !isResized())
if (!isStretchedEnabled())
{
return Constants.GAME_FIXED_SIZE;
return getCanvas().getSize();
}
return getCanvas().getSize();
if (cachedRealDimensions == null)
{
if (isResized())
{
Container canvasParent = getCanvas().getParent();
int parentWidth = canvasParent.getWidth();
int parentHeight = canvasParent.getHeight();
int widthOffset = parentWidth - Constants.GAME_FIXED_WIDTH;
int heightOffset = parentHeight - Constants.GAME_FIXED_HEIGHT;
int newWidth = Constants.GAME_FIXED_WIDTH + (int) (widthOffset * scalingFactor);
int newHeight = Constants.GAME_FIXED_HEIGHT + (int) (heightOffset * scalingFactor);
cachedRealDimensions = new Dimension(newWidth, newHeight);
}
else
{
cachedRealDimensions = Constants.GAME_FIXED_SIZE;
}
}
return cachedRealDimensions;
}
@Inject
@Override
public Dimension getStretchedDimensions()
{
Canvas canvas = getCanvas();
int width = canvas.getParent().getWidth();
int height = canvas.getParent().getHeight();
if (cachedStretchedDimensions == null || width != lastCanvasDimensions.width || height != lastCanvasDimensions.height)
if (cachedStretchedDimensions == null)
{
Container canvasParent = getCanvas().getParent();
int parentWidth = canvasParent.getWidth();
int parentHeight = canvasParent.getHeight();
Dimension realDimensions = getRealDimensions();
if (stretchedKeepAspectRatio)
{
int tempNewWidth = (int) (height * Constants.GAME_FIXED_ASPECT_RATIO);
double aspectRatio = realDimensions.getWidth() / realDimensions.getHeight();
if (tempNewWidth > canvas.getWidth())
int tempNewWidth = (int) (parentHeight * aspectRatio);
if (tempNewWidth > parentWidth)
{
height = (int) (width / Constants.GAME_FIXED_ASPECT_RATIO);
parentHeight = (int) (parentWidth / aspectRatio);
}
else
{
width = tempNewWidth;
parentWidth = tempNewWidth;
}
}
if (stretchedIntegerScaling)
{
if (width > Constants.GAME_FIXED_WIDTH)
if (parentWidth > realDimensions.width)
{
width = width - (width % Constants.GAME_FIXED_WIDTH);
parentWidth = parentWidth - (parentWidth % realDimensions.width);
}
if (height > Constants.GAME_FIXED_HEIGHT)
if (parentHeight > realDimensions.height)
{
height = height - (height % Constants.GAME_FIXED_HEIGHT);
parentHeight = parentHeight - (parentHeight % realDimensions.height);
}
}
cachedStretchedDimensions = new Dimension(width, height);
lastCanvasDimensions = new Dimension(width, height);
cachedStretchedDimensions = new Dimension(parentWidth, parentHeight);
}
return cachedStretchedDimensions;
}
@Inject
@Override
public void invalidateStretching(boolean resize)
{
cachedStretchedDimensions = null;
cachedRealDimensions = null;
if (resize && isResized())
{
/*
Tells the game to run resizeCanvas the next frame.
resizeCanvas in turn calls the method that
determines the maximum size of the canvas,
AFTER setting the size of the canvas.
The frame after that, the game sees that
the maximum size of the canvas isn't
the current size, so it runs resizeCanvas again.
This time it uses our new maximum size
as the bounds for the canvas size.
This is useful when resizeCanvas wouldn't usually run,
for example when we've only changed the scaling factor
and we still want the game's canvas to resize
with regards to the new maximum bounds.
*/
setResizeCanvasNextFrame(true);
}
}
}