Package com.badlogic.gdx.graphics.g2d

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


    return style;
  }

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

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

    font.setColor(fontColorUnselected.r, fontColorUnselected.g, fontColorUnselected.b, fontColorUnselected.a * parentAlpha);
    float itemY = height;
    for (int i = 0; i < items.length; i++) {
      if (cullingArea == null ||
        (itemY - itemHeight <= cullingArea.y + cullingArea.height && itemY >= cullingArea.y)) {
        if (selected == i) {
          selectedPatch.draw(batch, x, y + itemY - itemHeight, Math.max(prefWidth, width), itemHeight);
          font.setColor(fontColorSelected.r, fontColorSelected.g, fontColorSelected.b, fontColorSelected.a * parentAlpha);
        }
        font.draw(batch, items[i], x + textOffsetX, y + itemY - textOffsetY);
        if (selected == 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;

    selected = 0;

    final BitmapFont font = style.font;
    final NinePatch selectedPatch = style.selectedPatch;

    itemHeight = font.getCapHeight() - font.getDescent() * 2;
    itemHeight += selectedPatch.getTopHeight() + selectedPatch.getBottomHeight();
    prefWidth += selectedPatch.getLeftWidth() + selectedPatch.getRightWidth();
    textOffsetX = selectedPatch.getLeftWidth();
    textOffsetY = selectedPatch.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);
    }
    prefHeight = items.length * itemHeight;

    invalidateHierarchy();
 
View Full Code Here

    }
  }

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

    batch.setColor(color.r, color.g, color.b, color.a * parentAlpha);
    float bgLeftWidth = 0;
    if (style.background != null) {
      style.background.draw(batch, x, y, width, height);
      bgLeftWidth = style.background.getLeftWidth();
    }

    float textY = (int)(height / 2 + textBounds.height / 2 + font.getDescent());
    calculateOffsets();

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

    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;
        font.draw(batch, messageText, x + bgLeftWidth, y + textY);
      }
    } else {
      font.setColor(fontColor.r, fontColor.g, fontColor.b, fontColor.a * parentAlpha);
      font.draw(batch, displayText, x + bgLeftWidth + textOffset, y + textY, visibleTextStart, visibleTextEnd);
View Full Code Here

    cursor = Math.max(0, glyphPositions.size - 1);
    return true;
  }

  public boolean keyDown (int keycode) {
    final BitmapFont font = style.font;

    if (stage != null && stage.getKeyboardFocus() == this) {
      if (Gdx.input.isKeyPressed(Keys.CONTROL_LEFT) || Gdx.input.isKeyPressed(Keys.CONTROL_RIGHT)) {
        // paste
        if (keycode == Keys.V) paste();
View Full Code Here

    cursor = minIndex;
    clearSelection();
  }

  public boolean keyTyped (char character) {
    final BitmapFont font = style.font;

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

  }

  public void setText (String text) {
    if (text == null) throw new IllegalArgumentException("text cannot be null.");

    BitmapFont font = style.font;

    StringBuffer buffer = new StringBuffer();
    for (int i = 0; i < text.length(); i++) {
      char c = text.charAt(i);
      if (font.containsCharacter(c)) buffer.append(c);
    }

    this.text = buffer.toString();
    updateDisplayText();
    cursor = 0;
    clearSelection();

    textBounds.set(font.getBounds(displayText));
    textBounds.height -= font.getDescent() * 2;
    font.computeGlyphAdvancesAndPositions(displayText, glyphAdvances, glyphPositions);
  }
View Full Code Here

    }

    this.items = (String[])objects;

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

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

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

    invalidateHierarchy();
  }
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

      else
        this.y = y - height;
    }

    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 + style.itemSpacing;
      itemHeight += listSelection.getTopHeight() + listSelection.getBottomHeight();
      itemHeight *= SelectBox.this.parent.scaleY;
      prefWidth += listSelection.getLeftWidth() + listSelection.getRightWidth() + 2 * style.itemSpacing;
      prefHeight = items.length * itemHeight;
      textOffsetX = listSelection.getLeftWidth() + style.itemSpacing;
      textOffsetY = listSelection.getTopHeight() + -font.getDescent() + style.itemSpacing / 2;

      width = Math.max(prefWidth, SelectBox.this.width);
      width *= SelectBox.this.parent.scaleX;
      height = prefHeight;
    }
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(SelectBox.this.parent.scaleX, SelectBox.this.parent.scaleY);
        font.draw(batch, items[i], x + textOffsetX, y + posY - textOffsetY);
        font.setScale(1, 1);
        posY -= itemHeight;
      }
    }
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.