Package com.badlogic.gdx.graphics.g2d

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


      public BitmapFont read (Json json, Object jsonData, Class type) {
        String path = json.readValue(String.class, jsonData);
        FileHandle file = skinFile.parent().child(path);
        if (!file.exists()) file = Gdx.files.internal(path);
        return new BitmapFont(file, false);
      }
    });

    json.setSerializer(NinePatch.class, new Serializer<NinePatch>() {
      public void write (Json json, NinePatch ninePatch, Class valueType) {
View Full Code Here


  public void layout () {
  }

  @Override
  public void draw (SpriteBatch batch, float parentAlpha) {
    final BitmapFont font = style.font;
    final NinePatch selectedPatch = style.selectedPatch;
    final Color fontColorSelected = style.fontColorSelected;
    final Color fontColorUnselected = style.fontColorUnselected;

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

    float posY = height;
    for (int i = 0; i < items.length; i++) {
      if (selected == i) {
        selectedPatch.draw(batch, x, y + posY - itemHeight, Math.max(prefWidth, width), itemHeight);
        font.setColor(fontColorSelected.r, fontColorSelected.g, fontColorSelected.b, fontColorSelected.a * parentAlpha);
      } else {
        font.setColor(fontColorUnselected.r, fontColorUnselected.g, fontColorUnselected.b, fontColorUnselected.a
          * parentAlpha);
      }
      font.draw(batch, items[i], x + textOffsetX, y + posY - textOffsetY);
      posY -= itemHeight;
    }
  }
View Full Code Here

  public void setItems (String[] items) {
    if (items == null) throw new IllegalArgumentException("items cannot be null.");
    this.items = items;
    selected = 0;

    final BitmapFont font = style.font;
    final NinePatch selectedPatch = style.selectedPatch;
    prefWidth = 0;
    prefHeight = 0;

    for (int i = 0; i < items.length; i++) {
      String item = items[i];
      TextBounds bounds = font.getBounds(item);
      prefWidth = Math.max(bounds.width, prefWidth);
    }

    itemHeight = font.getCapHeight() - font.getDescent() * 2;
    itemHeight += selectedPatch.getTopHeight() + selectedPatch.getBottomHeight();
    prefWidth += selectedPatch.getLeftWidth() + selectedPatch.getRightWidth();
    prefHeight = items.length * itemHeight;
    textOffsetX = selectedPatch.getLeftWidth();
    textOffsetY = selectedPatch.getTopHeight() - font.getDescent();
  }
View Full Code Here

    this.style = style;
  }

  private void calculateBoundsAndScissors (Matrix4 transform) {
    final NinePatch background = style.background;
    final BitmapFont titleFont = style.titleFont;

    widgetBounds.x = background.getLeftWidth();
    widgetBounds.y = background.getBottomHeight();
    widgetBounds.width = width - background.getLeftWidth() - background.getRightWidth();
    widgetBounds.height = height - background.getTopHeight() - background.getBottomHeight();
    ScissorStack.calculateScissors(stage.getCamera(), transform, widgetBounds, scissors);
    titleBounds.x = 0;
    titleBounds.y = height - background.getTopHeight();
    titleBounds.width = width;
    titleBounds.height = background.getTopHeight();
    textBounds.set(titleFont.getBounds(title));
    textBounds.height -= titleFont.getDescent();
  }
View Full Code Here

    textBounds.height -= titleFont.getDescent();
  }

  public void draw (SpriteBatch batch, float parentAlpha) {
    final NinePatch backgroundPatch = style.background;
    final BitmapFont titleFont = style.titleFont;
    final Color titleFontColor = style.titleFontColor;

    layout();
    applyTransform(batch);
    calculateBoundsAndScissors(batch.getTransformMatrix());

    batch.setColor(color.r, color.g, color.b, color.a * parentAlpha);
    backgroundPatch.draw(batch, 0, 0, width, height);
    float textY = height - (int)(backgroundPatch.getTopHeight() / 2) + (int)(textBounds.height / 2);
    titleFont.setColor(titleFontColor.r, titleFontColor.g, titleFontColor.b, titleFontColor.a * parentAlpha);
    titleFont.drawMultiLine(batch, title, (int)(width / 2), textY, 0, HAlignment.CENTER);
    batch.flush();

    ScissorStack.pushScissors(scissors);
    super.drawChildren(batch, parentAlpha);
    ScissorStack.popScissors();
View Full Code Here

  public void setItems (String[] items) {
    if (items == null) throw new IllegalArgumentException("items cannot be null.");
    this.items = items;

    NinePatch background = style.background;
    BitmapFont font = style.font;

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

    float max = 0;
    for (int i = 0; i < items.length; i++)
      max = Math.max(font.getBounds(items[i]).width, max);
    prefWidth = background.getLeftWidth() + background.getRightWidth() + max;

    width = prefWidth;
    height = prefHeight;
  }
View Full Code Here

  }

  @Override
  public void draw (SpriteBatch batch, float parentAlpha) {
    final NinePatch background = style.background;
    final BitmapFont font = style.font;
    final Color fontColor = style.fontColor;

    batch.setColor(color.r, color.g, color.b, color.a * parentAlpha);
    background.draw(batch, x, y, width, height);
    if (items.length > 0) {
      float availableWidth = width - background.getLeftWidth() - background.getRightWidth();
      int numGlyphs = font.computeVisibleGlyphs(items[selection], 0, items[selection].length(), availableWidth);
      bounds.set(font.getBounds(items[selection]));
      float textY = (int)(height / 2) + (int)(bounds.height / 2);
      font.setColor(fontColor.r, fontColor.g, fontColor.b, fontColor.a * parentAlpha);
      font.draw(batch, items[selection], x + background.getLeftWidth(), y + textY, 0, numGlyphs);
    }

    // calculate screen coords where list should be displayed
    ScissorStack.toWindowCoordinates(stage.getCamera(), batch.getTransformMatrix(), screenCoords.set(x, y));
  }
View Full Code Here

      stage.getRoot().focus(this, 0);
      layout();
    }

    private void layout () {
      final BitmapFont font = style.font;
      final NinePatch listSelection = style.listSelection;

      float prefWidth = 0;
      float prefHeight = 0;

      for (int i = 0; i < items.length; i++) {
        String item = items[i];
        TextBounds bounds = font.getBounds(item);
        prefWidth = Math.max(bounds.width, prefWidth);

      }

      itemHeight = font.getCapHeight() + -font.getDescent() * 2;
      itemHeight += listSelection.getTopHeight() + listSelection.getBottomHeight();
      itemHeight *= ComboBox.this.parent.scaleY;
      prefWidth += listSelection.getLeftWidth() + listSelection.getRightWidth();
      prefHeight = items.length * itemHeight;
      textOffsetX = listSelection.getLeftWidth();
      textOffsetY = listSelection.getTopHeight() + -font.getDescent();

      width = Math.max(prefWidth, ComboBox.this.width);
      width *= ComboBox.this.parent.scaleX;
      height = prefHeight;
      y -= height;
View Full Code Here

    @Override
    public void draw (SpriteBatch batch, float parentAlpha) {
      final NinePatch listBackground = style.listBackground;
      final NinePatch listSelection = style.listSelection;
      final BitmapFont font = style.font;
      final Color fontColor = style.fontColor;

      batch.setColor(color.r, color.g, color.b, color.a * parentAlpha);
      listBackground.draw(batch, x, y, width, height);
      float posY = height;
      for (int i = 0; i < items.length; i++) {
        if (selected == i) {
          listSelection.draw(batch, x, y + posY - itemHeight, width, itemHeight);
        }
        font.setColor(fontColor.r, fontColor.g, fontColor.b, fontColor.a * parentAlpha);
        font.setScale(ComboBox.this.parent.scaleX, ComboBox.this.parent.scaleY);
        font.draw(batch, items[i], x + textOffsetX, y + posY - textOffsetY);
        font.setScale(1, 1);
        posY -= itemHeight;
      }
    }
View Full Code Here

    }
  }

  @Override
  public void draw (SpriteBatch batch, float parentAlpha) {
    final BitmapFont font = style.font;
    final Color fontColor = style.fontColor;
    final NinePatch background = style.background;
    final TextureRegion selection = style.selection;
    final NinePatch cursorPatch = style.cursor;

    batch.setColor(color.r, color.g, color.b, color.a * parentAlpha);
    background.draw(batch, x, y, width, height);
    float textY = (int)(height / 2) + (int)(textBounds.height / 2) + font.getDescent() / 2;
    font.setColor(fontColor.r, fontColor.g, fontColor.b, fontColor.a * parentAlpha);
    calculateOffsets();

    if (hasSelection) {
      batch.draw(selection, x + selectionX + background.getLeftWidth() + renderOffset,
        y + textY - textBounds.height - font.getDescent() / 2, selectionWidth, textBounds.height);
    }

    font.draw(batch, text, x + background.getLeftWidth() + textOffset, y + textY, visibleTextStart, visibleTextEnd);
    if (parent.keyboardFocusedActor == this) {
      blink();
      if (cursorOn) {
        cursorPatch.draw(batch, x + background.getLeftWidth() + glyphPositions.get(cursor) + renderOffset - 1, y + textY
          - textBounds.height - font.getDescent(), cursorPatch.getTotalWidth(), textBounds.height + font.getDescent() / 2);
      }
    }
  }
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.