Search in sources :

Example 1 with FloatArray

use of com.badlogic.gdx.utils.FloatArray in project libgdx by libgdx.

the class BitmapFontCache method addToCache.

private void addToCache(GlyphLayout layout, float x, float y) {
    // Check if the number of font pages has changed.
    int pageCount = font.regions.size;
    if (pageVertices.length < pageCount) {
        float[][] newPageVertices = new float[pageCount][];
        System.arraycopy(pageVertices, 0, newPageVertices, 0, pageVertices.length);
        pageVertices = newPageVertices;
        int[] newIdx = new int[pageCount];
        System.arraycopy(idx, 0, newIdx, 0, idx.length);
        idx = newIdx;
        IntArray[] newPageGlyphIndices = new IntArray[pageCount];
        int pageGlyphIndicesLength = 0;
        if (pageGlyphIndices != null) {
            pageGlyphIndicesLength = pageGlyphIndices.length;
            System.arraycopy(pageGlyphIndices, 0, newPageGlyphIndices, 0, pageGlyphIndices.length);
        }
        for (int i = pageGlyphIndicesLength; i < pageCount; i++) newPageGlyphIndices[i] = new IntArray();
        pageGlyphIndices = newPageGlyphIndices;
        tempGlyphCount = new int[pageCount];
    }
    layouts.add(layout);
    requireGlyphs(layout);
    for (int i = 0, n = layout.runs.size; i < n; i++) {
        GlyphRun run = layout.runs.get(i);
        Array<Glyph> glyphs = run.glyphs;
        FloatArray xAdvances = run.xAdvances;
        float color = run.color.toFloatBits();
        float gx = x + run.x, gy = y + run.y;
        for (int ii = 0, nn = glyphs.size; ii < nn; ii++) {
            Glyph glyph = glyphs.get(ii);
            gx += xAdvances.get(ii);
            addGlyph(glyph, gx, gy, color);
        }
    }
    // Cached glyphs have changed, reset the current tint.
    currentTint = whiteTint;
}
Also used : FloatArray(com.badlogic.gdx.utils.FloatArray) IntArray(com.badlogic.gdx.utils.IntArray) GlyphRun(com.badlogic.gdx.graphics.g2d.GlyphLayout.GlyphRun) Glyph(com.badlogic.gdx.graphics.g2d.BitmapFont.Glyph)

Example 2 with FloatArray

use of com.badlogic.gdx.utils.FloatArray in project libgdx by libgdx.

the class ConvexHull method computeIndices.

/** Computes a hull the same as {@link #computePolygon(float[], int, int, boolean)} but returns indices of the specified points. */
public IntArray computeIndices(float[] points, int offset, int count, boolean sorted, boolean yDown) {
    int end = offset + count;
    if (!sorted) {
        if (sortedPoints == null || sortedPoints.length < count)
            sortedPoints = new float[count];
        System.arraycopy(points, offset, sortedPoints, 0, count);
        points = sortedPoints;
        offset = 0;
        sortWithIndices(points, count, yDown);
    }
    IntArray indices = this.indices;
    indices.clear();
    FloatArray hull = this.hull;
    hull.clear();
    // Lower hull.
    for (int i = offset, index = i / 2; i < end; i += 2, index++) {
        float x = points[i];
        float y = points[i + 1];
        while (hull.size >= 4 && ccw(x, y) <= 0) {
            hull.size -= 2;
            indices.size--;
        }
        hull.add(x);
        hull.add(y);
        indices.add(index);
    }
    // Upper hull.
    for (int i = end - 4, index = i / 2, t = hull.size + 2; i >= offset; i -= 2, index--) {
        float x = points[i];
        float y = points[i + 1];
        while (hull.size >= t && ccw(x, y) <= 0) {
            hull.size -= 2;
            indices.size--;
        }
        hull.add(x);
        hull.add(y);
        indices.add(index);
    }
    // Convert sorted to unsorted indices.
    if (!sorted) {
        short[] originalIndicesArray = originalIndices.items;
        int[] indicesArray = indices.items;
        for (int i = 0, n = indices.size; i < n; i++) indicesArray[i] = originalIndicesArray[indicesArray[i]];
    }
    return indices;
}
Also used : FloatArray(com.badlogic.gdx.utils.FloatArray) IntArray(com.badlogic.gdx.utils.IntArray)

Example 3 with FloatArray

use of com.badlogic.gdx.utils.FloatArray in project libgdx by libgdx.

the class ConvexHull method ccw.

/** Returns > 0 if the points are a counterclockwise turn, < 0 if clockwise, and 0 if colinear. */
private float ccw(float p3x, float p3y) {
    FloatArray hull = this.hull;
    int size = hull.size;
    float p1x = hull.get(size - 4);
    float p1y = hull.get(size - 3);
    float p2x = hull.get(size - 2);
    float p2y = hull.peek();
    return (p2x - p1x) * (p3y - p1y) - (p2y - p1y) * (p3x - p1x);
}
Also used : FloatArray(com.badlogic.gdx.utils.FloatArray)

Example 4 with FloatArray

use of com.badlogic.gdx.utils.FloatArray in project libgdx by libgdx.

the class ConvexHull method computePolygon.

/** Returns a list of points on the convex hull in counter-clockwise order. Note: the last point in the returned list is the
	 * same as the first one. */
/** Returns the convex hull polygon for the given point cloud.
	 * @param points x,y pairs describing points. Duplicate points will result in undefined behavior.
	 * @param sorted If false, the points will be sorted by the x coordinate then the y coordinate, which is required by the convex
	 *           hull algorithm. If sorting is done the input array is not modified and count additional working memory is needed.
	 * @return pairs of coordinates that describe the convex hull polygon in counterclockwise order. Note the returned array is
	 *         reused for later calls to the same method. */
public FloatArray computePolygon(float[] points, int offset, int count, boolean sorted) {
    int end = offset + count;
    if (!sorted) {
        if (sortedPoints == null || sortedPoints.length < count)
            sortedPoints = new float[count];
        System.arraycopy(points, offset, sortedPoints, 0, count);
        points = sortedPoints;
        offset = 0;
        sort(points, count);
    }
    FloatArray hull = this.hull;
    hull.clear();
    // Lower hull.
    for (int i = offset; i < end; i += 2) {
        float x = points[i];
        float y = points[i + 1];
        while (hull.size >= 4 && ccw(x, y) <= 0) hull.size -= 2;
        hull.add(x);
        hull.add(y);
    }
    // Upper hull.
    for (int i = end - 4, t = hull.size + 2; i >= offset; i -= 2) {
        float x = points[i];
        float y = points[i + 1];
        while (hull.size >= t && ccw(x, y) <= 0) hull.size -= 2;
        hull.add(x);
        hull.add(y);
    }
    return hull;
}
Also used : FloatArray(com.badlogic.gdx.utils.FloatArray)

Example 5 with FloatArray

use of com.badlogic.gdx.utils.FloatArray in project libgdx by libgdx.

the class TextAreaTest2 method create.

@Override
public void create() {
    stage = new Stage();
    Gdx.input.setInputProcessor(stage);
    skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    //Create a string that perfectly fills the float array used in the textarea float array
    FloatArray dummyArray = new FloatArray();
    String limit = "";
    // Minus one, because TextField adds a magic char
    for (int i = 0; i < dummyArray.items.length - 1; i++) {
        limit += "a";
    }
    TextArea textArea = new TextArea(limit, skin);
    textArea.setX(10);
    textArea.setY(10);
    textArea.setWidth(200);
    textArea.setHeight(200);
    stage.addActor(textArea);
}
Also used : FloatArray(com.badlogic.gdx.utils.FloatArray) TextArea(com.badlogic.gdx.scenes.scene2d.ui.TextArea) Stage(com.badlogic.gdx.scenes.scene2d.Stage) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin)

Aggregations

FloatArray (com.badlogic.gdx.utils.FloatArray)11 Actor (com.badlogic.gdx.scenes.scene2d.Actor)4 Layout (com.badlogic.gdx.scenes.scene2d.utils.Layout)4 Glyph (com.badlogic.gdx.graphics.g2d.BitmapFont.Glyph)2 GlyphRun (com.badlogic.gdx.graphics.g2d.GlyphLayout.GlyphRun)2 IntArray (com.badlogic.gdx.utils.IntArray)2 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)1 BitmapFontData (com.badlogic.gdx.graphics.g2d.BitmapFont.BitmapFontData)1 Stage (com.badlogic.gdx.scenes.scene2d.Stage)1 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)1 TextArea (com.badlogic.gdx.scenes.scene2d.ui.TextArea)1