List of usage examples for com.badlogic.gdx.graphics.g2d BitmapFont setColor
public void setColor(float r, float g, float b, float a)
From source file:com.bladecoder.engineeditor.ui.components.CellRenderer.java
License:Apache License
public void draw(Batch batch, float parentAlpha, T item, boolean selected, float x, float y, float width, float height) { BitmapFont font = style.font; Drawable selectedDrawable = style.selection; Color fontColorSelected = style.fontColorSelected; Color fontColorUnselected = style.fontColorUnselected; if (selected) { selectedDrawable.draw(batch, x, y - height, width, height); font.setColor(fontColorSelected.r, fontColorSelected.g, fontColorSelected.b, fontColorSelected.a * parentAlpha); } else {//ww w.ja v a 2 s .c om font.setColor(fontColorUnselected.r, fontColorUnselected.g, fontColorUnselected.b, fontColorUnselected.a * parentAlpha); } if (hasImage()) { TextureRegion r = getCellImage(item); float ih = r.getRegionHeight(); float iw = r.getRegionWidth(); if (ih > getItemHeight() - MARGIN) { ih = getItemHeight() - MARGIN; iw *= ih / r.getRegionHeight(); } batch.draw(r, x, y - ih - MARGIN / 2, iw, ih); x += iw; } font.draw(batch, getCellTitle(item), x + textOffsetX, y - textOffsetY); if (hasSubtitle()) { String sub = getCellSubTitle(item); if (sub != null) { if (selected) { style.subtitleFont.setColor(fontColorSelected.r, fontColorSelected.g, fontColorSelected.b, fontColorSelected.a * parentAlpha * 0.5f); } else { style.subtitleFont.setColor(fontColorUnselected.r, fontColorUnselected.g, fontColorUnselected.b, fontColorUnselected.a * parentAlpha * 0.5f); } style.subtitleFont.draw(batch, sub, x + textOffsetX, y - textOffsetY - (font.getCapHeight() - font.getDescent() * 2)); } } }
From source file:com.calanti.androidnativekeyboardinputtest.libgdxModified_1_9_3.CalTextField.java
License:Apache License
@Override public void draw(Batch batch, float parentAlpha) { Stage stage = getStage();/* www . j a v a2 s . c o m*/ focused = stage != null && stage.getKeyboardFocus() == this; if (!focused) keyRepeatTask.cancel(); final BitmapFont font = style.font; final Color fontColor = (disabled && style.disabledFontColor != null) ? style.disabledFontColor : ((focused && style.focusedFontColor != null) ? style.focusedFontColor : style.fontColor); final Drawable selection = style.selection; final Drawable cursorPatch = style.cursor; final Drawable background = (disabled && style.disabledBackground != null) ? style.disabledBackground : ((focused && style.focusedBackground != null) ? style.focusedBackground : style.background); Color color = getColor(); float x = getX(); float y = getY(); float width = getWidth(); float height = getHeight(); batch.setColor(color.r, color.g, color.b, color.a * parentAlpha); float bgLeftWidth = 0, bgRightWidth = 0; if (background != null) { background.draw(batch, x, y, width, height); bgLeftWidth = background.getLeftWidth(); bgRightWidth = background.getRightWidth(); } float textY = getTextY(font, background); calculateOffsets(); if (focused && hasSelection && selection != null) { drawSelection(selection, batch, font, x + bgLeftWidth, y + textY); } float yOffset = font.isFlipped() ? -textHeight : 0; if (displayText.length() == 0) { if (!focused && messageText != null) { if (style.messageFontColor != null) { font.setColor(style.messageFontColor.r, style.messageFontColor.g, style.messageFontColor.b, style.messageFontColor.a * color.a * parentAlpha); } else font.setColor(0.7f, 0.7f, 0.7f, color.a * parentAlpha); BitmapFont messageFont = style.messageFont != null ? style.messageFont : font; messageFont.draw(batch, messageText, x + bgLeftWidth, y + textY + yOffset, 0, messageText.length(), width - bgLeftWidth - bgRightWidth, textHAlign, false, "..."); } } else { font.setColor(fontColor.r, fontColor.g, fontColor.b, fontColor.a * color.a * parentAlpha); drawText(batch, font, x + bgLeftWidth, y + textY + yOffset); } if (focused && !disabled) { blink(); if (cursorOn && cursorPatch != null) { drawCursor(cursorPatch, batch, font, x + bgLeftWidth, y + textY); } } }
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;/*from w w w.jav a 2 s. c om*/ 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.haxtastic.haxmasher.entity.hud.MasherHUD.java
License:Apache License
@Override public void draw(SpriteBatch batch, BitmapFont font) { //Draw hpframe AtlasRegion spriteRegion = Art.regions.get(name); if (width == 0) width = spriteRegion.getRegionWidth(); if (height == 0) height = spriteRegion.getRegionHeight(); if (width < 0) width = -width;/*from www .j a v a 2s .com*/ float posX = x * Constants.PIXELS_PER_METER_X; float posY = y * Constants.PIXELS_PER_METER_Y; batch.draw(spriteRegion, posX, posY, width * Constants.PIXELS_PER_METER_X, height * Constants.PIXELS_PER_METER_Y); //Draw health spriteRegion = Art.regions.get(hpslice.name); if (hpslice.width == 0) hpslice.width = spriteRegion.getRegionWidth(); if (hpslice.height == 0) hpslice.height = spriteRegion.getRegionHeight(); if (hpslice.width < 0) hpslice.width = -hpslice.width; /*for(float i = 0; i < bars*100; i++) { posX = (bar.x + (0.04f*i)) * Constants.PIXELS_PER_METER_X; posY = bar.y * Constants.PIXELS_PER_METER_Y; batch.draw(spriteRegion, posX, posY, bar.width * Constants.PIXELS_PER_METER_X, bar.height * Constants.PIXELS_PER_METER_Y); }*/ posX = hpslice.x * Constants.PIXELS_PER_METER_X; posY = hpslice.y * Constants.PIXELS_PER_METER_Y; float tempwidth = hpslice.width * (prevbars * 100); batch.draw(spriteRegion, posX, posY, tempwidth * Constants.PIXELS_PER_METER_X, hpslice.height * Constants.PIXELS_PER_METER_Y); //Draw text font.setColor(0, 0, 0, 1); String msg = (int) masher.health + "/" + (int) masher.maxhealth; posX = (x + (width / 2)) * Constants.PIXELS_PER_METER_X - (font.getBounds(msg).width / 2); posY = (y + (height / 2)) * Constants.PIXELS_PER_METER_Y + (font.getBounds(msg).height / 2); font.draw(batch, msg, posX, posY); posX = statsX; posY = statsY; msg = "Name: " + masher.nick; font.draw(batch, msg, posX, posY); posY -= (font.getBounds(msg).height * space); msg = "Level: " + masher.level; font.draw(batch, msg, posX, posY); msg = "Armor: " + (int) masher.armor + "(" + (int) ((masher.armor / (Constants.Stats.armorReduction + masher.armor)) * 100) + "%)"; posY -= (font.getBounds(msg).height * space); font.draw(batch, msg, posX, posY); msg = "Damage: " + (int) (masher.getDamage() * Constants.Stats.minDamage) + " - " + (int) (masher.getDamage() * Constants.Stats.maxDamage) + "(" + masher.crit + "%)"; posY -= (font.getBounds(msg).height * space); font.draw(batch, msg, posX, posY); if (masher.getClass().equals(Player.class)) { int exp = masher.getExp(); int nxp = masher.expForLevel(masher.getLevel() + 1); msg = "exp: " + exp + "/" + nxp + " (" + (nxp - exp) + " left)"; posY -= (font.getBounds(msg).height * space); font.draw(batch, msg, posX, posY); } else if (masher.getClass().equals(Guy.class)) { msg = "experience worth: " + masher.getExp(); posY -= (font.getBounds(msg).height * space); font.draw(batch, msg, posX, posY); } //font.setScale(1f, 1f); }
From source file:com.haxtastic.haxmasher.entity.ui.Button.java
License:Apache License
@Override public void draw(SpriteBatch batch, BitmapFont font) { AtlasRegion spriteRegion = null;//w ww . ja v a 2 s .com switch (getState()) { case normal: spriteRegion = Art.regions.get(States.states.get(States.state.normal)); break; case hover: spriteRegion = Art.regions.get(States.states.get(States.state.hover)); break; case clicked: case clicking: spriteRegion = Art.regions.get(States.states.get(States.state.clicked)); break; case blocked: spriteRegion = Art.regions.get(States.states.get(States.state.blocked)); break; default: spriteRegion = Art.regions.get(States.states.get(States.state.normal)); break; } if (width == 0) width = spriteRegion.getRegionWidth(); if (height == 0) height = spriteRegion.getRegionHeight(); if (width < 0) width = -width; float posX = x * Constants.PIXELS_PER_METER_X; float posY = y * Constants.PIXELS_PER_METER_Y; batch.draw(spriteRegion, posX, posY, width * Constants.PIXELS_PER_METER_X, height * Constants.PIXELS_PER_METER_Y); //Draw text font.setColor(0, 0, 0, 1); String msg = text; posX = (x + (width / 2)) * Constants.PIXELS_PER_METER_X - (font.getBounds(msg).width / 2); posY = (y + (height / 2)) * Constants.PIXELS_PER_METER_Y + (font.getBounds(msg).height / 2); font.draw(batch, msg, posX, posY); }
From source file:com.haxtastic.haxmasher.entity.ui.Console.java
License:Apache License
@Override public void draw(SpriteBatch batch, BitmapFont font) { AtlasRegion spriteRegion = Art.regions.get(name); if (width == 0) width = spriteRegion.getRegionWidth(); if (height == 0) height = spriteRegion.getRegionHeight(); if (width < 0) width = -width;/*from w ww . j a v a2 s.co m*/ float posX = x * Constants.PIXELS_PER_METER_X; float posY = y * Constants.PIXELS_PER_METER_Y; batch.draw(spriteRegion, posX, posY, width * Constants.PIXELS_PER_METER_X, height * Constants.PIXELS_PER_METER_Y); //Draw text font.setColor(0, 0, 0, 1); float sX = font.getScaleX(); float sY = font.getScaleY(); font.setScale(1.1f, 1.1f); String msg = null; int i = 0; ListIterator<String> iter = lines.listIterator(lines.size()); while (iter.hasPrevious()) { msg = iter.previous(); posX = linex * Constants.PIXELS_PER_METER_X; posY = (liney + (space * i)) * Constants.PIXELS_PER_METER_Y + (font.getBounds(msg).height * i); font.draw(batch, msg, posX, posY); i++; } font.setScale(sX, sY); }
From source file:com.haxtastic.haxmasher.scene.Stats.java
License:Apache License
@Override public void draw(float dt, SpriteBatch batch, BitmapFont font) { if (parent != null) parent.draw(dt, batch, font);/*from w w w . j a v a2s.c o m*/ Iterator<Actor> iter = getActors().iterator(); while (iter.hasNext()) { Actor actor = iter.next(); actor.draw(batch, font); } font.setColor(0, 0, 0, 1); float sX = font.getScaleX(); float sY = font.getScaleY(); font.setScale(1.575f, 1.725f); String msg = "You have gained " + level; msg += (level > 1 ? " levels." : " level."); float posX = (Constants.Positions.pointsTextX) * Constants.PIXELS_PER_METER_X + (font.getBounds(" to spend").width / 2); float posY = (Constants.Positions.pointsTextY + 0.1f) * Constants.PIXELS_PER_METER_Y + (font.getBounds(msg).height); font.draw(batch, msg, posX, posY); msg = "You have " + points + " skill points to spend."; posX = Constants.Positions.pointsTextX * Constants.PIXELS_PER_METER_X; posY = Constants.Positions.pointsTextY * Constants.PIXELS_PER_METER_Y; font.draw(batch, msg, posX, posY); msg = Constants.Stats.healthWeight + " * " + (PlayerStats.pHealth + PlayerStats.level); posX = Constants.Buttons.healthTextX * Constants.PIXELS_PER_METER_X - (font.getBounds(msg).width / 2); posY = Constants.Buttons.pointsY * Constants.PIXELS_PER_METER_Y + (font.getBounds(msg).height); font.draw(batch, msg, posX, posY); msg = Constants.Stats.damageWeight + " * " + (PlayerStats.pDamage + PlayerStats.level); posX = Constants.Buttons.damageTextX * Constants.PIXELS_PER_METER_X - (font.getBounds(msg).width / 2); posY = Constants.Buttons.pointsY * Constants.PIXELS_PER_METER_Y + (font.getBounds(msg).height); font.draw(batch, msg, posX, posY); msg = Constants.Stats.armorWeight + " * " + (PlayerStats.pArmor + PlayerStats.level); posX = Constants.Buttons.armorTextX * Constants.PIXELS_PER_METER_X - (font.getBounds(msg).width / 2); posY = Constants.Buttons.pointsY * Constants.PIXELS_PER_METER_Y + (font.getBounds(msg).height); font.draw(batch, msg, posX, posY); msg = Constants.Stats.critWeight + " * " + (PlayerStats.pCrit + PlayerStats.level); posX = Constants.Buttons.critTextX * Constants.PIXELS_PER_METER_X - (font.getBounds(msg).width / 2); posY = Constants.Buttons.pointsY * Constants.PIXELS_PER_METER_Y + (font.getBounds(msg).height); font.draw(batch, msg, posX, posY); font.setScale(sX, sY); }
From source file:com.kotcrab.vis.ui.widget.VisTextField.java
License:Apache License
@Override public void draw(Batch batch, float parentAlpha) { Stage stage = getStage();/*from w w w.ja v a2 s . c om*/ boolean focused = stage != null && stage.getKeyboardFocus() == this; if (!focused) keyRepeatTask.cancel(); final BitmapFont font = style.font; final Color fontColor = (disabled && style.disabledFontColor != null) ? style.disabledFontColor : ((focused && style.focusedFontColor != null) ? style.focusedFontColor : style.fontColor); final Drawable selection = style.selection; final Drawable cursorPatch = style.cursor; Drawable background = (disabled && style.disabledBackground != null) ? style.disabledBackground : ((focused && style.focusedBackground != null) ? style.focusedBackground : style.background); // vis if (!disabled && clickListener.isOver() && style.backgroundOver != null) background = style.backgroundOver; Color color = getColor(); float x = getX(); float y = getY(); float width = getWidth(); float height = getHeight(); batch.setColor(color.r, color.g, color.b, color.a * parentAlpha); float bgLeftWidth = 0, bgRightWidth = 0; if (background != null) { background.draw(batch, x, y, width, height); bgLeftWidth = background.getLeftWidth(); bgRightWidth = background.getRightWidth(); } float textY = getTextY(font, background); calculateOffsets(); if (focused && hasSelection && selection != null) { drawSelection(selection, batch, font, x + bgLeftWidth, y + textY); } float yOffset = font.isFlipped() ? -textHeight : 0; if (displayText.length() == 0) { if (!focused && messageText != null) { if (style.messageFontColor != null) { font.setColor(style.messageFontColor.r, style.messageFontColor.g, style.messageFontColor.b, style.messageFontColor.a * color.a * parentAlpha); } else font.setColor(0.7f, 0.7f, 0.7f, color.a * parentAlpha); BitmapFont messageFont = style.messageFont != null ? style.messageFont : font; messageFont.draw(batch, messageText, x + bgLeftWidth, y + textY + yOffset, 0, messageText.length(), width - bgLeftWidth - bgRightWidth, textHAlign, false, "..."); } } else { font.setColor(fontColor.r, fontColor.g, fontColor.b, fontColor.a * color.a * parentAlpha); drawText(batch, font, x + bgLeftWidth, y + textY + yOffset); } if (drawBorder && focused && !disabled) { blink(); if (cursorOn && cursorPatch != null) { drawCursor(cursorPatch, batch, font, x + bgLeftWidth, y + textY); } } // vis if (isDisabled() == false && inputValid == false && style.errorBorder != null) style.errorBorder.draw(batch, getX(), getY(), getWidth(), getHeight()); else if (focusBorderEnabled && drawBorder && style.focusBorder != null) style.focusBorder.draw(batch, getX(), getY(), getWidth(), getHeight()); }
From source file:com.minekrash.game.Paint.java
public void drawText(SpriteBatch g, BitmapFont _font, String _texto, Color _color, float _x, float _y, BitmapFont.HAlignment _alineacion, float _alphaText) { _font.setColor(Color.BLACK.r, Color.BLACK.g, Color.BLACK.b, _alphaText); _font.drawMultiLine(g, _texto, _x, _y - 0.2f, 0, _alineacion); _font.setColor(_color.r, _color.g, _color.b, _alphaText); _font.drawMultiLine(g, _texto, _x, _y, 0, _alineacion); }
From source file:com.minikara.ttfinput.TextField.java
License:Apache License
@Override public void draw(Batch batch, float parentAlpha) { Stage stage = getStage();//from w w w . jav a2 s . c o m boolean focused = stage != null && stage.getKeyboardFocus() == this; if (!focused) keyRepeatTask.cancel(); final BitmapFont font = style.font; final Color fontColor = (disabled && style.disabledFontColor != null) ? style.disabledFontColor : ((focused && style.focusedFontColor != null) ? style.focusedFontColor : style.fontColor); final Drawable selection = style.selection; final Drawable cursorPatch = style.cursor; final Drawable background = (disabled && style.disabledBackground != null) ? style.disabledBackground : ((focused && style.focusedBackground != null) ? style.focusedBackground : style.background); Color color = getColor(); float x = getX(); float y = getY(); float width = getWidth(); float height = getHeight(); batch.setColor(color.r, color.g, color.b, color.a * parentAlpha); float bgLeftWidth = 0, bgRightWidth = 0; if (background != null) { background.draw(batch, x, y, width, height); bgLeftWidth = background.getLeftWidth(); bgRightWidth = background.getRightWidth(); } float textY = getTextY(font, background); calculateOffsets(); if (focused && hasSelection && selection != null) { drawSelection(selection, batch, font, x + bgLeftWidth, y + textY); } float yOffset = font.isFlipped() ? -textHeight : 0; if (displayText.length() == 0) { if (!focused && messageText != null) { if (style.messageFontColor != null) { font.setColor(style.messageFontColor.r, style.messageFontColor.g, style.messageFontColor.b, style.messageFontColor.a * color.a * parentAlpha); } else font.setColor(0.7f, 0.7f, 0.7f, color.a * parentAlpha); BitmapFont messageFont = style.messageFont != null ? style.messageFont : font; messageFont.draw(batch, messageText, x + bgLeftWidth, y + textY + yOffset, width - bgLeftWidth - bgRightWidth, textHAlign, false); } } else { font.setColor(fontColor.r, fontColor.g, fontColor.b, fontColor.a * color.a * parentAlpha); drawText(batch, font, x + bgLeftWidth, y + textY + yOffset); } if (focused && !disabled) { blink(); if (cursorOn && cursorPatch != null) { drawCursor(cursorPatch, batch, font, x + bgLeftWidth, y + textY); } } }