Delegate some extra methods from NanoVG to GUI
This commit is contained in:
@@ -18,18 +18,44 @@ public interface GUI extends Renderable, Disposable {
|
|||||||
|
|
||||||
void beginPath();
|
void beginPath();
|
||||||
|
|
||||||
void drawRectangle(float x, float y, float w, float h);
|
void closePath();
|
||||||
|
|
||||||
void fillColor(float red, float green, float blue, float alpha);
|
void drawRectangle(float x, float y, float width, float height);
|
||||||
|
|
||||||
void strokeColor(float red, float green, float blue, float alpha);
|
void drawRoundedRectangle(float x, float y, float width, float height, float radius);
|
||||||
|
|
||||||
|
void drawCircle(float x, float y, float radius);
|
||||||
|
|
||||||
|
void drawEllipse(float x, float y, float radiusX, float radiusY);
|
||||||
|
|
||||||
|
void drawArc(float x, float y, float radius, float start, float end, WindingDirection direction);
|
||||||
|
|
||||||
|
void drawArcTo(float x1, float y1, float x2, float y2, float radius);
|
||||||
|
|
||||||
|
void drawLineTo(float x, float y);
|
||||||
|
|
||||||
|
void drawBezierTo(float controlX1, float controlY1, float controlX2, float controlY2, float targetX, float targetY);
|
||||||
|
|
||||||
|
void drawQuadBezierTo(float controlX, float controlY, float targetX, float targetY);
|
||||||
|
|
||||||
|
void setLineCap(LineCap cap);
|
||||||
|
|
||||||
|
void setLineJoin(LineCap join);
|
||||||
|
|
||||||
|
void moveTo(float x, float y);
|
||||||
|
|
||||||
|
void setPathWinding(WindingDirection direction);
|
||||||
|
|
||||||
void setFontFace(String fontUid);
|
void setFontFace(String fontUid);
|
||||||
|
|
||||||
void setFontSize(float size);
|
void setFontSize(float size);
|
||||||
|
|
||||||
|
void setFontBlur(float blur);
|
||||||
|
|
||||||
void setTextAlignment(int alignment);
|
void setTextAlignment(int alignment);
|
||||||
|
|
||||||
|
void setTextLineHeight(float textLineHeight);
|
||||||
|
|
||||||
void putText(float x, float y, CharSequence text, float[] outTextBounds);
|
void putText(float x, float y, CharSequence text, float[] outTextBounds);
|
||||||
|
|
||||||
void putText(float x, float y, CharSequence text);
|
void putText(float x, float y, CharSequence text);
|
||||||
@@ -37,4 +63,14 @@ public interface GUI extends Renderable, Disposable {
|
|||||||
void putTextBox(float x, float y, float lineWidth, CharSequence text, float[] outTextBounds);
|
void putTextBox(float x, float y, float lineWidth, CharSequence text, float[] outTextBounds);
|
||||||
|
|
||||||
void putTextBox(float x, float y, float lineWidth, CharSequence text);
|
void putTextBox(float x, float y, float lineWidth, CharSequence text);
|
||||||
|
|
||||||
|
void setGlobalAlpha(float alpha);
|
||||||
|
|
||||||
|
void fillColor(float red, float green, float blue, float alpha);
|
||||||
|
|
||||||
|
void setStrokeWidth(float width);
|
||||||
|
|
||||||
|
void strokeColor(float red, float green, float blue, float alpha);
|
||||||
|
|
||||||
|
void clip(float x, float y, float width, float height);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package com.bartlomiejpluta.base.api.game.gui.base;
|
||||||
|
|
||||||
|
public enum LineCap {
|
||||||
|
BUTT,
|
||||||
|
ROUND,
|
||||||
|
SQUARE,
|
||||||
|
BEVEL,
|
||||||
|
MITER
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package com.bartlomiejpluta.base.api.game.gui.base;
|
||||||
|
|
||||||
|
public enum WindingDirection {
|
||||||
|
CLOCKWISE,
|
||||||
|
COUNTER_CLOCKWISE
|
||||||
|
}
|
||||||
@@ -2,7 +2,9 @@ package com.bartlomiejpluta.base.engine.gui.render;
|
|||||||
|
|
||||||
import com.bartlomiejpluta.base.api.game.camera.Camera;
|
import com.bartlomiejpluta.base.api.game.camera.Camera;
|
||||||
import com.bartlomiejpluta.base.api.game.gui.base.GUI;
|
import com.bartlomiejpluta.base.api.game.gui.base.GUI;
|
||||||
|
import com.bartlomiejpluta.base.api.game.gui.base.LineCap;
|
||||||
import com.bartlomiejpluta.base.api.game.gui.base.Widget;
|
import com.bartlomiejpluta.base.api.game.gui.base.Widget;
|
||||||
|
import com.bartlomiejpluta.base.api.game.gui.base.WindingDirection;
|
||||||
import com.bartlomiejpluta.base.api.game.screen.Screen;
|
import com.bartlomiejpluta.base.api.game.screen.Screen;
|
||||||
import com.bartlomiejpluta.base.api.internal.render.ShaderManager;
|
import com.bartlomiejpluta.base.api.internal.render.ShaderManager;
|
||||||
import com.bartlomiejpluta.base.engine.error.AppException;
|
import com.bartlomiejpluta.base.engine.error.AppException;
|
||||||
@@ -25,7 +27,8 @@ public class NanoVGGUI implements GUI {
|
|||||||
@Setter
|
@Setter
|
||||||
private Widget root;
|
private Widget root;
|
||||||
|
|
||||||
private NVGColor color;
|
private NVGColor fillColor;
|
||||||
|
private NVGColor strokeColor;
|
||||||
private final Set<String> loadedFonts = new HashSet<>();
|
private final Set<String> loadedFonts = new HashSet<>();
|
||||||
private final float[] boundBuffer = new float[4];
|
private final float[] boundBuffer = new float[4];
|
||||||
|
|
||||||
@@ -38,7 +41,8 @@ public class NanoVGGUI implements GUI {
|
|||||||
public void init(Screen screen) {
|
public void init(Screen screen) {
|
||||||
context = nvgCreate(NVG_ANTIALIAS | NVG_STENCIL_STROKES);
|
context = nvgCreate(NVG_ANTIALIAS | NVG_STENCIL_STROKES);
|
||||||
|
|
||||||
color = NVGColor.create();
|
fillColor = NVGColor.create();
|
||||||
|
strokeColor = NVGColor.create();
|
||||||
|
|
||||||
if (context == NULL) {
|
if (context == NULL) {
|
||||||
throw new AppException("Could not onCreate NanoVG");
|
throw new AppException("Could not onCreate NanoVG");
|
||||||
@@ -62,8 +66,115 @@ public class NanoVGGUI implements GUI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void drawRectangle(float x, float y, float w, float h) {
|
public void closePath() {
|
||||||
nvgRect(context, x, y, w, h);
|
nvgClosePath(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void drawRectangle(float x, float y, float width, float height) {
|
||||||
|
nvgRect(context, x, y, width, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void drawRoundedRectangle(float x, float y, float width, float height, float radius) {
|
||||||
|
nvgRoundedRect(context, x, y, width, height, radius);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void drawCircle(float x, float y, float radius) {
|
||||||
|
nvgCircle(context, x, y, radius);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void drawEllipse(float x, float y, float radiusX, float radiusY) {
|
||||||
|
nvgEllipse(context, x, y, radiusX, radiusY);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void drawArc(float x, float y, float radius, float start, float end, WindingDirection direction) {
|
||||||
|
nvgArc(context, x, y, radius, start, end, direction == WindingDirection.CLOCKWISE ? NVG_CW : NVG_CCW);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void drawArcTo(float x1, float y1, float x2, float y2, float radius) {
|
||||||
|
nvgArcTo(context, x1, y1, x2, y2, radius);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void drawLineTo(float x, float y) {
|
||||||
|
nvgLineTo(context, x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void drawBezierTo(float controlX1, float controlY1, float controlX2, float controlY2, float targetX, float targetY) {
|
||||||
|
nvgBezierTo(context, controlX1, controlY1, controlX2, controlY2, targetX, targetY);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void drawQuadBezierTo(float controlX, float controlY, float targetX, float targetY) {
|
||||||
|
nvgQuadTo(context, controlX, controlY, targetX, targetY);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setLineCap(LineCap cap) {
|
||||||
|
nvgLineCap(context, lineCapToNanoVGInteger(cap));
|
||||||
|
}
|
||||||
|
|
||||||
|
private int lineCapToNanoVGInteger(LineCap cap) {
|
||||||
|
return switch (cap) {
|
||||||
|
case BUTT -> NVG_BUTT;
|
||||||
|
case ROUND -> NVG_ROUND;
|
||||||
|
case SQUARE -> NVG_SQUARE;
|
||||||
|
case BEVEL -> NVG_BEVEL;
|
||||||
|
case MITER -> NVG_MITER;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setLineJoin(LineCap join) {
|
||||||
|
nvgLineJoin(context, lineCapToNanoVGInteger(join));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void moveTo(float x, float y) {
|
||||||
|
nvgMoveTo(context, x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setGlobalAlpha(float alpha) {
|
||||||
|
nvgGlobalAlpha(context, alpha);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setPathWinding(WindingDirection direction) {
|
||||||
|
nvgPathWinding(context, direction == WindingDirection.CLOCKWISE ? NVG_CW : NVG_CCW);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void fillColor(float red, float green, float blue, float alpha) {
|
||||||
|
fillColor.r(red);
|
||||||
|
fillColor.g(green);
|
||||||
|
fillColor.b(blue);
|
||||||
|
fillColor.a(alpha);
|
||||||
|
|
||||||
|
nvgFillColor(context, fillColor);
|
||||||
|
nvgFill(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void strokeColor(float red, float green, float blue, float alpha) {
|
||||||
|
strokeColor.r(red);
|
||||||
|
strokeColor.g(green);
|
||||||
|
strokeColor.b(blue);
|
||||||
|
strokeColor.a(alpha);
|
||||||
|
|
||||||
|
nvgStrokeColor(context, strokeColor);
|
||||||
|
nvgStroke(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setStrokeWidth(float width) {
|
||||||
|
nvgStrokeWidth(context, width);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -88,28 +199,6 @@ public class NanoVGGUI implements GUI {
|
|||||||
nvgTextBox(context, x, y, lineWidth, text);
|
nvgTextBox(context, x, y, lineWidth, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void fillColor(float red, float green, float blue, float alpha) {
|
|
||||||
color.r(red);
|
|
||||||
color.g(green);
|
|
||||||
color.b(blue);
|
|
||||||
color.a(alpha);
|
|
||||||
|
|
||||||
nvgFillColor(context, color);
|
|
||||||
nvgFill(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void strokeColor(float red, float green, float blue, float alpha) {
|
|
||||||
color.r(red);
|
|
||||||
color.g(green);
|
|
||||||
color.b(blue);
|
|
||||||
color.a(alpha);
|
|
||||||
|
|
||||||
nvgStrokeColor(context, color);
|
|
||||||
nvgFill(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setFontFace(String fontUid) {
|
public void setFontFace(String fontUid) {
|
||||||
if (!loadedFonts.contains(fontUid)) {
|
if (!loadedFonts.contains(fontUid)) {
|
||||||
@@ -126,14 +215,30 @@ public class NanoVGGUI implements GUI {
|
|||||||
nvgFontSize(context, size);
|
nvgFontSize(context, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setFontBlur(float blur) {
|
||||||
|
nvgFontBlur(context, blur);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setTextAlignment(int alignment) {
|
public void setTextAlignment(int alignment) {
|
||||||
nvgTextAlign(context, alignment);
|
nvgTextAlign(context, alignment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setTextLineHeight(float textLineHeight) {
|
||||||
|
nvgTextLineHeight(context, textLineHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clip(float x, float y, float width, float height) {
|
||||||
|
nvgScissor(context, x, y, width, height);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void dispose() {
|
public void dispose() {
|
||||||
color.free();
|
fillColor.free();
|
||||||
|
strokeColor.free();
|
||||||
nvgDelete(context);
|
nvgDelete(context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user