Example usage for com.badlogic.gdx.graphics.g2d BitmapFont getData

List of usage examples for com.badlogic.gdx.graphics.g2d BitmapFont getData

Introduction

In this page you can find the example usage for com.badlogic.gdx.graphics.g2d BitmapFont getData.

Prototype

public BitmapFontData getData() 

Source Link

Document

Gets the underlying BitmapFontData for this BitmapFont.

Usage

From source file:CB_UI_Base.GL_UI.Controls.EditTextField.java

License:Open Source License

public boolean keyTyped(char character, boolean ignoreFocus) {

    if (!isEditable)
        return false;

    final BitmapFont font = style.font;
    Line line = getNthLine(cursor.y);
    if (line == null)
        return false;

    if (GL.that.hasFocus(this) || ignoreFocus) {
        if (character == BACKSPACE) {
            if (selection != null) {
                deleteSelection();/* w ww .j  av  a  2 s  . co  m*/
                sendKeyTyped(character);
                return true;
            } else {
                try {
                    if (cursor.x > 0) {
                        line.displayText = line.displayText.substring(0, cursor.x - 1)
                                + line.displayText.substring(cursor.x, line.displayText.length());
                        updateDisplayText(line, true);
                        cursor.x--;
                        setTextAtCursorVisible(true);
                        GL.that.renderOnce();
                        sendKeyTyped(character);
                        return true;
                    } else {
                        if (cursor.y > 0) {
                            setCursorLine(cursor.y - 1, true);
                            Line line2 = getNthLine(cursor.y);
                            cursor.x = line2.displayText.length();
                            setTextAtCursorVisible(true);
                            line2.displayText = line2.displayText + line.displayText;
                            lines.remove(cursor.y + 1);
                            updateDisplayText(line2, true);

                            int lineCount = lines.size();
                            sendLineCountChanged(lineCount, this.style.font.getLineHeight() * lineCount);
                        }
                        GL.that.renderOnce();
                        sendKeyTyped(character);
                        return true;
                    }
                } catch (Exception e) {
                    return true;
                }
            }
        }
        if (character == DELETE) {
            if (selection != null) {
                deleteSelection();
                return true;
            } else {
                if (cursor.x < line.displayText.length()) {
                    line.displayText = line.displayText.substring(0, cursor.x)
                            + line.displayText.substring(cursor.x + 1, line.displayText.length());
                    updateDisplayText(line, true);
                    GL.that.renderOnce();
                    sendKeyTyped(character);
                    return true;
                } else {
                    if (cursor.y + 1 < lines.size()) {
                        cursor.y++;
                        Line line2 = getNthLine(cursor.y);
                        cursor.y--;
                        lines.remove(line2);
                        line.displayText += line2.displayText;
                        updateDisplayText(line, true);
                        GL.that.renderOnce();
                    }
                    sendKeyTyped(character);
                    return true;
                }
            }
        }
        // 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 (isMultiLine()) {
                if (selection != null)
                    deleteSelection();
                insertNewLine();
                clearSelection();
                sendKeyTyped(character);
                return true;
            }
        }
        if (character != ENTER_DESKTOP && character != ENTER_ANDROID) {
            if (mTextFieldFilter != null && !mTextFieldFilter.acceptChar(this, character))
                return true;
        }

        if (font.getData().getGlyph(character) != null) {
            if (selection != null)
                deleteSelection();
            {
                try {
                    line.displayText = line.displayText.substring(0, cursor.x) + character
                            + line.displayText.substring(cursor.x, line.displayText.length());
                    updateDisplayText(line, true);
                    cursor.x++;
                    setTextAtCursorVisible(true);
                } catch (Exception e) {
                    return false;
                }
            }

            GL.that.renderOnce();
        }
        sendKeyTyped(character);
        if (passwordMode)
            updateDisplayTextList();
        return true;
    } else
        return false;
}

From source file:CB_UI_Base.GL_UI.Controls.EditTextField.java

License:Open Source License

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

    BitmapFont font = style.font;

    StringBuffer buffer = new StringBuffer();
    for (int i = 0; i < inputText.length(); i++) {
        char c = inputText.charAt(i);
        if (font.getData().hasGlyph(c) || (c == '\n'))
            buffer.append(c);//ww  w.j a  v a  2  s.c om
    }

    // replace lineBreaks
    String bText = buffer.toString().replace("\r\n", "\r");

    lines.clear();
    Line newLine = new Line("", true, style.font);
    lines.add(newLine);

    cursor.x = 0;
    cursor.y = 0;

    this.text = "";

    boolean stateIsEditable = isEditable;
    isEditable = true;
    for (int i = 0; i < bText.length(); i++) {
        char c = bText.charAt(i);
        keyTyped(c, true);
    }
    isEditable = stateIsEditable;

    setCursorPosition(inputText.length());

}

From source file:com.bagon.matchteam.mtx.scene2d.ui.AbstractButton.java

License:Apache License

public AbstractButton(BitmapFont bitMapFont, Drawable up, Drawable down, float width, float height,
        boolean DIPActive) {
    super(up, down);
    this.bitMapFont = bitMapFont;
    this.DIPActive = DIPActive;
    ///*w  ww .j a  v  a 2s  . c o m*/
    if (DIPActive) {
        setSize(width * AppSettings.getWorldSizeRatio(), height * AppSettings.getWorldSizeRatio());
        if (this.bitMapFont != null) {
            bitMapFont.getData().setScale(AppSettings.getWorldSizeRatio());
        }
    }
}

From source file:com.bagon.matchteam.mtx.scene2d.ui.AbstractButton.java

License:Apache License

/**
 * Set the font/*from   ww w.ja va 2s.  c  o m*/
 */
public void setBitMapFont(BitmapFont bitMapFont) {
    this.bitMapFont = bitMapFont;

    if (DIPActive) {
        bitMapFont.getData().setScale(AppSettings.getWorldSizeRatio());
    }
}

From source file:com.bagon.matchteam.mtx.scene2d.ui.Text.java

License:Apache License

public Text(BitmapFont bitMapFont, float width, float height, boolean DIPActive) {
    super(width, height, DIPActive);
    this.bitMapFont = bitMapFont;
    //// w ww.  j  a  v  a2s.c  o m
    if (DIPActive) {
        bitMapFont.getData().setScale(AppSettings.getWorldSizeRatio());
    }
}

From source file:com.bagon.matchteam.mtx.scene2d.ui.Text.java

License:Apache License

public void setBitMapFont(BitmapFont bitMapFont, boolean DIPActive) {
    this.bitMapFont = bitMapFont;
    ///*from  w ww  .  ja va2s .  c o m*/
    if (DIPActive) {
        bitMapFont.getData().setScale(AppSettings.getWorldSizeRatio());
    }
}

From source file:com.calanti.androidnativekeyboardinputtest.libgdxModified_1_9_3.CalTextField.java

License:Apache License

protected void drawCursor(Drawable cursorPatch, Batch batch, BitmapFont font, float x, float y) {
    //cursorPatch.draw(batch,
    //        x + textOffset + glyphPositions.get(cursor) - glyphPositions.get(visibleTextStart) + fontOffset + font.getData().cursorX,
    //        y - textHeight - font.getDescent(), cursorPatch.getMinWidth(), textHeight);

    /** calanti addition - proper centering of cursor */
    float cx = x + textOffset + glyphPositions.get(cursor) - glyphPositions.get(visibleTextStart) + fontOffset
            + font.getData().cursorX - cursorPatch.getMinWidth() / 2;
    float cy = y - textHeight - font.getDescent();
    float w = cursorPatch.getMinWidth();
    float h = textHeight;

    cursorPatch.draw(batch, cx, cy, w, h);
}

From source file:com.calanti.androidnativekeyboardinputtest.libgdxModified_1_9_3.CalTextField.java

License:Apache License

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

    StringBuilder buffer = new StringBuilder();
    for (int i = 0; i < textLength; i++) {
        char c = text.charAt(i);

        /** calanti addition - some fonts apparently have these glyphs,
         * causes building the glyphPositions to break for TextArea */
        if (c == ENTER_ANDROID || c == ENTER_DESKTOP) {
            buffer.append(' ');
            continue;
        }//from w  w  w  . j a va 2  s. c o m
        buffer.append(data.hasGlyph(c) ? c : ' ');
    }
    String newDisplayText = buffer.toString();

    if (passwordMode && data.hasGlyph(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;

    layout.setText(font, displayText);
    glyphPositions.clear();
    float x = 0;
    if (layout.runs.size > 0) {
        GlyphLayout.GlyphRun run = layout.runs.first();
        FloatArray xAdvances = run.xAdvances;
        fontOffset = xAdvances.first();
        for (int i = 1, n = xAdvances.size; i < n; i++) {
            glyphPositions.add(x);
            x += xAdvances.get(i);
        }
    } else
        fontOffset = 0;
    glyphPositions.add(x);

    if (selectionStart > newDisplayText.length())
        selectionStart = textLength;
}

From source file:com.finalproject.MainGame.EndScreen.java

public void create() {
    batch = new SpriteBatch();
    stage = new Stage();
    Gdx.input.setInputProcessor(stage);//from  w ww  . j  a va2s  .c o m

    skin = new Skin();
    // Generate a 1x1 white texture and store it in the skin named "black".                
    Pixmap pixmap = new Pixmap(100, 75, Format.RGBA8888);
    pixmap.setColor(Color.BLACK);
    pixmap.fill();

    skin.add("black", new Texture(pixmap));

    BitmapFont bfont = new BitmapFont();
    BitmapFont titleFont = new BitmapFont();
    titleFont.getData().setScale(1);
    bfont.getData().setScale(1);
    skin.add("default", bfont);

    TextButtonStyle textButtonStyle = new TextButtonStyle();
    textButtonStyle.up = skin.newDrawable("black", Color.DARK_GRAY);
    textButtonStyle.down = skin.newDrawable("black", Color.DARK_GRAY);
    textButtonStyle.checked = skin.newDrawable("black", Color.BLUE);
    textButtonStyle.over = skin.newDrawable("black", Color.LIGHT_GRAY);
    LabelStyle textLabelStyle = new LabelStyle();
    textLabelStyle.font = skin.getFont("default");

    textButtonStyle.font = skin.getFont("default");
    // Import the fonts for the Loose label
    skin.add("default", textButtonStyle);
    skin.add("default", textLabelStyle);

    // Add the end screen label
    final Label title = new Label("  Y o u  L o s e !  ", textLabelStyle);
    title.setPosition(265, 300);
    stage.addActor(title);
}

From source file:com.finalproject.MainGame.MenuScreen.java

public void create() {
    // play the start screen sound
    AssetManager.splash.play();//w ww.  j  av a  2 s  . co m
    batch = new SpriteBatch();
    stage = new Stage();
    Gdx.input.setInputProcessor(stage);

    skin = new Skin();
    // Generate a 1x1 white texture and store it in the skin named "black".
    Pixmap pixmap = new Pixmap(100, 75, Format.RGBA8888);
    pixmap.setColor(Color.BLACK);
    pixmap.fill();

    skin.add("black", new Texture(pixmap));

    BitmapFont bfont = new BitmapFont();
    BitmapFont titleFont = new BitmapFont();
    titleFont.getData().setScale(1);
    bfont.getData().setScale(1);
    skin.add("default", bfont);

    TextButtonStyle textButtonStyle = new TextButtonStyle();
    textButtonStyle.up = skin.newDrawable("black", Color.DARK_GRAY);
    textButtonStyle.down = skin.newDrawable("black", Color.DARK_GRAY);
    textButtonStyle.checked = skin.newDrawable("black", Color.BLUE);
    textButtonStyle.over = skin.newDrawable("black", Color.LIGHT_GRAY);
    LabelStyle textLabelStyle = new LabelStyle();
    textLabelStyle.font = skin.getFont("default");

    textButtonStyle.font = skin.getFont("default");
    // Import the fonts for the start button and the instructions
    skin.add("default", textButtonStyle);
    skin.add("default", textLabelStyle);

    // Add the start button and instructions labels
    final TextButton textButton = new TextButton("Start", textButtonStyle);
    final Label title = new Label("Call of Duty Ghosts - NAWN Edition", textLabelStyle);
    final Label Instructions = new Label(" W, A, S, D keys to move the player around   ", textLabelStyle);
    final Label Instructions2 = new Label(" Left click to shoot   ", textLabelStyle);

    //set the position of the start button and the instructions labels
    title.setPosition(210, 400);
    Instructions.setPosition(190, 150);
    Instructions2.setPosition(280, 100);
    textButton.setPosition(275, 300);

    //import the buttons and labels into the gameScreen
    stage.addActor(title);
    stage.addActor(Instructions);
    stage.addActor(Instructions2);
    stage.addActor(textButton);

    //add a listener to determine when the start button has been Clicked
    textButton.addListener(new ChangeListener() {

        public void changed(ChangeEvent event, Actor actor) {
            //When the start button has been clicked
            // remove the start button
            // start the game
            // turn of the start screen music    
            textButton.remove();
            g.setScreen(new MainGame(g));
            AssetManager.splash.dispose();
        }
    });
}