Package com.badlogic.gdx.graphics.g2d

Examples of com.badlogic.gdx.graphics.g2d.BitmapFont


    return items;
  }

  public void layout () {
    Drawable bg = style.background;
    BitmapFont font = style.font;

    prefHeight = Math.max(bg.getTopHeight() + bg.getBottomHeight() + font.getCapHeight() - font.getDescent() * 2,
      bg.getMinHeight());

    float maxItemWidth = 0;
    for (int i = 0; i < items.size; i++)
      maxItemWidth = Math.max(font.getBounds(items.get(i).toString()).width, maxItemWidth);

    prefWidth = bg.getLeftWidth() + bg.getRightWidth() + maxItemWidth;

    ListStyle listStyle = style.listStyle;
    ScrollPaneStyle scrollStyle = style.scrollStyle;
View Full Code Here


      background = style.backgroundOpen;
    else if (clickListener.isOver() && style.backgroundOver != null)
      background = style.backgroundOver;
    else
      background = style.background;
    final BitmapFont font = style.font;
    final Color fontColor = (disabled && style.disabledFontColor != null) ? style.disabledFontColor : style.fontColor;

    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);
    background.draw(batch, x, y, width, height);
    T selected = this.selected != null ? this.selected : selection.first();
    if (selected != null) {
      float availableWidth = width - background.getLeftWidth() - background.getRightWidth();
      String string = selected.toString();
      int numGlyphs = font.computeVisibleGlyphs(string, 0, string.length(), availableWidth);
      bounds.set(font.getBounds(string));
      height -= background.getBottomHeight() + background.getTopHeight();
      float textY = (int)(height / 2 + background.getBottomHeight() + bounds.height / 2);
      font.setColor(fontColor.r, fontColor.g, fontColor.b, fontColor.a * parentAlpha);
      font.draw(batch, string, x + background.getLeftWidth(), y + textY, 0, numGlyphs);
    }
  }
View Full Code Here

  @Override
  public void draw (Batch batch, float parentAlpha) {
    Stage stage = getStage();
    boolean focused = stage != null && stage.getKeyboardFocus() == this;

    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;
    if (background != null) {
      background.draw(batch, x, y, width, height);
      bgLeftWidth = background.getLeftWidth();
    }

    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 * parentAlpha);
        } else
          font.setColor(0.7f, 0.7f, 0.7f, parentAlpha);
        BitmapFont messageFont = style.messageFont != null ? style.messageFont : font;
        messageFont.draw(batch, messageText, x + bgLeftWidth, y + textY + yOffset);
      }
    } else {
      font.setColor(fontColor.r, fontColor.g, fontColor.b, fontColor.a * parentAlpha);
      drawText(batch, font, x + bgLeftWidth, y + textY + yOffset);
    }
View Full Code Here

  public ListStyle getStyle () {
    return style;
  }

  public void layout () {
    final BitmapFont font = style.font;
    final Drawable selectedDrawable = style.selection;

    itemHeight = font.getCapHeight() - font.getDescent() * 2;
    itemHeight += selectedDrawable.getTopHeight() + selectedDrawable.getBottomHeight();

    textOffsetX = selectedDrawable.getLeftWidth();
    textOffsetY = selectedDrawable.getTopHeight() - font.getDescent();

    prefWidth = 0;
    for (int i = 0; i < items.size; i++) {
      TextBounds bounds = font.getBounds(items.get(i).toString());
      prefWidth = Math.max(bounds.width, prefWidth);
    }
    prefWidth += selectedDrawable.getLeftWidth() + selectedDrawable.getRightWidth();
    prefHeight = items.size * itemHeight;

 
View Full Code Here

  @Override
  public void draw (Batch batch, float parentAlpha) {
    validate();

    BitmapFont font = style.font;
    Drawable selectedDrawable = style.selection;
    Color fontColorSelected = style.fontColorSelected;
    Color fontColorUnselected = style.fontColorUnselected;

    Color color = getColor();
    batch.setColor(color.r, color.g, color.b, color.a * parentAlpha);

    float x = getX(), y = getY(), width = getWidth(), height = getHeight();
    float itemY = height;

    Drawable background = style.background;
    if (background != null) {
      background.draw(batch, x, y, width, height);
      float leftWidth = background.getLeftWidth();
      x += leftWidth;
      itemY -= background.getTopHeight();
      width -= leftWidth + background.getRightWidth();
    }

    font.setColor(fontColorUnselected.r, fontColorUnselected.g, fontColorUnselected.b, fontColorUnselected.a * parentAlpha);
    for (int i = 0; i < items.size; i++) {
      if (cullingArea == null || (itemY - itemHeight <= cullingArea.y + cullingArea.height && itemY >= cullingArea.y)) {
        T item = items.get(i);
        boolean selected = selection.contains(item);
        if (selected) {
          selectedDrawable.draw(batch, x, y + itemY - itemHeight, width, itemHeight);
          font.setColor(fontColorSelected.r, fontColorSelected.g, fontColorSelected.b, fontColorSelected.a * parentAlpha);
        }
        font.draw(batch, item.toString(), x + textOffsetX, y + itemY - textOffsetY);
        if (selected) {
          font.setColor(fontColorUnselected.r, fontColorUnselected.g, fontColorUnselected.b, fontColorUnselected.a
            * parentAlpha);
        }
      } else if (itemY < cullingArea.y) {
        break;
      }
View Full Code Here

    cursorPatch.draw(batch, x + textOffset + glyphPositions.get(cursor) - glyphPositions.items[visibleTextStart] - 1, y
      - textHeight - font.getDescent(), cursorPatch.getMinWidth(), textHeight + font.getDescent() / 2);
  }

  void updateDisplayText () {
    BitmapFont font = style.font;
    String text = this.text;
    int textLength = text.length();

    StringBuilder buffer = new StringBuilder();
    for (int i = 0; i < textLength; i++) {
      char c = text.charAt(i);
      buffer.append(font.containsCharacter(c) ? c : ' ');
    }
    String newDisplayText = buffer.toString();

    if (passwordMode && font.containsCharacter(passwordCharacter)) {
      if (passwordBuffer == null) passwordBuffer = new StringBuilder(newDisplayText.length());
      if (passwordBuffer.length() > textLength) //
        passwordBuffer.setLength(textLength);
      else {
        for (int i = passwordBuffer.length(); i < textLength; i++)
          passwordBuffer.append(passwordCharacter);
      }
      displayText = passwordBuffer;
    } else
      displayText = newDisplayText;
    font.computeGlyphAdvancesAndPositions(displayText, glyphAdvances, glyphPositions);
    if (selectionStart > newDisplayText.length()) selectionStart = textLength;
  }
View Full Code Here

    public ConfigurationManager configurationManager;
 
  @Override
  public void create() {
    spriteBatch = new SpriteBatch();
    font = new BitmapFont();
        font.setScale(0.5f);
   
    // Crea la cámara y define la zona de visión del juego (toda la pantalla)
    /*camera = new OrthographicCamera();
    camera.setToOrtho(false, Constants.SCREEN_WIDTH, Constants.SCREEN_HEIGHT);
View Full Code Here

    super.invalidate();
    sizeInvalid = true;
  }

  private void scaleAndComputeSize () {
    BitmapFont font = cache.getFont();
    float oldScaleX = font.getScaleX();
    float oldScaleY = font.getScaleY();
    if (fontScaleX != 1 || fontScaleY != 1) font.setScale(fontScaleX, fontScaleY);

    computeSize();

    if (fontScaleX != 1 || fontScaleY != 1) font.setScale(oldScaleX, oldScaleY);
  }
View Full Code Here

    } else
      bounds.set(cache.getFont().getMultiLineBounds(text));
  }

  public void layout () {
    BitmapFont font = cache.getFont();
    float oldScaleX = font.getScaleX();
    float oldScaleY = font.getScaleY();
    if (fontScaleX != 1 || fontScaleY != 1) font.setScale(fontScaleX, fontScaleY);

    if (sizeInvalid) computeSize();

    if (wrap) {
      float prefHeight = getPrefHeight();
      if (prefHeight != lastPrefHeight) {
        lastPrefHeight = prefHeight;
        invalidateHierarchy();
      }
    }

    float width = getWidth(), height = getHeight();
    StringBuilder text;
    if (ellipse && width < bounds.width) {
      float ellipseWidth = font.getBounds("...").width;
      text = tempText != null ? tempText : (tempText = new StringBuilder());
      text.setLength(0);
      if (width > ellipseWidth) {
        text.append(this.text, 0, font.computeVisibleGlyphs(this.text, 0, this.text.length, width - ellipseWidth));
        text.append("...");
      }
    } else
      text = this.text;

    Drawable background = style.background;
    float x = 0, y = 0;
    if (background != null) {
      x = background.getLeftWidth();
      y = background.getBottomHeight();
      width -= background.getLeftWidth() + background.getRightWidth();
      height -= background.getBottomHeight() + background.getTopHeight();
    }
    if ((labelAlign & Align.top) != 0) {
      y += cache.getFont().isFlipped() ? 0 : height - bounds.height;
      y += style.font.getDescent();
    } else if ((labelAlign & Align.bottom) != 0) {
      y += cache.getFont().isFlipped() ? height - bounds.height : 0;
      y -= style.font.getDescent();
    } else
      y += (int)((height - bounds.height) / 2);
    if (!cache.getFont().isFlipped()) y += bounds.height;

    if ((labelAlign & Align.left) == 0) {
      if ((labelAlign & Align.right) != 0)
        x += width - bounds.width;
      else
        x += (int)((width - bounds.width) / 2);
    }

    if (wrap)
      cache.setWrappedText(text, x, y, bounds.width, lineAlign);
    else
      cache.setMultiLineText(text, x, y, bounds.width, lineAlign);

    if (fontScaleX != 1 || fontScaleY != 1) font.setScale(oldScaleX, oldScaleY);
  }
View Full Code Here

  }

  public void reInit() {       
    initShader();

    font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false);
  }
View Full Code Here

TOP

Related Classes of com.badlogic.gdx.graphics.g2d.BitmapFont

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.