aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io/github/moulberry/notenoughupdates/mbgui/MBGuiGroup.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/io/github/moulberry/notenoughupdates/mbgui/MBGuiGroup.java')
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/mbgui/MBGuiGroup.java64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/mbgui/MBGuiGroup.java b/src/main/java/io/github/moulberry/notenoughupdates/mbgui/MBGuiGroup.java
new file mode 100644
index 00000000..4759d99b
--- /dev/null
+++ b/src/main/java/io/github/moulberry/notenoughupdates/mbgui/MBGuiGroup.java
@@ -0,0 +1,64 @@
+package io.github.moulberry.notenoughupdates.mbgui;
+
+import org.lwjgl.util.vector.Vector2f;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+public abstract class MBGuiGroup extends MBGuiElement {
+
+ public int width;
+ public int height;
+ protected HashMap<MBGuiElement, Vector2f> childrenPosition = new HashMap<>();
+
+ public MBGuiGroup() {
+ }
+
+ public abstract Collection<MBGuiElement> getChildren();
+
+ public Map<MBGuiElement, Vector2f> getChildrenPosition() {
+ return Collections.unmodifiableMap(childrenPosition);
+ }
+
+ @Override
+ public int getWidth() {
+ return width;
+ }
+
+ @Override
+ public int getHeight() {
+ return height;
+ }
+
+
+ @Override
+ public void mouseClick(float x, float y, int mouseX, int mouseY) {
+ for(MBGuiElement child : getChildren()) {
+ Vector2f childPos = childrenPosition.get(child);
+ if(mouseX > x+childPos.x && mouseX < x+childPos.x+child.getWidth()) {
+ if(mouseY > y+childPos.y && mouseY < y+childPos.y+child.getHeight()) {
+ child.mouseClick(x+childPos.x, y+childPos.y, mouseX, mouseY);
+ }
+ }
+ }
+ }
+
+ @Override
+ public void mouseClickOutside() {
+ for(MBGuiElement child : getChildren()) {
+ child.mouseClickOutside();
+ }
+ }
+
+ @Override
+ public void render(float x, float y) {
+ for(MBGuiElement child : getChildren()) {
+ Vector2f childPos = childrenPosition.get(child);
+ child.render(x+childPos.x, y+childPos.y);
+ }
+ }
+
+
+}