/** * Creates a new Hud using the specified ScreenOptions, Font, width and height values. * * @param options - Screen options. * @param font - Font to use in the Hud. * @param width - Width of the Hud space. * @param height - Height of the Hud space. * * @throws Exception */ public Hud(ScreenOptions options, Font font, int width, int height) throws Exception { this.hudComponents = new ArrayList<>(); this.font = font; this.width = width; this.height = height; this.vg = options.getAntialiasing() ? nvgCreate(NVG_ANTIALIAS | NVG_STENCIL_STROKES) : nvgCreate(NVG_STENCIL_STROKES); if (this.vg == NULL) { throw new Exception("Failed to initialize NanoVG"); } int fontId = nvgCreateFontMem(vg, FONT_NAME, font.getFontBuffer(), 0); if (fontId == -1) { throw new Exception("Failed to add font to NanoVG"); } this.color = NVGColor.create(); }
public NVGColor rgba(float r, float g, float b, float a) { if(r > 1) { r = r / 255f; } if(g > 1) { g = g / 255f; } if(b > 1) { b = b / 255f; } if(a > 1) { a = a / 255f; } color.r(r); color.g(g); color.b(b); color.a(a); return color; }
public void init(Window window) throws Exception { this.vg = window.getOptions().antialiasing ? nvgCreate(NVG_ANTIALIAS | NVG_STENCIL_STROKES) : nvgCreate(NVG_STENCIL_STROKES); if (this.vg == NULL) { throw new Exception("Could not init nanovg"); } fontBuffer = Utils.ioResourceToByteBuffer("/fonts/OpenSans-Bold.ttf", 150 * 1024); int font = nvgCreateFontMem(vg, FONT_NAME, fontBuffer, 0); if (font == -1) { throw new Exception("Could not add font"); } colour = NVGColor.create(); posx = MemoryUtil.memAllocDouble(1); posy = MemoryUtil.memAllocDouble(1); counter = 0; }
@Override public float renderText(long vg, String text, String font, int align, float x, float y, float fontSize, NVGColor color) { nvgSave(vg); nvgFontSize(vg, fontSize); nvgFontFace(vg, font); nvgTextAlign(vg, align); nvgFillColor(vg, color); nvgText(vg, x, y, text); float[] bounds = new float[4]; nvgTextBounds(vg, x, y, text, bounds); if (Theme.DEBUG) { nvgIntersectScissor(vg, bounds[0], bounds[1], bounds[2] - bounds[0], bounds[3] - bounds[1]); nvgBeginPath(vg); nvgRect(vg, bounds[0], bounds[1], bounds[2] - bounds[0], bounds[3] - bounds[1]); nvgStrokeWidth(vg, Theme.DEBUG_STROKE); nvgStrokeColor(vg, Theme.debugB); nvgStroke(vg); } nvgRestore(vg); return bounds[2]; }
@Override public void renderBox(long vg, float x, float y, float w, float h, NVGColor color, float rt, float lt, float rb, float lb) { nvgSave(vg); nvgIntersectScissor(vg, x, y, w, h); nvgBeginPath(vg); nvgRoundedRectVarying(vg, x, y, w, h, lt, rt, lb, rb); nvgFillColor(vg, color); nvgFill(vg); if (Theme.DEBUG) { nvgStrokeWidth(vg, Theme.DEBUG_STROKE); nvgStrokeColor(vg, Theme.debugB); nvgStroke(vg); } nvgRestore(vg); }
public void init(MainWindow window) throws Exception { this.vg = window.getOptions().antialiasing ? nvgCreate(NVG_ANTIALIAS | NVG_STENCIL_STROKES) : nvgCreate(NVG_STENCIL_STROKES); if (this.vg == NULL) { throw new Exception("Could not init nanovg"); } fontBuffer = Util.ioResourceToByteBuffer("/fonts/OpenSans-Bold.ttf", 150 * 1024); int font = nvgCreateFontMem(vg, FONT_NAME, fontBuffer, 0); if (font == -1) { throw new Exception("Could not add font"); } colour = NVGColor.create(); posx = MemoryUtil.memAllocDouble(1); posy = MemoryUtil.memAllocDouble(1); counter = 0; }
public INVGRenderCommand getRenderCommand() { if (command == null) { command = new INVGRenderCommand() { Vec2 position = Rectangle.this.position; Vec2 dimension = Rectangle.this.dimension; NVGColor color = Rectangle.this.color; // XXX not safe! @Override public void render(long context) { NanoVG.nvgBeginPath(context); NanoVG.nvgRect(context, position.x, position.y, dimension.x, dimension.y); NanoVG.nvgFillColor(context, color); NanoVG.nvgFill(context); } }; } return command; }
@Override public void gui(long nvgCtx) { gui.markForRedraw(); NVGColor c = NVGColor.calloc(); NanoVG.nvgFillColor(nvgCtx, NanoVG.nvgRGBAf(0f, 0f, 0f, 0.65f, c)); GUIDrawUtils.drawRoundedRectangle(0, 0, 205, 145, 0, 0, 0, 5); NanoVG.nvgFillColor(nvgCtx, NanoVG.nvgRGBA((byte) 255, (byte) 192, (byte) 0, (byte) 255, c)); gui.setFontSize(20); int i = 0; gui.drawText(10, 30 + 20*(i++), "==== Debug info ===="); gui.drawText(10, 30 + 20*(i++), "%d FPS (%.2f)", this.t.fps, 1/this.t.frameTime); gui.drawText(10, 30 + 20*(i++), "%d visible points", cantidad); gui.drawText(10, 30 + 20*(i++), "%sabled drugs", phosphorEffectEnabler ? "En" : "Dis"); gui.drawText(10, 30 + 20*(i++), "%.0f u of X position", camera.getPosition().x()); gui.drawText(10, 30 + 20 * i, "=================="); c.free(); }
@Override protected void paint() { NVGColor c = NVGColor.calloc(); NanoVG.nvgSave(ctx); NanoVG.nvgIntersectScissor(ctx, frame.x, frame.y, frame.width, frame.height); NanoVG.nvgTranslate(ctx, x + paddingLeft, y + paddingTop); subViews.forEach(v -> { NanoVG.nvgSave(ctx); v.draw(); NanoVG.nvgRestore(ctx); }); NanoVG.nvgRestore(ctx); /*Color.rgb(1, 0.6, 0.8).convert(c); NanoVG.nvgStrokeColor(ctx, c); NanoVG.nvgStrokeWidth(ctx, 2); NanoVG.nvgBeginPath(ctx); NanoVG.nvgRect(ctx, frame.x, frame.y, frame.width, frame.height); NanoVG.nvgStroke(ctx);*/ c.free(); }
public Node(float x, float y, float width, float height) { this.x = x; this.y = y; this.width = width; this.height = height; color = NVGColor.create(); paint = NVGPaint.create(); }
private NVGColor rgba(int r, int g, int b, int a, NVGColor colour) { colour.r(r / 255.0f); colour.g(g / 255.0f); colour.b(b / 255.0f); colour.a(a / 255.0f); return colour; }
public static NVGColor setColor(float r, float g, float b, float a, NVGColor color) { color.r(r); color.g(g); color.b(b); color.a(a); return color; }
public static NVGColor setColor(String hex, NVGColor color) { color.r(Integer.valueOf(hex.substring(1, 3), 16) / 255f); color.g(Integer.valueOf(hex.substring(3, 5), 16) / 255f); color.b(Integer.valueOf(hex.substring(5, 7), 16) / 255f); color.a(Integer.valueOf(hex.substring(7, 9), 16) / 255f); return color; }
@Override public void renderTitlebar(long vg, float w, NVGColor color) { nvgSave(vg); nvgIntersectScissor(vg, 0, 1, w, Variables.TITLEBAR_HEIGHT); nvgBeginPath(vg); nvgRect(vg, 0, 1, w, Variables.TITLEBAR_HEIGHT); nvgFillColor(vg, color); nvgFill(vg); if (Theme.DEBUG) { nvgStrokeWidth(vg, Theme.DEBUG_STROKE); nvgStrokeColor(vg, Theme.debugB); nvgStroke(vg); } nvgRestore(vg); }
@Override public float renderParagraph(long vg, float x, float y, float width, float fontSize, String font, String text, int align, NVGColor color) { if (text == null) text = ""; ByteBuffer paragraph = memUTF8(text); nvgSave(vg); nvgFontSize(vg, fontSize); nvgFontFace(vg, font); nvgTextAlign(vg, align); nvgTextMetrics(vg, null, null, lineh); long start = memAddress(paragraph); long end = start + paragraph.remaining(); int nrows; float yy = y; while ((nrows = nnvgTextBreakLines(vg, start, end, width, memAddress(rows), 3)) != 0) { for (int i = 0; i < nrows; i++) { NVGTextRow row = rows.get(i); nvgFillColor(vg, color); nnvgText(vg, x, yy, row.start(), row.end()); yy += lineh.get(0); } start = rows.get(nrows - 1).next(); } if (Theme.DEBUG) { nvgIntersectScissor(vg, x, y, width, yy - y); nvgBeginPath(vg); nvgRect(vg, x, y, width, yy - y); nvgStrokeWidth(vg, Theme.DEBUG_STROKE); nvgStrokeColor(vg, Theme.debugB); nvgStroke(vg); } nvgRestore(vg); return yy - y; }
private NVGColor unwrap(@Nullable Color color) { if (color == null) throw new IllegalArgumentException("Cannot use a null color"); if (!(color instanceof NanoVGColor)) { return nvgRGBAf(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha(), NVGColor.create()); } return ((NanoVGColor)color).wrapped; }
private void nvgGradient(NVGPaint paint) { try(MemoryStack stack = MemoryStack.stackPush()) { NVGColor icolor = NVGColor.mallocStack(stack), ocolor = NVGColor.mallocStack(stack); inside.convert(icolor); outside.convert(ocolor); if(type == 0) { nvgLinearGradient(gui.nvgCtx, a, b, c, d, icolor, ocolor, paint); } else if(type == 1) { nvgBoxGradient(gui.nvgCtx, a, b, c, d, e, f, icolor, ocolor, paint); } else if(type == 2) { nvgRadialGradient(gui.nvgCtx, a, b, c, d, icolor, ocolor, paint); } } }
/** * Sets the current fill color to this color */ public void setAsFillColor() { try(MemoryStack stack = MemoryStack.stackPush()) { NVGColor c = NVGColor.mallocStack(stack); NanoVG.nvgFillColor(GUI.gui.nvgCtx, convert(c)); } }
/** * Sets the current stroke color to this color */ public void setAsStrokeColor() { try(MemoryStack stack = MemoryStack.stackPush()) { NVGColor c = NVGColor.mallocStack(stack); NanoVG.nvgStrokeColor(GUI.gui.nvgCtx, convert(c)); } }
public static NVGColor rgba(int r, int g, int b, int a, NVGColor color) { return setColor(r / 255f, g / 255f, b / 255f, a / 255f, color); }
public static NVGColor rgba(int r, int g, int b, int a) { return setColor(r / 255f, g / 255f, b / 255f, a / 255f); }
public static NVGColor setColor(float r, float g, float b, float a) { return setColor(r, g, b, a, NVGColor.create()); }
public static NVGColor setColor(String hex) { return setColor(hex, NVGColor.create()); }
public static void renderTitlebar(long vg, float w, NVGColor color) { theme.renderTitlebar(vg, w, color); }
public static float renderText(long vg, String text, String font, int align, float x, float y, float fontSize, NVGColor color) { return theme.renderText(vg, text, font, align, x, y, fontSize, color); }