Example usage for com.badlogic.gdx.graphics.g2d GlyphLayout GlyphLayout

List of usage examples for com.badlogic.gdx.graphics.g2d GlyphLayout GlyphLayout

Introduction

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

Prototype

public GlyphLayout(BitmapFont font, CharSequence str) 

Source Link

Usage

From source file:at.therefactory.jewelthief.ui.buttons.GrayButton.java

License:Open Source License

public GrayButton(String caption, float x, float y, float width, float height) {
    this.x = x;/*from  w  w  w .j  ava 2s.  c om*/
    this.y = y;
    this.width = width;
    this.height = height;
    this.caption = caption;
    font = JewelThief.getInstance().getFont();
    captionColor = Color.DARK_GRAY;
    borderSize = 3;

    // horizontally and vertically align to center
    layout = new GlyphLayout(font, caption);
    xCaptionOffset = width / 2 - layout.width / 2;
    yCaptionOffset = height / 2 + layout.height / 2;
}

From source file:CB_UI.GL_UI.Views.MapView.java

License:Open Source License

public void renderWPI(Batch batch, SizeF WpUnderlay, SizeF WpSize, WaypointRenderInfo wpi) {
    Vector2 screen = worldToScreen(new Vector2(wpi.MapX, wpi.MapY));

    screen.y -= ySpeedVersatz;/*from ww  w  .  jav  a2 s  .c  o m*/
    // FIXME create a LineDrawable class for create one times and set the Coordinates with calculated Triangles
    if (myPointOnScreen != null && showDirectLine && (wpi.Selected)
            && (wpi.Waypoint == GlobalCore.getSelectedWaypoint())) {
        // FIXME render only if visible on screen (intersect the screen rec)
        Quadrangle line = new Quadrangle(myPointOnScreen.x, myPointOnScreen.y, screen.x, screen.y,
                3 * UI_Size_Base.that.getScale());
        if (paint == null) {
            paint = new GL_Paint();
            paint.setGLColor(Color.RED);
        }
        PolygonDrawable po = new PolygonDrawable(line.getVertices(), line.getTriangles(), paint,
                this.mapIntWidth, this.mapIntHeight);
        po.draw(batch, 0, 0, this.mapIntWidth, this.mapIntHeight, 0);
        po.dispose();
    }
    // Don't render if outside of screen !!
    if ((screen.x < 0 - WpSize.width || screen.x > this.getWidth() + WpSize.height)
            || (screen.y < 0 - WpSize.height || screen.y > this.getHeight() + WpSize.height)) {
        if (wpi.Cache != null && (wpi.Cache.Id == infoBubble.getCacheId()) && infoBubble.isVisible()) {
            // check if wp selected
            if (wpi.Waypoint != null && wpi.Waypoint.equals(infoBubble.getWaypoint())
                    || wpi.Waypoint == null && infoBubble.getWaypoint() == null)
                infoBubble.setInvisible();
        }
        return;
    }

    float NameYMovement = 0;

    if ((aktZoom >= zoomCross) && (wpi.Selected) && (wpi.Waypoint == GlobalCore.getSelectedWaypoint())) {
        // Draw Cross and move screen vector
        Sprite cross = Sprites.MapOverlay.get(3);
        cross.setBounds(screen.x - WpUnderlay.halfWidth, screen.y - WpUnderlay.halfHeight, WpUnderlay.width,
                WpUnderlay.height);
        cross.draw(batch);

        screen.add(-WpUnderlay.width, WpUnderlay.height);
        NameYMovement = WpUnderlay.height;
    }

    if (wpi.UnderlayIcon != null) {
        wpi.UnderlayIcon.setBounds(screen.x - WpUnderlay.halfWidth, screen.y - WpUnderlay.halfHeight,
                WpUnderlay.width, WpUnderlay.height);
        wpi.UnderlayIcon.draw(batch);
    }
    if (wpi.Icon != null) {
        wpi.Icon.setBounds(screen.x - WpSize.halfWidth, screen.y - WpSize.halfHeight, WpSize.width,
                WpSize.height);
        wpi.Icon.draw(batch);
    }

    // draw Favorite symbol
    if (wpi.Cache != null && wpi.Cache.isFavorite()) {
        batch.draw(Sprites.getSprite(IconName.favorit.name()), screen.x + (WpSize.halfWidth / 2),
                screen.y + (WpSize.halfHeight / 2), WpSize.width, WpSize.height);
    }

    if (wpi.OverlayIcon != null) {
        wpi.OverlayIcon.setBounds(screen.x - WpUnderlay.halfWidth, screen.y - WpUnderlay.halfHeight,
                WpUnderlay.width, WpUnderlay.height);
        wpi.OverlayIcon.draw(batch);
    }

    boolean drawAsWaypoint = wpi.Waypoint != null;

    // Rating des Caches darstellen
    if (wpi.Cache != null && showRating && (!drawAsWaypoint) && (wpi.Cache.Rating > 0) && (aktZoom >= 15)) {
        Sprite rating = Sprites.MapStars.get((int) Math.min(wpi.Cache.Rating * 2, 5 * 2));
        rating.setBounds(screen.x - WpUnderlay.halfWidth,
                screen.y - WpUnderlay.halfHeight - WpUnderlay.Height4_8, WpUnderlay.width,
                WpUnderlay.Height4_8);
        rating.setOrigin(WpUnderlay.width / 2, WpUnderlay.Height4_8 / 2);
        rating.setRotation(0);
        rating.draw(batch);
        NameYMovement += WpUnderlay.Height4_8;
    }

    // Beschriftung
    if (wpi.Cache != null && showTitles && (aktZoom >= 15)) {
        try {
            String Name = drawAsWaypoint ? wpi.Waypoint.getTitle() : wpi.Cache.getName();

            if (layout == null)
                layout = new GlyphLayout(Fonts.getNormal(), Name);
            else
                layout.setText(Fonts.getNormal(), Name);

            float halfWidth = layout.width / 2;
            Fonts.getNormal().draw(batch, layout, screen.x - halfWidth,
                    screen.y - WpUnderlay.halfHeight - NameYMovement);
        } catch (Exception e) {
        }
    }

    // Show D/T-Rating
    if (wpi.Cache != null && showDT && (!drawAsWaypoint) && (aktZoom >= 15)) {
        Sprite difficulty = Sprites.MapStars.get((int) Math.min(wpi.Cache.getDifficulty() * 2, 5 * 2));
        difficulty.setBounds(screen.x - WpUnderlay.width - GL_UISizes.infoShadowHeight,
                screen.y - (WpUnderlay.Height4_8 / 2), WpUnderlay.width, WpUnderlay.Height4_8);
        difficulty.setOrigin(WpUnderlay.width / 2, WpUnderlay.Height4_8 / 2);
        difficulty.setRotation(90);
        difficulty.draw(batch);

        Sprite terrain = Sprites.MapStars.get((int) Math.min(wpi.Cache.getTerrain() * 2, 5 * 2));
        terrain.setBounds(screen.x + GL_UISizes.infoShadowHeight, screen.y - (WpUnderlay.Height4_8 / 2),
                WpUnderlay.width, WpUnderlay.Height4_8);
        terrain.setOrigin(WpUnderlay.width / 2, WpUnderlay.Height4_8 / 2);
        terrain.setRotation(90);
        terrain.draw(batch);

    }

    if (wpi.Cache != null && (wpi.Cache.Id == infoBubble.getCacheId()) && infoBubble.isVisible()) {
        if (infoBubble.getWaypoint() == wpi.Waypoint) {
            Vector2 pos = new Vector2(screen.x - infoBubble.getHalfWidth(), screen.y);
            infoBubble.setPos(pos);
        }
    }
}

From source file:com.johnogel.astrobros.managers.screens.AwardScreen.java

public AwardScreen(GameManager mngr) {

    super(mngr);//from   w ww. j  a  v a2 s .  c  o  m

    font = new BitmapFont(Gdx.files.internal("data/score.fnt"));
    font.getData().setScale(0.3f, 0.3f);
    bonus_text = "";
    bottom_text = "";
    //middle_text = "0";

    layout_bonus = new GlyphLayout(font, bonus_text);

    layout_bottom = new GlyphLayout(font, bottom_text);
    bonus_font_x = -layout_bonus.width / 2;
    bonus_font_y = -40;

    middle_font_y = 0;

    bottom_font_x = -layout_bottom.width / 2;
    bottom_font_y = -20;

    //ticker = 0;
    state_time = 0;
}

From source file:com.johnogel.astrobros.managers.screens.AwardScreen.java

@Override
public void initialize() {
    initializeWorld();//from  w  w  w  .ja v  a2s  . c  o m
    updateReferences();
    String s = "" + mngr.getPreviousScore();
    //middle_text = "YOU SAVED " + s + " BROS";
    System.out.println("score: " + s);

    SoundPlayer sp = mngr.getSuperManager().getSoundPlayer();
    sp.setSong(SoundPlayer.AWARDED);
    sp.setLooping(true);
    sp.setVolume(.9f);
    sp.playSong();

    int total_score = mngr.getTotalScore();
    int top_score = mngr.getTopScore();
    //AnimatedSprite sp;

    //adding moving animation
    Color color;

    if (total_score == top_score) {
        animation = new Animation(FPS,
                mngr.getTextureHandler().getTextureAtlas(TextureHandler.PLATINUM).getRegions());
        middle_text = "PERFECT!";
        bottom_text = "BONUS LEVEL! ONE LIFE!";
        bonus_text = "YOU MUST BE FLAWLESS";
        color = Color.WHITE;
    } else if (mngr.getTotalScore() > mngr.getTopScore() - 2) {
        animation = new Animation(FPS,
                mngr.getTextureHandler().getTextureAtlas(TextureHandler.GOLD).getRegions());
        middle_text = "AWESOME!";
        bottom_text = "TRY FOR PLATINUM!";
        color = Color.GOLD;
    } else if (mngr.getTotalScore() > mngr.getTopScore() - 3) {
        animation = new Animation(FPS,
                mngr.getTextureHandler().getTextureAtlas(TextureHandler.SILVER).getRegions());
        middle_text = "GREAT!";
        bottom_text = "TRY FOR GOLD!";
        color = Color.SLATE;
    } else if (mngr.getTotalScore() > mngr.getTopScore() - 5) {
        animation = new Animation(FPS,
                mngr.getTextureHandler().getTextureAtlas(TextureHandler.BRONZE).getRegions());
        middle_text = "GOOD!";
        bottom_text = "TRY FOR SILVER!";
        color = Color.TAN;
    } else {
        animation = new Animation(FPS,
                mngr.getTextureHandler().getTextureAtlas(TextureHandler.BRONZE).getRegions());
        middle_text = "";
        bottom_text = "WHAT!";
        color = Color.BLACK;
    }

    new PointLight(ray_handler, 5000, color, 500, camera.viewportWidth / 2, -300);
    new PointLight(ray_handler, 5000, Color.BLACK, 500, camera.viewportWidth / 2, 300);
    new PointLight(ray_handler, 5000, Color.BLACK, 500, -camera.viewportWidth / 2, -300);
    new PointLight(ray_handler, 5000, color, 500, -camera.viewportWidth / 2, 300);
    layout_middle = new GlyphLayout(font, middle_text);
    layout_bottom = new GlyphLayout(font, bottom_text);
    sprite = new AnimatedSprite(animation);

    animation.setPlayMode(Animation.PlayMode.LOOP);
    sprite.setTime(0);
    sprite.play();

}

From source file:com.johnogel.astrobros.managers.screens.BonusAwardScreen.java

public BonusAwardScreen(GameManager mngr) {

    super(mngr);/*from w w  w. jav a2 s . c  o  m*/

    font = new BitmapFont(Gdx.files.internal("data/score.fnt"));
    font.getData().setScale(0.3f, 0.3f);
    game_over = "AWARD!";
    bottom_text = "";
    //middle_text = "0";

    layout_top = new GlyphLayout(font, game_over);

    layout_bottom = new GlyphLayout(font, bottom_text);
    top_font_x = -layout_top.width / 2;
    top_font_y = 20;

    middle_font_y = 0;

    bottom_font_x = -layout_bottom.width / 2;
    bottom_font_y = -20;

    //ticker = 0;
    state_time = 0;
}

From source file:com.johnogel.astrobros.managers.screens.BonusAwardScreen.java

@Override
public void initialize() {
    initializeWorld();/*from   w ww. j  a  v a 2  s  . co  m*/
    updateReferences();
    String s = "" + mngr.getPreviousScore();
    //middle_text = "YOU SAVED " + s + " BROS";
    System.out.println("score: " + s);

    SoundPlayer sp = mngr.getSuperManager().getSoundPlayer();
    sp.setSong(SoundPlayer.AWARDED);
    sp.setLooping(true);
    sp.setVolume(.9f);
    sp.playSong();

    int total_score = mngr.getTotalScore();
    int top_score = mngr.getTopScore();
    //AnimatedSprite sp;

    //adding moving animation
    Color color;
    animation = new Animation(FPS, mngr.getTextureHandler().getTextureAtlas(TextureHandler.BLACK).getRegions());
    middle_text = "YOU ROCK";
    bottom_text = "SERIOUSLY!";
    color = Color.BLACK;

    new PointLight(ray_handler, 5000, color, 500, camera.viewportWidth / 2, -300);
    new PointLight(ray_handler, 5000, Color.BLACK, 500, camera.viewportWidth / 2, 300);
    new PointLight(ray_handler, 5000, Color.BLACK, 500, -camera.viewportWidth / 2, -300);
    new PointLight(ray_handler, 5000, color, 500, -camera.viewportWidth / 2, 300);
    layout_middle = new GlyphLayout(font, middle_text);
    layout_bottom = new GlyphLayout(font, bottom_text);
    sprite = new AnimatedSprite(animation);

    animation.setPlayMode(Animation.PlayMode.LOOP);
    sprite.setTime(0);
    sprite.play();

}

From source file:com.johnogel.astrobros.managers.screens.GameEndScreen.java

public GameEndScreen(GameManager mngr) {

    super(mngr);//from w w w . j  a  v a2  s  .  c  o m

    font = new BitmapFont(Gdx.files.internal("data/score.fnt"));
    font.getData().setScale(0.33f, 0.33f);
    game_over = "YOU SAVED";
    press_space = "ASTRO BROS";
    score = "0";

    layout_top = new GlyphLayout(font, game_over);

    layout_bottom = new GlyphLayout(font, press_space);
    top_font_x = -layout_top.width / 2;
    top_font_y = 20;

    middle_font_y = 0;

    bottom_font_x = -layout_bottom.width / 2;
    bottom_font_y = -20;

}

From source file:com.johnogel.astrobros.managers.screens.GameEndScreen.java

@Override
public void initialize() {
    initializeWorld();// w w w  .  j  a v  a 2s.  c o m
    updateReferences();
    String s = "" + mngr.getTotalScore();
    String t = "" + mngr.getTopScore();
    score = s + " OUT OF " + t;
    System.out.println("score: " + s);
    layout_middle = new GlyphLayout(font, score);
    new PointLight(ray_handler, 5000, Color.BLUE, 500, camera.viewportWidth / 2, -300);
    new PointLight(ray_handler, 5000, Color.BLUE, 500, camera.viewportWidth / 2, 300);
    new PointLight(ray_handler, 5000, Color.WHITE, 500, -camera.viewportWidth / 2, -300);
    new PointLight(ray_handler, 5000, Color.BLUE, 500, -camera.viewportWidth / 2, 300);

}

From source file:com.johnogel.astrobros.managers.screens.GameOverScreen.java

public GameOverScreen(GameManager mngr) {

    super(mngr);/*from   w ww.j a  v a2s .  com*/

    font = new BitmapFont(Gdx.files.internal("data/score.fnt"));
    font.getData().setScale(0.3f, 0.3f);

    game_over = "GAME OVER";
    press_space = "PRESS SPACE TO RESTART";
    layout_top = new GlyphLayout(font, game_over);
    layout_bottom = new GlyphLayout(font, press_space);
    top_font_x = -layout_top.width / 2;
    top_font_y = 20;

    bottom_font_x = -layout_bottom.width / 2;
    bottom_font_y = -20;
}

From source file:com.johnogel.astrobros.managers.screens.LevelLossScreen.java

public LevelLossScreen(GameManager mngr) {

    super(mngr);/* w ww . j a va2 s .  c o  m*/

    font = new BitmapFont(Gdx.files.internal("data/score.fnt"));
    font.getData().setScale(0.2f, 0.3f);

    game_over = "LEVEL LOSS";
    press_space = "PRESS SPACE TO RESTART LEVEL";
    layout_top = new GlyphLayout(font, game_over);
    layout_bottom = new GlyphLayout(font, press_space);
    top_font_x = -layout_top.width / 2;
    top_font_y = 20;

    bottom_font_x = -layout_bottom.width / 2;
    bottom_font_y = -20;
}