Java 类org.newdawn.slick.util.FontUtils 实例源码

项目:Generic-Zombie-Shooter-Redux    文件:LoadingState.java   
@Override
public void render(GameContainer gc, StateBasedGame game, Graphics g) throws SlickException {
    g.resetTransform();
    g.clear();

    float lw = 400.0f;
    float lh = 50.0f;
    float lx = (Globals.WIDTH / 2) - (lw / 2);
    float ly = (Globals.HEIGHT / 2) - (lh / 2);
    float loadWidth = lw * percentLoaded;

    g.setColor(new Color(0x808080));
    g.fillRect(lx, ly, lw, lh);
    g.setColor(new Color(0x9B2111));
    g.fillRect(lx, ly, loadWidth, lh);
    g.setColor(Color.white);
    g.drawRect(lx, ly, lw, lh);

    g.setColor(Color.white);
    UnicodeFont uni = assets.getFont("PressStart2P-Regular_large");
    if(uni != null) {
        g.setFont(uni);
        FontUtils.drawCenter(uni, "Loading...", ((Globals.WIDTH / 2) - 200), (int)(ly - uni.getLineHeight() - 10), (int)lw, g.getColor());
    }
}
项目:awesome-game-store    文件:ListColumn.java   
/**
 * Draws the Column text with an specific alignment
 * @param container
 * @param game
 * @param g
 * @param alignment
 * @throws SlickException
 */
public void render(GameContainer container, StateBasedGame game, Graphics g, Font panelFont, Font disabledFont, Font shadowFont) throws SlickException {

    if(button != null) {

        // Renders the Button amazingly
        button.render(container, game, g);

    } else if(bulletsImage != null) {

        // Renders the Image amazingly
        g.drawImage(bulletsImage, (int)this.xPos + imageLeftPadding, (int)this.yPos + imageTopPadding);

    } else {

        // Renders the Text amazingly
        if(isAvailable) {
            FontUtils.drawString(shadowFont, this.text, this.textAlignment, (int)this.xPos + 1, (int)this.yPos + 1 + 4, (int)this.width, lightGrayColor);
            FontUtils.drawString(panelFont, this.text, this.textAlignment, (int)this.xPos, (int)this.yPos + 4, (int)this.width, Color.black);   
        } else {
            FontUtils.drawString(shadowFont, this.text, this.textAlignment, (int)this.xPos + 1, (int)this.yPos + 1 + 4, (int)this.width, lightGrayColor);
            FontUtils.drawString(disabledFont, this.text, this.textAlignment, (int)this.xPos, (int)this.yPos + 4, (int)this.width, Color.gray);
        }   
    }
}
项目:awesome-game-store    文件:FinancesListRow.java   
public void render(GameContainer container, StateBasedGame game, Graphics g, Font greenFont, Font redFont, Font shadowFont, int[] values) throws SlickException {

    // Header
    FontUtils.drawString(ResourceLoader.getInstance().tinyLightGrayFont, columns[0].text, columns[0].textAlignment, (int)columns[0].xPos + 1, (int)columns[0].yPos + 1 + 4, (int)columns[0].width, lightGrayColor);
    FontUtils.drawString(ResourceLoader.getInstance().tinyBlackFont, columns[0].text, columns[0].textAlignment, (int)columns[0].xPos, (int)columns[0].yPos + 4, (int)columns[0].width, Color.black);

    // Render the columns
    for(int i = 1; i < columns.length; i++) {

        // Positive or negative value?
        String value = GameSystem.printMoney(values[i - 1], false);

        if(values[i - 1] > 0) {
            FontUtils.drawString(shadowFont, value, columns[i].textAlignment, (int)columns[i].xPos + 1, (int)columns[i].yPos + 1 + 4, (int)columns[i].width, lightGrayColor);
            FontUtils.drawString(greenFont, value, columns[i].textAlignment, (int)columns[i].xPos, (int)columns[i].yPos + 4, (int)columns[i].width, Color.gray);
        } else if (values[i - 1] == 0) {
            FontUtils.drawString(shadowFont, value, columns[i].textAlignment, (int)columns[i].xPos + 1, (int)columns[i].yPos + 1 + 4, (int)columns[i].width, lightGrayColor);
            FontUtils.drawString(ResourceLoader.getInstance().tinyBlackFont, value, columns[i].textAlignment, (int)columns[i].xPos, (int)columns[i].yPos + 4, (int)columns[i].width, Color.gray);
        } else {
            FontUtils.drawString(shadowFont, value, columns[i].textAlignment, (int)columns[i].xPos + 1, (int)columns[i].yPos + 1 + 4, (int)columns[i].width, lightGrayColor);
            FontUtils.drawString(redFont, value, columns[i].textAlignment, (int)columns[i].xPos, (int)columns[i].yPos + 4, (int)columns[i].width, Color.gray);
        }
    }
}
项目:Generic-Zombie-Shooter-Redux    文件:Calculate.java   
/**
 * Draws the given text using the given font to the graphics context and wraps
 * the text according to the specified max width. Draws the text with the specified color.
 * @param g The graphics context to draw the text on.
 * @param text The text to draw on the screen.
 * @param font The font to render the text with.
 * @param x The top-left x-coordinate at which to draw the text.
 * @param y The top-left y-coordinate at which to draw the text.
 * @param maxWidth The max width for the line before text wraps.
 * @param center Whether or not to draw the text centered.
 * @param color The color to use when rendering the text.
 */
public static void TextWrap(Graphics g, String text, Font font, float x, float y, float maxWidth, boolean center, Color color) {
    float charWidth = font.getWidth("A"); // How wide are characters in this font?
    float lines = (charWidth * text.length()) / maxWidth; // How many lines will be needed to draw this string?

    g.setColor(color);
    g.setFont(font);

    int i = 0; // The current beginning index of the line substring from the text.
    int line = 0; // The current line - 1.
    int charsPerLine = (int)(maxWidth / charWidth); // How many characters can fit on each line?
    while(lines > 0.0f) {
        // Choose which characters will be drawn on this line.
        String substr = "";
        if((i + charsPerLine) <= text.length()) {
            substr = text.substring(i, (i + charsPerLine));
        } else {
            substr = text.substring(i);
        }
        substr = substr.trim(); // Trim leading and trailing whitespace to avoid ruining text centering.

        // Get the y-coordinate to draw this line on.
        float cy = y + (line * font.getLineHeight());

        if(center) FontUtils.drawCenter(font, substr, (int)x, (int)cy, (int)maxWidth, color);
        else g.drawString(substr, x, cy);

        i += charsPerLine;
        line++;
        lines -= 1.0f;
    }
}
项目:awesome-game-store    文件:TextButton.java   
@Override
public void render(GameContainer container, StateBasedGame game, Graphics g) throws SlickException {
    if (visible) {

        g.setLineWidth(2f);

        if (isEnabled) {
            g.setColor(Color.black);
        } else {
            g.setColor(Color.lightGray);
        }

        g.fillRoundRect(xPos + 2f, yPos + 2f, width, height, 2);

        g.setColor(Color.white);
        g.fillRoundRect(xPos, yPos, width, height, 2);

        if(isEnabled) {
            FontUtils.drawCenter(ResourceLoader.getInstance().tinyLightGrayFont, text, (int)(xPos + 1f), (int)(yPos + 1f + padding), (int)(width));
            FontUtils.drawCenter(ResourceLoader.getInstance().tinyBlackFont, text, (int)(xPos), (int)(yPos + padding), (int)(width));
            g.setColor(Color.black);
        } else {
            FontUtils.drawCenter(ResourceLoader.getInstance().tinyLightGrayFont, text, (int)(xPos + 1f), (int)(yPos + 1f + padding), (int)(width));
            FontUtils.drawCenter(ResourceLoader.getInstance().tinyGrayFont, text, (int)(xPos), (int)(yPos + padding), (int)(width));
            g.setColor(Color.lightGray);
        }

        g.drawRoundRect(xPos, yPos, width, height, 2);
    }
}
项目:awesome-game-store    文件:List.java   
/**
 * Render
 * @param container
 * @param game
 * @param g
 * @throws SlickException
 */
public void render(GameContainer container, StateBasedGame game, Graphics g, Font panelFont, Font disabledFont, Font shadowFont) throws SlickException {

    // Renders the List Headers
    if (listHeaders != null) {
        for(ListHeader lh : listHeaders) {
            lh.render(container, game, g, panelFont, disabledFont, shadowFont);
        }
    }

    // Renders the List Rows
    for(int i = 0; i < listRows.size(); i++) {

        // Here we make sure we render only what's in the current page
        if((i >= page * pageSize) && (i < (page + 1) * (pageSize))) {
            listRows.get(i).render(container, game, g, panelFont, disabledFont, shadowFont);
        }
    }

    // Renders the Page Number
    int safePageSize = 0;
    safePageSize = pageSize;

    FontUtils.drawRight(shadowFont,
            (page + 1) + "/" + (((listRows.size() - 1) / safePageSize) + 1),
            1 + (int)this.xPos + (int)this.width - (int)lineSize * 4 + 4,
            1 + (int)this.yPos + (int)this.height - (int)lineSize - (int)lineSize / 2 + 6, 30);

    FontUtils.drawRight(panelFont,
            (page + 1) + "/" + (((listRows.size() - 1) / safePageSize) + 1),
            (int)this.xPos + (int)this.width - (int)lineSize * 4 + 4,
            (int)this.yPos + (int)this.height - (int)lineSize - (int)lineSize / 2 + 6, 30);

    // Renders the Buttons
    nextPageButton.render(container, game, g);
    previousPageButton.render(container, game, g);

}
项目:GPVM    文件:TextComponent.java   
@Override
public void drawForeground() {
  if(font == null) return;

  for(int i = 0; i < text.length; i++) {
    int x = getLineX(i);
    int y = getLineY(i);
    int w = getLineWidth(i);

    FontUtils.drawString(font, name, alignment, x, y, w, color);
  }
}
项目:Generic-Zombie-Shooter-Redux    文件:GameState.java   
@Override
public void render(GameContainer gc, StateBasedGame game, Graphics g) throws SlickException {
    Player player = Globals.player;

    g.resetTransform();
    g.clear();

    Image background = assets.getImage("GZS_Background6");
    g.drawImage(background, 0.0f, 0.0f, Globals.WIDTH, Globals.HEIGHT, 0.0f, 0.0f, background.getWidth(), background.getHeight());

    player.render(g, time);

    Iterator<Entry<String, Entity>> it = entities.entrySet().iterator();
    while(it.hasNext()) {
        Map.Entry<String, Entity> pair = (Map.Entry<String, Entity>) it.next();
        pair.getValue().render(g, time);
    }

    /*
    // Draw the "shadow layer".
    g.clearAlphaMap();
    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
    g.setDrawMode(Graphics.MODE_ALPHA_MAP);

    g.setColor(new Color(1.0f, 1.0f, 1.0f, 0.85f));
    g.fillRect(0.0f, 0.0f, Globals.WIDTH, Globals.HEIGHT);

    AssetManager.getManager().getImage("GZS_LightAlphaMap").drawCentered(Globals.player.getPosition().x, Globals.player.getPosition().y);

    GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
    g.setDrawMode(Graphics.MODE_ALPHA_BLEND);

    g.setColor(Color.black);
    g.fillRect(0.0f, 0.0f, Globals.WIDTH, Globals.HEIGHT);

    g.setDrawMode(Graphics.MODE_NORMAL);*/

    hud.render(g, player, time);

    if(paused) {
        g.setColor(Color.white);
        int w = GameState.FONT_PAUSE.getWidth("Paused");
        int h = GameState.FONT_PAUSE.getHeight();
        FontUtils.drawCenter(GameState.FONT_PAUSE, "Paused", 
                             ((Globals.WIDTH / 2) - (w / 2)), ((Globals.HEIGHT / 2) - (h / 2)), w);
    }

    if(consoleOpen) console.render(g, time);
}
项目:awesome-game-store    文件:BuyFurnituresListRow.java   
@Override
public void render(GameContainer container, StateBasedGame game, Graphics g, Font panelFont, Font disabledFont, Font shadowFont) throws SlickException {

    // Calculate the Console sprite position
    float spriteXPos = this.xPos + 38f;
    float spriteYPos = this.yPos + 4f;
    if (referringMarketAsset instanceof MarketTable) {
        spriteXPos -= 12f;
        spriteYPos += 36f;
    } else if (referringMarketAsset instanceof MarketMisc) {
        spriteYPos += 16f;
    } else if (referringMarketAsset instanceof MarketTv) {
        spriteYPos += 38f;
    }
    spriteXPos /= 2f;
    spriteYPos /= 2f;

    // Switch to Global Graphics Scale for a while here
    g.scale(GameSystem.globalScale / 2f, GameSystem.globalScale / 2f);
        g.drawImage(referringMarketAsset.getSpriteSheet().getSprite(0, 0), (int)spriteXPos, (int)spriteYPos);
    g.scale(2f / GameSystem.globalScale, 2f / GameSystem.globalScale);

    // If it's a shelf, show its capacity
    if (referringMarketAsset instanceof MarketShelf) {
        // Asset Name, capacity and release date
        shadowFont.drawString((int)(this.xPos + 140) + 1, (int)(this.yPos + topMargin + lineSize/2f) + 1, referringMarketAsset.getName());
        panelFont.drawString((int)(this.xPos + 140), (int)(this.yPos + topMargin + lineSize/2f), referringMarketAsset.getName());
        shadowFont.drawString((int)(this.xPos + 140) + 1, (int)(this.yPos + topMargin + lineSize + lineSize/2f) + 1, "Capacity: " + ((MarketShelf)referringMarketAsset).getCapacity());
        panelFont.drawString((int)(this.xPos + 140), (int)(this.yPos + topMargin + lineSize + lineSize/2f), "Capacity: " + ((MarketShelf)referringMarketAsset).getCapacity());
        shadowFont.drawString((int)(this.xPos + 140) + 1, (int)(this.yPos + topMargin + lineSize * 2 + lineSize/2f) + 1, "Released: " + new SimpleDateFormat("dd").format(new Date(referringMarketAsset.getReleaseDate())) + "/" + new SimpleDateFormat("MM").format(new Date(referringMarketAsset.getReleaseDate())) + "/" + new SimpleDateFormat("yyyy").format(new Date(referringMarketAsset.getReleaseDate())));
        panelFont.drawString((int)(this.xPos + 140), (int)(this.yPos + topMargin + lineSize * 2 + lineSize/2f), "Released: " + new SimpleDateFormat("dd").format(new Date(referringMarketAsset.getReleaseDate())) + "/" + new SimpleDateFormat("MM").format(new Date(referringMarketAsset.getReleaseDate())) + "/" + new SimpleDateFormat("yyyy").format(new Date(referringMarketAsset.getReleaseDate())));         
    } else {
        // Asset Name and Release date
        shadowFont.drawString((int)(this.xPos + 140) + 1, (int)(this.yPos + topMargin + lineSize) + 1, referringMarketAsset.getName());
        panelFont.drawString((int)(this.xPos + 140), (int)(this.yPos + topMargin + lineSize), referringMarketAsset.getName());
        shadowFont.drawString((int)(this.xPos + 140) + 1, (int)(this.yPos + topMargin + lineSize * 2) + 1, "Released: " + new SimpleDateFormat("dd").format(new Date(referringMarketAsset.getReleaseDate())) + "/" + new SimpleDateFormat("MM").format(new Date(referringMarketAsset.getReleaseDate())) + "/" + new SimpleDateFormat("yyyy").format(new Date(referringMarketAsset.getReleaseDate())));
        panelFont.drawString((int)(this.xPos + 140), (int)(this.yPos + topMargin + lineSize * 2), "Released: " + new SimpleDateFormat("dd").format(new Date(referringMarketAsset.getReleaseDate())) + "/" + new SimpleDateFormat("MM").format(new Date(referringMarketAsset.getReleaseDate())) + "/" + new SimpleDateFormat("yyyy").format(new Date(referringMarketAsset.getReleaseDate())));
    }

    // Price
    shadowFont.drawString((int)(this.xPos + 492) + 1, (int)(this.yPos + topMargin + lineSize / 2 - 4) + 1, GameSystem.printMoney(referringMarketAsset.getPrice(), true));
    panelFont.drawString((int)(this.xPos + 492), (int)(this.yPos + topMargin + lineSize / 2 - 4), GameSystem.printMoney(referringMarketAsset.getPrice(), true));

    // Buy Button
    buyButton.render(container, game, g);
    Font tinyWhiteFont = ResourceLoader.getInstance().tinyWhiteFont;
    FontUtils.drawCenter(tinyWhiteFont, "Buy", (int)buyButton.getxPos(), (int)(buyButton.getyPos() + buyButton.getHeight() / 2 - 9f), (int)(buyButton.getWidth()));

    // Render the rectangle around
    g.setLineWidth(4f);
    Color previousColor = g.getColor();
    Color strokeColor = new Color(0, 0, 0);
    g.setColor(strokeColor);
    g.draw(rectangle);
    g.setColor(previousColor);
}
项目:awesome-game-store    文件:BuyConsolesListRow.java   
@Override
public void render(GameContainer container, StateBasedGame game, Graphics g, Font panelFont, Font disabledFont, Font shadowFont) throws SlickException {

    // Calculate the Console sprite position
    float consoleSpriteXPos = this.xPos + 25f; consoleSpriteXPos /= GameSystem.globalScale;
    float consoleSpriteYPos = this.yPos + 35f; consoleSpriteYPos /= GameSystem.globalScale;

    // Switch to Global Graphics Scale for a while here
    g.scale(GameSystem.globalScale, GameSystem.globalScale);
        g.drawImage(referringMarketConsole.getSpriteSheet().getSprite(0, 0), (int)consoleSpriteXPos, (int)consoleSpriteYPos);
    g.scale(1f/GameSystem.globalScale, 1f/GameSystem.globalScale);

    // Console Name
    shadowFont.drawString((int)(this.xPos + 140) + 1, (int)(this.yPos + topMargin) + 1, referringMarketConsole.getName());
    panelFont.drawString((int)(this.xPos + 140), (int)(this.yPos + topMargin), referringMarketConsole.getName());

    // Release Date
    shadowFont.drawString((int)(this.xPos + 140) + 1, (int)(this.yPos + topMargin + lineSize) + 1, "Released: " + new SimpleDateFormat("dd").format(new Date(referringMarketConsole.getReleaseDate())) + "/" + new SimpleDateFormat("MM").format(new Date(referringMarketConsole.getReleaseDate())) + "/" + new SimpleDateFormat("yyyy").format(new Date(referringMarketConsole.getReleaseDate())));
    panelFont.drawString((int)(this.xPos + 140), (int)(this.yPos + topMargin + lineSize), "Released: " + new SimpleDateFormat("dd").format(new Date(referringMarketConsole.getReleaseDate())) + "/" + new SimpleDateFormat("MM").format(new Date(referringMarketConsole.getReleaseDate())) + "/" + new SimpleDateFormat("yyyy").format(new Date(referringMarketConsole.getReleaseDate())));

    // Available Games
    shadowFont.drawString((int)(this.xPos + 140) + 1, (int)(this.yPos + topMargin + lineSize * 2) + 1, "Available games: " + referringMarketConsole.getNumberOfGames());
    panelFont.drawString((int)(this.xPos + 140), (int)(this.yPos + topMargin + lineSize * 2), "Available games: " + referringMarketConsole.getNumberOfGames());

    // Console Rating
    shadowFont.drawString((int)(this.xPos + 140) + 1, (int)(this.yPos + topMargin + lineSize * 3) + 1, "Reviews rating: ");
    panelFont.drawString((int)(this.xPos + 140), (int)(this.yPos + topMargin + lineSize * 3), "Reviews rating: ");
    g.drawImage(ResourceLoader.getInstance().gameRatingImages[referringMarketConsole.getQuality()], (int)(this.xPos + 326f), (int)(this.yPos + 100f));

    // Price
    shadowFont.drawString((int)(this.xPos + 492) + 1, (int)(this.yPos + topMargin + lineSize / 2 - 4) + 1, GameSystem.printMoney(referringMarketConsole.getPrice(), true));
    panelFont.drawString((int)(this.xPos + 492), (int)(this.yPos + topMargin + lineSize / 2 - 4), GameSystem.printMoney(referringMarketConsole.getPrice(), true));

    // Buy Button
    buyButton.render(container, game, g);
    Font tinyWhiteFont = ResourceLoader.getInstance().tinyWhiteFont;
    FontUtils.drawCenter(tinyWhiteFont, "Buy", (int)buyButton.getxPos(), (int)(buyButton.getyPos() + buyButton.getHeight() / 2 - 9f), (int)(buyButton.getWidth()));

    // Render the rectangle around
    g.setLineWidth(4f);
    Color previousColor = g.getColor();
    Color strokeColor = new Color(0, 0, 0);
    g.setColor(strokeColor);
    g.draw(rectangle);
    g.setColor(previousColor);
}