Refactor com.bartlomiejpluta.base.api.gui package
This commit is contained in:
@@ -2,7 +2,7 @@ package com.bartlomiejpluta.base.api.game.context;
|
||||
|
||||
import com.bartlomiejpluta.base.api.game.camera.Camera;
|
||||
import com.bartlomiejpluta.base.api.game.entity.Entity;
|
||||
import com.bartlomiejpluta.base.api.game.gui.GUI;
|
||||
import com.bartlomiejpluta.base.api.game.gui.base.GUI;
|
||||
import com.bartlomiejpluta.base.api.game.image.Image;
|
||||
import com.bartlomiejpluta.base.api.game.screen.Screen;
|
||||
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
package com.bartlomiejpluta.base.api.game.gui;
|
||||
|
||||
public class Bounds {
|
||||
private float minX;
|
||||
private float minY;
|
||||
private float maxX;
|
||||
private float maxY;
|
||||
|
||||
public void update(float minX, float minY, float maxX, float maxY) {
|
||||
this.minX = minX;
|
||||
this.minY = minY;
|
||||
this.maxX = maxX;
|
||||
this.maxY = maxY;
|
||||
}
|
||||
|
||||
public float getMinX() {
|
||||
return minX;
|
||||
}
|
||||
|
||||
public float getMinY() {
|
||||
return minY;
|
||||
}
|
||||
|
||||
public float getMaxX() {
|
||||
return maxX;
|
||||
}
|
||||
|
||||
public float getMaxY() {
|
||||
return maxY;
|
||||
}
|
||||
|
||||
public float getWidth() {
|
||||
return maxX - minX;
|
||||
}
|
||||
|
||||
public float getHeight() {
|
||||
return maxY - minY;
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package com.bartlomiejpluta.base.api.game.gui;
|
||||
|
||||
public interface Color {
|
||||
float getRed();
|
||||
|
||||
float getGreen();
|
||||
|
||||
float getBlue();
|
||||
|
||||
float getAlpha();
|
||||
|
||||
void setRed(float value);
|
||||
|
||||
void setGreen(float value);
|
||||
|
||||
void setBlue(float value);
|
||||
|
||||
void setAlpha(float value);
|
||||
|
||||
void setColor(float red, float green, float blue);
|
||||
|
||||
void setColor(float red, float green, float blue, float alpha);
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package com.bartlomiejpluta.base.api.game.gui;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class Container extends Component {
|
||||
protected final List<Component> children = new LinkedList<>();
|
||||
|
||||
public void addChild(Component component) {
|
||||
this.children.add(component);
|
||||
component.setParent(this);
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
package com.bartlomiejpluta.base.api.game.gui;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public interface Font {
|
||||
String getName();
|
||||
|
||||
ByteBuffer getByteBuffer();
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.bartlomiejpluta.base.api.game.gui;
|
||||
package com.bartlomiejpluta.base.api.game.gui.base;
|
||||
|
||||
import com.bartlomiejpluta.base.api.internal.gc.Disposable;
|
||||
import com.bartlomiejpluta.base.api.internal.render.Renderable;
|
||||
@@ -30,11 +30,11 @@ public interface GUI extends Renderable, Disposable {
|
||||
|
||||
void setTextAlignment(int alignment);
|
||||
|
||||
void putText(float x, float y, CharSequence text, Bounds outTextBounds);
|
||||
void putText(float x, float y, CharSequence text, float[] outTextBounds);
|
||||
|
||||
void putText(float x, float y, CharSequence text);
|
||||
|
||||
void putTextBox(float x, float y, float lineWidth, CharSequence text, Bounds outTextBoxBounds);
|
||||
void putTextBox(float x, float y, float lineWidth, CharSequence text, float[] outTextBounds);
|
||||
|
||||
void putTextBox(float x, float y, float lineWidth, CharSequence text);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.bartlomiejpluta.base.api.game.gui;
|
||||
package com.bartlomiejpluta.base.api.game.gui.base;
|
||||
|
||||
import com.bartlomiejpluta.base.api.game.screen.Screen;
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.bartlomiejpluta.base.api.game.gui.component;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class BaseContainer extends Component implements Container {
|
||||
protected final List<Component> children = new LinkedList<>();
|
||||
|
||||
@Override
|
||||
public void add(Component component) {
|
||||
this.children.add(component);
|
||||
component.setParent(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(Component component) {
|
||||
this.children.remove(component);
|
||||
component.setParent(null);
|
||||
}
|
||||
|
||||
protected float maxChildrenWidth() {
|
||||
var theWidestChild = 0.0f;
|
||||
|
||||
for (var child : children) {
|
||||
var width = child.getMarginLeft() + child.getWidth() + child.getMarginRight();
|
||||
if (width > theWidestChild) {
|
||||
theWidestChild = width;
|
||||
}
|
||||
}
|
||||
|
||||
return theWidestChild;
|
||||
}
|
||||
|
||||
protected float maxChildrenHeight() {
|
||||
var theHighestChild = 0.0f;
|
||||
|
||||
for (var child : children) {
|
||||
var height = child.getMarginTop() + child.getHeight() + child.getMarginBottom();
|
||||
if (height > theHighestChild) {
|
||||
theHighestChild = height;
|
||||
}
|
||||
}
|
||||
|
||||
return theHighestChild;
|
||||
}
|
||||
|
||||
protected float sumChildrenWidth() {
|
||||
var childrenWidth = 0.0f;
|
||||
|
||||
for (var child : children) {
|
||||
childrenWidth += child.getMarginLeft() + child.getWidth() + child.getMarginRight();
|
||||
}
|
||||
|
||||
return childrenWidth;
|
||||
}
|
||||
|
||||
protected float sumChildrenHeight() {
|
||||
var childrenHeight = 0.0f;
|
||||
|
||||
for (var child : children) {
|
||||
childrenHeight += child.getMarginTop() + child.getHeight() + child.getMarginBottom();
|
||||
}
|
||||
|
||||
return childrenHeight;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
package com.bartlomiejpluta.base.api.game.gui;
|
||||
package com.bartlomiejpluta.base.api.game.gui.component;
|
||||
|
||||
import com.bartlomiejpluta.base.api.game.gui.base.Widget;
|
||||
|
||||
public abstract class Component implements Widget {
|
||||
protected Widget parent;
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.bartlomiejpluta.base.api.game.gui.component;
|
||||
|
||||
import com.bartlomiejpluta.base.api.game.gui.base.Widget;
|
||||
|
||||
public interface Container extends Widget {
|
||||
void add(Component component);
|
||||
|
||||
void remove(Component component);
|
||||
}
|
||||
@@ -1,32 +1,18 @@
|
||||
package com.bartlomiejpluta.base.api.game.gui;
|
||||
package com.bartlomiejpluta.base.api.game.gui.component;
|
||||
|
||||
import com.bartlomiejpluta.base.api.game.gui.base.GUI;
|
||||
import com.bartlomiejpluta.base.api.game.screen.Screen;
|
||||
|
||||
public class HBox extends Container {
|
||||
public class HLayout extends BaseContainer {
|
||||
|
||||
@Override
|
||||
public float getWidth() {
|
||||
var childrenWidth = 0.0f;
|
||||
|
||||
for (var child : children) {
|
||||
childrenWidth += child.getMarginLeft() + child.getWidth() + child.getMarginRight();
|
||||
}
|
||||
|
||||
return paddingLeft + childrenWidth + paddingRight;
|
||||
return paddingLeft + sumChildrenWidth() + paddingRight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getHeight() {
|
||||
var theHighestChild = 0.0f;
|
||||
|
||||
for (var child : children) {
|
||||
var height = child.getMarginTop() + child.getHeight() + child.getMarginBottom();
|
||||
if (height > theHighestChild) {
|
||||
theHighestChild = height;
|
||||
}
|
||||
}
|
||||
|
||||
return paddingTop + theHighestChild + paddingBottom;
|
||||
return paddingTop + maxChildrenHeight() + paddingBottom;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1,32 +1,18 @@
|
||||
package com.bartlomiejpluta.base.api.game.gui;
|
||||
package com.bartlomiejpluta.base.api.game.gui.component;
|
||||
|
||||
import com.bartlomiejpluta.base.api.game.gui.base.GUI;
|
||||
import com.bartlomiejpluta.base.api.game.screen.Screen;
|
||||
|
||||
public class VBox extends Container {
|
||||
public class VLayout extends BaseContainer {
|
||||
|
||||
@Override
|
||||
public float getWidth() {
|
||||
var theWidestChild = 0.0f;
|
||||
|
||||
for (var child : children) {
|
||||
var width = child.getMarginLeft() + child.getWidth() + child.getMarginRight();
|
||||
if (width > theWidestChild) {
|
||||
theWidestChild = width;
|
||||
}
|
||||
}
|
||||
|
||||
return paddingLeft + theWidestChild + paddingRight;
|
||||
return paddingLeft + maxChildrenWidth() + paddingRight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getHeight() {
|
||||
var childrenHeight = 0.0f;
|
||||
|
||||
for (var child : children) {
|
||||
childrenHeight += child.getMarginTop() + child.getHeight() + child.getMarginBottom();
|
||||
}
|
||||
|
||||
return paddingTop + childrenHeight + paddingBottom;
|
||||
return paddingTop + sumChildrenHeight() + paddingBottom;
|
||||
}
|
||||
|
||||
@Override
|
||||
Reference in New Issue
Block a user