Search in sources :

Example 21 with Inject

use of net.runelite.api.mixins.Inject in project runelite by runelite.

the class RSSpritePixelsMixin method toBufferedImage.

@Inject
@Override
public BufferedImage toBufferedImage() {
    int width = getWidth();
    int height = getHeight();
    int[] pixels = getPixels();
    int[] transPixels = new int[pixels.length];
    BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
    for (int i = 0; i < pixels.length; i++) {
        if (pixels[i] != 0) {
            transPixels[i] = pixels[i] | 0xff000000;
        }
    }
    img.setRGB(0, 0, width, height, transPixels, 0, width);
    return img;
}
Also used : BufferedImage(java.awt.image.BufferedImage) Inject(net.runelite.api.mixins.Inject)

Example 22 with Inject

use of net.runelite.api.mixins.Inject 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)

Example 23 with Inject

use of net.runelite.api.mixins.Inject in project runelite by runelite.

the class RSWidgetMixin method broadcastHidden.

@Inject
@Override
public void broadcastHidden(boolean hidden) {
    WidgetHiddenChanged event = new WidgetHiddenChanged();
    event.setWidget(this);
    event.setHidden(hidden);
    eventBus.post(event);
    RSWidget[] children = getChildren();
    if (children != null) {
        // recursive through children
        for (RSWidget child : children) {
            // if the widget is hidden it will not magically unhide from its parent changing
            if (child == null || child.isSelfHidden())
                continue;
            child.broadcastHidden(hidden);
        }
    }
    // make sure we iterate nested children as well
    // cannot be null
    Widget[] nestedChildren = getNestedChildren();
    for (Widget nestedChild : nestedChildren) {
        if (nestedChild == null || nestedChild.isSelfHidden())
            continue;
        ((RSWidget) nestedChild).broadcastHidden(hidden);
    }
}
Also used : RSWidget(net.runelite.rs.api.RSWidget) Widget(net.runelite.api.widgets.Widget) RSWidget(net.runelite.rs.api.RSWidget) WidgetHiddenChanged(net.runelite.api.events.WidgetHiddenChanged) Inject(net.runelite.api.mixins.Inject)

Example 24 with Inject

use of net.runelite.api.mixins.Inject in project runelite by runelite.

the class RSWidgetMixin method getNestedChildren.

@Inject
@Override
public Widget[] getNestedChildren() {
    RSHashTable componentTable = client.getComponentTable();
    int group = -1;
    // iteration here...
    for (Node node : componentTable.getNodes()) {
        WidgetNode wn = (WidgetNode) node;
        if (wn.getHash() == getId()) {
            group = wn.getId();
            break;
        }
    }
    if (group == -1) {
        return new Widget[0];
    }
    List<Widget> widgets = new ArrayList<Widget>();
    for (Widget widget : client.getGroup(group)) {
        if (widget != null && widget.getParentId() == getId()) {
            widgets.add(widget);
        }
    }
    return widgets.toArray(new Widget[widgets.size()]);
}
Also used : RSNode(net.runelite.rs.api.RSNode) Node(net.runelite.api.Node) WidgetNode(net.runelite.api.WidgetNode) Widget(net.runelite.api.widgets.Widget) RSWidget(net.runelite.rs.api.RSWidget) ArrayList(java.util.ArrayList) WidgetNode(net.runelite.api.WidgetNode) RSHashTable(net.runelite.rs.api.RSHashTable) Point(net.runelite.api.Point) Inject(net.runelite.api.mixins.Inject)

Example 25 with Inject

use of net.runelite.api.mixins.Inject in project runelite by runelite.

the class RSWidgetMixin method onHiddenChanged.

@FieldHook("isHidden")
@Inject
public void onHiddenChanged(int idx) {
    int id = getId();
    if (id == -1) {
        return;
    }
    Widget parent = getParent();
    // so ignore them
    if (parent != null) {
        if (parent.isHidden()) {
            return;
        }
    } else if (TO_GROUP(id) != client.getWidgetRoot()) {
        return;
    }
    broadcastHidden(isSelfHidden());
}
Also used : Widget(net.runelite.api.widgets.Widget) RSWidget(net.runelite.rs.api.RSWidget) Point(net.runelite.api.Point) Inject(net.runelite.api.mixins.Inject) FieldHook(net.runelite.api.mixins.FieldHook)

Aggregations

Inject (net.runelite.api.mixins.Inject)57 Point (net.runelite.api.Point)20 FieldHook (net.runelite.api.mixins.FieldHook)20 ArrayList (java.util.ArrayList)14 LocalPoint (net.runelite.api.coords.LocalPoint)10 RSWidget (net.runelite.rs.api.RSWidget)6 Vertex (net.runelite.api.model.Vertex)5 Widget (net.runelite.api.widgets.Widget)5 Node (net.runelite.api.Node)4 RSNode (net.runelite.rs.api.RSNode)4 WidgetNode (net.runelite.api.WidgetNode)3 Triangle (net.runelite.api.model.Triangle)3 Polygon (java.awt.Polygon)2 MenuEntry (net.runelite.api.MenuEntry)2 Model (net.runelite.api.Model)2 NPC (net.runelite.api.NPC)2 Player (net.runelite.api.Player)2 Skill (net.runelite.api.Skill)2 WidgetItem (net.runelite.api.widgets.WidgetItem)2 RSCombatInfoList (net.runelite.rs.api.RSCombatInfoList)2