Allow screenmarker resizing below base point

This commit is contained in:
Kamiel
2018-06-03 22:12:56 -04:00
committed by Adam
parent 40771c5918
commit 983ab1d540
2 changed files with 10 additions and 33 deletions

View File

@@ -24,10 +24,7 @@
*/ */
package net.runelite.client.plugins.screenmarkers; package net.runelite.client.plugins.screenmarkers;
import java.awt.Point;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import static java.lang.Math.max;
import static java.lang.Math.min;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import net.runelite.client.input.MouseListener; import net.runelite.client.input.MouseListener;
@@ -36,7 +33,6 @@ import net.runelite.client.input.MouseListener;
public class ScreenMarkerMouseListener extends MouseListener public class ScreenMarkerMouseListener extends MouseListener
{ {
private final ScreenMarkerPlugin plugin; private final ScreenMarkerPlugin plugin;
private Point lastMousePoint = null;
ScreenMarkerMouseListener(ScreenMarkerPlugin plugin) ScreenMarkerMouseListener(ScreenMarkerPlugin plugin)
{ {
@@ -65,13 +61,11 @@ public class ScreenMarkerMouseListener extends MouseListener
if (SwingUtilities.isLeftMouseButton(event)) if (SwingUtilities.isLeftMouseButton(event))
{ {
lastMousePoint = event.getPoint();
plugin.startCreation(event.getPoint()); plugin.startCreation(event.getPoint());
} }
else if (plugin.isCreatingScreenMarker()) else if (plugin.isCreatingScreenMarker())
{ {
plugin.finishCreation(true); plugin.finishCreation(true);
lastMousePoint = null;
} }
event.consume(); event.consume();
@@ -106,29 +100,7 @@ public class ScreenMarkerMouseListener extends MouseListener
if (SwingUtilities.isLeftMouseButton(event)) if (SwingUtilities.isLeftMouseButton(event))
{ {
Point currentPoint = event.getPoint(); plugin.resizeMarker(event.getPoint());
int dx = currentPoint.x - lastMousePoint.x;
int dy = currentPoint.y - lastMousePoint.y;
//if shift is down, constrain proportions
if (event.isShiftDown() && dx != dy)
{
int x = dx;
if (dx > 0 || dy > 0)
{
dx = max(dx, dy);
dy = max(dy, x);
}
else
{
dx = min(dx, dy);
dy = min(dy, x);
}
}
plugin.resizeMarker(dx, dy);
lastMousePoint = currentPoint;
} }
return event; return event;

View File

@@ -32,6 +32,7 @@ import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Point; import java.awt.Point;
import java.awt.Rectangle;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.time.Instant; import java.time.Instant;
import java.util.ArrayList; import java.util.ArrayList;
@@ -95,6 +96,7 @@ public class ScreenMarkerPlugin extends Plugin
@Getter @Getter
private boolean creatingScreenMarker = false; private boolean creatingScreenMarker = false;
private Point startLocation = null;
@Override @Override
public Collection<Overlay> getOverlays() public Collection<Overlay> getOverlays()
@@ -180,6 +182,7 @@ public class ScreenMarkerPlugin extends Plugin
); );
// Set overlay creator bounds to current position and default size // Set overlay creator bounds to current position and default size
startLocation = location;
overlay.setPreferredLocation(location); overlay.setPreferredLocation(location);
overlay.setPreferredSize(DEFAULT_SIZE); overlay.setPreferredSize(DEFAULT_SIZE);
creatingScreenMarker = true; creatingScreenMarker = true;
@@ -201,6 +204,7 @@ public class ScreenMarkerPlugin extends Plugin
} }
creatingScreenMarker = false; creatingScreenMarker = false;
startLocation = null;
currentMarker = null; currentMarker = null;
setMouseListenerEnabled(false); setMouseListenerEnabled(false);
@@ -222,11 +226,12 @@ public class ScreenMarkerPlugin extends Plugin
overlayRenderer.rebuildOverlays(); overlayRenderer.rebuildOverlays();
} }
public void resizeMarker(int dx, int dy) void resizeMarker(Point point)
{ {
// TODO: Allow resizing below base point Rectangle bounds = new Rectangle(startLocation);
Dimension currentSize = overlay.getPreferredSize(); bounds.add(point);
overlay.setPreferredSize(new Dimension(currentSize.width + dx, currentSize.height + dy)); overlay.setPreferredLocation(bounds.getLocation());
overlay.setPreferredSize(bounds.getSize());
} }
public void updateConfig() public void updateConfig()