Skip to content

Commit

Permalink
Check if mouse is in bounds to do cursor operations.
Browse files Browse the repository at this point in the history
<log>backport cursor bound check from 1.20.4</log>
  • Loading branch information
ThatGravyBoat committed Jan 31, 2024
1 parent 85017c2 commit fd494eb
Showing 1 changed file with 20 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,26 @@ protected BaseCursorScreen(Component component) {

@Override
public void render(@NotNull GuiGraphics graphics, int mouseX, int mouseY, float f) {
setCursor(Cursor.DEFAULT);
actuallyRender(graphics, mouseX, mouseY, f);
setCursor(children(), mouseX, mouseY);

switch (cursor) {
case DEFAULT -> CursorUtils.setDefault();
case POINTER -> CursorUtils.setPointing();
case DISABLED -> CursorUtils.setDisabled();
case TEXT -> CursorUtils.setText();
case CROSSHAIR -> CursorUtils.setCrosshair();
case RESIZE_EW -> CursorUtils.setResizeEastWest();
case RESIZE_NS -> CursorUtils.setResizeNorthSouth();
case RESIZE_NESW -> CursorUtils.setResizeNorthEastSouthWest();
case RESIZE_NWSE -> CursorUtils.setResizeNorthWestSouthEast();
case RESIZE_ALL -> CursorUtils.setResizeAll();
boolean wihinBounds = mouseX >= 0 && mouseY >= 0 && mouseX < this.width && mouseY < this.height;
if (!wihinBounds) {
actuallyRender(graphics, mouseX, mouseY, f);
} else {
setCursor(Cursor.DEFAULT);
actuallyRender(graphics, mouseX, mouseY, f);
setCursor(children(), mouseX, mouseY);

switch (cursor) {
case DEFAULT -> CursorUtils.setDefault();
case POINTER -> CursorUtils.setPointing();
case DISABLED -> CursorUtils.setDisabled();
case TEXT -> CursorUtils.setText();
case CROSSHAIR -> CursorUtils.setCrosshair();
case RESIZE_EW -> CursorUtils.setResizeEastWest();
case RESIZE_NS -> CursorUtils.setResizeNorthSouth();
case RESIZE_NESW -> CursorUtils.setResizeNorthEastSouthWest();
case RESIZE_NWSE -> CursorUtils.setResizeNorthWestSouthEast();
case RESIZE_ALL -> CursorUtils.setResizeAll();
}
}
}

Expand Down

0 comments on commit fd494eb

Please sign in to comment.