Add support for GUI image flags

This commit is contained in:
2021-03-14 23:21:12 +01:00
parent 3aac855fea
commit 449278b3cf
2 changed files with 39 additions and 7 deletions

View File

@@ -13,6 +13,13 @@ public interface GUI extends Renderable, Disposable, KeyEventHandler {
int ALIGN_BOTTOM = 1 << 5;
int ALIGN_BASELINE = 1 << 6;
int IMAGE_GENERATE_MIPMAPS = 1 << 0;
int IMAGE_REPEAT_X = 1 << 1;
int IMAGE_REPEAT_Y = 1 << 2;
int IMAGE_FLIP_Y = 1 << 3;
int IMAGE_PREMULTIPLIED = 1 << 4;
int IMAGE_NEAREST = 1 << 5;
Widget getRoot();
void setRoot(Widget root);
@@ -23,6 +30,8 @@ public interface GUI extends Renderable, Disposable, KeyEventHandler {
Image getImage(String imageUid);
Image getImage(String imageUid, int imageFlags);
void beginPath();
void closePath();
@@ -93,6 +102,8 @@ public interface GUI extends Renderable, Disposable, KeyEventHandler {
void radialGradient(float x, float y, float innerRadius, float outerRadius, Color start, Color end, Paint target);
void imagePattern(float x, float y, float angle, float alpha, Image image, Paint target);
void imagePattern(float x, float y, float width, float height, float angle, float alpha, Image image, Paint target);
void clip(float x, float y, float width, float height);

View File

@@ -18,6 +18,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import java.util.*;
import static java.lang.Integer.toBinaryString;
import static java.lang.String.format;
import static org.lwjgl.nanovg.NanoVG.*;
import static org.lwjgl.nanovg.NanoVGGL3.*;
import static org.lwjgl.system.MemoryUtil.NULL;
@@ -69,7 +71,6 @@ public class NanoVGGUI implements GUI {
@Override
public Color createColor() {
log.info("Creating new GUI color");
var color = new NanoVGColor(NVGColor.create());
colors.add(color);
return color;
@@ -77,7 +78,6 @@ public class NanoVGGUI implements GUI {
@Override
public Paint createPaint() {
log.info("Creating new GUI paint");
var paint = new NanoVGPaint(NVGPaint.create());
paints.add(paint);
return paint;
@@ -85,20 +85,26 @@ public class NanoVGGUI implements GUI {
@Override
public Image getImage(String imageUid) {
var image = loadedImages.get(imageUid);
return getImage(imageUid, 0);
}
@Override
public Image getImage(String imageUid, int imageFlags) {
var key = format("%s_%d", imageUid, imageFlags);
var image = loadedImages.get(key);
if (image == null) {
log.info("Loading GUI image with UID: [{}]", imageUid);
log.info("Loading GUI image with UID: [{}] into cache under the key: [{}]", imageUid, key);
var data = imageManager.loadObjectByteBuffer(imageUid);
var handle = nvgCreateImageMem(context, 0, data);
var handle = nvgCreateImageMem(context, imageFlags, data);
var width = new int[1];
var height = new int[1];
nvgImageSize(context, handle, width, height);
log.info("GUI image with UID: [{}] and size {}x{} has been loaded", imageUid, width, height);
log.info("GUI image with UID: [{}], size {}x{} and flags [0b{}] has been loaded", imageUid, width[0], height[0], toBinaryString(imageFlags));
image = new NanoVGImage(handle, width[0], height[0]);
loadedImages.put(imageUid, image);
loadedImages.put(key, image);
}
return image;
@@ -268,6 +274,21 @@ public class NanoVGGUI implements GUI {
);
}
@Override
public void imagePattern(float x, float y, float angle, float alpha, Image image, Paint target) {
nvgImagePattern(
context,
x,
y,
image.getWidth(),
image.getHeight(),
angle,
((NanoVGImage) image).getImageHandle(),
alpha,
((NanoVGPaint) target).getPaint()
);
}
@Override
public void imagePattern(float x, float y, float width, float height, float angle, float alpha, Image image, Paint target) {
nvgImagePattern(