use of mathax.client.systems.hud.HudElement in project Client by MatHax.
the class HudEditorScreen method mouseMoved.
@Override
public void mouseMoved(double mouseX, double mouseY) {
double s = mc.getWindow().getScaleFactor();
mouseX *= s;
mouseY *= s;
if (selecting) {
selectedElements.clear();
for (HudElement module : hud.elements) {
double mX = module.box.getX();
double mY = module.box.getY();
double mW = module.box.width;
double mH = module.box.height;
if (isInSelection(mouseX, mouseY, mX, mY) || isInSelection(mouseX, mouseY, mX + mW, mY) || (isInSelection(mouseX, mouseY, mX, mY + mH) || isInSelection(mouseX, mouseY, mX + mW, mY + mH))) {
selectedElements.add(module);
}
}
} else if (dragging) {
for (HudElement element : selectedElements) {
element.box.addPos(mouseX - lastMouseX, mouseY - lastMouseY);
}
double r = hud.snappingRange.get();
if (r > 0) {
double x = Double.MAX_VALUE;
double y = Double.MAX_VALUE;
double w = 0;
double h = 0;
for (HudElement element : selectedElements) {
x = Math.min(x, element.box.getX());
y = Math.min(y, element.box.getY());
}
for (HudElement element : selectedElements) {
w = Math.max(w, element.box.getX() - x + element.box.width);
h = Math.max(h, element.box.getY() - y + element.box.height);
}
boolean movedX = false;
boolean movedY = false;
for (HudElement element : hud.elements) {
if (selectedElements.contains(element))
continue;
double eX = element.box.getX();
double eY = element.box.getY();
double eW = element.box.width;
double eH = element.box.height;
boolean isHorizontallyIn = isPointBetween(x, w, eX) || isPointBetween(x, w, eX + eW) || isPointBetween(eX, eW, x) || isPointBetween(eX, eW, x + w);
boolean isVerticallyIn = isPointBetween(y, h, eY) || isPointBetween(y, h, eY + eH) || isPointBetween(eY, eH, y) || isPointBetween(eY, eH, y + h);
double moveX = 0;
double moveY = 0;
if (!movedX && isVerticallyIn) {
double x2 = x + w;
double eX2 = eX + eW;
if (Math.abs(eX - x) < r)
moveX = eX - x;
else if (Math.abs(eX2 - x2) <= r)
moveX = eX2 - x2;
else if (Math.abs(eX2 - x) <= r)
moveX = eX2 - x;
else if (Math.abs(eX - x2) <= r)
moveX = eX - x2;
}
if (!movedY && isHorizontallyIn) {
double y2 = y + h;
double eY2 = eY + eH;
if (Math.abs(eY - y) <= r)
moveY = eY - y;
else if (Math.abs(eY2 - y2) <= r)
moveY = eY2 - y2;
else if (Math.abs(eY2 - y) <= r)
moveY = eY2 - y;
else if (Math.abs(eY - y2) <= r)
moveY = eY - y2;
}
if (moveX != 0 || moveY != 0) {
for (HudElement e : selectedElements) e.box.addPos(moveX, moveY);
if (moveX != 0)
movedX = true;
if (moveY != 0)
movedY = true;
}
if (movedX && movedY)
break;
}
dragged = true;
}
}
lastMouseX = mouseX;
lastMouseY = mouseY;
}
use of mathax.client.systems.hud.HudElement in project Client by MatHax.
the class HudEditorScreen method render.
@Override
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
if (!Utils.canUpdate())
renderBackground(matrices);
double s = mc.getWindow().getScaleFactor();
mouseX *= s;
mouseY *= s;
Utils.unscaledProjection();
if (!Utils.canUpdate())
hud.render(delta, hudElement -> true);
Renderer2D.COLOR.begin();
for (HudElement element : hud.elements) {
if (element.active)
continue;
renderElement(element, INACTIVE_BG_COLOR, INACTIVE_OL_COLOR);
}
for (HudElement element : selectedElements) {
renderElement(element, HOVER_BG_COLOR, HOVER_OL_COLOR);
}
if (!dragging) {
hoveredModule = null;
for (HudElement module : hud.elements) {
if (module.box.isOver(mouseX, mouseY)) {
if (!selectedElements.contains(module))
renderElement(module, HOVER_BG_COLOR, HOVER_OL_COLOR);
hoveredModule = module;
break;
}
}
if (selecting)
renderQuad(mouseStartX, mouseStartY, mouseX - mouseStartX, mouseY - mouseStartY, HOVER_BG_COLOR, HOVER_OL_COLOR);
}
Renderer2D.COLOR.render(new MatrixStack());
Utils.scaledProjection();
runAfterRenderTasks();
}
Aggregations