use of org.lwjgl.nanovg.NVGColor in project legui by SpinyOwl.
the class NvgText method drawTextLineToRect.
public static void drawTextLineToRect(long nvg, Vector4fc rect, boolean hideOverflow, HorizontalAlign horizontalAlign, VerticalAlign verticalAlign, float fontSize, String font, String textToRender, Vector4f fontColor, TextDirection direction) {
if (textToRender.length() == 0) {
return;
}
nvgFontSize(nvg, fontSize);
nvgFontFace(nvg, font);
textAlign(nvg, horizontalAlign, verticalAlign);
ByteBuffer byteText = null;
try {
byteText = memUTF8(textToRender, false);
long startPointer = memAddress(byteText);
long endPointer = startPointer + byteText.remaining();
long rowStart = startPointer;
long rowEnd = endPointer;
if (hideOverflow) {
try (NVGTextRow.Buffer buffer = NVGTextRow.calloc(1)) {
int rows = nnvgTextBreakLines(nvg, startPointer, endPointer, direction == TextDirection.HORIZONTAL ? rect.z() : rect.w(), memAddress(buffer), 1);
if (rows != 0) {
NVGTextRow row = buffer.get(0);
rowStart = row.start();
rowEnd = row.end();
}
}
}
Vector2f textPosition = new Vector2f(rect.x() + rect.z() * horizontalAlign.index / 2f, rect.y() + rect.w() * verticalAlign.index / 2f);
if (rowStart != 0 || rowEnd != 0) {
try (NVGColor textColor = NvgColorUtil.create(fontColor)) {
nvgSave(nvg);
nvgBeginPath(nvg);
nvgFillColor(nvg, textColor);
float x;
float y;
if (direction == TextDirection.VERTICAL_TOP_DOWN) {
nvgTranslate(nvg, rect.x() + rect.z(), rect.y());
nvgRotate(nvg, _90);
x = rect.w() * horizontalAlign.index / 2f;
y = rect.z() * verticalAlign.index / 2f;
} else if (direction == TextDirection.VERTICAL_DOWN_TOP) {
nvgTranslate(nvg, rect.x(), rect.y() + rect.w());
nvgRotate(nvg, _270);
x = rect.w() * horizontalAlign.index / 2f;
y = rect.z() * verticalAlign.index / 2f;
} else {
nvgTranslate(nvg, rect.x(), rect.y());
x = textPosition.x - rect.x();
y = (int) textPosition.y - rect.y();
}
int xx = (int) x;
int yy = (int) y;
nnvgText(nvg, xx, yy, rowStart, rowEnd);
nvgRestore(nvg);
}
}
} finally {
if (byteText != null) {
MemoryUtil.memFree(byteText);
}
}
}
use of org.lwjgl.nanovg.NVGColor in project legui by SpinyOwl.
the class NvgColorUtil method create.
/**
* Used to allocate and fill instance of {@link NVGColor}. Should be used in try-with-resources to
* avoid memory leaks.
*
* @param r red.
* @param g green.
* @param b blue.
* @param a alpha.
* @return allocated and filled color.
*/
public static NVGColor create(float r, float g, float b, float a) {
NVGColor color = NVGColor.calloc();
color.r(r);
color.g(g);
color.b(b);
color.a(a);
return color;
}
use of org.lwjgl.nanovg.NVGColor in project legui by SpinyOwl.
the class NvgShapes method drawRect.
/**
* Used to draw rectangle.
*
* @param nvg nanovg context
* @param rectangle rectangle size and position.
* @param bgColor rectangle background color.
*/
public static void drawRect(long nvg, Vector4fc rectangle, Vector4fc bgColor) {
if (bgColor.w() <= MIN_ALPHA) {
return;
}
try (NVGColor fillColor = NvgColorUtil.create(bgColor)) {
nvgBeginPath(nvg);
nvgFillColor(nvg, fillColor);
nvgRect(nvg, rectangle.x(), rectangle.y(), rectangle.z(), rectangle.w());
nvgFill(nvg);
}
}
use of org.lwjgl.nanovg.NVGColor in project legui by SpinyOwl.
the class NvgShapes method drawRect.
/**
* Used to draw rectangle.
*
* @param nvg nanovg context.
* @param position rectangle position.
* @param size rectangle size.
* @param bgColor rectangle background color.
* @param radius cornder radius
*/
public static void drawRect(long nvg, Vector2fc position, Vector2fc size, Vector4fc bgColor, float radius) {
if (bgColor.w() <= MIN_ALPHA) {
return;
}
try (NVGColor fillColor = NvgColorUtil.create(bgColor)) {
nvgBeginPath(nvg);
nvgFillColor(nvg, fillColor);
nvgRoundedRect(nvg, position.x(), position.y(), size.x(), size.y(), radius);
nvgFill(nvg);
}
}
use of org.lwjgl.nanovg.NVGColor in project legui by SpinyOwl.
the class NvgShapes method drawRect.
/**
* Used to draw rectangle.
*
* @param nvg nanovg context
* @param rectangle rectangle size and position.
* @param bgColor rectangle background color.
* @param radius cornder radius
*/
public static void drawRect(long nvg, Vector4fc rectangle, Vector4fc bgColor, float radius) {
if (bgColor.w() <= MIN_ALPHA) {
return;
}
try (NVGColor fillColor = NvgColorUtil.create(bgColor)) {
nvgBeginPath(nvg);
nvgFillColor(nvg, fillColor);
nvgRoundedRect(nvg, rectangle.x(), rectangle.y(), rectangle.z(), rectangle.w(), radius);
nvgFill(nvg);
}
}
Aggregations