fix: Offests in GUI now work correctly

This commit is contained in:
TopchetoEU 2022-09-22 10:55:35 +03:00
parent 7197e75cb4
commit 976e91c837
No known key found for this signature in database
GPG Key ID: 0F2543CA49C81E3A
3 changed files with 13 additions and 19 deletions

View File

@ -83,7 +83,7 @@ public class Button extends DrawableHelper implements Drawable, Element, Selecta
matrices.push();
matrices.translate(this.x, this.y, getZOffset());
hovered = isMouseOver(x, y);
hovered = isMouseOver(x - this.x, y - this.y);
if (hovered) {
fill(matrices, 0, 0, (int)getWidth(), (int)getHeight(), Argb.getArgb(32, 255, 255, 255));
@ -109,9 +109,6 @@ public class Button extends DrawableHelper implements Drawable, Element, Selecta
public boolean isMouseOver(double x, double y) {
if (clicked) return true;
x -= this.x;
y -= this.y;
return x >= 0 && x < getWidth() && y >= 0 && y < getHeight();
}
@ -136,7 +133,7 @@ public class Button extends DrawableHelper implements Drawable, Element, Selecta
@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
if (button != 0) return false;
if (isMouseOver(mouseX, mouseY)) {
if (isMouseOver(mouseX - this.x, mouseY - this.x)) {
clicked = true;
hovered = true;
}

View File

@ -246,9 +246,6 @@ public class ChunkPreview extends DrawableHelper implements Drawable, Element, S
public boolean isMouseOver(double x, double y) {
if (clicked) return true;
x -= this.x;
y -= this.y;
return x >= 0 && x < getWidth() && y >= 0 && y < getHeight();
}

View File

@ -181,7 +181,7 @@ public abstract class Section extends AbstractParentElement implements Drawable,
@Override
public Optional<Element> hoveredElement(double mouseX, double mouseY) {
for (Selectable element : this.children.selectables) {
var offset = children.getOffsetAndPos(element);
var offset = children.getOffset(element);
if (element.getType() != SelectionType.HOVERED || !((Element)element).isMouseOver(mouseX - offset.x, mouseY - offset.y)) continue;
return Optional.of((Element)element);
}
@ -191,8 +191,8 @@ public abstract class Section extends AbstractParentElement implements Drawable,
@Override
public boolean mouseScrolled(double mouseX, double mouseY, double delta) {
for (Element element : this.children()) {
var offset = children.getOffsetAndPos(element);
if (!element.mouseScrolled(mouseX - offset.x, mouseY - offset.y, delta)) continue;
var offset = children.getOffset(element);
if (!element.mouseScrolled(mouseX - offset.x - x, mouseY - offset.y - y, delta)) continue;
return true;
}
return false;
@ -200,8 +200,8 @@ public abstract class Section extends AbstractParentElement implements Drawable,
@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
for (Element element : this.children()) {
var offset = children.getOffsetAndPos(element);
if (!element.mouseClicked(mouseX - offset.x, mouseY - offset.y, button)) continue;
var offset = children.getOffset(element);
if (!element.mouseClicked(mouseX - offset.x - x, mouseY - offset.y - y, button)) continue;
this.setFocused(element);
if (button == 0) {
this.setDragging(true);
@ -214,8 +214,8 @@ public abstract class Section extends AbstractParentElement implements Drawable,
@Override
public void mouseMoved(double mouseX, double mouseY) {
for (Element element : this.children()) {
var offset = children.getOffsetAndPos(element);
element.mouseMoved(mouseX - offset.x, mouseY - offset.y);
var offset = children.getOffset(element);
element.mouseMoved(mouseX - offset.x - x, mouseY - offset.y - y);
}
}
@ -224,8 +224,8 @@ public abstract class Section extends AbstractParentElement implements Drawable,
this.setDragging(false);
for (Element element : children.get()) {
var offset = children.getOffsetAndPos(element);
if (element.mouseReleased(mouseX - (int)offset.x, mouseY - (int)offset.y, button)) return true;
var offset = children.getOffset(element);
if (element.mouseReleased(mouseX - (int)offset.x - x, mouseY - (int)offset.y - y, button)) return true;
}
return false;
@ -234,8 +234,8 @@ public abstract class Section extends AbstractParentElement implements Drawable,
@Override
public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) {
if (this.getFocused() != null && this.isDragging() && button == 0) {
var offset = children.getOffsetAndPos(getFocused());
return this.getFocused().mouseDragged(mouseX - offset.x, mouseY - offset.y, button, deltaX, deltaY);
var offset = children.getOffset(getFocused());
return this.getFocused().mouseDragged(mouseX - offset.x - x, mouseY - offset.y - y, button, deltaX, deltaY);
}
return false;
}