Package com.badlogic.gdx.graphics.g2d

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


   * be generated. Using big sizes might cause such an exception. All characters need to fit onto a single texture.
   *
   * @param parameter configures how the font is generated */
  public BitmapFont generateFont (FreeTypeFontParameter parameter) {
    FreeTypeBitmapFontData data = generateData(parameter);
    BitmapFont font = new BitmapFont(data, data.getTextureRegions(), false);
    font.setOwnsTexture(true);
    return font;
  }
View Full Code Here


  @Override
  public BitmapFont loadSync (AssetManager manager, String fileName, FileHandle file, FreeTypeFontLoaderParameter parameter) {
    if(parameter == null) throw new RuntimeException("FreetypeFontParameter must be set in AssetManager#load to point at a TTF file!");
    FreeTypeFontGenerator generator = manager.get(parameter.fontFileName, FreeTypeFontGenerator.class)
    FreeTypeBitmapFontData data = generator.generateData(parameter.fontParameters);
    BitmapFont font = new BitmapFont(data, data.getTextureRegions(), false);
    font.setOwnsTexture(true);
    return font;
  }
View Full Code Here

   * @param characters the characters the font should contain
   * @param flip whether to flip the font vertically, see {@link BitmapFont#BitmapFont(FileHandle, TextureRegion, boolean)}
   * @deprecated use {@link #generateFont(FreeTypeFontParameter)} instead */
  public BitmapFont generateFont (int size, String characters, boolean flip) {
    FreeTypeBitmapFontData data = generateData(size, characters, flip, null);
    BitmapFont font = new BitmapFont(data, data.getTextureRegions(), false);
    font.setOwnsTexture(true);
    return font;
  }
View Full Code Here

   * be generated. Using big sizes might cause such an exception. All characters need to fit onto a single texture.
   *
   * @param parameter configures how the font is generated */
  public BitmapFont generateFont (FreeTypeFontParameter parameter) {
    FreeTypeBitmapFontData data = generateData(parameter);
    BitmapFont font = new BitmapFont(data, data.getTextureRegions(), false);
    font.setOwnsTexture(true);
    return font;
  }
View Full Code Here

        lastPrefHeight = prefHeight;
        invalidateHierarchy();
      }
    }

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

    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

        // Use a region with the same name as the font, else use a PNG file in the same directory as the FNT file.
        String regionName = fontFile.nameWithoutExtension();
        try {
          TextureRegion region = skin.optional(regionName, TextureRegion.class);
          if (region != null)
            return new BitmapFont(fontFile, region, false);
          else {
            FileHandle imageFile = fontFile.parent().child(regionName + ".png");
            if (imageFile.exists())
              return new BitmapFont(fontFile, imageFile, false);
            else
              return new BitmapFont(fontFile, false);
          }
        } catch (RuntimeException ex) {
          throw new SerializationException("Error loading bitmap font: " + fontFile, ex);
        }
      }
View Full Code Here

    return style;
  }

  @Override
  public void draw (SpriteBatch batch, float parentAlpha) {
    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();
    float y = getY();

    font.setColor(fontColorUnselected.r, fontColorUnselected.g, fontColorUnselected.b, fontColorUnselected.a * parentAlpha);
    float itemY = getHeight();
    for (int i = 0; i < items.length; i++) {
      if (cullingArea == null || (itemY - itemHeight <= cullingArea.y + cullingArea.height && itemY >= cullingArea.y)) {
        if (selectedIndex == i) {
          selectedDrawable.draw(batch, x, y + itemY - itemHeight, getWidth(), itemHeight);
          font.setColor(fontColorSelected.r, fontColorSelected.g, fontColorSelected.b, fontColorSelected.a * parentAlpha);
        }
        font.draw(batch, items[i], x + textOffsetX, y + itemY - textOffsetY);
        if (selectedIndex == i) {
          font.setColor(fontColorUnselected.r, fontColorUnselected.g, fontColorUnselected.b, fontColorUnselected.a
            * parentAlpha);
        }
      } else if (itemY < cullingArea.y) {
        break;
      }
View Full Code Here

    } else
      items = (String[])objects;

    selectedIndex = 0;

    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.length; i++) {
      TextBounds bounds = font.getBounds(items[i]);
      prefWidth = Math.max(bounds.width, prefWidth);
    }
    prefWidth += selectedDrawable.getLeftWidth() + selectedDrawable.getRightWidth();
    prefHeight = items.length * itemHeight;

 
View Full Code Here

      }

      public boolean keyTyped (InputEvent event, char character) {
        if (disabled) return false;

        final BitmapFont font = style.font;

        Stage stage = getStage();
        if (stage != null && stage.getKeyboardFocus() == TextField.this) {
          if (character == BACKSPACE) {
            if (cursor > 0 || hasSelection) {
              if (!hasSelection) {
                text = text.substring(0, cursor - 1) + text.substring(cursor);
                updateDisplayText();
                cursor--;
                renderOffset = 0;
              } else {
                delete();
              }
            }
          } else if (character == DELETE) {
            if (cursor < text.length() || hasSelection) {
              if (!hasSelection) {
                text = text.substring(0, cursor) + text.substring(cursor + 1);
                updateDisplayText();
              } else {
                delete();
              }
            }
          } else if ((character == TAB || character == ENTER_ANDROID) && focusTraversal) {
            next(Gdx.input.isKeyPressed(Keys.SHIFT_LEFT) || Gdx.input.isKeyPressed(Keys.SHIFT_RIGHT));
          } else if (font.containsCharacter(character)) {
            // Character may be added to the text.
            if (character != ENTER_DESKTOP && character != ENTER_ANDROID) {
              if (filter != null && !filter.acceptChar(TextField.this, character)) return true;
            }
            if (maxLength > 0 && text.length() + 1 > maxLength) return true;
View Full Code Here

  public void draw (SpriteBatch 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();
    float textY = textBounds.height / 2 + font.getDescent();

    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 bottom = background.getBottomHeight();
      textY = (int)(textY + (height - background.getTopHeight() - bottom) / 2 + bottom);
    } else
      textY = (int)(textY + height / 2);

    calculateOffsets();

    if (focused && hasSelection && selection != null) {
      selection.draw(batch, x + selectionX + bgLeftWidth + renderOffset, y + textY - textBounds.height - font.getDescent(),
        selectionWidth, textBounds.height + font.getDescent() / 2);
    }

    float yOffset = font.isFlipped() ? -textBounds.height : 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);
      font.draw(batch, displayText, x + bgLeftWidth + textOffset, y + textY + yOffset, visibleTextStart, visibleTextEnd);
    }
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.