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

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

Introduction

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

Prototype

public float getCapHeight() 

Source Link

Document

Returns the cap height, which is the distance from the top of most uppercase characters to the baseline.

Usage

From source file:com.bladecoder.engine.ui.MenuScreen.java

License:Apache License

@Override
public void show() {
    stage = new Stage(new ScreenViewport());

    final Skin skin = ui.getSkin();
    final World world = World.getInstance();

    final MenuScreenStyle style = skin.get(MenuScreenStyle.class);
    final BitmapFont f = skin.get(style.textButtonStyle, TextButtonStyle.class).font;
    float buttonWidth = f.getCapHeight() * 15f;

    // Image background = new Image(style.background);
    Drawable bg = style.background;//from   w  ww .  j  a v a  2  s.c o m

    if (bg == null && style.bgFile != null) {
        bgTexFile = new Texture(EngineAssetManager.getInstance().getResAsset(style.bgFile));
        bgTexFile.setFilter(TextureFilter.Linear, TextureFilter.Linear);

        bg = new TextureRegionDrawable(new TextureRegion(bgTexFile));
    }

    final Table table = new Table();
    table.setFillParent(true);
    table.center();

    if (bg != null)
        table.setBackground(bg);

    table.addListener(new InputListener() {
        @Override
        public boolean keyUp(InputEvent event, int keycode) {
            if (keycode == Input.Keys.ESCAPE || keycode == Input.Keys.BACK)
                if (world.getCurrentScene() != null)
                    ui.setCurrentScreen(Screens.SCENE_SCREEN);

            return true;
        }
    });

    table.defaults().pad(BUTTON_PADDING).width(buttonWidth);

    stage.setKeyboardFocus(table);

    if (style.showTitle) {

        Label title = new Label(Config.getProperty(Config.TITLE_PROP, "Adventure Blade Engine"), skin,
                style.titleStyle);

        title.setAlignment(Align.center);

        table.add(title).padBottom(DPIUtils.getMarginSize() * 2);
        table.row();
    }

    if (world.savedGameExists() || world.getCurrentScene() != null) {
        TextButton continueGame = new TextButton(I18N.getString("ui.continue"), skin, style.textButtonStyle);

        continueGame.addListener(new ClickListener() {
            public void clicked(InputEvent event, float x, float y) {
                if (world.getCurrentScene() == null)
                    try {
                        world.load();
                    } catch (Exception e) {
                        Gdx.app.exit();
                    }

                ui.setCurrentScreen(Screens.SCENE_SCREEN);
            }
        });

        table.add(continueGame);
    }

    TextButton newGame = new TextButton(I18N.getString("ui.new"), skin, style.textButtonStyle);
    newGame.addListener(new ClickListener() {
        public void clicked(InputEvent event, float x, float y) {
            if (world.savedGameExists()) {
                Dialog d = new Dialog("", skin) {
                    protected void result(Object object) {
                        if (((Boolean) object).booleanValue()) {
                            try {
                                world.newGame();
                            } catch (Exception e) {
                                Gdx.app.exit();
                            }
                            ui.setCurrentScreen(Screens.SCENE_SCREEN);
                        }
                    }
                };

                d.pad(DPIUtils.getMarginSize());
                d.getButtonTable().padTop(DPIUtils.getMarginSize());
                d.getButtonTable().defaults().padLeft(DPIUtils.getMarginSize())
                        .padRight(DPIUtils.getMarginSize());

                Label l = new Label(I18N.getString("ui.override"), ui.getSkin(), "ui-dialog");
                l.setWrap(true);
                l.setAlignment(Align.center);

                d.getContentTable().add(l).prefWidth(Gdx.graphics.getWidth() * .7f);

                d.button(I18N.getString("ui.yes"), true, ui.getSkin().get("ui-dialog", TextButtonStyle.class));
                d.button(I18N.getString("ui.no"), false, ui.getSkin().get("ui-dialog", TextButtonStyle.class));
                d.key(Keys.ENTER, true).key(Keys.ESCAPE, false);

                d.show(stage);
            } else {

                try {
                    world.newGame();
                } catch (Exception e) {
                    Gdx.app.exit();
                }
                ui.setCurrentScreen(Screens.SCENE_SCREEN);
            }
        }
    });

    table.row();
    table.add(newGame);

    TextButton loadGame = new TextButton(I18N.getString("ui.load"), skin, style.textButtonStyle);
    loadGame.addListener(new ClickListener() {
        public void clicked(InputEvent event, float x, float y) {
            ui.setCurrentScreen(Screens.LOAD_GAME_SCREEN);
        }
    });

    table.row();
    table.add(loadGame);

    //      if (world.getCurrentScene() != null) {
    //         TextButton saveGame = new TextButton(I18N.getString("ui.save"), skin, style.textButtonStyle);
    //         saveGame.addListener(new ClickListener() {
    //            public void clicked(InputEvent event, float x, float y) {
    //               ui.setCurrentScreen(Screens.SAVE_GAME_SCREEN);
    //            }
    //         });
    //
    //         table.row();
    //         table.add(saveGame);
    //      }

    TextButton quit = new TextButton(I18N.getString("ui.quit"), skin, style.textButtonStyle);
    quit.addListener(new ClickListener() {
        public void clicked(InputEvent event, float x, float y) {
            Gdx.app.exit();
        }
    });

    table.row();
    table.add(quit);

    table.pack();

    stage.addActor(table);

    // BOTTOM-RIGHT BUTTON STACK
    credits = new Button(skin, "credits");
    credits.addListener(new ClickListener() {
        public void clicked(InputEvent event, float x, float y) {
            ui.setCurrentScreen(Screens.CREDIT_SCREEN);
        }
    });

    help = new Button(skin, "help");
    help.addListener(new ClickListener() {
        public void clicked(InputEvent event, float x, float y) {
            ui.setCurrentScreen(Screens.HELP_SCREEN);
        }
    });

    debug = new Button(skin, "debug");
    debug.addListener(new ClickListener() {
        public void clicked(InputEvent event, float x, float y) {
            DebugScreen debugScr = new DebugScreen();
            debugScr.setUI(ui);
            ui.setCurrentScreen(debugScr);
        }
    });

    Table buttonStack = new Table();
    buttonStack.defaults().pad(DPIUtils.getSpacing()).size(DPIUtils.getPrefButtonSize(),
            DPIUtils.getPrefButtonSize());
    buttonStack.pad(DPIUtils.getMarginSize() * 2);

    if (EngineLogger.debugMode() && world.getCurrentScene() != null) {
        buttonStack.add(debug);
        buttonStack.row();
    }

    buttonStack.add(help);
    buttonStack.row();
    buttonStack.add(credits);
    buttonStack.bottom().right();
    buttonStack.setFillParent(true);
    buttonStack.pack();
    stage.addActor(buttonStack);

    Label version = new Label("v" + Config.getProperty(Config.VERSION_PROP, " unspecified"), skin);
    version.setPosition(DPIUtils.getMarginSize(), DPIUtils.getMarginSize());
    stage.addActor(version);

    debug.addListener(new ClickListener() {
        public void clicked(InputEvent event, float x, float y) {
            DebugScreen debugScr = new DebugScreen();
            debugScr.setUI(ui);
            ui.setCurrentScreen(debugScr);
        }
    });

    pointer = new Pointer(skin);
    stage.addActor(pointer);

    Gdx.input.setInputProcessor(stage);
}

From source file:com.bladecoder.engineeditor.ui.components.CellRenderer.java

License:Apache License

public void draw(Batch batch, float parentAlpha, T item, boolean selected, float x, float y, float width,
        float height) {
    BitmapFont font = style.font;
    Drawable selectedDrawable = style.selection;
    Color fontColorSelected = style.fontColorSelected;
    Color fontColorUnselected = style.fontColorUnselected;

    if (selected) {
        selectedDrawable.draw(batch, x, y - height, width, height);
        font.setColor(fontColorSelected.r, fontColorSelected.g, fontColorSelected.b,
                fontColorSelected.a * parentAlpha);
    } else {//from w w  w .  j  a  va  2  s .com
        font.setColor(fontColorUnselected.r, fontColorUnselected.g, fontColorUnselected.b,
                fontColorUnselected.a * parentAlpha);
    }

    if (hasImage()) {
        TextureRegion r = getCellImage(item);

        float ih = r.getRegionHeight();
        float iw = r.getRegionWidth();

        if (ih > getItemHeight() - MARGIN) {
            ih = getItemHeight() - MARGIN;
            iw *= ih / r.getRegionHeight();
        }

        batch.draw(r, x, y - ih - MARGIN / 2, iw, ih);
        x += iw;
    }

    font.draw(batch, getCellTitle(item), x + textOffsetX, y - textOffsetY);

    if (hasSubtitle()) {
        String sub = getCellSubTitle(item);

        if (sub != null) {
            if (selected) {
                style.subtitleFont.setColor(fontColorSelected.r, fontColorSelected.g, fontColorSelected.b,
                        fontColorSelected.a * parentAlpha * 0.5f);
            } else {
                style.subtitleFont.setColor(fontColorUnselected.r, fontColorUnselected.g, fontColorUnselected.b,
                        fontColorUnselected.a * parentAlpha * 0.5f);
            }

            style.subtitleFont.draw(batch, sub, x + textOffsetX,
                    y - textOffsetY - (font.getCapHeight() - font.getDescent() * 2));
        }
    }
}

From source file:com.bladecoder.engineeditor.ui.components.CellRenderer.java

License:Apache License

public void layout(CustomListStyle style) {
    this.style = style;

    BitmapFont font = style.font;
    Drawable selectedDrawable = style.selection;

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

    itemHeight = font.getCapHeight() - font.getDescent() * 2;

    if (hasSubtitle()) {
        itemHeight += style.subtitleFont.getCapHeight() - style.subtitleFont.getDescent() * 2;
        ;/* w w  w  .j  a  v a2 s.c o m*/
    }

    itemHeight += selectedDrawable.getTopHeight() + selectedDrawable.getBottomHeight();
}

From source file:com.idp.engine.ui.graphics.base.IdpLogger.java

/**
 * Sets font that will be used to render the log.
 * @param font/*from w w  w . ja v a2s .c om*/
 */
public void setFont(BitmapFont font) {
    this.font = font;
    if (font != null) {

        this.font.setColor(Color.LIGHT_GRAY);
        this.font.setUseIntegerPositions(true);
        this.lineLength = (int) (Gdx.graphics.getWidth() / font.getSpaceWidth());
        this.lineHeight = (int) (font.getCapHeight() - font.getDescent() + 2);

        if (blackRectangle != null)
            blackRectangle.dispose();
        this.blackRectangle = new Texture(1, 1, Pixmap.Format.RGB565);
    }
}

From source file:nl.basroding.director.views.actors.basic.ListDeluxe.java

License:Apache License

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

    for (int i = 0; i < objects.length; i++) {
        if (!(objects[i] instanceof Image) && !(objects[i] instanceof String)) {
            objects[i] = String.valueOf(objects[i]);
        }/*from   w  w w .  jav  a 2 s.c om*/
    }

    selectedIndex = 0;

    final BitmapFont font = style.font;
    final Drawable selectedDrawable = style.selection;

    itemHeight = font.getCapHeight() - font.getDescent() * 2;
    textOffsetY = tableStyle.rowHeight / 2 - font.getCapHeight() / 2;

    prefWidth = 0;
    for (int i = 0; i < objects.length; i++) {
        prefWidth += style.width;
    }
    prefHeight = objects.length * itemHeight;

    this.setWidth(this.getPrefWidth());
    this.setHeight(this.getPrefHeight());

    items = objects;

    invalidateHierarchy();
}

From source file:no.mehl.libgdx.ui.List.java

License:Apache License

public void setItems(Array objects) {
    if (objects == null)
        throw new IllegalArgumentException("items cannot be null.");

    //      if (!(objects instanceof String[])) {
    //         String[] strings = new String[objects.length];
    //         for (int i = 0, n = objects.length; i < n; i++)
    //            strings[i] = String.valueOf(objects[i]);
    //         items = strings;
    //      } else
    //         items = (String[])objects;

    items = objects;/*from  w w  w. j  a va2 s . c o m*/
    selectedIndex = 0;

    final BitmapFont font = style.font;
    final Drawable selectedDrawable = style.selection;

    itemHeight = font.getCapHeight() - font.getDescent() * 2;
    itemHeight += selectedDrawable.getTopHeight() + selectedDrawable.getBottomHeight();
    prefWidth += selectedDrawable.getLeftWidth() + selectedDrawable.getRightWidth();
    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);
    }
    prefHeight = items.size * itemHeight;
    fire(new ChangeListener.ChangeEvent());
    invalidateHierarchy();
}