Create some GUI text methods
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,14 @@ import com.bartlomiejpluta.base.api.internal.gc.Disposable;
|
||||
import com.bartlomiejpluta.base.api.internal.render.Renderable;
|
||||
|
||||
public interface GUI extends Renderable, Disposable {
|
||||
int ALIGN_LEFT = 1 << 0;
|
||||
int ALIGN_CENTER = 1 << 1;
|
||||
int ALIGN_RIGHT = 1 << 2;
|
||||
int ALIGN_TOP = 1 << 3;
|
||||
int ALIGN_MIDDLE = 1 << 4;
|
||||
int ALIGN_BOTTOM = 1 << 5;
|
||||
int ALIGN_BASELINE = 1 << 6;
|
||||
|
||||
Widget getRoot();
|
||||
|
||||
void setRoot(Widget root);
|
||||
@@ -20,5 +28,13 @@ public interface GUI extends Renderable, Disposable {
|
||||
|
||||
void setFontSize(float size);
|
||||
|
||||
void setTextAlignment(int alignment);
|
||||
|
||||
void putText(float x, float y, CharSequence text, Bounds 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);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
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.screen.Screen;
|
||||
@@ -27,6 +28,7 @@ public class NanoVGGUI implements GUI {
|
||||
|
||||
private NVGColor color;
|
||||
private final Set<String> loadedFonts = new HashSet<>();
|
||||
private final float[] boundBuffer = new float[4];
|
||||
|
||||
private final FontManager fontManager;
|
||||
|
||||
@@ -65,11 +67,30 @@ public class NanoVGGUI implements GUI {
|
||||
nvgRect(context, x, y, w, h);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putText(float x, float y, CharSequence text, Bounds outTextBounds) {
|
||||
nvgText(context, x, y, text);
|
||||
nvgTextBounds(context, x, y, text, boundBuffer);
|
||||
outTextBounds.update(boundBuffer[0], boundBuffer[1], boundBuffer[2], boundBuffer[3]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putText(float x, float y, CharSequence text) {
|
||||
nvgText(context, x, y, text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putTextBox(float x, float y, float lineWidth, CharSequence text, Bounds outTextBoxBounds) {
|
||||
nvgTextBox(context, x, y, lineWidth, text);
|
||||
nvgTextBoxBounds(context, x, y, lineWidth, text, boundBuffer);
|
||||
outTextBoxBounds.update(boundBuffer[0], boundBuffer[1], boundBuffer[2], boundBuffer[3]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putTextBox(float x, float y, float lineWidth, CharSequence text) {
|
||||
nvgTextBox(context, x, y, lineWidth, text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fillColor(float red, float green, float blue, float alpha) {
|
||||
color.r(red);
|
||||
@@ -108,6 +129,11 @@ public class NanoVGGUI implements GUI {
|
||||
nvgFontSize(context, size);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTextAlignment(int alignment) {
|
||||
nvgTextAlign(context, alignment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
color.free();
|
||||
|
||||
Reference in New Issue
Block a user