Search in sources :

Example 11 with RectF

use of com.watabou.utils.RectF in project shattered-pixel-dungeon-gdx by 00-Evan.

the class TerrainFeaturesTilemap method tile.

public static Image tile(int pos, int tile) {
    RectF uv = instance.tileset.get(instance.getTileVisual(pos, tile, true));
    if (uv == null)
        return null;
    Image img = new Image(instance.texture);
    img.frame(uv);
    return img;
}
Also used : RectF(com.watabou.utils.RectF) Image(com.watabou.noosa.Image)

Example 12 with RectF

use of com.watabou.utils.RectF in project shattered-pixel-dungeon-gdx by 00-Evan.

the class KeyDisplay method updateVertices.

private void updateVertices() {
    // assumes shorter key sprite
    int maxRows = (int) (height + 1) / 5;
    // 1 pixel of padding between each key
    int maxPerRow = (int) (width + 1) / 4;
    int maxKeys = maxPerRow * maxRows;
    while (totalKeys > maxKeys) {
        Class<? extends Key> mostType = null;
        int mostNum = 0;
        for (Class<? extends Key> k : keyMap.keySet()) {
            if (keys[keyMap.get(k)] >= mostNum) {
                mostType = k;
                mostNum = keys[keyMap.get(k)];
            }
        }
        keys[keyMap.get(mostType)]--;
        totalKeys--;
    }
    int rows = (int) Math.ceil(totalKeys / (float) maxPerRow);
    boolean shortKeys = (rows * 8) > height;
    float left;
    if (totalKeys > maxPerRow) {
        left = 0;
    } else {
        left = (width + 1 - (totalKeys * 4)) / 2;
    }
    float top = (height + 1 - (rows * (shortKeys ? 5 : 8))) / 2;
    quads = Quad.createSet(totalKeys);
    for (int i = 0; i < totalKeys; i++) {
        int keyIdx = 0;
        if (i == 0 && keys[0] > 0) {
            // black key
            keyIdx = 0;
        } else {
            for (int j = 1; j < keys.length; j++) {
                if (keys[j] > 0) {
                    keys[j]--;
                    keyIdx = j;
                    break;
                }
            }
        }
        // texture coordinates
        RectF r = tx.uvRect(43 + 3 * keyIdx, shortKeys ? 8 : 0, 46 + 3 * keyIdx, shortKeys ? 12 : 7);
        vertices[2] = r.left;
        vertices[3] = r.top;
        vertices[6] = r.right;
        vertices[7] = r.top;
        vertices[10] = r.right;
        vertices[11] = r.bottom;
        vertices[14] = r.left;
        vertices[15] = r.bottom;
        // screen coordinates
        vertices[0] = left;
        vertices[1] = top;
        vertices[4] = left + 3;
        vertices[5] = top;
        vertices[8] = left + 3;
        vertices[9] = top + (shortKeys ? 4 : 7);
        vertices[12] = left;
        vertices[13] = top + (shortKeys ? 4 : 7);
        quads.put(vertices);
        // move to the right for more keys, drop down if the row is done
        left += 4;
        if (left + 3 > width) {
            left = 0;
            top += (shortKeys ? 5 : 8);
        }
    }
    dirty = false;
}
Also used : RectF(com.watabou.utils.RectF)

Aggregations

RectF (com.watabou.utils.RectF)12 Image (com.watabou.noosa.Image)3 SmartTexture (com.watabou.gltextures.SmartTexture)1 PointF (com.watabou.utils.PointF)1