List of usage examples for com.badlogic.gdx.graphics.g2d BitmapFont getLineHeight
public float getLineHeight()
From source file:com.game.libgdx.roguelikeengine.PopupInfoText.java
License:Open Source License
public void drawScreen(SpriteBatch batch, BitmapFont font, String text, float fadein, int linedist, Color color, boolean resize) { float scaleX = font.getScaleX(); float scaleY = font.getScaleY(); update_x((int) (Gdx.graphics.getWidth() * 0.5f - this.width * 0.5f)); update_y((int) (Gdx.graphics.getHeight() * 0.5f - this.height * 0.5f)); mouseOverElement = ""; if (!lastMessage.equals(text) || resize) { this.clearRenderWords(); lineCount = 0;/* w w w. ja v a 2 s . co m*/ int linepos = 0; int currentWidth = textoffsetx; int nextWidth = 0; int maxWidth = (int) (width - textoffsetx); String[] words = null; for (String line : text.split("\n")) { lineCount = lineCount + 1; currentWidth = textoffsetx; words = line.split(" "); for (String word : words) { if (word.contains("\t")) { word = word.replace("\t", " "); } Color wordColor = color; if (word.length() > 7) { String hex = word.substring(0, 7); if (Pattern.matches(colorPattern, hex)) { wordColor = this.hex2Rgb(hex); word = word.replace(hex, ""); } } nextWidth = (int) (currentWidth + font.getBounds(word + " ").width); if (nextWidth > maxWidth) { currentWidth = textoffsetx; nextWidth = (int) (currentWidth + font.getBounds(word + " ").width); linepos = linepos + 1; lineCount = lineCount + 1; } int wordx = currentWidth; int wordy = height - ((textoffsety) + (linepos * linedist)); this.addWordToRender(word, new WordRectangle(wordx, wordy, font.getBounds(word + " ").width, font.getLineHeight()) .withColor(wordColor)); currentWidth = nextWidth; } linepos++; currentWidth = x + textoffsetx; } } this.background.draw(batch, x, y, width, height); while (((lineCount * font.getLineHeight() + lineCount * linedist) * font.getScaleY()) > height - textoffsety) { font.setScale(font.getScaleY() - 0.1f); } if (font.getScaleY() != scaleY) { drawScreen(batch, font, text, fadein, linedist, color, true); font.setScale(scaleX, scaleY); return; } boolean anyClickable = false; Set<Entry<String, LinkedList<WordRectangle>>> keys = renderWords.entrySet(); for (Entry<String, LinkedList<WordRectangle>> entry : keys) { for (WordRectangle rect : entry.getValue()) { font.setColor(rect.color.r, rect.color.g, rect.color.b, fadein); if (wordClickListeners.containsKey(entry.getKey())) { if (mouseOverWord(rect, font)) { font.setColor(Color.BLUE.r, Color.BLUE.g, Color.BLUE.b, fadein); mouseOverElement = entry.getKey(); } else { font.setColor(Color.CYAN); font.setColor(Color.CYAN.r, Color.CYAN.g, Color.CYAN.b, fadein); } anyClickable = true; } font.draw(batch, entry.getKey().replace("_", " "), rect.x + x, rect.y + y); } } if (!anyClickable) { Color c = font.getColor(); font.setColor(instructionsColor.r, instructionsColor.g, instructionsColor.b, fadein); font.draw(batch, instructions, x + (width * 0.5f) - (font.getBounds(instructions).width * 0.5f), y + font.getBounds(instructions).height + Gdx.graphics.getHeight() * 0.05f); font.setColor(c); } lastMessage = text; font.setScale(scaleX, scaleY); }
From source file:com.game.libgdx.roguelikeengine.PopupInfoText.java
License:Open Source License
protected boolean mouseOverWord(Rectangle rect, BitmapFont font) { int mouseX = Gdx.input.getX(); int mouseY = Gdx.graphics.getHeight() + ((int) font.getLineHeight()) - Gdx.input.getY(); rect.x += x;// w w w . jav a 2 s . c om rect.y += y; boolean result = rect.contains(mouseX, mouseY); rect.x -= x; rect.y -= y; return result; }
From source file:com.kotcrab.vis.ui.widget.HighlightTextArea.java
License:Apache License
@Override protected void drawText(Batch batch, BitmapFont font, float x, float y) { maxAreaHeight = 0;//w ww. j a v a2 s . c o m float offsetY = 0; for (int i = firstLineShowing * 2; i < (firstLineShowing + linesShowing) * 2 && i < linesBreak.size; i += 2) { for (Chunk chunk : renderChunks) { if (chunk.lineIndex == i) { font.setColor(chunk.color); font.draw(batch, chunk.text, x + chunk.offsetX, y + offsetY); } } offsetY -= font.getLineHeight(); maxAreaHeight += font.getLineHeight(); } maxAreaHeight += 30; }
From source file:com.kotcrab.vis.ui.widget.VisTextArea.java
License:Apache License
@Override protected void sizeChanged() { lastText = null; // Cause calculateOffsets to recalculate the line breaks. // The number of lines showed must be updated whenever the height is updated BitmapFont font = style.font; Drawable background = style.background; float availableHeight = getHeight() - (background == null ? 0 : background.getBottomHeight() + background.getTopHeight()); linesShowing = (int) Math.floor(availableHeight / font.getLineHeight()); }
From source file:com.kotcrab.vis.ui.widget.VisTextArea.java
License:Apache License
@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()); }//from ww w. j a v a2s . c o m offsetY += font.getLineHeight(); i += 2; } }
From source file:com.kotcrab.vis.ui.widget.VisTextArea.java
License:Apache License
@Override protected void drawText(Batch batch, BitmapFont font, float x, float y) { float offsetY = 0; for (int i = firstLineShowing * 2; i < (firstLineShowing + linesShowing) * 2 && i < linesBreak.size; i += 2) { font.draw(batch, displayText, x, y + offsetY, linesBreak.items[i], linesBreak.items[i + 1], 0, Align.left, false);//from w w w. j av a 2 s .co m offsetY -= font.getLineHeight(); } }
From source file:com.kotcrab.vis.ui.widget.VisTextArea.java
License:Apache License
@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]); cursorX = textOffset + fontOffset + font.getData().cursorX; cursorPatch.draw(batch, x + cursorX, y - font.getDescent() / 2 - (cursorLine - firstLineShowing + 1) * font.getLineHeight(), cursorPatch.getMinWidth(), font.getLineHeight()); }
From source file:com.kotcrab.vis.ui.widget.VisTextArea.java
License:Apache License
public float getCursorY() { BitmapFont font = style.font; return -(-font.getDescent() / 2 - (cursorLine - firstLineShowing + 1) * font.getLineHeight()); }
From source file:de.hasait.tanks.util.common.Abstract2DScreen.java
License:Apache License
protected final void drawText(final int pLine, final CharSequence pText, final AlignH pAlignH, final AlignV pAlignV) { final BitmapFont font = _context.getFont(); final float y = pAlignV.getY(_viewportH, font.getLineHeight(), _textMargin) + pLine * font.getLineHeight(); final int alignH = pAlignH.getAlign(); font.draw(_context.getBatch(), pText, _textMargin, y, _viewportW - 2 * _textMargin, alignH, false); }
From source file:org.ah.gcode.preview.GCodePreviewWindow.java
License:Open Source License
public void initialise(TextureProvider textureProvider, BitmapFont font) { leftPanel = new VerticalGroup(); leftPanel.setStretchLast(true);/* w w w. j a v a 2s. c om*/ leftPanel.setFillWidth(true); addChild(leftPanel); fpsPanel = new Panel(font, (int) font.getBounds("FPS: 00.00 ").width); fpsPanel.setPosition(3, 3); addChild(fpsPanel); Button detailsHeaderButton = createDarkButtonHeader(font, "Details:"); leftPanel.addChild(detailsHeaderButton); playPanel = new Panel(font, (int) font.getBounds("Instr: 00000000/00000000").width, (int) font.getLineHeight() * 5 + 4); leftPanel.addChild(playPanel); Button consoleHeaderButton = createDarkButtonHeader(font, "Console:"); leftPanel.addChild(consoleHeaderButton); console = new Console(font, 320, 240, 5, 5); console.println("GCode Preview 0.1a"); console.println("(C) Abstract Horizon"); console.println("(http://www.abstracthorizon.org"); console.println(); console.setVisible(true); leftPanel.addChild(console); hideSliderPanel = new Panel(null, 16, height); hideSliderPanel.setBackgroundColor(hideSliderPanel.getBackgroundColor().sub(0.25f, 0.25f, 0.25f, 0f)); hideSliderPanel.refresh(); addChild(hideSliderPanel); hideSliderPanelButton = createButton(textureProvider, "gui/three-circles", false); hideSliderPanelButton.registerButtonClickedListener(new ButtonClicked() { @Override public void buttonClicked(Button button) { leftPanel.setVisible(!leftPanel.isVisible()); } }); // (Button button) -> leftPanel.setVisible(!leftPanel.isVisible()) // ); addChild(hideSliderPanelButton); horizontalSlider = new HorizontalSlider(textureProvider); addChild(horizontalSlider); verticalSlider = new VerticalSlider(textureProvider); addChild(verticalSlider); okButton = createButton(textureProvider, "gui/ok", true); okButton.setPreferredSize(32, 32); cancelButton = createButton(textureProvider, "gui/cancel", true); cancelButton.setVisible(false); cancelButton.setSize(32, 32); cancelButton.setPreferredSize(32, 32); okCancelGroup = new HorizontalGroup(); okCancelGroup.setMargin(3); okCancelGroup.addChild(cancelButton); okCancelGroup.addChild(okButton); addChild(okCancelGroup); okCancelGroup.registerMouseOverListener(new MouseOverListener() { @Override public void mouseOver(Component component, int x, int y, boolean mouseOver) { mouseOverListener(component, x, y, mouseOver); } }); // this::mouseOverListener); twoDButton = createTextButton(font, " 2D "); addChild(twoDButton); threeDButton = createTextButton(font, " 3D "); addChild(threeDButton); initialised = true; doLayout(); }