Merge pull request #469 from Lucwousin/clampthatshit
Use MiscUtils.clamp instead of Ints.constrainToRange
This commit is contained in:
@@ -25,7 +25,6 @@
|
||||
package net.runelite.client.game.chatbox;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.primitives.Ints;
|
||||
import com.google.inject.Inject;
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
@@ -58,6 +57,7 @@ import net.runelite.api.widgets.WidgetType;
|
||||
import net.runelite.client.callback.ClientThread;
|
||||
import net.runelite.client.input.KeyListener;
|
||||
import net.runelite.client.input.MouseListener;
|
||||
import net.runelite.client.util.MiscUtils;
|
||||
import net.runelite.client.util.Text;
|
||||
|
||||
@Slf4j
|
||||
@@ -349,8 +349,8 @@ public class ChatboxTextInput extends ChatboxInput implements KeyListener, Mouse
|
||||
|
||||
if (isStartLine || isEndLine || (cursorEnd > line.end && cursorStart < line.start))
|
||||
{
|
||||
final int cIdx = Ints.constrainToRange(cursorStart - line.start, 0, len);
|
||||
final int ceIdx = Ints.constrainToRange(cursorEnd - line.start, 0, len);
|
||||
final int cIdx = MiscUtils.clamp(cursorStart - line.start, 0, len);
|
||||
final int ceIdx = MiscUtils.clamp(cursorEnd - line.start, 0, len);
|
||||
|
||||
lt = Text.escapeJagex(text.substring(0, cIdx));
|
||||
mt = Text.escapeJagex(text.substring(cIdx, ceIdx));
|
||||
@@ -452,7 +452,7 @@ public class ChatboxTextInput extends ChatboxInput implements KeyListener, Mouse
|
||||
int cx = p.x - ccl.getX() - ox;
|
||||
int cy = p.y - ccl.getY() - oy;
|
||||
|
||||
int currentLine = Ints.constrainToRange(cy / oh, 0, editLines.size() - 1);
|
||||
int currentLine = MiscUtils.clamp(cy / oh, 0, editLines.size() - 1);
|
||||
|
||||
final Line line = editLines.get(currentLine);
|
||||
final String tsValue = line.text;
|
||||
@@ -489,7 +489,7 @@ public class ChatboxTextInput extends ChatboxInput implements KeyListener, Mouse
|
||||
break;
|
||||
}
|
||||
|
||||
charIndex = Ints.constrainToRange(charIndex, 0, tsValue.length());
|
||||
charIndex = MiscUtils.clamp(charIndex, 0, tsValue.length());
|
||||
return line.start + charIndex;
|
||||
};
|
||||
|
||||
|
||||
@@ -26,7 +26,6 @@ package net.runelite.client.plugins.config;
|
||||
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.primitives.Ints;
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
@@ -108,6 +107,7 @@ import net.runelite.client.ui.components.IconTextField;
|
||||
import net.runelite.client.ui.components.colorpicker.RuneliteColorPicker;
|
||||
import net.runelite.client.util.ColorUtil;
|
||||
import net.runelite.client.util.ImageUtil;
|
||||
import net.runelite.client.util.MiscUtils;
|
||||
import net.runelite.client.util.Text;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
@@ -701,7 +701,7 @@ public class ConfigPanel extends PluginPanel
|
||||
}
|
||||
|
||||
// Config may previously have been out of range
|
||||
value = Ints.constrainToRange(value, min, max);
|
||||
value = MiscUtils.clamp(value, min, max);
|
||||
|
||||
if (max < Integer.MAX_VALUE)
|
||||
{
|
||||
|
||||
@@ -27,7 +27,6 @@ package net.runelite.client.plugins.devtools;
|
||||
import ch.qos.logback.classic.Level;
|
||||
import ch.qos.logback.classic.Logger;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.primitives.Ints;
|
||||
import com.google.inject.Provides;
|
||||
import java.awt.image.BufferedImage;
|
||||
import static java.lang.Math.min;
|
||||
@@ -60,6 +59,7 @@ import net.runelite.client.ui.NavigationButton;
|
||||
import net.runelite.client.ui.overlay.OverlayManager;
|
||||
import net.runelite.client.util.ColorUtil;
|
||||
import net.runelite.client.util.ImageUtil;
|
||||
import net.runelite.client.util.MiscUtils;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@PluginDescriptor(
|
||||
@@ -288,7 +288,7 @@ public class DevToolsPlugin extends Plugin
|
||||
Skill skill = Skill.valueOf(args[0].toUpperCase());
|
||||
int level = Integer.parseInt(args[1]);
|
||||
|
||||
level = Ints.constrainToRange(level, 1, Experience.MAX_REAL_LEVEL);
|
||||
level = MiscUtils.clamp(level, 1, Experience.MAX_REAL_LEVEL);
|
||||
int xp = Experience.getXpForLevel(level);
|
||||
|
||||
client.getBoostedSkillLevels()[skill.ordinal()] = level;
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
*/
|
||||
package net.runelite.client.plugins.zoom;
|
||||
|
||||
import com.google.common.primitives.Ints;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provides;
|
||||
import java.awt.event.KeyEvent;
|
||||
@@ -41,6 +40,7 @@ import net.runelite.client.input.KeyListener;
|
||||
import net.runelite.client.input.KeyManager;
|
||||
import net.runelite.client.plugins.Plugin;
|
||||
import net.runelite.client.plugins.PluginDescriptor;
|
||||
import net.runelite.client.util.MiscUtils;
|
||||
|
||||
@PluginDescriptor(
|
||||
name = "Camera Zoom",
|
||||
@@ -103,7 +103,7 @@ public class ZoomPlugin extends Plugin implements KeyListener
|
||||
|
||||
if ("outerZoomLimit".equals(event.getEventName()))
|
||||
{
|
||||
int outerLimit = Ints.constrainToRange(zoomConfig.outerLimit(), ZoomConfig.OUTER_LIMIT_MIN, ZoomConfig.OUTER_LIMIT_MAX);
|
||||
int outerLimit = MiscUtils.clamp(zoomConfig.outerLimit(), ZoomConfig.OUTER_LIMIT_MIN, ZoomConfig.OUTER_LIMIT_MAX);
|
||||
int outerZoomLimit = 128 - outerLimit;
|
||||
intStack[intStackSize - 1] = outerZoomLimit;
|
||||
return;
|
||||
@@ -192,7 +192,7 @@ public class ZoomPlugin extends Plugin implements KeyListener
|
||||
controlDown = false;
|
||||
if (zoomConfig.controlFunction() == ControlFunction.CONTROL_TO_RESET)
|
||||
{
|
||||
final int zoomValue = Ints.constrainToRange(zoomConfig.ctrlZoomValue(), zoomConfig.OUTER_LIMIT_MIN, INNER_ZOOM_LIMIT);
|
||||
final int zoomValue = MiscUtils.clamp(zoomConfig.ctrlZoomValue(), zoomConfig.OUTER_LIMIT_MIN, INNER_ZOOM_LIMIT);
|
||||
clientThread.invokeLater(() -> client.runScript(ScriptID.CAMERA_DO_ZOOM, zoomValue, zoomValue));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
*/
|
||||
package net.runelite.client.ui.components.colorpicker;
|
||||
|
||||
import com.google.common.primitives.Ints;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.GradientPaint;
|
||||
@@ -39,6 +38,7 @@ import java.awt.image.BufferedImage;
|
||||
import java.util.function.Consumer;
|
||||
import javax.swing.JPanel;
|
||||
import lombok.Setter;
|
||||
import net.runelite.client.util.MiscUtils;
|
||||
|
||||
public class ColorPanel extends JPanel
|
||||
{
|
||||
@@ -144,8 +144,8 @@ public class ColorPanel extends JPanel
|
||||
return;
|
||||
}
|
||||
|
||||
x = Ints.constrainToRange(x, 0, size - 1);
|
||||
y = Ints.constrainToRange(y, 0, size - 1);
|
||||
x = MiscUtils.clamp(x, 0, size - 1);
|
||||
y = MiscUtils.clamp(y, 0, size - 1);
|
||||
|
||||
targetPosition = new Point(x, y);
|
||||
paintImmediately(0, 0, size, size);
|
||||
@@ -200,8 +200,8 @@ public class ColorPanel extends JPanel
|
||||
*/
|
||||
private Color colorAt(int x, int y)
|
||||
{
|
||||
x = Ints.constrainToRange(x, 0, size - 1);
|
||||
y = Ints.constrainToRange(y, 0, size - 1);
|
||||
x = MiscUtils.clamp(x, 0, size - 1);
|
||||
y = MiscUtils.clamp(y, 0, size - 1);
|
||||
return new Color(image.getRGB(x, y));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
*/
|
||||
package net.runelite.client.ui.components.colorpicker;
|
||||
|
||||
import com.google.common.primitives.Ints;
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.event.MouseAdapter;
|
||||
@@ -35,6 +34,7 @@ import java.util.function.Consumer;
|
||||
import javax.swing.JPanel;
|
||||
import lombok.Setter;
|
||||
import net.runelite.client.util.ColorUtil;
|
||||
import net.runelite.client.util.MiscUtils;
|
||||
|
||||
public class ColorValueSlider extends JPanel
|
||||
{
|
||||
@@ -83,7 +83,7 @@ public class ColorValueSlider extends JPanel
|
||||
|
||||
private void moveTarget(int x, boolean shouldUpdate)
|
||||
{
|
||||
value = Ints.constrainToRange(x, ColorUtil.MIN_RGB_VALUE + KNOB_WIDTH, ColorUtil.MAX_RGB_VALUE + KNOB_WIDTH);
|
||||
value = MiscUtils.clamp(x, ColorUtil.MIN_RGB_VALUE + KNOB_WIDTH, ColorUtil.MAX_RGB_VALUE + KNOB_WIDTH);
|
||||
paintImmediately(0, 0, this.getWidth(), this.getHeight());
|
||||
|
||||
if (shouldUpdate && onValueChanged != null)
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
*/
|
||||
package net.runelite.client.ui.components.colorpicker;
|
||||
|
||||
import com.google.common.primitives.Ints;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
@@ -36,6 +35,7 @@ import java.util.function.Consumer;
|
||||
import javax.swing.JPanel;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.runelite.client.util.MiscUtils;
|
||||
|
||||
public class HuePanel extends JPanel
|
||||
{
|
||||
@@ -94,7 +94,7 @@ public class HuePanel extends JPanel
|
||||
*/
|
||||
private void moveSelector(int y)
|
||||
{
|
||||
y = Ints.constrainToRange(y, 0, height - 1);
|
||||
y = MiscUtils.clamp(y, 0, height - 1);
|
||||
if (y == this.selectedY)
|
||||
{
|
||||
return;
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
package net.runelite.client.ui.overlay;
|
||||
|
||||
import com.google.common.base.MoreObjects;
|
||||
import com.google.common.primitives.Ints;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics2D;
|
||||
@@ -54,6 +53,7 @@ import net.runelite.client.input.MouseAdapter;
|
||||
import net.runelite.client.input.MouseManager;
|
||||
import net.runelite.client.ui.JagexColors;
|
||||
import net.runelite.client.util.ColorUtil;
|
||||
import net.runelite.client.util.MiscUtils;
|
||||
|
||||
@Singleton
|
||||
public class OverlayRenderer extends MouseAdapter implements KeyListener
|
||||
@@ -250,8 +250,8 @@ public class OverlayRenderer extends MouseAdapter implements KeyListener
|
||||
}
|
||||
|
||||
final Dimension realDimensions = client.getRealDimensions();
|
||||
location.x = Ints.constrainToRange(location.x, 0, Math.max(0, realDimensions.width - dimension.width));
|
||||
location.y = Ints.constrainToRange(location.y, 0, Math.max(0, realDimensions.height - dimension.height));
|
||||
location.x = MiscUtils.clamp(location.x, 0, Math.max(0, realDimensions.width - dimension.width));
|
||||
location.y = MiscUtils.clamp(location.y, 0, Math.max(0, realDimensions.height - dimension.height));
|
||||
}
|
||||
|
||||
if (overlay.getPreferredSize() != null)
|
||||
@@ -347,8 +347,8 @@ public class OverlayRenderer extends MouseAdapter implements KeyListener
|
||||
{
|
||||
final Dimension realDimension = client.getRealDimensions();
|
||||
mousePoint.translate(-overlayOffset.x, -overlayOffset.y);
|
||||
mousePoint.x = Ints.constrainToRange(mousePoint.x, 0, Math.max(0, realDimension.width - movedOverlay.getBounds().width));
|
||||
mousePoint.y = Ints.constrainToRange(mousePoint.y, 0, Math.max(0, realDimension.height - movedOverlay.getBounds().height));
|
||||
mousePoint.x = MiscUtils.clamp(mousePoint.x, 0, Math.max(0, realDimension.width - movedOverlay.getBounds().width));
|
||||
mousePoint.y = MiscUtils.clamp(mousePoint.y, 0, Math.max(0, realDimension.height - movedOverlay.getBounds().height));
|
||||
movedOverlay.setPreferredPosition(null);
|
||||
movedOverlay.setPreferredLocation(mousePoint);
|
||||
mouseEvent.consume();
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
*/
|
||||
package net.runelite.client.util;
|
||||
|
||||
import com.google.common.primitives.Ints;
|
||||
import java.awt.Color;
|
||||
import java.util.regex.Pattern;
|
||||
import javax.annotation.Nonnull;
|
||||
@@ -171,7 +170,7 @@ public class ColorUtil
|
||||
*/
|
||||
public static int constrainValue(int value)
|
||||
{
|
||||
return Ints.constrainToRange(value, MIN_RGB_VALUE, MAX_RGB_VALUE);
|
||||
return MiscUtils.clamp(value, MIN_RGB_VALUE, MAX_RGB_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user