package org.saturnclient.ui; public class ElementContext { /** * Where a container's children are drawn: the screen position of their * (0, 0), and the part of the screen, top to bottom, where they can be seen. */ public record Frame(int x, int y, int visibleTop, int visibleBottom) { /** The whole screen, for top-level elements */ public static final Frame SCREEN = new Frame(0, 0, Integer.MIN_VALUE, Integer.MAX_VALUE); } public int mouseX, mouseY; /** The element's top-left corner on the screen, for placing popups next to it */ public int originX, originY; /** The part of the screen, top to bottom, where the element can be seen */ public int visibleTop, visibleBottom; public int elementWidth, elementHeight; public float elementScale; public long elapsed; public ElementContext(long elapsed, int mouseX, int mouseY, Frame frame, Element e) { this.mouseX = mouseX - e.x; this.mouseY = mouseY - e.y; this.originX = frame.x() + e.x; this.originY = frame.y() + e.y; this.visibleTop = frame.visibleTop(); this.visibleBottom = frame.visibleBottom(); this.elementWidth = e.width; this.elementHeight = e.height; this.elementScale = e.scale; this.elapsed = elapsed; } /** * The frame for this element's children, drawn {@code dx}, {@code dy} from * its corner and seen only between {@code clipTop} and {@code clipBottom} * (relative to its corner). */ public Frame childFrame(int dx, int dy, int clipTop, int clipBottom) { return new Frame(originX + dx, originY + dy, Math.max(visibleTop, originY + clipTop), Math.min(visibleBottom, originY + clipBottom)); } /** * The frame for children drawn at this element's corner and not clipped. */ public Frame childFrame() { return new Frame(originX, originY, visibleTop, visibleBottom); } public boolean isHovering() { return Utils.isHovering(mouseX, mouseY, elementWidth, elementHeight, elementScale); } public boolean isHovering(int x, int y, int width, int height) { return Utils.isHovering(mouseX - x, mouseY - y, width, height, elementScale); } }