Java 类org.lwjgl.nanovg.NanoVG 实例源码

项目:ether    文件:SimpleNanoVG.java   
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;
}
项目:Java-GLEngine    文件:EspacioEuclideo.java   
@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();
}
项目:Java-GLEngine    文件:Container.java   
@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();
}
项目:Java-GLEngine    文件:Gradient.java   
/**
 * Sets the current fill paint to this image
 */
public void setAsFillPaint() {
    try(MemoryStack stack = MemoryStack.stackPush()) {
        NVGPaint c = NVGPaint.mallocStack(stack);
        nvgGradient(c);
        NanoVG.nvgFillPaint(GUI.gui.nvgCtx, c);
    }
}
项目:Java-GLEngine    文件:Gradient.java   
/**
 * Sets the current stroke paint to this image
 */
public void setAsStrokePaint() {
    try(MemoryStack stack = MemoryStack.stackPush()) {
        NVGPaint c = NVGPaint.mallocStack(stack);
        nvgGradient(c);
        NanoVG.nvgStrokePaint(GUI.gui.nvgCtx, c);
    }
}
项目:Java-GLEngine    文件:Color.java   
/**
 * 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));
    }
}
项目:Java-GLEngine    文件:Color.java   
/**
 * 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));
    }
}
项目:Java-GLEngine    文件:GUI.java   
/**
 * Loads a font from the System fonts locations with file name
 * {@code fileName} (<i>without extension</i>) and gives a name
 * to it. Only supports {@code ttf} fonts. When this method is called, if there's
 * only one loaded font (the one loaded in that moment) then this become
 * the default font.
 * @param name a name for the font
 * @param fileName file name of the font
 * @throws FileNotFoundException if file doesn't exist
 * @throws IllegalArgumentException if file extension is not a ttf
 * @throws RuntimeException if something else bad happens
 * @see #setDefaultFont(String) Change default font
 */
public void loadSystemFont(String name, String fileName) throws FileNotFoundException {
    File ttf;
    if(org.lwjgl.system.Platform.get() == org.lwjgl.system.Platform.MACOSX) {
        ttf = new File(System.getenv("HOME") + "/Library/Fonts", fileName + ".ttf");
        if(!ttf.exists()) {
            ttf = new File("/Library/Fonts", fileName + ".ttf");
            if(!ttf.exists()) {
                ttf = new File("/System/Library/Fonts", fileName + ".ttf");
                if(!ttf.exists()) {
                    throw new FileNotFoundException("Cannot find " + fileName + ".ttf");
                }
            }
        }
    } else if(org.lwjgl.system.Platform.get() == org.lwjgl.system.Platform.LINUX) {
        ttf = new File(System.getenv("HOME") + "/.fonts/truetype", fileName + ".ttf");
        if(!ttf.exists()) {
            ttf = new File("/usr/local/share/fonts/truetype", fileName + ".ttf");
            if(!ttf.exists()) {
                ttf = new File("/usr/share/fonts/truetype", fileName + ".ttf");
                if(!ttf.exists()) {
                    throw new FileNotFoundException("Cannot find " + fileName + ".ttf");
                }
            }
        }
    } else if(org.lwjgl.system.Platform.get() == org.lwjgl.system.Platform.WINDOWS) {
        ttf = new File("\\Windows\\Fonts", fileName + ".ttf");
        if(!ttf.exists()) {
            throw new FileNotFoundException("Cannot find " + fileName + ".ttf");
        }
    } else {
        throw new RuntimeException("Platform not supported");
    }
    int handle = NanoVG.nvgCreateFont(nvgCtx, name, ttf.getAbsolutePath());
    if(handle == -1) throw new RuntimeException("Could not load TTF Font");
    fontsMap.put(name, handle);
    if(fontsMap.size() == 1) defaultFont = name;
}
项目:Java-GLEngine    文件:Image.java   
/**
 * Sets the current fill paint to this image
 */
public void setAsFillPaint() {
    try(MemoryStack stack = MemoryStack.stackPush()) {
        NVGPaint c = NVGPaint.mallocStack(stack);
        c = nvgImagePattern(gui.nvgCtx, x, y, width, height, angle, handle, alpha, c);
        NanoVG.nvgFillPaint(GUI.gui.nvgCtx, c);
    }
}
项目:Java-GLEngine    文件:Image.java   
/**
 * Sets the current stroke paint to this image
 */
public void setAsStrokePaint() {
    try(MemoryStack stack = MemoryStack.stackPush()) {
        NVGPaint c = NVGPaint.mallocStack(stack);
        c = nvgImagePattern(gui.nvgCtx, x, y, width, height, angle, handle, alpha, c);
        NanoVG.nvgStrokePaint(GUI.gui.nvgCtx, c);
    }
}
项目:ether    文件:SimpleNanoVG.java   
public void setColor(RGBA color) {
    NanoVG.nvgRGBAf(color.r, color.g, color.b, color.a, this.color);
    invalidate();
}
项目:Java-GLEngine    文件:GUI.java   
/**
 * Sets the current font for drawing text to {@code name} font.
 * If the font doesn't exist, does nothing.
 * @param name name of the font, or {@code null} for default font
 */
public void setFont(String name) {
    Integer id = fontsMap.get(name != null ? name : defaultFont);
    if(id == null) throw new NoSuchElementException("Font named by " + name + " is not loaded");
    NanoVG.nvgFontFaceId(nvgCtx, id);
}
项目:Java-GLEngine    文件:GUI.java   
/**
 * Loads a font from the disk and gives a {@code name} to it. Only
 * supports {@code ttf} fonts. When this method is called, if there's
 * only one loaded font (the one loaded in that moment) then this become
 * the default font.
 * @param name a name for the font
 * @param path path to the font file
 * @throws FileNotFoundException if file doesn't exist
 * @throws RuntimeException if something else bad happens
 * @see #setDefaultFont(String) Change default font
 */
public void loadFont(String name, File path) throws FileNotFoundException {
    if(!path.getName().endsWith(".ttf")) throw new IllegalArgumentException("File must be a TTF Font");
    if(!path.exists()) throw new FileNotFoundException("File must exist");
    int handle = NanoVG.nvgCreateFont(nvgCtx, name, path.getAbsolutePath());
    if(handle == -1) throw new RuntimeException("Could not load TTF Font");
    fontsMap.put(name, handle);
    if(fontsMap.size() == 1) defaultFont = name;
}
项目:Java-GLEngine    文件:GUI.java   
/**
 * Sets the current font for drawing text to {@code name} font and
 * its font size in px (DPI independent).
 * If the font doesn't exist, does nothing.
 * @param name name of the font, or {@code null} for default font
 * @param size size in px of the font
 */
public void setFont(String name, float size) {
    Integer id = fontsMap.get(name != null ? name : defaultFont);
    if(id == null) throw new NoSuchElementException("Font named by " + name + " is not loaded");
    NanoVG.nvgFontFaceId(nvgCtx, id);
    NanoVG.nvgFontSize(nvgCtx, size);
}
项目:Java-GLEngine    文件:Color.java   
/**
 * Sets the value of the {@link NVGColor} struct to the
 * one stored in this {@link Color} instance.
 * @param color allocated {@link NVGColor} struct
 * @return the same {@code color} {@link NVGColor} struct
 */
NVGColor convert(NVGColor color) {
    return NanoVG.nvgRGBAf(r, g, b, a, color);
}
项目:Java-GLEngine    文件:GUI.java   
/**
 * Changes the font size in px (DPI independent).
 * @param size size in px of the font
 */
public void setFontSize(int size) {
    NanoVG.nvgFontSize(nvgCtx, size);
}
项目:Java-GLEngine    文件:GUI.java   
/**
 * Draws a text on the position. The position
 * is on the bottom right corner of the <i>text box</i>.
 * @param x X position
 * @param y Y position
 * @param text text to draw
 */
public void drawText(float x, float y, String text) {
    throwIfNoGui();
    NanoVG.nvgText(nvgCtx, x, y, text, 0);
}