diff options
Diffstat (limited to 'src/main/java/io/github/moulberry/notenoughupdates/mbgui/MBGuiGroupFloating.java')
-rw-r--r-- | src/main/java/io/github/moulberry/notenoughupdates/mbgui/MBGuiGroupFloating.java | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mbgui/MBGuiGroupFloating.java b/src/main/java/io/github/moulberry/notenoughupdates/mbgui/MBGuiGroupFloating.java new file mode 100644 index 00000000..91cca2d7 --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/mbgui/MBGuiGroupFloating.java @@ -0,0 +1,42 @@ +package io.github.moulberry.notenoughupdates.mbgui; + +import org.lwjgl.util.vector.Vector2f; + +import java.util.*; + +public class MBGuiGroupFloating extends MBGuiGroup { + + private LinkedHashMap<MBGuiElement, MBAnchorPoint> children; + + public MBGuiGroupFloating(int width, int height, LinkedHashMap<MBGuiElement, MBAnchorPoint> children) { + this.width = width; + this.height = height; + this.children = children; + recalculate(); + } + + public Map<MBGuiElement, MBAnchorPoint> getChildrenMap() { + return Collections.unmodifiableMap(children); + } + + @Override + public void recalculate() { + for(MBGuiElement child : children.keySet()) { + child.recalculate(); + } + + for(Map.Entry<MBGuiElement, MBAnchorPoint> entry : children.entrySet()) { + MBGuiElement child = entry.getKey(); + MBAnchorPoint anchorPoint = entry.getValue(); + float x = anchorPoint.anchorPoint.x * width - anchorPoint.anchorPoint.x * child.getWidth() + anchorPoint.offset.x; + float y = anchorPoint.anchorPoint.y * height - anchorPoint.anchorPoint.y * child.getHeight() + anchorPoint.offset.y; + childrenPosition.put(child, new Vector2f(x, y)); + } + } + + @Override + public Collection<MBGuiElement> getChildren() { + return children.keySet(); + } + +} |