use of net.runelite.api.Point in project runelite by runelite.
the class ScreenshotPlugin method takeScreenshot.
private void takeScreenshot(String fileName, boolean displayDate) {
if (client.getGameState() == GameState.LOGIN_SCREEN) {
// Prevent the screenshot from being captured
log.info("Login screenshot prevented");
return;
}
overlayRenderer.requestScreenshot(image -> {
BufferedImage screenshot = config.includeFrame() ? new BufferedImage(clientUi.getWidth(), clientUi.getHeight(), BufferedImage.TYPE_INT_ARGB) : new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics graphics = screenshot.getGraphics();
int gameOffsetX = 0;
int gameOffsetY = 0;
if (config.includeFrame()) {
// Draw the client frame onto the screenshot
clientUi.paint(graphics);
// 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);
if (displayDate) {
try (InputStream reportButton = ScreenshotPlugin.class.getResourceAsStream("report_button.png")) {
BufferedImage reportButtonImage;
synchronized (ImageIO.class) {
reportButtonImage = ImageIO.read(reportButton);
}
int x = gameOffsetX + 403;
int y = gameOffsetY + image.getHeight() - reportButtonImage.getHeight() - 1;
graphics.drawImage(reportButtonImage, x, y, null);
graphics.setFont(FontManager.getRunescapeSmallFont());
FontMetrics fontMetrics = graphics.getFontMetrics();
String date = DATE_FORMAT.format(new Date());
int dateWidth = fontMetrics.stringWidth(date);
int dateHeight = fontMetrics.getHeight();
int textX = x + reportButtonImage.getWidth() / 2 - dateWidth / 2;
int textY = y + reportButtonImage.getHeight() / 2 + dateHeight / 2;
graphics.setColor(Color.BLACK);
graphics.drawString(date, textX + 1, textY + 1);
graphics.setColor(Color.WHITE);
graphics.drawString(date, textX, textY);
} catch (Exception ex) {
log.warn("error displaying date on screenshot", ex);
}
}
File playerFolder;
if (client.getLocalPlayer() != null) {
playerFolder = new File(RuneLite.SCREENSHOT_DIR, client.getLocalPlayer().getName());
} else {
playerFolder = RuneLite.SCREENSHOT_DIR;
}
playerFolder.mkdirs();
executor.execute(() -> {
try {
File screenshotFile = new File(playerFolder, fileName + ".png");
ImageIO.write(screenshot, "PNG", screenshotFile);
if (config.uploadScreenshot()) {
uploadScreenshot(screenshotFile);
} else if (config.notifyWhenTaken()) {
notifier.notify("A screenshot was saved to " + screenshotFile, TrayIcon.MessageType.INFO);
}
} catch (IOException ex) {
log.warn("error writing screenshot", ex);
}
});
});
}
use of net.runelite.api.Point in project runelite by runelite.
the class RaidsPlugin method buildRaid.
private Raid buildRaid() {
Point gridBase = findLobbyBase();
if (gridBase == null) {
return null;
}
Raid raid = new Raid();
Tile[][] tiles;
int position, x, y, offsetX;
int startX = -2;
for (int plane = 3; plane > 1; plane--) {
tiles = client.getRegion().getTiles()[plane];
if (tiles[gridBase.getX() + RaidRoom.ROOM_MAX_SIZE][gridBase.getY()] == null) {
position = 1;
} else {
position = 0;
}
for (int i = 1; i > -2; i--) {
y = gridBase.getY() + (i * RaidRoom.ROOM_MAX_SIZE);
for (int j = startX; j < 4; j++) {
x = gridBase.getX() + (j * RaidRoom.ROOM_MAX_SIZE);
offsetX = 0;
if (x > SCENE_SIZE && position > 1 && position < 4) {
position++;
}
if (x < 0) {
// add 1 because the tile at x=0 will always be null
offsetX = Math.abs(x) + 1;
}
if (x < SCENE_SIZE && y >= 0 && y < SCENE_SIZE) {
if (tiles[x + offsetX][y] == null) {
if (position == 4) {
position++;
break;
}
continue;
}
if (position == 0 && startX != j) {
startX = j;
}
Tile base = tiles[offsetX > 0 ? 1 : x][y];
RaidRoom room = determineRoom(base);
raid.setRoom(room, position + Math.abs((plane - 3) * 8));
position++;
}
}
}
}
return raid;
}
use of net.runelite.api.Point in project runelite by runelite.
the class BurnerOverlay method drawBurner.
private void drawBurner(Graphics2D graphics, String text, TileObject tileObject, Color color) {
Point canvasText = Perspective.getCanvasTextLocation(client, graphics, tileObject.getLocalLocation(), text, 200);
if (canvasText == null) {
return;
}
textComponent.setText(text);
textComponent.setPosition(new java.awt.Point(canvasText.getX(), canvasText.getY()));
textComponent.setColor(color);
textComponent.render(graphics);
// render tile
OverlayUtil.renderPolygon(graphics, tileObject.getCanvasTilePoly(), color);
}
use of net.runelite.api.Point in project runelite by runelite.
the class PlayerIndicatorsOverlay method renderPlayerOverlay.
private void renderPlayerOverlay(Graphics2D graphics, Player actor, Color color) {
if (config.drawTiles()) {
Polygon poly = actor.getCanvasTilePoly();
if (poly != null) {
OverlayUtil.renderPolygon(graphics, poly, color);
}
}
String name = actor.getName().replace('\u00A0', ' ');
int offset = actor.getLogicalHeight() + 40;
Point textLocation = actor.getCanvasTextLocation(graphics, name, offset);
if (textLocation != null) {
if (actor.isClanMember()) {
ClanMemberRank rank = clanManager.getRank(name);
if (rank != ClanMemberRank.UNRANKED) {
BufferedImage clanchatImage = clanManager.getClanImage(rank);
if (clanchatImage != null) {
int width = clanchatImage.getWidth();
Point imageLocation = new Point(textLocation.getX() - width / 2, textLocation.getY() - clanchatImage.getHeight());
OverlayUtil.renderImageLocation(graphics, imageLocation, clanchatImage);
// move text
textLocation = new Point(textLocation.getX() + width / 2, textLocation.getY());
}
}
}
OverlayUtil.renderTextLocation(graphics, textLocation, name, color);
}
}
use of net.runelite.api.Point in project runelite by runelite.
the class OverlayUtil method renderImageLocation.
public static void renderImageLocation(Graphics2D graphics, Point imgLoc, BufferedImage image) {
int x = imgLoc.getX();
int y = imgLoc.getY();
graphics.drawImage(image, x, y, null);
}
Aggregations