Java Code Examples for net.runelite.api.Point#getX()

The following examples show how to use net.runelite.api.Point#getX() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Jarvis.java    From runelite with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Computes and returns the convex hull of the passed points.
 * <p>
 * The size of the list must be at least 3, otherwise this method will
 * return null.
 *
 * @param points list of points
 * @return list containing the points part of the convex hull
 */
@Deprecated
public static List<Point> convexHull(List<Point> points)
{
	int[] xs = new int[points.size()];
	int[] ys = new int[xs.length];
	for (int i = 0; i < xs.length; i++)
	{
		Point p = points.get(i);
		xs[i] = p.getX();
		ys[i] = p.getY();
	}

	SimplePolygon poly = convexHull(xs, ys);
	if (poly == null)
	{
		return null;
	}

	return poly.toRuneLitePointList();
}
 
Example 2
Source File: OverlayUtil.java    From runelite with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public static void renderTextLocation(Graphics2D graphics, Point txtLoc, String text, Color color)
{
	if (Strings.isNullOrEmpty(text))
	{
		return;
	}

	int x = txtLoc.getX();
	int y = txtLoc.getY();

	graphics.setColor(Color.BLACK);
	graphics.drawString(text, x + 1, y + 1);

	graphics.setColor(color);
	graphics.drawString(text, x, y);
}
 
Example 3
Source File: WoodcuttingPlugin.java    From plugins with GNU General Public License v3.0 5 votes vote down vote up
@Subscribe
private void onGameObjectDespawned(final GameObjectDespawned event)
{
	final GameObject object = event.getGameObject();

	Tree tree = Tree.findTree(object.getId());
	if (tree != null)
	{
		if (tree.getRespawnTime() != null && !recentlyLoggedIn && currentPlane == object.getPlane())
		{
			Point max = object.getSceneMaxLocation();
			Point min = object.getSceneMinLocation();
			int lenX = max.getX() - min.getX();
			int lenY = max.getY() - min.getY();
			log.debug("Adding respawn timer for {} tree at {}", tree, object.getLocalLocation());

			final int region = client.getLocalPlayer().getWorldLocation().getRegionID();
			TreeRespawn treeRespawn = new TreeRespawn(tree, lenX, lenY, WorldPoint.fromScene(client, min.getX(), min.getY(), client.getPlane()), Instant.now(), (int) tree.getRespawnTime(region).toMillis());
			respawns.add(treeRespawn);
		}

		if (tree == Tree.REDWOOD)
		{
			treeObjects.remove(event.getGameObject());
		}
	}
}
 
Example 4
Source File: PortalWeaknessOverlay.java    From plugins with GNU General Public License v3.0 5 votes vote down vote up
private void renderDoublePortalWeakness(
	Graphics2D graphics,
	Portal portal,
	BufferedImage imageLeft,
	BufferedImage imageRight
)
{
	Point portalPoint = getPortalPoint(portal);

	if (portalPoint != null)
	{
		Point portalLeft = new Point(
			portalPoint.getX() - (imageLeft.getWidth() / 2) - 5,
			portalPoint.getY()
		);

		Point portalRight = new Point(
			portalPoint.getX() + (imageRight.getWidth() / 2) + 5,
			portalPoint.getY()
		);

		Composite originalComposite = graphics.getComposite();
		Composite translucentComposite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.6f);
		graphics.setComposite(translucentComposite);

		OverlayUtil.renderImageLocation(graphics, portalLeft, imageLeft);
		OverlayUtil.renderImageLocation(graphics, portalRight, imageRight);

		graphics.setComposite(originalComposite);
	}
}
 
Example 5
Source File: WoodcuttingPlugin.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Subscribe
public void onGameObjectDespawned(final GameObjectDespawned event)
{
	final GameObject object = event.getGameObject();

	Tree tree = Tree.findTree(object.getId());
	if (tree != null)
	{
		if (tree.getRespawnTime() != null && !recentlyLoggedIn && currentPlane == object.getPlane())
		{
			Point max = object.getSceneMaxLocation();
			Point min = object.getSceneMinLocation();
			int lenX = max.getX() - min.getX();
			int lenY = max.getY() - min.getY();
			log.debug("Adding respawn timer for {} tree at {}", tree, object.getLocalLocation());

			final int region = client.getLocalPlayer().getWorldLocation().getRegionID();
			TreeRespawn treeRespawn = new TreeRespawn(tree, lenX, lenY, WorldPoint.fromScene(client, min.getX(), min.getY(), client.getPlane()), Instant.now(), (int) tree.getRespawnTime(region).toMillis());
			respawns.add(treeRespawn);
		}

		if (tree == Tree.REDWOOD)
		{
			treeObjects.remove(event.getGameObject());
		}
	}
}
 
Example 6
Source File: ScreenshotPlugin.java    From plugins with GNU General Public License v3.0 5 votes vote down vote up
private void takeScreenshot(String fileName, String subDir, Image image)
{
	if (!config.includeOverlays())
	{
		overlayRenderer.setShouldRender(false);
	}
	BufferedImage screenshot = config.includeFrame()
		? new BufferedImage(clientUi.getWidth(), clientUi.getHeight(), BufferedImage.TYPE_INT_ARGB)
		: new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB);

	Graphics graphics = screenshot.getGraphics();

	int gameOffsetX = 0;
	int gameOffsetY = 0;

	if (config.includeFrame())
	{
		// Draw the client frame onto the screenshot
		try
		{
			SwingUtilities.invokeAndWait(() -> clientUi.paint(graphics));
		}
		catch (InterruptedException | InvocationTargetException e)
		{
			log.warn("unable to paint client UI on screenshot", e);
		}

		// Evaluate the position of the game inside the frame
		final Point canvasOffset = clientUi.getCanvasOffset();
		gameOffsetX = canvasOffset.getX();
		gameOffsetY = canvasOffset.getY();
	}

	// Draw the game onto the screenshot
	graphics.drawImage(image, gameOffsetX, gameOffsetY, null);
	imageCapture.takeScreenshot(screenshot, fileName, subDir, config.notifyWhenTaken(), config.uploadScreenshot());
	overlayRenderer.setShouldRender(true);
}
 
Example 7
Source File: WorldArea.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Checks whether this area is within melee distance of another.
 * <p>
 * Melee distance is exactly 1 tile, so this method computes and returns
 * whether the shortest distance to the passed area is directly
 * on the outside of this areas edge.
 *
 * @param other the other area
 * @return true if in melee distance, false otherwise
 */
public boolean isInMeleeDistance(WorldArea other)
{
	if (other == null || this.getPlane() != other.getPlane())
	{
		return false;
	}

	Point distances = getAxisDistances(other);
	return distances.getX() + distances.getY() == 1;
}
 
Example 8
Source File: OverlayUtil.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static void renderImageLocation(Graphics2D graphics, Point imgLoc, BufferedImage image)
{
	int x = imgLoc.getX();
	int y = imgLoc.getY();

	graphics.drawImage(image, x, y, null);
}
 
Example 9
Source File: ImplingMinimapOverlay.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public Dimension render(Graphics2D graphics)
{
	List<NPC> imps = plugin.getImplings();
	if (imps.isEmpty())
	{
		return null;
	}

	for (NPC imp : imps)
	{
		Point impLocation = imp.getMinimapLocation();
		Color color = plugin.npcToColor(imp);
		if (!plugin.showNpc(imp) || impLocation == null || color == null)
		{
			continue;
		}

		OverlayUtil.renderMinimapLocation(graphics, impLocation, color);

		if (config.showName())
		{
			Point textLocation = new Point(impLocation.getX() + 1, impLocation.getY());
			OverlayUtil.renderTextLocation(graphics, textLocation, imp.getName(), color);
		}
	}

	return null;
}
 
Example 10
Source File: VirtualLevelsPlugin.java    From plugins with GNU General Public License v3.0 5 votes vote down vote up
void takeScreenshot(String fileName, String subDir, Image image)
{
	final boolean includeFrame = configManager.getConfiguration("screenshot", "includeFrame").equals("true");

	BufferedImage screenshot = includeFrame
		? new BufferedImage(clientUi.getWidth(), clientUi.getHeight(), BufferedImage.TYPE_INT_ARGB)
		: new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB);

	Graphics graphics = screenshot.getGraphics();

	int gameOffsetX = 0;
	int gameOffsetY = 0;

	if (includeFrame)
	{
		// Draw the client frame onto the screenshot
		try
		{
			SwingUtilities.invokeAndWait(() -> clientUi.paint(graphics));
		}
		catch (InterruptedException | InvocationTargetException e)
		{
			log.warn("unable to paint client UI on screenshot", e);
		}

		// Evaluate the position of the game inside the frame
		final Point canvasOffset = clientUi.getCanvasOffset();
		gameOffsetX = canvasOffset.getX();
		gameOffsetY = canvasOffset.getY();
	}

	// Draw the game onto the screenshot
	graphics.drawImage(image, gameOffsetX, gameOffsetY, null);
	imageCapture.takeScreenshot(
		screenshot,
		fileName,
		subDir,
		configManager.getConfiguration("screenshot", "notifyWhenTaken").equals("true"),
		ImageUploadStyle.valueOf(configManager.getConfiguration("screenshot", "uploadScreenshot")));
}
 
Example 11
Source File: WorldArea.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Checks whether this area intersects with another.
 *
 * @param other the other area
 * @return true if the areas intersect, false otherwise
 */
public boolean intersectsWith(WorldArea other)
{
	if (this.getPlane() != other.getPlane())
	{
		return false;
	}

	Point distances = getAxisDistances(other);
	return distances.getX() + distances.getY() == 0;
}
 
Example 12
Source File: RaidsPlugin.java    From runelite with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * Finds the lobby room index in the room array
 * There are 8 rooms per floor in a 4 wide (x) and 2 high (y) rectangle
 * The rooms on plane 3 (the lobby plane) have the following indexes
 *     0 1 2 3
 *     4 5 6 7
 */
private int findLobbyIndex(Point gridBase)
{
	int x;
	int y;

	// the lobby will always be on the top/first floor (plane 3)
	Tile[][] tiles = client.getScene().getTiles()[LOBBY_PLANE];

	/*
	 * if there is no room north the lobby then it is the north most room
	 * The north rooms will have a y value of 0 and the south will have a value of 1
	 * The rooms have the following y values
	 *     0 0 0 0
	 *     1 1 1 1
	 */
	if (tiles[gridBase.getX()][gridBase.getY() + RaidRoom.ROOM_MAX_SIZE] == null)
	{
		y = 0;
	}
	else
	{
		y = 1;
	}

	/*
	 * if there is no room east of the lobby then it is the east most room
	 * The west most room will have a value of 0 and the east most will have a value of 3
	 * The rooms have the following x values
	 *     0 1 2 3
	 *     0 1 2 3
	 */
	if (tiles[gridBase.getX() + RaidRoom.ROOM_MAX_SIZE][gridBase.getY()] == null)
	{
		x = 3;
	}
	else
	{
		// determine x based on how many rooms are to the west of it.
		for (x = 0; x < 3; x++)
		{
			int sceneX = gridBase.getX() - 1 - RaidRoom.ROOM_MAX_SIZE * x;
			if (sceneX < 0 || tiles[sceneX][gridBase.getY()] == null)
			{
				break;
			}
		}
	}

	// the room index based on its x and y values
	return x + y * AMOUNT_OF_ROOMS_PER_X_AXIS_PER_PLANE;
}
 
Example 13
Source File: WorldMapOverlay.java    From runelite with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * Get the screen coordinates for a WorldPoint on the world map
 * @param worldPoint WorldPoint to get screen coordinates of
 * @return Point of screen coordinates of the center of the world point
 */
public Point mapWorldPointToGraphicsPoint(WorldPoint worldPoint)
{
	RenderOverview ro = client.getRenderOverview();

	if (!ro.getWorldMapData().surfaceContainsPosition(worldPoint.getX(), worldPoint.getY()))
	{
		return null;
	}

	Float pixelsPerTile = ro.getWorldMapZoom();

	Widget map = client.getWidget(WidgetInfo.WORLD_MAP_VIEW);
	if (map != null)
	{
		Rectangle worldMapRect = map.getBounds();

		int widthInTiles = (int) Math.ceil(worldMapRect.getWidth() / pixelsPerTile);
		int heightInTiles = (int) Math.ceil(worldMapRect.getHeight() / pixelsPerTile);

		Point worldMapPosition = ro.getWorldMapPosition();

		//Offset in tiles from anchor sides
		int yTileMax = worldMapPosition.getY() - heightInTiles / 2;
		int yTileOffset = (yTileMax - worldPoint.getY() - 1) * -1;
		int xTileOffset = worldPoint.getX() + widthInTiles / 2 - worldMapPosition.getX();

		int xGraphDiff = ((int) (xTileOffset * pixelsPerTile));
		int yGraphDiff = (int) (yTileOffset * pixelsPerTile);

		//Center on tile.
		yGraphDiff -= pixelsPerTile - Math.ceil(pixelsPerTile / 2);
		xGraphDiff += pixelsPerTile - Math.ceil(pixelsPerTile / 2);

		yGraphDiff = worldMapRect.height - yGraphDiff;
		yGraphDiff += (int) worldMapRect.getY();
		xGraphDiff += (int) worldMapRect.getX();

		return new Point(xGraphDiff, yGraphDiff);
	}
	return null;
}
 
Example 14
Source File: NpcSceneOverlay.java    From runelite with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private void renderNpcRespawn(final MemorizedNpc npc, final Graphics2D graphics)
{
	if (npc.getPossibleRespawnLocations().isEmpty())
	{
		return;
	}

	final WorldPoint respawnLocation = npc.getPossibleRespawnLocations().get(0);
	final LocalPoint lp = LocalPoint.fromWorld(client, respawnLocation.getX(), respawnLocation.getY());

	if (lp == null)
	{
		return;
	}

	final Color color = config.getHighlightColor();

	final LocalPoint centerLp = new LocalPoint(
		lp.getX() + Perspective.LOCAL_TILE_SIZE * (npc.getNpcSize() - 1) / 2,
		lp.getY() + Perspective.LOCAL_TILE_SIZE * (npc.getNpcSize() - 1) / 2);

	final Polygon poly = Perspective.getCanvasTileAreaPoly(client, centerLp, npc.getNpcSize());

	if (poly != null)
	{
		OverlayUtil.renderPolygon(graphics, poly, color);
	}

	final Instant now = Instant.now();
	final double baseTick = ((npc.getDiedOnTick() + npc.getRespawnTime()) - client.getTickCount()) * (Constants.GAME_TICK_LENGTH / 1000.0);
	final double sinceLast = (now.toEpochMilli() - plugin.getLastTickUpdate().toEpochMilli()) / 1000.0;
	final double timeLeft = Math.max(0.0, baseTick - sinceLast);
	final String timeLeftStr = TIME_LEFT_FORMATTER.format(timeLeft);

	final int textWidth = graphics.getFontMetrics().stringWidth(timeLeftStr);
	final int textHeight = graphics.getFontMetrics().getAscent();

	final Point canvasPoint = Perspective
		.localToCanvas(client, centerLp, respawnLocation.getPlane());

	if (canvasPoint != null)
	{
		final Point canvasCenterPoint = new Point(
			canvasPoint.getX() - textWidth / 2,
			canvasPoint.getY() + textHeight / 2);

		OverlayUtil.renderTextLocation(graphics, canvasCenterPoint, timeLeftStr, TEXT_COLOR);
	}
}
 
Example 15
Source File: XpGlobesOverlay.java    From runelite with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private void renderProgressCircle(Graphics2D graphics, XpGlobe skillToDraw, int startXp, int goalXp, int x, int y, Rectangle bounds)
{
	double radiusCurrentXp = getSkillProgressRadius(startXp, skillToDraw.getCurrentXp(), goalXp);
	double radiusToGoalXp = 360; //draw a circle

	Ellipse2D backgroundCircle = drawEllipse(graphics, x, y);

	drawSkillImage(graphics, skillToDraw, x, y);

	Point mouse = client.getMouseCanvasPosition();
	int mouseX = mouse.getX() - bounds.x;
	int mouseY = mouse.getY() - bounds.y;

	// If mouse is hovering the globe
	if (backgroundCircle.contains(mouseX, mouseY))
	{
		// Fill a darker overlay circle
		graphics.setColor(DARK_OVERLAY_COLOR);
		graphics.fill(backgroundCircle);

		drawProgressLabel(graphics, skillToDraw, startXp, goalXp, x, y);

		if (config.enableTooltips())
		{
			drawTooltip(skillToDraw, goalXp);
		}
	}

	graphics.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);

	drawProgressArc(
		graphics,
		x, y,
		config.xpOrbSize(), config.xpOrbSize(),
		PROGRESS_RADIUS_REMAINDER, radiusToGoalXp,
		5,
		config.progressOrbOutLineColor()
	);
	drawProgressArc(
		graphics,
		x, y,
		config.xpOrbSize(), config.xpOrbSize(),
		PROGRESS_RADIUS_START, radiusCurrentXp,
		config.progressArcStrokeWidth(),
		config.enableCustomArcColor() ? config.progressArcColor() : SkillColor.find(skillToDraw.getSkill()).getColor());
}
 
Example 16
Source File: NpcSceneOverlay.java    From plugins with GNU General Public License v3.0 4 votes vote down vote up
private void renderNpcRespawn(final MemorizedNpc npc, final Graphics2D graphics)
{
	if (npc.getPossibleRespawnLocations().isEmpty())
	{
		return;
	}

	final WorldPoint respawnLocation = npc.getPossibleRespawnLocations().get(0);
	final LocalPoint lp = LocalPoint.fromWorld(client, respawnLocation.getX(), respawnLocation.getY());

	if (lp == null)
	{
		return;
	}

	final Color color = config.getHighlightColor();

	final LocalPoint centerLp = new LocalPoint(
		lp.getX() + Perspective.LOCAL_TILE_SIZE * (npc.getNpcSize() - 1) / 2,
		lp.getY() + Perspective.LOCAL_TILE_SIZE * (npc.getNpcSize() - 1) / 2);

	final Polygon poly = Perspective.getCanvasTileAreaPoly(client, centerLp, npc.getNpcSize());

	if (poly != null)
	{
		OverlayUtil.renderPolygon(graphics, poly, color);
	}


	final String timeLeftStr = plugin.formatTime(plugin.getTimeLeftForNpc(npc));

	final int textWidth = graphics.getFontMetrics().stringWidth(timeLeftStr);
	final int textHeight = graphics.getFontMetrics().getAscent();

	final Point canvasPoint = Perspective
		.localToCanvas(client, centerLp, respawnLocation.getPlane());

	if (canvasPoint != null)
	{
		final Point canvasCenterPoint = new Point(
			canvasPoint.getX() - textWidth / 2,
			canvasPoint.getY() + textHeight / 2);

		OverlayUtil.renderTextLocation(graphics, canvasCenterPoint, timeLeftStr, TEXT_COLOR);
	}
}
 
Example 17
Source File: XpGlobesOverlay.java    From plugins with GNU General Public License v3.0 4 votes vote down vote up
private void renderProgressCircle(Graphics2D graphics, XpGlobe skillToDraw, int startXp, int goalXp, int x, int y, Rectangle bounds)
{
	double radiusCurrentXp = getSkillProgressRadius(startXp, skillToDraw.getCurrentXp(), goalXp);
	double radiusToGoalXp = 360; //draw a circle

	Ellipse2D backgroundCircle = drawEllipse(graphics, x, y);

	drawSkillImage(graphics, skillToDraw, x, y);

	Point mouse = client.getMouseCanvasPosition();
	int mouseX = mouse.getX() - bounds.x;
	int mouseY = mouse.getY() - bounds.y;

	// If mouse is hovering the globe
	if (backgroundCircle.contains(mouseX, mouseY))
	{
		// Fill a darker overlay circle
		graphics.setColor(DARK_OVERLAY_COLOR);
		graphics.fill(backgroundCircle);

		drawProgressLabel(graphics, skillToDraw, startXp, goalXp, x, y);

		if (config.enableTooltips())
		{
			drawTooltip(skillToDraw, goalXp);
		}
	}

	graphics.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);

	drawProgressArc(
		graphics,
		x, y,
		config.xpOrbSize(), config.xpOrbSize(),
		PROGRESS_RADIUS_REMAINDER, radiusToGoalXp,
		5,
		config.progressOrbOutLineColor()
	);
	drawProgressArc(
		graphics,
		x, y,
		config.xpOrbSize(), config.xpOrbSize(),
		PROGRESS_RADIUS_START, radiusCurrentXp,
		config.progressArcStrokeWidth(),
		config.enableCustomArcColor() ? config.progressArcColor() : SkillColor.find(skillToDraw.getSkill()).getColor());
}
 
Example 18
Source File: IDAStarMM.java    From plugins with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Assumes locBlank is first point for swap and locVal is last point for swap
 * <p>
 * swap(locBlank, loc1);
 * swap(loc1, loc2);
 * swap(loc2, locVal);
 */
private void performSwapPattern(Point locBlank, Point locVal, PuzzleSwapPattern pattern)
{
	int[] offsets;
	switch (pattern)
	{
		case ROTATE_LEFT_UP:
		case ROTATE_RIGHT_UP:
		case ROTATE_RIGHT_DOWN:
		case ROTATE_LEFT_DOWN:
			offsets = ROTATE_LEFT_UP.getPoints();
			break;
		case ROTATE_UP_LEFT:
		case ROTATE_UP_RIGHT:
		case ROTATE_DOWN_LEFT:
		case ROTATE_DOWN_RIGHT:
			offsets = ROTATE_UP_LEFT.getPoints();
			break;
		default:
			offsets = pattern.getPoints();
	}

	if (offsets == null || offsets.length % 2 == 1)
	{
		// This should never happen
		throw new IllegalStateException("Unexpected points given in pattern!");
	}

	int modX = pattern.getModX();
	int modY = pattern.getModY();

	ArrayList<Point> points = new ArrayList<>();

	for (int i = 0; i < offsets.length; i += 2)
	{
		int x = locVal.getX() + modX * offsets[i];
		int y = locVal.getY() + modY * offsets[i + 1];

		points.add(new Point(x, y));
	}

	// Add locVal as last point
	points.add(locVal);

	if (pattern != LAST_PIECE_ROW && pattern != LAST_PIECE_COLUMN)
	{
		Point start = locBlank;
		for (Point p : points)
		{
			swap(start, p);
			start = p;
		}
	}
	else
	{
		Point loc1 = points.get(0);
		Point loc2 = points.get(1);
		Point loc3 = points.get(2);
		Point loc4 = points.get(3);

		swap(locBlank, locVal);
		swap(locVal, loc3);
		swap(loc3, loc1);
		swap(loc1, loc2);
		swap(loc2, locVal);
		swap(locVal, loc3);
		swap(loc3, loc1);
		swap(loc1, loc2);
		swap(loc2, locVal);
		swap(locVal, locBlank);
		swap(locBlank, loc4);
		swap(loc4, loc3);
		swap(loc3, loc1);
		swap(loc1, loc2);
		swap(loc2, locVal);
	}
}
 
Example 19
Source File: ClueScrollPlugin.java    From plugins with GNU General Public License v3.0 4 votes vote down vote up
void highlightWidget(Graphics2D graphics, Widget toHighlight, Widget container, Rectangle padding, String text)
{
	padding = Objects.requireNonNullElse(padding, new Rectangle());

	Point canvasLocation = toHighlight.getCanvasLocation();

	if (canvasLocation == null)
	{
		return;
	}

	Point windowLocation = container.getCanvasLocation();

	if (windowLocation.getY() > canvasLocation.getY() + toHighlight.getHeight()
		|| windowLocation.getY() + container.getHeight() < canvasLocation.getY())
	{
		return;
	}

	// Visible area of widget
	Area widgetArea = new Area(
		new Rectangle(
			canvasLocation.getX() - padding.x,
			Math.max(canvasLocation.getY(), windowLocation.getY()) - padding.y,
			toHighlight.getWidth() + padding.x + padding.width,
			Math.min(
				Math.min(windowLocation.getY() + container.getHeight() - canvasLocation.getY(), toHighlight.getHeight()),
				Math.min(canvasLocation.getY() + toHighlight.getHeight() - windowLocation.getY(), toHighlight.getHeight())) + padding.y + padding.height
		));

	OverlayUtil.renderHoverableArea(graphics, widgetArea, client.getMouseCanvasPosition(),
		HIGHLIGHT_FILL_COLOR, HIGHLIGHT_BORDER_COLOR, HIGHLIGHT_HOVER_BORDER_COLOR);

	if (text == null)
	{
		return;
	}

	FontMetrics fontMetrics = graphics.getFontMetrics();

	textComponent.setPosition(new java.awt.Point(
		canvasLocation.getX() + toHighlight.getWidth() / 2 - fontMetrics.stringWidth(text) / 2,
		canvasLocation.getY() + fontMetrics.getHeight()));
	textComponent.setText(text);
	textComponent.render(graphics);
}
 
Example 20
Source File: IDAStarMM.java    From runelite with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * Assumes locBlank is first point for swap and locVal is last point for swap
 *
 * swap(locBlank, loc1);
 * swap(loc1, loc2);
 * swap(loc2, locVal);
 */
private void performSwapPattern(Point locBlank, Point locVal, PuzzleSwapPattern pattern)
{
	int[] offsets;
	switch (pattern)
	{
		case ROTATE_LEFT_UP:
		case ROTATE_RIGHT_UP:
		case ROTATE_RIGHT_DOWN:
		case ROTATE_LEFT_DOWN:
			offsets = ROTATE_LEFT_UP.getPoints();
			break;
		case ROTATE_UP_LEFT:
		case ROTATE_UP_RIGHT:
		case ROTATE_DOWN_LEFT:
		case ROTATE_DOWN_RIGHT:
			offsets = ROTATE_UP_LEFT.getPoints();
			break;
		default:
			offsets = pattern.getPoints();
	}

	if (offsets == null || offsets.length % 2 == 1)
	{
		// This should never happen
		throw new IllegalStateException("Unexpected points given in pattern!");
	}

	int modX = pattern.getModX();
	int modY = pattern.getModY();

	ArrayList<Point> points = new ArrayList<>();

	for (int i = 0; i < offsets.length; i += 2)
	{
		int x = locVal.getX() + modX * offsets[i];
		int y = locVal.getY() + modY * offsets[i + 1];

		points.add(new Point(x, y));
	}

	// Add locVal as last point
	points.add(locVal);

	if (pattern != LAST_PIECE_ROW && pattern != LAST_PIECE_COLUMN)
	{
		Point start = locBlank;
		for (Point p : points)
		{
			swap(start, p);
			start = p;
		}
	}
	else
	{
		Point loc1 = points.get(0);
		Point loc2 = points.get(1);
		Point loc3 = points.get(2);
		Point loc4 = points.get(3);

		swap(locBlank, locVal);
		swap(locVal, loc3);
		swap(loc3, loc1);
		swap(loc1, loc2);
		swap(loc2, locVal);
		swap(locVal, loc3);
		swap(loc3, loc1);
		swap(loc1, loc2);
		swap(loc2, locVal);
		swap(locVal, locBlank);
		swap(locBlank, loc4);
		swap(loc4, loc3);
		swap(loc3, loc1);
		swap(loc1, loc2);
		swap(loc2, locVal);
	}
}