Java Code Examples for com.badlogic.gdx.graphics.g2d.GlyphLayout#setText()
The following examples show how to use
com.badlogic.gdx.graphics.g2d.GlyphLayout#setText() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AMScreen.java From cocos-ui-libgdx with Apache License 2.0 | 6 votes |
@Override public void show() { super.show(); layout = new GlyphLayout(); font = new NativeFont(new NativeFontPaint(25)); font.appendText("正在加载...0123456789%"); font.setColor(Color.BLACK); layout.setText(font, "正在加载...100%"); stage = new Stage(new StretchViewport(1280, 720)); assetManager = new AssetManager(); assetManager.setLogger(new Logger("log", Logger.DEBUG)); assetManager.setLoader(CocosScene.class, new CocosLoader(new InternalFileHandleResolver())); assetManager.load("mainscene/MenuScene.json", CocosScene.class); }
Example 2
Source File: RenderedConsole.java From riiablo with Apache License 2.0 | 5 votes |
public void render(Batch b) { if (!visible || font == null) return; b.draw(modalBackground, 0, consoleY - 4, clientWidth, consoleHeight + 4); final int x = 2; String inputContents = in.getContents(); GlyphLayout glyphs = font.draw(b, BUFFER_PREFIX + inputContents, x, bufferY - 2); b.draw(cursorTexture, x, bufferY, clientWidth, 2); if (showCaret) { final int caret = in.getCaretPosition(); if (caret != in.length()) { glyphs.setText(font, BUFFER_PREFIX + inputContents.substring(0, caret)); } b.draw(cursorTexture, x + glyphs.width, consoleY - 2, 2, textHeight); } Pools.free(glyphs); final float outputOffset = scrollOffset * lineHeight; if (outputOffset < outputHeight) { // offsets output to always appear that it starts at top of console window scrollOffset = Math.max(scrollOffset, scrollOffsetMin); } float position = outputY; final int outputSize = OUTPUT.size; if (scrollOffset > outputSize) { scrollOffset = outputSize; position += ((scrollOffsetMin - scrollOffset) * lineHeight); } for (int i = scrollOffset - 1; i >= 0; i--) { if (position > clientHeight) break; String line = OUTPUT.get(i); font.draw(b, line, x, position); position += lineHeight; } }
Example 3
Source File: GlythData.java From seventh with GNU General Public License v2.0 | 5 votes |
public static int getWidth(BitmapFont font, GlyphLayout bounds, String str) { bounds.setText(font, str); int textWidth = (int)bounds.width+1; // bug in libgdx, doesn't like strings ending with a space, // it ignores it if(str.endsWith(" ")) { textWidth += font.getSpaceWidth(); } return textWidth; }
Example 4
Source File: VisSpeller.java From buffer_bci with GNU General Public License v3.0 | 5 votes |
public Text(String text_) { text = text_; GlyphLayout layout = new GlyphLayout(); layout.setText(font,text_); //TextBounds bounds = font.getBounds(text); x = Gdx.graphics.getWidth() / 2 - layout.width / 2; y = Gdx.graphics.getHeight() / 2 - layout.height / 2; }
Example 5
Source File: GameOverScreen.java From libgdx-2d-tutorial with MIT License | 4 votes |
@Override public void render (float delta) { Gdx.gl.glClearColor(0, 0, 0, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); game.batch.begin(); game.scrollingBackground.updateAndRender(delta, game.batch); game.batch.draw(gameOverBanner, SpaceGame.WIDTH / 2 - BANNER_WIDTH / 2, SpaceGame.HEIGHT - BANNER_HEIGHT - 15, BANNER_WIDTH, BANNER_HEIGHT); GlyphLayout scoreLayout = new GlyphLayout(scoreFont, "Score: \n" + score, Color.WHITE, 0, Align.left, false); GlyphLayout highscoreLayout = new GlyphLayout(scoreFont, "Highscore: \n" + highscore, Color.WHITE, 0, Align.left, false); scoreFont.draw(game.batch, scoreLayout, SpaceGame.WIDTH / 2 - scoreLayout.width / 2, SpaceGame.HEIGHT - BANNER_HEIGHT - 15 * 2); scoreFont.draw(game.batch, highscoreLayout, SpaceGame.WIDTH / 2 - highscoreLayout.width / 2, SpaceGame.HEIGHT - BANNER_HEIGHT - scoreLayout.height - 15 * 3); float touchX = game.cam.getInputInGameWorld().x, touchY = SpaceGame.HEIGHT - game.cam.getInputInGameWorld().y; GlyphLayout tryAgainLayout = new GlyphLayout(scoreFont, "Try Again"); GlyphLayout mainMenuLayout = new GlyphLayout(scoreFont, "Main Menu"); float tryAgainX = SpaceGame.WIDTH / 2 - tryAgainLayout.width /2; float tryAgainY = SpaceGame.HEIGHT / 2 - tryAgainLayout.height / 2; float mainMenuX = SpaceGame.WIDTH / 2 - mainMenuLayout.width /2; float mainMenuY = SpaceGame.HEIGHT / 2 - mainMenuLayout.height / 2 - tryAgainLayout.height - 15; //Checks if hovering over try again button if (touchX >= tryAgainX && touchX < tryAgainX + tryAgainLayout.width && touchY >= tryAgainY - tryAgainLayout.height && touchY < tryAgainY) tryAgainLayout.setText(scoreFont, "Try Again", Color.YELLOW, 0, Align.left, false); //Checks if hovering over main menu button if (touchX >= mainMenuX && touchX < mainMenuX + mainMenuLayout.width && touchY >= mainMenuY - mainMenuLayout.height && touchY < mainMenuY) mainMenuLayout.setText(scoreFont, "Main Menu", Color.YELLOW, 0, Align.left, false); //If try again and main menu is being pressed if (Gdx.input.isTouched()) { //Try again if (touchX > tryAgainX && touchX < tryAgainX + tryAgainLayout.width && touchY > tryAgainY - tryAgainLayout.height && touchY < tryAgainY) { this.dispose(); game.batch.end(); game.setScreen(new MainGameScreen(game)); return; } //main menu if (touchX > mainMenuX && touchX < mainMenuX + mainMenuLayout.width && touchY > mainMenuY - mainMenuLayout.height && touchY < mainMenuY) { this.dispose(); game.batch.end(); game.setScreen(new MainMenuScreen(game)); return; } } //Draw buttons scoreFont.draw(game.batch, tryAgainLayout, tryAgainX, tryAgainY); scoreFont.draw(game.batch, mainMenuLayout, mainMenuX, mainMenuY); game.batch.end(); }
Example 6
Source File: HighlightTextArea.java From vis-ui with Apache License 2.0 | 4 votes |
@Override protected void calculateOffsets () { super.calculateOffsets(); if (chunkUpdateScheduled == false) return; chunkUpdateScheduled = false; highlights.sort(); renderChunks.clear(); String text = getText(); Pool<GlyphLayout> layoutPool = Pools.get(GlyphLayout.class); GlyphLayout layout = layoutPool.obtain(); boolean carryHighlight = false; for (int lineIdx = 0, highlightIdx = 0; lineIdx < linesBreak.size; lineIdx += 2) { int lineStart = linesBreak.items[lineIdx]; int lineEnd = linesBreak.items[lineIdx + 1]; int lineProgress = lineStart; float chunkOffset = 0; for (; highlightIdx < highlights.size; ) { Highlight highlight = highlights.get(highlightIdx); if (highlight.getStart() > lineEnd) { break; } if (highlight.getStart() == lineProgress || carryHighlight) { renderChunks.add(new Chunk(text.substring(lineProgress, Math.min(highlight.getEnd(), lineEnd)), highlight.getColor(), chunkOffset, lineIdx)); lineProgress = Math.min(highlight.getEnd(), lineEnd); if (highlight.getEnd() > lineEnd) { carryHighlight = true; } else { carryHighlight = false; highlightIdx++; } } else { //protect against overlapping highlights boolean noMatch = false; while (highlight.getStart() <= lineProgress) { highlightIdx++; if (highlightIdx >= highlights.size) { noMatch = true; break; } highlight = highlights.get(highlightIdx); if (highlight.getStart() > lineEnd) { noMatch = true; break; } } if (noMatch) break; renderChunks.add(new Chunk(text.substring(lineProgress, highlight.getStart()), defaultColor, chunkOffset, lineIdx)); lineProgress = highlight.getStart(); } Chunk chunk = renderChunks.peek(); layout.setText(style.font, chunk.text); chunkOffset += layout.width; //current highlight needs to be applied to next line meaning that there is no other highlights that can be applied to currently parsed line if (carryHighlight) break; } if (lineProgress < lineEnd) { renderChunks.add(new Chunk(text.substring(lineProgress, lineEnd), defaultColor, chunkOffset, lineIdx)); } } maxAreaWidth = 0; for (String line : text.split("\\n")) { layout.setText(style.font, line); maxAreaWidth = Math.max(maxAreaWidth, layout.width + 30); } layoutPool.free(layout); updateScrollLayout(); }
Example 7
Source File: VisTextArea.java From vis-ui with Apache License 2.0 | 4 votes |
@Override protected void calculateOffsets () { super.calculateOffsets(); if (!this.text.equals(lastText)) { this.lastText = text; BitmapFont font = style.font; float maxWidthLine = this.getWidth() - (style.background != null ? style.background.getLeftWidth() + style.background.getRightWidth() : 0); linesBreak.clear(); int lineStart = 0; int lastSpace = 0; char lastCharacter; Pool<GlyphLayout> layoutPool = Pools.get(GlyphLayout.class); GlyphLayout layout = layoutPool.obtain(); for (int i = 0; i < text.length(); i++) { lastCharacter = text.charAt(i); if (lastCharacter == ENTER_DESKTOP || lastCharacter == ENTER_ANDROID) { linesBreak.add(lineStart); linesBreak.add(i); lineStart = i + 1; } else { lastSpace = (continueCursor(i, 0) ? lastSpace : i); layout.setText(font, text.subSequence(lineStart, i + 1)); if (layout.width > maxWidthLine && softwrap) { if (lineStart >= lastSpace) { lastSpace = i - 1; } linesBreak.add(lineStart); linesBreak.add(lastSpace + 1); lineStart = lastSpace + 1; lastSpace = lineStart; } } } layoutPool.free(layout); // Add last line if (lineStart < text.length()) { linesBreak.add(lineStart); linesBreak.add(text.length()); } showCursor(); } }
Example 8
Source File: CustomList.java From bladecoder-adventure-engine with Apache License 2.0 | 4 votes |
public void layout() { final BitmapFont font = style.font; final BitmapFont subfont = style.subtitleFont; final Drawable selectedDrawable = style.selection; cellRenderer.layout(style); GlyphLayout textLayout = new GlyphLayout(); prefWidth = 0; for (int i = 0; i < items.size; i++) { textLayout.setText(font, cellRenderer.getCellTitle(items.get(i))); prefWidth = Math.max(textLayout.width, prefWidth); if (cellRenderer.hasImage()) { TextureRegion r = cellRenderer.getCellImage(items.get(i)); float ih = r.getRegionHeight(); float iw = r.getRegionWidth(); if (ih > getItemHeight() - 10) { ih = getItemHeight() - 10; iw *= ih / r.getRegionHeight(); } prefWidth = Math.max(iw + textLayout.width, prefWidth); } if (cellRenderer.hasSubtitle()) { String subtitle = cellRenderer.getCellSubTitle(items.get(i)); if (subtitle != null) { textLayout.setText(subfont, subtitle); prefWidth = Math.max(textLayout.width, prefWidth); } } } prefWidth += selectedDrawable.getLeftWidth() + selectedDrawable.getRightWidth(); prefHeight = items.size * cellRenderer.getItemHeight(); Drawable background = style.background; if (background != null) { prefWidth += background.getLeftWidth() + background.getRightWidth(); prefHeight += background.getTopHeight() + background.getBottomHeight(); } }
Example 9
Source File: Message.java From bladecoder-adventure-engine with Apache License 2.0 | 4 votes |
private static void add(Stage stage, String text) { msg.clearActions(); msg.setText(text); GlyphLayout textLayout = new GlyphLayout(); textLayout.setText(msg.getStyle().font, text, Color.BLACK, stage.getWidth() * .8f, Align.center, true); msg.setSize(textLayout.width + textLayout.height, textLayout.height + textLayout.height * 2); if (!stage.getActors().contains(msg, true)) stage.addActor(msg); msg.setPosition(Math.round((stage.getWidth() - msg.getWidth()) / 2), Math.round((stage.getHeight() - msg.getHeight()) / 2)); msg.invalidate(); }
Example 10
Source File: GlythData.java From seventh with GNU General Public License v2.0 | 4 votes |
public static int getHeight(BitmapFont font, GlyphLayout bounds, String str) { bounds.setText(font, str); return (int)bounds.height + 8; }