forked from Clones/Controlify
✏️ Move button guide to screen processor + vmouse improvements
This commit is contained in:
@ -1,9 +1,6 @@
|
||||
package dev.isxander.controlify.gui.layout;
|
||||
|
||||
import org.joml.Vector2f;
|
||||
import org.joml.Vector2fc;
|
||||
import org.joml.Vector2i;
|
||||
import org.joml.Vector2ic;
|
||||
|
||||
public enum AnchorPoint {
|
||||
TOP_LEFT(0, 0),
|
||||
@ -23,7 +20,7 @@ public enum AnchorPoint {
|
||||
this.anchorY = anchorY;
|
||||
}
|
||||
|
||||
public Vector2i getAnchorPosition(Vector2ic windowSize) {
|
||||
return new Vector2i((int) (windowSize.x() * anchorX), (int) (windowSize.y() * anchorY));
|
||||
public Vector2i getAnchorPosition(int w, int h) {
|
||||
return new Vector2i((int) (w * anchorX), (int) (h * anchorY));
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,11 @@
|
||||
package dev.isxander.controlify.gui.layout;
|
||||
|
||||
import com.mojang.blaze3d.platform.Window;
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import org.joml.Vector2i;
|
||||
import net.minecraft.client.gui.components.Renderable;
|
||||
import org.joml.Vector2ic;
|
||||
|
||||
public class PositionedComponent<T extends RenderComponent> {
|
||||
public class PositionedComponent<T extends RenderComponent> implements Renderable {
|
||||
private final T component;
|
||||
|
||||
private int x, y;
|
||||
@ -21,19 +20,24 @@ public class PositionedComponent<T extends RenderComponent> {
|
||||
this.offsetY = offsetY;
|
||||
this.windowAnchor = windowAnchor;
|
||||
this.origin = origin;
|
||||
|
||||
updatePosition();
|
||||
}
|
||||
|
||||
public void updatePosition() {
|
||||
Vector2ic windowPosition = windowAnchor.getAnchorPosition(windowSize());
|
||||
Vector2ic anchoredPosition = origin.getAnchorPosition(component.size());
|
||||
Vector2ic componentSize = component.size();
|
||||
|
||||
Vector2ic windowPosition = windowAnchor.getAnchorPosition(Minecraft.getInstance().getWindow().getGuiScaledWidth(), Minecraft.getInstance().getWindow().getGuiScaledHeight());
|
||||
Vector2ic anchoredPosition = origin.getAnchorPosition(componentSize.x(), componentSize.y());
|
||||
|
||||
this.x = windowPosition.x() + offsetX - anchoredPosition.x();
|
||||
this.y = windowPosition.y() + offsetY - anchoredPosition.y();
|
||||
}
|
||||
|
||||
public void render(PoseStack stack, float deltaTime) {
|
||||
@Override
|
||||
public void render(PoseStack matrices, int mouseX, int mouseY, float delta) {
|
||||
this.renderComponent(matrices, delta);
|
||||
}
|
||||
|
||||
public void renderComponent(PoseStack stack, float deltaTime) {
|
||||
component.render(stack, x, y, deltaTime);
|
||||
}
|
||||
|
||||
@ -48,9 +52,4 @@ public class PositionedComponent<T extends RenderComponent> {
|
||||
public T getComponent() {
|
||||
return component;
|
||||
}
|
||||
|
||||
private Vector2i windowSize() {
|
||||
Window window = Minecraft.getInstance().getWindow();
|
||||
return new Vector2i(window.getGuiScaledWidth(), window.getGuiScaledHeight());
|
||||
}
|
||||
}
|
||||
|
@ -111,7 +111,8 @@ public class RowLayoutComponent<T extends RenderComponent> extends AbstractLayou
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<T> elements(T... elements) {
|
||||
@SafeVarargs
|
||||
public final Builder<T> elements(T... elements) {
|
||||
this.elements.addAll(Arrays.asList(elements));
|
||||
return this;
|
||||
}
|
||||
|
Reference in New Issue
Block a user