Skip to content

Commit

Permalink
Merge pull request runelite#6119 from devLotto/resizablescaling
Browse files Browse the repository at this point in the history
Stretched Resizable Mode
  • Loading branch information
Adam- authored Oct 31, 2018
2 parents 97849ee + e7aea25 commit 673a290
Show file tree
Hide file tree
Showing 13 changed files with 299 additions and 79 deletions.
35 changes: 26 additions & 9 deletions runelite-api/src/main/java/net/runelite/api/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -1103,9 +1103,9 @@ public interface Client extends GameEngine
RenderOverview getRenderOverview();

/**
* Checked whether the client is in stretched mode.
* Checks whether the client is in stretched mode.
*
* @return true if the client is in stretched, false otherwise
* @return true if the client is in stretched mode, false otherwise
*/
boolean isStretchedEnabled();

Expand All @@ -1117,36 +1117,53 @@ public interface Client extends GameEngine
void setStretchedEnabled(boolean state);

/**
* Checks whether the client is using fast rendering techniques when
* stretching the client in fixed mode.
* Checks whether the client is using fast
* rendering techniques when stretching the canvas.
*
* @return true if client is fast rendering, false otherwise
* @return true if stretching is fast rendering, false otherwise
*/
boolean isStretchedFast();

/**
* Sets whether to use fast rendering techniques when in stretch
* fixed mode.
* Sets whether to use fast rendering techniques
* when stretching the canvas.
*
* @param state new fast rendering state
*/
void setStretchedFast(boolean state);

/**
* Sets whether to force integer scale factor by rounding scale
* factors towards {@code zero} when stretching fixed mode.
* factors towards {@code zero} when stretching.
*
* @param state new integer scaling state
*/
void setStretchedIntegerScaling(boolean state);

/**
* Sets whether to keep aspect ratio when stretching fixed mode.
* Sets whether to keep aspect ratio when stretching.
*
* @param state new keep aspect ratio state
*/
void setStretchedKeepAspectRatio(boolean state);

/**
* Sets the scaling factor when scaling resizable mode.
*
* @param factor new scaling factor
*/
void setScalingFactor(int factor);

/**
* Invalidates cached dimensions that are
* used for stretching and scaling.
*
* @param resize true to tell the game to
* resize the canvas on the next frame,
* false otherwise.
*/
void invalidateStretching(boolean resize);

/**
* Gets the current stretched dimensions of the client.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* 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.api.events;

/**
* An event posted when the canvas size might have changed.
*/
public class CanvasSizeChanged
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@
import lombok.Data;

/**
* An event where the client window has been resized.
* An event where the game has changed from fixed to resizable mode or vice versa.
*/
@Data
public class ResizeableChanged
{
/**
* Whether the window is resized.
* Whether the game is in resizable mode.
*/
private boolean isResized;
}
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ public void draw(MainBufferProvider mainBufferProvider, Graphics graphics, int x
notifier.processFlash(graphics2d);

// Stretch the game image if the user has that enabled
if (!client.isResized() && client.isStretchedEnabled())
if (client.isStretchedEnabled())
{
GraphicsConfiguration gc = clientUi.getGraphicsConfiguration();
Dimension stretchedDimensions = client.getStretchedDimensions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@
* 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.client.plugins.stretchedfixedmode;
package net.runelite.client.plugins.stretchedmode;

import net.runelite.client.config.Config;
import net.runelite.client.config.ConfigGroup;
import net.runelite.client.config.ConfigItem;

@ConfigGroup("stretchedfixedmode")
public interface StretchedFixedModeConfig extends Config
@ConfigGroup("stretchedmode")
public interface StretchedModeConfig extends Config
{
@ConfigItem(
keyName = "keepAspectRatio",
name = "Keep aspect ratio",
description = "Keeps the aspect ratio when stretching"
description = "Keeps the aspect ratio when stretching."
)
default boolean keepAspectRatio()
{
Expand All @@ -45,7 +45,7 @@ default boolean keepAspectRatio()
@ConfigItem(
keyName = "increasedPerformance",
name = "Increased performance mode",
description = "Uses a fast algorithm when stretching, lowering quality but increasing performance"
description = "Uses a fast algorithm when stretching, lowering quality but increasing performance."
)
default boolean increasedPerformance()
{
Expand All @@ -55,10 +55,20 @@ default boolean increasedPerformance()
@ConfigItem(
keyName = "integerScaling",
name = "Integer Scaling",
description = "Forces use of a whole number scale factor"
description = "Forces use of a whole number scale factor when stretching."
)
default boolean integerScaling()
{
return false;
}

@ConfigItem(
keyName = "scalingFactor",
name = "Resizable Scaling (%)",
description = "In resizable mode, the game is reduced in size this much before it's stretched."
)
default int scalingFactor()
{
return 50;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,33 @@
* 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.client.plugins.stretchedfixedmode;
package net.runelite.client.plugins.stretchedmode;

import com.google.common.eventbus.Subscribe;
import com.google.inject.Provides;
import javax.inject.Inject;
import net.runelite.api.Client;
import net.runelite.api.events.CanvasSizeChanged;
import net.runelite.api.events.ConfigChanged;
import net.runelite.api.events.ResizeableChanged;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.input.MouseManager;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor;

@PluginDescriptor(
name = "Stretched Fixed Mode",
description = "Resize the game while in fixed mode",
tags = {"resize"},
name = "Stretched Mode",
description = "Stretches the game in fixed and resizable modes.",
tags = {"resize", "ui", "interface", "stretch", "scaling", "fixed"},
enabledByDefault = false
)
public class StretchedFixedModePlugin extends Plugin
public class StretchedModePlugin extends Plugin
{
@Inject
private Client client;

@Inject
private StretchedFixedModeConfig config;
private StretchedModeConfig config;

@Inject
private MouseManager mouseManager;
Expand All @@ -59,9 +61,9 @@ public class StretchedFixedModePlugin extends Plugin
private TranslateMouseWheelListener mouseWheelListener;

@Provides
StretchedFixedModeConfig provideConfig(ConfigManager configManager)
StretchedModeConfig provideConfig(ConfigManager configManager)
{
return configManager.getConfig(StretchedFixedModeConfig.class);
return configManager.getConfig(StretchedModeConfig.class);
}

@Override
Expand All @@ -83,10 +85,22 @@ protected void shutDown() throws Exception
mouseManager.unregisterMouseWheelListener(mouseWheelListener);
}

@Subscribe
public void onResizableChanged(ResizeableChanged event)
{
client.invalidateStretching(true);
}

@Subscribe
public void onCanvasSizeChanged(CanvasSizeChanged event)
{
client.invalidateStretching(false);
}

@Subscribe
public void onConfigChanged(ConfigChanged event)
{
if (!event.getGroup().equals("stretchedfixedmode"))
if (!event.getGroup().equals("stretchedmode"))
{
return;
}
Expand All @@ -99,5 +113,8 @@ private void updateConfig()
client.setStretchedIntegerScaling(config.integerScaling());
client.setStretchedKeepAspectRatio(config.keepAspectRatio());
client.setStretchedFast(config.increasedPerformance());
client.setScalingFactor(config.scalingFactor());

client.invalidateStretching(true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@
* 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.client.plugins.stretchedfixedmode;
package net.runelite.client.plugins.stretchedmode;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.MouseEvent;
import javax.inject.Inject;
import net.runelite.api.Client;
import net.runelite.api.Constants;
import net.runelite.client.input.MouseListener;

public class TranslateMouseListener implements MouseListener
Expand Down Expand Up @@ -87,17 +86,13 @@ public MouseEvent mouseMoved(MouseEvent mouseEvent)

private MouseEvent translateEvent(MouseEvent e)
{
if (!client.isResized())
{
Dimension stretchedDimensions = client.getStretchedDimensions();
Dimension stretchedDimensions = client.getStretchedDimensions();
Dimension realDimensions = client.getRealDimensions();

int newX = (int) (e.getX() / (stretchedDimensions.width / (double) Constants.GAME_FIXED_WIDTH));
int newY = (int) (e.getY() / (stretchedDimensions.height / (double) Constants.GAME_FIXED_HEIGHT));
int newX = (int) (e.getX() / (stretchedDimensions.width / realDimensions.getWidth()));
int newY = (int) (e.getY() / (stretchedDimensions.height / realDimensions.getHeight()));

return new MouseEvent((Component) e.getSource(), e.getID(), e.getWhen(), e.getModifiersEx(),
newX, newY, e.getClickCount(), e.isPopupTrigger(), e.getButton());
}

return e;
return new MouseEvent((Component) e.getSource(), e.getID(), e.getWhen(), e.getModifiersEx(),
newX, newY, e.getClickCount(), e.isPopupTrigger(), e.getButton());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@
* 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.client.plugins.stretchedfixedmode;
package net.runelite.client.plugins.stretchedmode;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.MouseWheelEvent;
import javax.inject.Inject;
import net.runelite.api.Client;
import net.runelite.api.Constants;
import net.runelite.client.input.MouseWheelListener;

public class TranslateMouseWheelListener implements MouseWheelListener
Expand All @@ -51,17 +50,13 @@ public MouseWheelEvent mouseWheelMoved(MouseWheelEvent event)

private MouseWheelEvent translateEvent(MouseWheelEvent e)
{
if (!client.isResized())
{
Dimension stretchedDimensions = client.getStretchedDimensions();
Dimension stretchedDimensions = client.getStretchedDimensions();
Dimension realDimensions = client.getRealDimensions();

int newX = (int) (e.getX() / (stretchedDimensions.width / (double) Constants.GAME_FIXED_WIDTH));
int newY = (int) (e.getY() / (stretchedDimensions.height / (double) Constants.GAME_FIXED_HEIGHT));
int newX = (int) (e.getX() / (stretchedDimensions.width / realDimensions.getWidth()));
int newY = (int) (e.getY() / (stretchedDimensions.height / realDimensions.getHeight()));

return new MouseWheelEvent((Component) e.getSource(), e.getID(), e.getWhen(), e.getModifiers(), newX, newY,
e.getClickCount(), e.isPopupTrigger(), e.getScrollType(), e.getScrollAmount(), e.getWheelRotation());
}

return e;
return new MouseWheelEvent((Component) e.getSource(), e.getID(), e.getWhen(), e.getModifiers(), newX, newY,
e.getClickCount(), e.isPopupTrigger(), e.getScrollType(), e.getScrollAmount(), e.getWheelRotation());
}
}
Loading

0 comments on commit 673a290

Please sign in to comment.