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
|
||||
@@ -1,9 +1,8 @@
|
||||
package com.bartlomiejpluta.base.engine.gui.manager;
|
||||
|
||||
import com.bartlomiejpluta.base.api.game.gui.Font;
|
||||
import com.bartlomiejpluta.base.engine.error.AppException;
|
||||
import com.bartlomiejpluta.base.engine.gui.asset.FontAsset;
|
||||
import com.bartlomiejpluta.base.engine.gui.model.DefaultFont;
|
||||
import com.bartlomiejpluta.base.engine.gui.model.Font;
|
||||
import com.bartlomiejpluta.base.engine.project.config.ProjectConfiguration;
|
||||
import com.bartlomiejpluta.base.engine.util.res.ResourcesManager;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -47,6 +46,6 @@ public class DefaultFontManager implements FontManager {
|
||||
fontBuffers.put(uid, buffer);
|
||||
}
|
||||
|
||||
return new DefaultFont(uid, buffer.duplicate());
|
||||
return new Font(uid, buffer.duplicate());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.bartlomiejpluta.base.engine.gui.manager;
|
||||
|
||||
import com.bartlomiejpluta.base.api.game.gui.Font;
|
||||
import com.bartlomiejpluta.base.engine.common.manager.AssetManager;
|
||||
import com.bartlomiejpluta.base.engine.gui.asset.FontAsset;
|
||||
import com.bartlomiejpluta.base.engine.gui.model.Font;
|
||||
|
||||
public interface FontManager extends AssetManager<FontAsset, Font> {
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.bartlomiejpluta.base.engine.gui.model;
|
||||
|
||||
import com.bartlomiejpluta.base.api.game.gui.Font;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@@ -8,7 +7,7 @@ import java.nio.ByteBuffer;
|
||||
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public class DefaultFont implements Font {
|
||||
public class Font {
|
||||
private final String name;
|
||||
private final ByteBuffer byteBuffer;
|
||||
}
|
||||
@@ -1,78 +0,0 @@
|
||||
package com.bartlomiejpluta.base.engine.gui.model;
|
||||
|
||||
import com.bartlomiejpluta.base.api.game.gui.Color;
|
||||
import com.bartlomiejpluta.base.api.internal.gc.Disposable;
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.nanovg.NVGColor;
|
||||
|
||||
public class NanoVGColorAdapter extends NVGColor implements Color, Disposable {
|
||||
|
||||
public NanoVGColorAdapter(float red, float green, float blue, float alpha) {
|
||||
super(BufferUtils.createByteBuffer(SIZEOF));
|
||||
|
||||
r(red);
|
||||
g(green);
|
||||
b(blue);
|
||||
a(alpha);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getRed() {
|
||||
return r();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getGreen() {
|
||||
return g();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getBlue() {
|
||||
return b();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getAlpha() {
|
||||
return a();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRed(float value) {
|
||||
r(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGreen(float value) {
|
||||
g(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBlue(float value) {
|
||||
b(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAlpha(float value) {
|
||||
a(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setColor(float red, float green, float blue) {
|
||||
r(red);
|
||||
g(green);
|
||||
b(blue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setColor(float red, float green, float blue, float alpha) {
|
||||
r(red);
|
||||
g(green);
|
||||
b(blue);
|
||||
a(alpha);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
free();
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,8 @@
|
||||
package com.bartlomiejpluta.base.engine.gui.render;
|
||||
|
||||
import com.bartlomiejpluta.base.api.game.camera.Camera;
|
||||
import com.bartlomiejpluta.base.api.game.gui.Bounds;
|
||||
import com.bartlomiejpluta.base.api.game.gui.GUI;
|
||||
import com.bartlomiejpluta.base.api.game.gui.Widget;
|
||||
import com.bartlomiejpluta.base.api.game.gui.base.GUI;
|
||||
import com.bartlomiejpluta.base.api.game.gui.base.Widget;
|
||||
import com.bartlomiejpluta.base.api.game.screen.Screen;
|
||||
import com.bartlomiejpluta.base.api.internal.render.ShaderManager;
|
||||
import com.bartlomiejpluta.base.engine.error.AppException;
|
||||
@@ -68,10 +67,9 @@ public class NanoVGGUI implements GUI {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putText(float x, float y, CharSequence text, Bounds outTextBounds) {
|
||||
public void putText(float x, float y, CharSequence text, float[] outTextBounds) {
|
||||
nvgText(context, x, y, text);
|
||||
nvgTextBounds(context, x, y, text, boundBuffer);
|
||||
outTextBounds.update(boundBuffer[0], boundBuffer[1], boundBuffer[2], boundBuffer[3]);
|
||||
nvgTextBounds(context, x, y, text, outTextBounds);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -80,10 +78,9 @@ public class NanoVGGUI implements GUI {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putTextBox(float x, float y, float lineWidth, CharSequence text, Bounds outTextBoxBounds) {
|
||||
public void putTextBox(float x, float y, float lineWidth, CharSequence text, float[] outTextBounds) {
|
||||
nvgTextBox(context, x, y, lineWidth, text);
|
||||
nvgTextBoxBounds(context, x, y, lineWidth, text, boundBuffer);
|
||||
outTextBoxBounds.update(boundBuffer[0], boundBuffer[1], boundBuffer[2], boundBuffer[3]);
|
||||
nvgTextBoxBounds(context, x, y, lineWidth, text, outTextBounds);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -3,7 +3,7 @@ package com.bartlomiejpluta.base.engine.project.model;
|
||||
import com.bartlomiejpluta.base.api.game.camera.Camera;
|
||||
import com.bartlomiejpluta.base.api.game.context.Context;
|
||||
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.map.handler.MapHandler;
|
||||
import com.bartlomiejpluta.base.api.game.screen.Screen;
|
||||
|
||||
Reference in New Issue
Block a user