Add support for GUI image flags
This commit is contained in:
@@ -13,6 +13,13 @@ public interface GUI extends Renderable, Disposable, KeyEventHandler {
|
|||||||
int ALIGN_BOTTOM = 1 << 5;
|
int ALIGN_BOTTOM = 1 << 5;
|
||||||
int ALIGN_BASELINE = 1 << 6;
|
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();
|
Widget getRoot();
|
||||||
|
|
||||||
void setRoot(Widget root);
|
void setRoot(Widget root);
|
||||||
@@ -23,6 +30,8 @@ public interface GUI extends Renderable, Disposable, KeyEventHandler {
|
|||||||
|
|
||||||
Image getImage(String imageUid);
|
Image getImage(String imageUid);
|
||||||
|
|
||||||
|
Image getImage(String imageUid, int imageFlags);
|
||||||
|
|
||||||
void beginPath();
|
void beginPath();
|
||||||
|
|
||||||
void closePath();
|
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 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 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);
|
void clip(float x, float y, float width, float height);
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
|
|
||||||
import java.util.*;
|
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.NanoVG.*;
|
||||||
import static org.lwjgl.nanovg.NanoVGGL3.*;
|
import static org.lwjgl.nanovg.NanoVGGL3.*;
|
||||||
import static org.lwjgl.system.MemoryUtil.NULL;
|
import static org.lwjgl.system.MemoryUtil.NULL;
|
||||||
@@ -69,7 +71,6 @@ public class NanoVGGUI implements GUI {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Color createColor() {
|
public Color createColor() {
|
||||||
log.info("Creating new GUI color");
|
|
||||||
var color = new NanoVGColor(NVGColor.create());
|
var color = new NanoVGColor(NVGColor.create());
|
||||||
colors.add(color);
|
colors.add(color);
|
||||||
return color;
|
return color;
|
||||||
@@ -77,7 +78,6 @@ public class NanoVGGUI implements GUI {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Paint createPaint() {
|
public Paint createPaint() {
|
||||||
log.info("Creating new GUI paint");
|
|
||||||
var paint = new NanoVGPaint(NVGPaint.create());
|
var paint = new NanoVGPaint(NVGPaint.create());
|
||||||
paints.add(paint);
|
paints.add(paint);
|
||||||
return paint;
|
return paint;
|
||||||
@@ -85,20 +85,26 @@ public class NanoVGGUI implements GUI {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Image getImage(String imageUid) {
|
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) {
|
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 data = imageManager.loadObjectByteBuffer(imageUid);
|
||||||
var handle = nvgCreateImageMem(context, 0, data);
|
var handle = nvgCreateImageMem(context, imageFlags, data);
|
||||||
var width = new int[1];
|
var width = new int[1];
|
||||||
var height = new int[1];
|
var height = new int[1];
|
||||||
nvgImageSize(context, handle, width, height);
|
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]);
|
image = new NanoVGImage(handle, width[0], height[0]);
|
||||||
|
|
||||||
loadedImages.put(imageUid, image);
|
loadedImages.put(key, image);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 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
|
@Override
|
||||||
public void imagePattern(float x, float y, float width, float height, float angle, float alpha, Image image, Paint target) {
|
public void imagePattern(float x, float y, float width, float height, float angle, float alpha, Image image, Paint target) {
|
||||||
nvgImagePattern(
|
nvgImagePattern(
|
||||||
|
|||||||
Reference in New Issue
Block a user