Search in sources :

Example 11 with Point

use of net.runelite.api.Point in project runelite by runelite.

the class GroundItemInputListener method mousePressed.

@Override
public MouseEvent mousePressed(MouseEvent e) {
    if (plugin.isHotKeyPressed()) {
        // Check if left click
        if (e.getButton() == MouseEvent.BUTTON1) {
            Point mousePos = client.getMouseCanvasPosition();
            for (Map.Entry<Rectangle, String> entry : plugin.getHiddenBoxes().entrySet()) {
                if (entry.getKey().contains(mousePos.getX(), mousePos.getY())) {
                    plugin.updateList(entry.getValue(), true);
                    e.consume();
                    return e;
                }
            }
            for (Map.Entry<Rectangle, String> entry : plugin.getHighlightBoxes().entrySet()) {
                if (entry.getKey().contains(mousePos.getX(), mousePos.getY())) {
                    plugin.updateList(entry.getValue(), false);
                    e.consume();
                    return e;
                }
            }
        }
    }
    return e;
}
Also used : Rectangle(java.awt.Rectangle) Point(net.runelite.api.Point) Map(java.util.Map)

Example 12 with Point

use of net.runelite.api.Point in project runelite by runelite.

the class RSPlayerMixin method getPolygons.

@Inject
@Override
public Polygon[] getPolygons() {
    Model model = getModel();
    if (model == null) {
        return null;
    }
    int localX = getX();
    int localY = getY();
    int orientation = getOrientation();
    List<Triangle> triangles = model.getTriangles();
    triangles = rotate(triangles, orientation);
    List<Polygon> polys = new ArrayList<Polygon>();
    for (Triangle triangle : triangles) {
        Vertex vx = triangle.getA();
        Vertex vy = triangle.getB();
        Vertex vz = triangle.getC();
        Point x = Perspective.worldToCanvas(client, localX - vx.getX(), localY - vx.getZ(), -vx.getY());
        Point y = Perspective.worldToCanvas(client, localX - vy.getX(), localY - vy.getZ(), -vy.getY());
        Point z = Perspective.worldToCanvas(client, localX - vz.getX(), localY - vz.getZ(), -vz.getY());
        int[] xx = { x.getX(), y.getX(), z.getX() };
        int[] yy = { x.getY(), y.getY(), z.getY() };
        polys.add(new Polygon(xx, yy, 3));
    }
    return polys.toArray(new Polygon[polys.size()]);
}
Also used : Vertex(net.runelite.api.model.Vertex) Model(net.runelite.api.Model) Triangle(net.runelite.api.model.Triangle) ArrayList(java.util.ArrayList) Point(net.runelite.api.Point) Polygon(java.awt.Polygon) Point(net.runelite.api.Point) Inject(net.runelite.api.mixins.Inject)

Example 13 with Point

use of net.runelite.api.Point in project runelite by runelite.

the class RSModelMixin method getConvexHull.

@Override
@Inject
public Polygon getConvexHull(int localX, int localY, int orientation) {
    List<Vertex> vertices = getVertices();
    // rotate vertices
    for (int i = 0; i < vertices.size(); ++i) {
        Vertex v = vertices.get(i);
        vertices.set(i, v.rotate(orientation));
    }
    List<Point> points = new ArrayList<Point>();
    for (Vertex v : vertices) {
        // Compute canvas location of vertex
        Point p = Perspective.worldToCanvas(client, localX - v.getX(), localY - v.getZ(), -v.getY());
        if (p != null) {
            points.add(p);
        }
    }
    // Run Jarvis march algorithm
    points = Jarvis.convexHull(points);
    if (points == null) {
        return null;
    }
    // Convert to a polygon
    Polygon p = new Polygon();
    for (Point point : points) {
        p.addPoint(point.getX(), point.getY());
    }
    return p;
}
Also used : Vertex(net.runelite.api.model.Vertex) ArrayList(java.util.ArrayList) Point(net.runelite.api.Point) Polygon(java.awt.Polygon) Point(net.runelite.api.Point) Inject(net.runelite.api.mixins.Inject)

Example 14 with Point

use of net.runelite.api.Point in project runelite by runelite.

the class RunepouchOverlay method render.

@Override
public Dimension render(Graphics2D graphics) {
    Query query = new InventoryWidgetItemQuery().idEquals(ItemID.RUNE_POUCH);
    WidgetItem[] items = queryRunner.runQuery(query);
    if (items.length == 0) {
        return null;
    }
    WidgetItem runePouch = items[0];
    Point location = runePouch.getCanvasLocation();
    if (location == null) {
        return null;
    }
    assert AMOUNT_VARBITS.length == RUNE_VARBITS.length;
    graphics.setFont(FontManager.getRunescapeSmallFont());
    StringBuilder tooltipBuilder = new StringBuilder();
    for (int i = 0; i < AMOUNT_VARBITS.length; i++) {
        Varbits amountVarbit = AMOUNT_VARBITS[i];
        int amount = client.getSetting(amountVarbit);
        if (amount <= 0) {
            continue;
        }
        Varbits runeVarbit = RUNE_VARBITS[i];
        int runeId = client.getSetting(runeVarbit);
        Runes rune = Runes.getRune(runeId);
        if (rune == null) {
            continue;
        }
        tooltipBuilder.append(amount).append(" <col=ffff00>").append(rune.getName()).append("</col></br>");
        if (config.showOnlyOnHover()) {
            continue;
        }
        graphics.setColor(Color.black);
        graphics.drawString("" + formatNumber(amount), location.getX() + (config.showIcons() ? 13 : 6), location.getY() + 14 + (graphics.getFontMetrics().getHeight() - 1) * i);
        graphics.setColor(config.fontColor());
        graphics.drawString("" + formatNumber(amount), location.getX() + (config.showIcons() ? 12 : 5), location.getY() + 13 + (graphics.getFontMetrics().getHeight() - 1) * i);
        if (!config.showIcons()) {
            continue;
        }
        BufferedImage image = getRuneImage(rune);
        if (image != null) {
            OverlayUtil.renderImageLocation(graphics, new Point(location.getX(), location.getY() + graphics.getFontMetrics().getHeight() * i), image);
        }
    }
    String tooltip = tooltipBuilder.toString();
    if (!tooltip.isEmpty() && runePouch.getCanvasBounds().contains(client.getMouseCanvasPosition().getX(), client.getMouseCanvasPosition().getY())) {
        tooltipManager.add(new Tooltip(tooltip));
    }
    return null;
}
Also used : InventoryWidgetItemQuery(net.runelite.api.queries.InventoryWidgetItemQuery) Query(net.runelite.api.Query) InventoryWidgetItemQuery(net.runelite.api.queries.InventoryWidgetItemQuery) Tooltip(net.runelite.client.ui.overlay.tooltip.Tooltip) WidgetItem(net.runelite.api.widgets.WidgetItem) Point(net.runelite.api.Point) Point(net.runelite.api.Point) BufferedImage(java.awt.image.BufferedImage) Varbits(net.runelite.api.Varbits)

Example 15 with Point

use of net.runelite.api.Point in project runelite by runelite.

the class RSWidgetMixin method getCanvasLocation.

@Inject
@Override
public Point getCanvasLocation() {
    int x = 0;
    int y = 0;
    RSWidget cur;
    for (cur = this; cur.getParent() != null; cur = (RSWidget) cur.getParent()) {
        x += cur.getRelativeX();
        y += cur.getRelativeY();
        x -= cur.getScrollX();
        y -= cur.getScrollY();
    }
    // cur is now the root
    int[] widgetBoundsWidth = client.getWidgetPositionsX();
    int[] widgetBoundsHeight = client.getWidgetPositionsY();
    int boundsIndex = cur.getBoundsIndex();
    if (boundsIndex != -1) {
        x += widgetBoundsWidth[boundsIndex];
        y += widgetBoundsHeight[boundsIndex];
        if (cur.getType() > 0) {
            x += cur.getRelativeX();
            y += cur.getRelativeY();
        }
    } else {
        x += cur.getRelativeX();
        y += cur.getRelativeY();
    }
    return new Point(x, y);
}
Also used : RSWidget(net.runelite.rs.api.RSWidget) Point(net.runelite.api.Point) Point(net.runelite.api.Point) Inject(net.runelite.api.mixins.Inject)

Aggregations

Point (net.runelite.api.Point)28 LocalPoint (net.runelite.api.coords.LocalPoint)12 Polygon (java.awt.Polygon)9 Color (java.awt.Color)6 BufferedImage (java.awt.image.BufferedImage)5 Inject (net.runelite.api.mixins.Inject)4 FontMetrics (java.awt.FontMetrics)3 Rectangle (java.awt.Rectangle)3 Area (java.awt.geom.Area)3 ArrayList (java.util.ArrayList)3 WorldPoint (net.runelite.api.coords.WorldPoint)3 WidgetItem (net.runelite.api.widgets.WidgetItem)3 ImageIO (javax.imageio.ImageIO)2 Player (net.runelite.api.Player)2 Vertex (net.runelite.api.model.Vertex)2 Test (org.junit.Test)2 Inject (com.google.inject.Inject)1 Dimension (java.awt.Dimension)1 Graphics (java.awt.Graphics)1 Graphics2D (java.awt.Graphics2D)1