refactor(jui): backport hovering over helper from 1.6.x

This commit is contained in:
Sally Knight 2026-03-29 04:55:54 +03:00 committed by Tropical
parent 80966a501c
commit 32149b7ec3
2 changed files with 12 additions and 3 deletions

View file

@ -283,14 +283,20 @@ Slot* AbstractContainerScreen::findSlot(int x, int y) {
return NULL;
}
bool AbstractContainerScreen::isHovering(Slot* slot, int xm, int ym) {
// 4jcraft: equivalent to MCP 8.11 (1.6.x)'s GuiContainer.isPointInRegion() for
// use in other derived classes
bool AbstractContainerScreen::isHoveringOver(int x, int y, int w, int h, int xm,
int ym) {
int xo = (width - imageWidth) / 2;
int yo = (height - imageHeight) / 2;
xm -= xo;
ym -= yo;
return xm >= slot->x - 1 && xm < slot->x + 16 + 1 && ym >= slot->y - 1 &&
ym < slot->y + 16 + 1;
return xm >= x - 1 && xm < x + w + 1 && ym >= y - 1 && ym < y + h + 1;
}
bool AbstractContainerScreen::isHovering(Slot* slot, int xm, int ym) {
return isHoveringOver(slot->x, slot->y, 16, 16, xm, ym);
}
void AbstractContainerScreen::mouseClicked(int x, int y, int buttonNum) {

View file

@ -28,6 +28,9 @@ protected:
// can call findSlot() and isHovering() directly for its custom click
// handling.
virtual Slot* findSlot(int x, int y);
// 4jcraft: equivalent to MCP 8.11 (1.6.x)'s GuiContainer.isPointInRegion()
// for use in other derived classes
virtual bool isHoveringOver(int x, int y, int w, int h, int xm, int ym);
virtual bool isHovering(Slot* slot, int xm, int ym);
// 4jcraft: extracted from render() into a standalone method so this can be
// used in other classes