Refactor NanoVGGUI - prepare to support NVGPaint and images
This commit is contained in:
@@ -67,11 +67,15 @@ public interface GUI extends Renderable, Disposable, KeyEventHandler {
|
|||||||
|
|
||||||
void setGlobalAlpha(float alpha);
|
void setGlobalAlpha(float alpha);
|
||||||
|
|
||||||
void fillColor(float red, float green, float blue, float alpha);
|
void setFillColor(float red, float green, float blue, float alpha);
|
||||||
|
|
||||||
|
void fill();
|
||||||
|
|
||||||
|
void setStrokeColor(float red, float green, float blue, float alpha);
|
||||||
|
|
||||||
void setStrokeWidth(float width);
|
void setStrokeWidth(float width);
|
||||||
|
|
||||||
void strokeColor(float red, float green, float blue, float alpha);
|
void stroke();
|
||||||
|
|
||||||
void clip(float x, float y, float width, float height);
|
void clip(float x, float y, float width, float height);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -144,7 +144,8 @@ public class Label extends BaseComponent {
|
|||||||
gui.setFontFace(font);
|
gui.setFontFace(font);
|
||||||
gui.setTextAlignment(alignment);
|
gui.setTextAlignment(alignment);
|
||||||
gui.setFontSize(fontSize);
|
gui.setFontSize(fontSize);
|
||||||
gui.fillColor(red, green, blue, alpha);
|
gui.setFillColor(red, green, blue, alpha);
|
||||||
|
gui.fill();
|
||||||
gui.putTextBox(x + paddingLeft, y + paddingTop, getWidth() - paddingLeft - paddingRight, text, bounds);
|
gui.putTextBox(x + paddingLeft, y + paddingTop, getWidth() - paddingLeft - paddingRight, text, bounds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import com.bartlomiejpluta.base.engine.world.image.manager.ImageManager;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.lwjgl.nanovg.NVGColor;
|
import org.lwjgl.nanovg.NVGColor;
|
||||||
|
import org.lwjgl.nanovg.NVGPaint;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -34,11 +35,14 @@ public class NanoVGGUI implements GUI {
|
|||||||
|
|
||||||
private long context;
|
private long context;
|
||||||
private ScreenWidget screenWidget;
|
private ScreenWidget screenWidget;
|
||||||
|
|
||||||
private NVGColor fillColor;
|
private NVGColor fillColor;
|
||||||
private NVGColor strokeColor;
|
private NVGColor strokeColor;
|
||||||
|
private NVGPaint fillPaint;
|
||||||
|
private NVGPaint strokePaint;
|
||||||
|
|
||||||
private final Set<String> loadedFonts = new HashSet<>();
|
private final Set<String> loadedFonts = new HashSet<>();
|
||||||
private final Map<String, Integer> loadedImages = new HashMap<>();
|
private final Map<String, Integer> loadedImages = new HashMap<>();
|
||||||
private final float[] boundBuffer = new float[4];
|
|
||||||
|
|
||||||
public void init(Screen screen) {
|
public void init(Screen screen) {
|
||||||
context = nvgCreate(NVG_ANTIALIAS | NVG_STENCIL_STROKES);
|
context = nvgCreate(NVG_ANTIALIAS | NVG_STENCIL_STROKES);
|
||||||
@@ -51,6 +55,8 @@ public class NanoVGGUI implements GUI {
|
|||||||
|
|
||||||
fillColor = NVGColor.create();
|
fillColor = NVGColor.create();
|
||||||
strokeColor = NVGColor.create();
|
strokeColor = NVGColor.create();
|
||||||
|
fillPaint = NVGPaint.create();
|
||||||
|
strokePaint = NVGPaint.create();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -164,24 +170,32 @@ public class NanoVGGUI implements GUI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fillColor(float red, float green, float blue, float alpha) {
|
public void setFillColor(float red, float green, float blue, float alpha) {
|
||||||
fillColor.r(red);
|
fillColor.r(red);
|
||||||
fillColor.g(green);
|
fillColor.g(green);
|
||||||
fillColor.b(blue);
|
fillColor.b(blue);
|
||||||
fillColor.a(alpha);
|
fillColor.a(alpha);
|
||||||
|
|
||||||
nvgFillColor(context, fillColor);
|
nvgFillColor(context, fillColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void fill() {
|
||||||
nvgFill(context);
|
nvgFill(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void strokeColor(float red, float green, float blue, float alpha) {
|
public void setStrokeColor(float red, float green, float blue, float alpha) {
|
||||||
strokeColor.r(red);
|
strokeColor.r(red);
|
||||||
strokeColor.g(green);
|
strokeColor.g(green);
|
||||||
strokeColor.b(blue);
|
strokeColor.b(blue);
|
||||||
strokeColor.a(alpha);
|
strokeColor.a(alpha);
|
||||||
|
|
||||||
nvgStrokeColor(context, strokeColor);
|
nvgStrokeColor(context, strokeColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void stroke() {
|
||||||
nvgStroke(context);
|
nvgStroke(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -257,6 +271,8 @@ public class NanoVGGUI implements GUI {
|
|||||||
public void dispose() {
|
public void dispose() {
|
||||||
fillColor.free();
|
fillColor.free();
|
||||||
strokeColor.free();
|
strokeColor.free();
|
||||||
|
fillPaint.free();
|
||||||
|
strokePaint.free();
|
||||||
nvgDelete(context);
|
nvgDelete(context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user