/** 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); }
/** 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); }
/** Removes from this array all of elements contained in the specified array. * @return true if this array was modified. */ public boolean removeAll (FloatArray array) { int size = this.size; int startSize = size; float[] items = this.items; for (int i = 0, n = array.size; i < n; i++) { float item = array.get(i); for (int ii = 0; ii < size; ii++) { if (item == items[ii]) { removeIndex(ii); size--; break; } } } return size != startSize; }
/** Removes from this array all of elements contained in the specified array. * @return true if this array was modified. */ public boolean removeAll (FloatArray array) { int size = this.size; int startSize = size; float[] items = this.items; for (int i = 0, n = array.size; i < n; i++) { float item = array.get(i); for (int ii = 0; ii < size; ii++) { if (item == items[ii]) { removeIndex(ii); size--; break; } } } return size != startSize; }
protected void drawCursor (Drawable cursorPatch, Batch batch, BitmapFont font, float x, float y) { cursorPatch.draw(batch, x + textOffset + glyphPositions.get(cursor) - glyphPositions.get(visibleTextStart) + fontOffset + font.getData().cursorX, y - textHeight - font.getDescent(), cursorPatch.getMinWidth(), textHeight); }
protected void drawCursor (Drawable cursorPatch, Batch batch, BitmapFont font, float x, float y) { cursorPatch.draw(batch, x + textOffset + glyphPositions.get(cursor) - glyphPositions.get(visibleTextStart) + fontOffset + font.getData().cursorX, y - textHeight - font.getDescent(), cursorPatch.getMinWidth(), textHeight); }
public void render () { Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); renderer.setColor(Color.RED); renderer.begin(ShapeType.Filled); for (int i = 0; i < points.size; i += 2) renderer.circle(points.get(i), points.get(i + 1), 4, 12); renderer.end(); renderer.setColor(Color.WHITE); renderer.begin(ShapeType.Line); for (int i = 0; i < triangles.size; i += 3) { int p1 = triangles.get(i) * 2; int p2 = triangles.get(i + 1) * 2; int p3 = triangles.get(i + 2) * 2; renderer.triangle( // points.get(p1), points.get(p1 + 1), // points.get(p2), points.get(p2 + 1), // points.get(p3), points.get(p3 + 1)); } renderer.end(); }
@Override protected void drawSelection (Drawable selection, Batch batch, BitmapFont font, float x, float y) { int i = firstLineShowing * 2; float offsetY = 0; int minIndex = Math.min(cursor, selectionStart); int maxIndex = Math.max(cursor, selectionStart); while (i + 1 < linesBreak.size && i < (firstLineShowing + linesShowing) * 2) { int lineStart = linesBreak.get(i); int lineEnd = linesBreak.get(i + 1); if (!((minIndex < lineStart && minIndex < lineEnd && maxIndex < lineStart && maxIndex < lineEnd) || (minIndex > lineStart && minIndex > lineEnd && maxIndex > lineStart && maxIndex > lineEnd))) { int start = Math.max(linesBreak.get(i), minIndex); int end = Math.min(linesBreak.get(i + 1), maxIndex); float selectionX = glyphPositions.get(start) - glyphPositions.get(linesBreak.get(i)); float selectionWidth = glyphPositions.get(end) - glyphPositions.get(start); selection.draw(batch, x + selectionX + fontOffset, y - textHeight - font.getDescent() - offsetY, selectionWidth, font.getLineHeight()); } offsetY += font.getLineHeight(); i += 2; } }
@Override protected void drawSelection (Drawable selection, Batch batch, BitmapFont font, float x, float y) { int i = firstLineShowing * 2; float offsetY = 0; int minIndex = Math.min(cursor, selectionStart); int maxIndex = Math.max(cursor, selectionStart); while (i + 1 < linesBreak.size && i < (firstLineShowing + linesShowing) * 2) { int lineStart = linesBreak.get(i); int lineEnd = linesBreak.get(i + 1); if (!((minIndex < lineStart && minIndex < lineEnd && maxIndex < lineStart && maxIndex < lineEnd) || (minIndex > lineStart && minIndex > lineEnd && maxIndex > lineStart && maxIndex > lineEnd))) { int start = Math.max(linesBreak.get(i), minIndex); int end = Math.min(linesBreak.get(i + 1), maxIndex); float selectionX = glyphPositions.get(start) - glyphPositions.get(linesBreak.get(i)); float selectionWidth = glyphPositions.get(end) - glyphPositions.get(start); selection.draw(batch, x + selectionX + fontOffset, y - textHeight - font.getDescent() - offsetY, selectionWidth, font.getLineHeight()); } offsetY += font.getLineHeight(); i += 2; } }
/** Moves the cursor to the given number line **/ public void moveCursorLine (int line) { if (line < 0) { cursorLine = 0; cursor = 0; moveOffset = -1; } else if (line >= getLines()) { int newLine = getLines() - 1; cursor = text.length(); if (line > getLines() || newLine == cursorLine) { moveOffset = -1; } cursorLine = newLine; } else if (line != cursorLine) { if (moveOffset < 0) { moveOffset = linesBreak.size <= cursorLine * 2 ? 0 : glyphPositions.get(cursor) - glyphPositions.get(linesBreak.get(cursorLine * 2)); } cursorLine = line; cursor = cursorLine * 2 >= linesBreak.size ? text.length() : linesBreak.get(cursorLine * 2); while (cursor < text.length() && cursor <= linesBreak.get(cursorLine * 2 + 1) - 1 && glyphPositions.get(cursor) - glyphPositions.get(linesBreak.get(cursorLine * 2)) < moveOffset) { cursor++; } showCursor(); } }
/** Moves the cursor to the given number line **/ public void moveCursorLine (int line) { if (line < 0) { cursorLine = 0; cursor = 0; moveOffset = -1; } else if (line >= getLines()) { int newLine = getLines() - 1; cursor = text.length(); if (line > getLines() || newLine == cursorLine) { moveOffset = -1; } cursorLine = newLine; } else if (line != cursorLine) { if (moveOffset < 0) { moveOffset = linesBreak.size <= cursorLine * 2 ? 0 : glyphPositions.get(cursor) - glyphPositions.get(linesBreak.get(cursorLine * 2)); } cursorLine = line; cursor = cursorLine * 2 >= linesBreak.size ? text.length() : linesBreak.get(cursorLine * 2); while (cursor < text.length() && cursor <= linesBreak.get(cursorLine * 2 + 1) - 1 && glyphPositions.get(cursor) - glyphPositions.get(linesBreak.get(cursorLine * 2)) < moveOffset) { cursor++; } showCursor(); } }
@Override protected void drawCursor (Drawable cursorPatch, Batch batch, BitmapFont font, float x, float y) { float textOffset = cursor >= glyphPositions.size || cursorLine * 2 >= linesBreak.size ? 0 : glyphPositions.get(cursor) - glyphPositions.get(linesBreak.items[cursorLine * 2]); cursorPatch.draw(batch, x + textOffset + fontOffset + font.getData().cursorX, y - font.getDescent() / 2 - (cursorLine - firstLineShowing + 1) * font.getLineHeight(), cursorPatch.getMinWidth(), font.getLineHeight()); }
@Override protected void drawCursor (Drawable cursorPatch, Batch batch, BitmapFont font, float x, float y) { float textOffset = cursor >= glyphPositions.size || cursorLine * 2 >= linesBreak.size ? 0 : glyphPositions.get(cursor) - glyphPositions.get(linesBreak.items[cursorLine * 2]); cursorPatch.draw(batch, x + textOffset + fontOffset + font.getData().cursorX, y - font.getDescent() / 2 - (cursorLine - firstLineShowing + 1) * font.getLineHeight(), cursorPatch.getMinWidth(), font.getLineHeight()); }
protected int letterUnderCursor (float x) { x -= textOffset + fontOffset - style.font.getData().cursorX - glyphPositions.get(visibleTextStart); Drawable background = getBackgroundDrawable(); if (background != null) x -= style.background.getLeftWidth(); int n = this.glyphPositions.size; float[] glyphPositions = this.glyphPositions.items; for (int i = 1; i < n; i++) { if (glyphPositions[i] > x) { if (glyphPositions[i] - x <= x - glyphPositions[i - 1]) return i; return i - 1; } } return n - 1; }
protected int letterUnderCursor (float x) { x -= textOffset + fontOffset - style.font.getData().cursorX - glyphPositions.get(visibleTextStart); Drawable background = getBackgroundDrawable(); if (background != null) x -= style.background.getLeftWidth(); int n = this.glyphPositions.size; float[] glyphPositions = this.glyphPositions.items; for (int i = 1; i < n; i++) { if (glyphPositions[i] > x) { if (glyphPositions[i] - x <= x - glyphPositions[i - 1]) return i; return i - 1; } } return n - 1; }
for (int i = 1, n = xAdvances.size; i < n; i++) { glyphPositions.add(x); x += xAdvances.get(i);
for (int ii = 0, nn = glyphs.size; ii < nn; ii++) { Glyph glyph = glyphs.get(ii); gx += xAdvances.get(ii); addGlyph(glyph, gx, gy, color);
for (int ii = 0, nn = glyphs.size; ii < nn; ii++) { Glyph glyph = glyphs.get(ii); gx += xAdvances.get(ii); addGlyph(glyph, gx, gy, color);