Search in sources :

Example 1 with Border

use of binnie.core.gui.geometry.Border in project Binnie by ForestryMC.

the class StyleSheetParser method parseTextures.

private static Map<String, Texture> parseTextures(JsonObject jsonObject, Map<String, ParsedTextureSheet> textureSheets) {
    JsonArray texturesJson = JsonUtils.getJsonArray(jsonObject, TEXTURES_KEY);
    if (texturesJson == null) {
        return Collections.emptyMap();
    }
    Map<String, Texture> textures = new HashMap<>();
    for (JsonElement element : texturesJson) {
        if (!element.isJsonObject()) {
            continue;
        }
        try {
            JsonObject sheetJson = element.getAsJsonObject();
            String name = JsonUtils.getString(sheetJson, NAME_KEY);
            String sheet = JsonUtils.getString(sheetJson, SHEET_KEY);
            JsonArray uvArray = JsonUtils.getJsonArray(sheetJson, UV_KEY);
            IBinnieTexture textureSheet = textureSheets.get(sheet);
            Area uv = parseArea(uvArray);
            Border border = Border.ZERO;
            Border padding = Border.ZERO;
            if (sheetJson.has(BORDER_KEY)) {
                JsonArray array = JsonUtils.getJsonArray(sheetJson, BORDER_KEY);
                border = parseBorder(array);
            }
            if (sheetJson.has(PADDING_KEY)) {
                JsonArray array = JsonUtils.getJsonArray(sheetJson, PADDING_KEY);
                padding = parseBorder(array);
            }
            Texture texture = new Texture(uv, padding, border, textureSheet);
            textures.put(name, texture);
        } catch (Exception e) {
            Log.warning("Failed to load stylesheet for Binnie's Mods.", e);
        }
    }
    return textures;
}
Also used : JsonArray(com.google.gson.JsonArray) Area(binnie.core.gui.geometry.Area) HashMap(java.util.HashMap) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) IBinnieTexture(binnie.core.resource.IBinnieTexture) IBinnieTexture(binnie.core.resource.IBinnieTexture) Texture(binnie.core.gui.resource.textures.Texture) Border(binnie.core.gui.geometry.Border) JsonParseException(com.google.gson.JsonParseException) IOException(java.io.IOException)

Example 2 with Border

use of binnie.core.gui.geometry.Border in project Binnie by ForestryMC.

the class StyleSheetParser method parseBorder.

private static Border parseBorder(JsonArray array) {
    int[] ints = new int[array.size()];
    if (ints.length < 1 || ints.length > 4) {
        throw new JsonParseException("Parameter must have between one and four numbers");
    }
    for (int i = 0; i < array.size(); i++) {
        JsonElement object = array.get(i);
        ints[i] = JsonUtils.getInt(object, UV_KEY + i);
    }
    if (ints.length == 1) {
        return new Border(ints[0]);
    }
    if (ints.length == 2) {
        return new Border(ints[0], ints[1]);
    }
    if (ints.length == 3) {
        return new Border(ints[0], ints[1], ints[2]);
    }
    return new Border(ints[0], ints[1], ints[2], ints[3]);
}
Also used : JsonElement(com.google.gson.JsonElement) JsonParseException(com.google.gson.JsonParseException) Border(binnie.core.gui.geometry.Border)

Example 3 with Border

use of binnie.core.gui.geometry.Border in project Binnie by ForestryMC.

the class ControlToleranceBar method onRenderBackground.

@Override
@SideOnly(Side.CLIENT)
public void onRenderBackground(int guiWidth, int guiHeight) {
    RenderUtil.drawGradientRect(getArea(), -1431655766, -1431655766);
    int w = getArea().width() / fullSet.size();
    int t = 0;
    for (T value : fullSet) {
        int col = (tolerated.contains(value) ? -16777216 : 855638016) + getColour(value);
        Border inset = new Border(tolerated.contains(value) ? 1 : 3);
        RenderUtil.drawGradientRect(new Area(w * t, 0, w, getHeight()).inset(inset), col, col);
        ++t;
    }
}
Also used : Area(binnie.core.gui.geometry.Area) Border(binnie.core.gui.geometry.Border) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Aggregations

Border (binnie.core.gui.geometry.Border)3 Area (binnie.core.gui.geometry.Area)2 JsonElement (com.google.gson.JsonElement)2 JsonParseException (com.google.gson.JsonParseException)2 Texture (binnie.core.gui.resource.textures.Texture)1 IBinnieTexture (binnie.core.resource.IBinnieTexture)1 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)1