Java 类org.newdawn.slick.Font 实例源码

项目:trashjam2017    文件:FontUtils.java   
/**
 * Calculates and returns the width of a single justified space for the
 * given {@link String}, in pixels.
 * 
 * @param font The font to draw with
 * @param s
 *            The given non-null {@link String} to use to calculate the
 *            width of a space for.
 * @param leftWidth
 *            The integer specifying the left width buffer to use to
 *            calculate how much space a space should take up in
 *            justification.
 * @return The width of a single justified space for the given
 *         {@link String}, in pixels.
 */
private static int calculateWidthOfJustifiedSpaceInPixels(final Font font,
        final String s, final int leftWidth) {
    int space = 0; // hold total space; hold space width in pixel
    int curpos = 0; // current string position

    // count total space
    while (curpos < s.length()) {
        if (s.charAt(curpos++) == ' ') {
            space++;
        }
    }

    if (space > 0) {
        // width left plus with total space
        // space width (in pixel) = width left / total space
        space = (leftWidth + (font.getWidth(" ") * space)) / space;
    }
    return space;
}
项目:Progetto-C    文件:FontUtils.java   
/**
 * Calculates and returns the width of a single justified space for the
 * given {@link String}, in pixels.
 * 
 * @param font The font to draw with
 * @param s
 *            The given non-null {@link String} to use to calculate the
 *            width of a space for.
 * @param leftWidth
 *            The integer specifying the left width buffer to use to
 *            calculate how much space a space should take up in
 *            justification.
 * @return The width of a single justified space for the given
 *         {@link String}, in pixels.
 */
private static int calculateWidthOfJustifiedSpaceInPixels(final Font font,
        final String s, final int leftWidth) {
    int space = 0; // hold total space; hold space width in pixel
    int curpos = 0; // current string position

    // count total space
    while (curpos < s.length()) {
        if (s.charAt(curpos++) == ' ') {
            space++;
        }
    }

    if (space > 0) {
        // width left plus with total space
        // space width (in pixel) = width left / total space
        space = (leftWidth + (font.getWidth(" ") * space)) / space;
    }
    return space;
}
项目:BaseClient    文件:FontUtils.java   
/**
 * Calculates and returns the width of a single justified space for the
 * given {@link String}, in pixels.
 * 
 * @param font The font to draw with
 * @param s
 *            The given non-null {@link String} to use to calculate the
 *            width of a space for.
 * @param leftWidth
 *            The integer specifying the left width buffer to use to
 *            calculate how much space a space should take up in
 *            justification.
 * @return The width of a single justified space for the given
 *         {@link String}, in pixels.
 */
private static int calculateWidthOfJustifiedSpaceInPixels(final Font font,
        final String s, final int leftWidth) {
    int space = 0; // hold total space; hold space width in pixel
    int curpos = 0; // current string position

    // count total space
    while (curpos < s.length()) {
        if (s.charAt(curpos++) == ' ') {
            space++;
        }
    }

    if (space > 0) {
        // width left plus with total space
        // space width (in pixel) = width left / total space
        space = (leftWidth + (font.getWidth(" ") * space)) / space;
    }
    return space;
}
项目:awesome-game-store    文件:Character.java   
protected Character(int id, SpriteSheet spriteSheet, Font font, Font shadowFont) throws SlickException {
    super(id, spriteSheet);

    // Basic stuff
    moving = false;
    xSize = 1;
    ySize = 1;
    state = IDLE;
    targetAsset = null;
    canBeDisposed = false;

    // Floating Text
    floatingText = new FloatingText(font, shadowFont, xPos * 2, yPos * 2, xOffset * 2, yOffset * 2, this.image[0].getWidth(), this.image[0].getHeight(), 3000);
    floatingMoney = new FloatingText(ResourceLoader.getInstance().tinyGreenFont, shadowFont, xPos * 2, yPos * 2, xOffset * 2, yOffset * 2 - 22f, this.image[0].getWidth(), this.image[0].getHeight(), 3000);
    floatingMoney.setLocalYOffset(-100f);
}
项目:awesome-game-store    文件:MiscMiniPanel.java   
/**
 * Render!
 */
@Override
public void render(GameContainer container, StateBasedGame game, Graphics g, Font panelFont, Font shadowFont) throws SlickException {

    // Only if visible!
    if(visible) {

        // Super Class Render
        super.render(container, game, g, panelFont, shadowFont);

        // Misc label
        shadowFont.drawString(xPos + leftMargin + 1f, yPos + topHeaderMargin + 1f, misc.getReferringMarketAsset().getName());
        panelFont.drawString(xPos + leftMargin, yPos + topHeaderMargin, misc.getReferringMarketAsset().getName());

        // Render Buttons!
        moveMiscButton.render(container, game, g);
        sellMiscButton.render(container, game, g);
        shadowFont.drawString(sellMiscButton.getxPos() + sellMiscButton.getWidth() + leftMargin + 1f, sellMiscButton.getyPos() + 2f + 1f, "Sell for $ " + GameSystem.printMoney((int)(misc.getReferringMarketAsset().getPrice() * 0.4), false));
        panelFont.drawString(sellMiscButton.getxPos() + sellMiscButton.getWidth() + leftMargin, sellMiscButton.getyPos() + 2f, "Sell for $ " + GameSystem.printMoney((int)(misc.getReferringMarketAsset().getPrice() * 0.4), false));

    }
}
项目:awesome-game-store    文件:TvMiniPanel.java   
/**
 * Render!
 */
@Override
public void render(GameContainer container, StateBasedGame game, Graphics g, Font panelFont, Font shadowFont) throws SlickException {

    // Only if visible!
    if(visible) {

        // Super Class Render
        super.render(container, game, g, panelFont, shadowFont);

        // Title
        shadowFont.drawString(xPos + leftMargin + 1f, yPos + topHeaderMargin + 1f, tv.getReferringMarketAsset().getName());
        panelFont.drawString(xPos + leftMargin, yPos + topHeaderMargin, tv.getReferringMarketAsset().getName());

        // Attributes
        shadowFont.drawString(xPos + leftMargin + 1f, yPos + topBodyMargin + 1f, "Rating: " + tv.getReferringMarketTv().getLevelOfAwesome() + "/10");
        panelFont.drawString(xPos + leftMargin, yPos + topBodyMargin, "Rating: " + tv.getReferringMarketTv().getLevelOfAwesome() + "/10");

        // Render Buttons!
        moveTvButton.render(container, game, g);
        sellTvButton.render(container, game, g);
        shadowFont.drawString(sellTvButton.getxPos() + sellTvButton.getWidth() + leftMargin + 1f, sellTvButton.getyPos() + 2f + 1f, "Sell for $ " + GameSystem.printMoney((int)(tv.getReferringMarketAsset().getPrice() * 0.4), false));
        panelFont.drawString(sellTvButton.getxPos() + sellTvButton.getWidth() + leftMargin, sellTvButton.getyPos() + 2f, "Sell for $ " + GameSystem.printMoney((int)(tv.getReferringMarketAsset().getPrice() * 0.4), false));

    }
}
项目:awesome-game-store    文件:ShelfMiniPanel.java   
/**
 * Render!
 */
@Override
public void render(GameContainer container, StateBasedGame game, Graphics g, Font panelFont, Font shadowFont) throws SlickException {

    // Only if visible!
    if(visible) {

        // Super Class Render
        super.render(container, game, g, panelFont, shadowFont);

        // Title
        shadowFont.drawString(xPos + leftMargin + 1f, yPos + topHeaderMargin + 1f, shelf.getReferringMarketAsset().getName());
        panelFont.drawString(xPos + leftMargin, yPos + topHeaderMargin, shelf.getReferringMarketAsset().getName());

        // Capacity
        shadowFont.drawString(xPos + leftMargin + 1f, yPos + topBodyMargin + 1f, "Games capacity: " + totalNumberOfGames + "/" + totalShelfCapacity);
        panelFont.drawString(xPos + leftMargin, yPos + topBodyMargin, "Games capacity: " + totalNumberOfGames + "/" + totalShelfCapacity);

        // Render Buttons!
        moveShelfButton.render(container, game, g);
        sellShelfButton.render(container, game, g);
        shadowFont.drawString(sellShelfButton.getxPos() + sellShelfButton.getWidth() + leftMargin + 1f, sellShelfButton.getyPos() + 2f + 1f, "Sell for $ " + GameSystem.printMoney((int)(shelf.getReferringMarketAsset().getPrice() * 0.4), false));
        panelFont.drawString(sellShelfButton.getxPos() + sellShelfButton.getWidth() + leftMargin, sellShelfButton.getyPos() + 2f, "Sell for $ " + GameSystem.printMoney((int)(shelf.getReferringMarketAsset().getPrice() * 0.4), false));
    }
}
项目: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);
        }
    }
}
项目:awesome-game-store    文件:FinancesList.java   
@Override
public void render(GameContainer container, StateBasedGame game, Graphics g, Font panelFont, Font disabledFont, Font shadowFont) throws SlickException {

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

    // Renders the List Rows
    int r = 0;
    for(ListRow lr : listRows) {
        if (r == rows - 2) { // Skip the row before the last, to separate the totals row
            r++;
            continue;
        }
        ((FinancesListRow)lr).render(container, game, g, ResourceLoader.getInstance().tinyGreenFont, ResourceLoader.getInstance().tinyRedFont, shadowFont, values[r]);
        r++;
    }
}
项目:celestial-pole-motion    文件:GUI.java   
public GUI(GameContainer container, int x, int y) {
super(container);

setLocation(x, y);
Font buttonFont = new TrueTypeFont(new java.awt.Font("Arial", java.awt.Font.PLAIN, 14), true);
//North and south
speedUp = new TextButton(container, "Speed Up", getCompX(0), getCompY(0), buttonFont);
speedDown = new TextButton(container, "Speed Down", getCompX(speedUp.getWidth() + 30), getCompY(0), buttonFont);

pause = new TextButton(container, "Pause", getCompX(0), speedUp.getY() + speedUp.getHeight() + 10, buttonFont);
restart = new TextButton(container, "Restart", speedDown.getX(), speedUp.getY() + speedUp.getHeight() + 10, buttonFont);

euler = new TextButton(container, "Angle set: " + getAngleSet(), getCompX(0), pause.getY() + pause.getHeight() + 10, buttonFont);

hemisphere = new TextButton(container, getHemisphereText(), getCompX(0), euler.getY() + euler.getHeight() + 10, buttonFont);

close = new TextButton(container, "X", speedDown.getX() + speedDown.getWidth() + 50, getCompY(0), buttonFont);

contents = new Rectangle(x - 5, y - 5, width, height);
sf = new GradientFill(0, 0, new Color(10, 10, 10, 200), width, 0, new Color(60, 60, 60, 200));
   }
项目:Pixel-Planet    文件:GUI.java   
void render(){
    Point2D.Float coord;
    Point2D.Float size;
    Font font;
    Color color;
    int i = 0;
    for (String text : texts){
        coord = coords.get(i);
        color = colors.get(i);
        font = fonts.get(i);
        font.drawString(coord.x, coord.y, text, color);
        i++;
    }
    i = 0;
    for (Rectangle rect : rects){
        g.setColor(rectColors.get(i));
        g.fill(rect);
        i++;
    }
}
项目:Pixel-Planet    文件:DeathMessages.java   
public static void render(Graphics g, Font font, int gcWidth){
    if (!messages.isEmpty()){
        int x,y,
        fH = font.getHeight("");
        float currFrame;
        for (int i = 0; i < messages.size(); i++){
            String msg = messages.get(i);
            currFrame = currentFrame.get(i);
            y = 100+(i*fH)-Math.round(currFrame);
            x = gcWidth-font.getWidth(msg)-10;
            font.drawString(x, y, msg, new Color(0,174,239,Math.round( 255 - 2.55f*(currFrame) )));
            currentFrame.set(i, currFrame+100f/DURATION);
            if (y < 30){
                messages.remove(i);
                currentFrame.remove(i);
            }
        }
    }
}
项目:GPVM    文件:FontUtils.java   
/**
 * Calculates and returns the width of a single justified space for the
 * given {@link String}, in pixels.
 * 
 * @param font The font to draw with
 * @param s
 *            The given non-null {@link String} to use to calculate the
 *            width of a space for.
 * @param leftWidth
 *            The integer specifying the left width buffer to use to
 *            calculate how much space a space should take up in
 *            justification.
 * @return The width of a single justified space for the given
 *         {@link String}, in pixels.
 */
private static int calculateWidthOfJustifiedSpaceInPixels(final Font font,
        final String s, final int leftWidth) {
    int space = 0; // hold total space; hold space width in pixel
    int curpos = 0; // current string position

    // count total space
    while (curpos < s.length()) {
        if (s.charAt(curpos++) == ' ') {
            space++;
        }
    }

    if (space > 0) {
        // width left plus with total space
        // space width (in pixel) = width left / total space
        space = (leftWidth + (font.getWidth(" ") * space)) / space;
    }
    return space;
}
项目:GPVM    文件:FontUtils.java   
/**
 * Calculates and returns the width of a single justified space for the
 * given {@link String}, in pixels.
 * 
 * @param font The font to draw with
 * @param s
 *            The given non-null {@link String} to use to calculate the
 *            width of a space for.
 * @param leftWidth
 *            The integer specifying the left width buffer to use to
 *            calculate how much space a space should take up in
 *            justification.
 * @return The width of a single justified space for the given
 *         {@link String}, in pixels.
 */
private static int calculateWidthOfJustifiedSpaceInPixels(final Font font,
        final String s, final int leftWidth) {
    int space = 0; // hold total space; hold space width in pixel
    int curpos = 0; // current string position

    // count total space
    while (curpos < s.length()) {
        if (s.charAt(curpos++) == ' ') {
            space++;
        }
    }

    if (space > 0) {
        // width left plus with total space
        // space width (in pixel) = width left / total space
        space = (leftWidth + (font.getWidth(" ") * space)) / space;
    }
    return space;
}
项目:Tower-Scaler    文件:TSTextButton.java   
public TSTextButton(GUIContext container, Engine parent, TSBooleanSupplier onState,
        int x, int y, String text, Font font, Color textColor,
        Color boxFillColor, Color boxBorderColor, int padding, int alignX,
        int alignY){
    super(container, x, y);
    this.text = text;
    this.font = font;
    this.textColor = textColor;
    this.boxFillColor = boxFillColor;
    this.boxBorderColor = boxBorderColor;
    borderPadding = padding;
    this.alignX = alignX;
    this.alignY = alignY;
    this.parent = parent;
    this.onState = onState;
}
项目:SpaceStationAlpha    文件:FontUtils.java   
/**
 * Calculates and returns the width of a single justified space for the
 * given {@link String}, in pixels.
 * 
 * @param font The font to draw with
 * @param s
 *            The given non-null {@link String} to use to calculate the
 *            width of a space for.
 * @param leftWidth
 *            The integer specifying the left width buffer to use to
 *            calculate how much space a space should take up in
 *            justification.
 * @return The width of a single justified space for the given
 *         {@link String}, in pixels.
 */
private static int calculateWidthOfJustifiedSpaceInPixels(final Font font,
        final String s, final int leftWidth) {
    int space = 0; // hold total space; hold space width in pixel
    int curpos = 0; // current string position

    // count total space
    while (curpos < s.length()) {
        if (s.charAt(curpos++) == ' ') {
            space++;
        }
    }

    if (space > 0) {
        // width left plus with total space
        // space width (in pixel) = width left / total space
        space = (leftWidth + (font.getWidth(" ") * space)) / space;
    }
    return space;
}
项目:cretion    文件:FontUtils.java   
/**
 * Calculates and returns the width of a single justified space for the
 * given {@link String}, in pixels.
 * 
 * @param font The font to draw with
 * @param s
 *            The given non-null {@link String} to use to calculate the
 *            width of a space for.
 * @param leftWidth
 *            The integer specifying the left width buffer to use to
 *            calculate how much space a space should take up in
 *            justification.
 * @return The width of a single justified space for the given
 *         {@link String}, in pixels.
 */
private static int calculateWidthOfJustifiedSpaceInPixels(final Font font,
        final String s, final int leftWidth) {
    int space = 0; // hold total space; hold space width in pixel
    int curpos = 0; // current string position

    // count total space
    while (curpos < s.length()) {
        if (s.charAt(curpos++) == ' ') {
            space++;
        }
    }

    if (space > 0) {
        // width left plus with total space
        // space width (in pixel) = width left / total space
        space = (leftWidth + (font.getWidth(" ") * space)) / space;
    }
    return space;
}
项目:slick2d-maven    文件:FontUtils.java   
/**
 * Calculates and returns the width of a single justified space for the
 * given {@link String}, in pixels.
 * 
 * @param font The font to draw with
 * @param s
 *            The given non-null {@link String} to use to calculate the
 *            width of a space for.
 * @param leftWidth
 *            The integer specifying the left width buffer to use to
 *            calculate how much space a space should take up in
 *            justification.
 * @return The width of a single justified space for the given
 *         {@link String}, in pixels.
 */
private static int calculateWidthOfJustifiedSpaceInPixels(final Font font,
        final String s, final int leftWidth) {
    int space = 0; // hold total space; hold space width in pixel
    int curpos = 0; // current string position

    // count total space
    while (curpos < s.length()) {
        if (s.charAt(curpos++) == ' ') {
            space++;
        }
    }

    if (space > 0) {
        // width left plus with total space
        // space width (in pixel) = width left / total space
        space = (leftWidth + (font.getWidth(" ") * space)) / space;
    }
    return space;
}
项目:trashjam2017    文件:FontUtils.java   
/**
 * Draw a string
 * 
 * @param font The font to draw with
 * @param s The text to draw
 * @param alignment The alignment to apply
 * @param x The x location to draw at
 * @param y The y location to draw at
 * @param width The width to fill with the string 
 * @param color The color to draw in 
 * @return The final x coordinate of the text
 */
public static final int drawString(Font font, final String s,
        final int alignment, final int x, final int y, final int width,
        Color color) {
    int resultingXCoordinate = 0;
    if (alignment == Alignment.LEFT) {
        font.drawString(x, y, s, color);
    } else if (alignment == Alignment.CENTER) {
        font.drawString(x + (width / 2) - (font.getWidth(s) / 2), y, s,
                color);
    } else if (alignment == Alignment.RIGHT) {
        font.drawString(x + width - font.getWidth(s), y, s, color);
    } else if (alignment == Alignment.JUSTIFY) {
        // calculate left width
        int leftWidth = width - font.getWidth(s);
        if (leftWidth <= 0) {
            // no width left, use standard draw string
            font.drawString(x, y, s, color);
        }

        return FontUtils.drawJustifiedSpaceSeparatedSubstrings(font, s, x,
                y, FontUtils.calculateWidthOfJustifiedSpaceInPixels(font,
                        s, leftWidth));
    }

    return resultingXCoordinate;
}
项目:Progetto-C    文件:FontUtils.java   
/**
 * Draw a string
 * 
 * @param font The font to draw with
 * @param s The text to draw
 * @param alignment The alignment to apply
 * @param x The x location to draw at
 * @param y The y location to draw at
 * @param width The width to fill with the string 
 * @param color The color to draw in 
 * @return The final x coordinate of the text
 */
public static final int drawString(Font font, final String s,
        final int alignment, final int x, final int y, final int width,
        Color color) {
    int resultingXCoordinate = 0;
    if (alignment == Alignment.LEFT) {
        font.drawString(x, y, s, color);
    } else if (alignment == Alignment.CENTER) {
        font.drawString(x + (width / 2) - (font.getWidth(s) / 2), y, s,
                color);
    } else if (alignment == Alignment.RIGHT) {
        font.drawString(x + width - font.getWidth(s), y, s, color);
    } else if (alignment == Alignment.JUSTIFY) {
        // calculate left width
        int leftWidth = width - font.getWidth(s);
        if (leftWidth <= 0) {
            // no width left, use standard draw string
            font.drawString(x, y, s, color);
        }

        return FontUtils.drawJustifiedSpaceSeparatedSubstrings(font, s, x,
                y, FontUtils.calculateWidthOfJustifiedSpaceInPixels(font,
                        s, leftWidth));
    }

    return resultingXCoordinate;
}
项目:Spark    文件:SlickResources.java   
public SlickResources(Spark game)
{
    this.game = game;

    images = new Image[GameResources.imgCount];
    colors = new Color[GameResources.colorCount];
    fonts = new Font[GameResources.fontCount];

    LoadColors();
}
项目:BaseClient    文件:FontUtils.java   
/**
 * Draw a string
 * 
 * @param font The font to draw with
 * @param s The text to draw
 * @param alignment The alignment to apply
 * @param x The x location to draw at
 * @param y The y location to draw at
 * @param width The width to fill with the string 
 * @param color The color to draw in 
 * @return The final x coordinate of the text
 */
public static final int drawString(Font font, final String s,
        final int alignment, final int x, final int y, final int width,
        Color color) {
    int resultingXCoordinate = 0;
    if (alignment == Alignment.LEFT) {
        font.drawString(x, y, s, color);
    } else if (alignment == Alignment.CENTER) {
        font.drawString(x + (width / 2) - (font.getWidth(s) / 2), y, s,
                color);
    } else if (alignment == Alignment.RIGHT) {
        font.drawString(x + width - font.getWidth(s), y, s, color);
    } else if (alignment == Alignment.JUSTIFY) {
        // calculate left width
        int leftWidth = width - font.getWidth(s);
        if (leftWidth <= 0) {
            // no width left, use standard draw string
            font.drawString(x, y, s, color);
        }

        return FontUtils.drawJustifiedSpaceSeparatedSubstrings(font, s, x,
                y, FontUtils.calculateWidthOfJustifiedSpaceInPixels(font,
                        s, leftWidth));
    }

    return resultingXCoordinate;
}
项目: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;
    }
}
项目:opsu-dance    文件:TextField.java   
public TextField(Font font, int x, int y, int width, int height) {
    this.font = font;
    this.x = x;
    this.y = y;
    this.width = width;
    this.height = height;
}
项目:opsu-dance    文件:SimpleButton.java   
public SimpleButton(int x, int y, int width, int height, Font font, String text, Color bg, Color fg, Color border, Color hoverBorder) {
    this.bg = bg;
    this.fg = fg;
    this.border = border;
    this.hoverBorder = hoverBorder;
    this.hitbox = new Rectangle(x, y, width, height);
    this.font = font;
    this.text = text;
    this.textY = y + (height - font.getLineHeight()) / 2;
}
项目:awesome-game-store    文件:BuyGamesPanel.java   
public void render(GameContainer container, StateBasedGame game, Graphics g, Font panelFont, Font disabledFont, Font shadowFont)
        throws SlickException {

    // Let the Panel render
    super.render(container, game, g, panelFont, shadowFont);

    // Render the List, only if the Panel is visible
    if (visible) {
        buyGamesList.render(container, game, g, panelFont, disabledFont, shadowFont);
    }
}
项目:awesome-game-store    文件:FinancesPanel.java   
public void render(GameContainer container, StateBasedGame game, Graphics g, Font panelFont, Font disabledFont, Font shadowFont) throws SlickException {

    // Let the Panel render
    super.render(container, game, g, panelFont, shadowFont);

    if(visible) {
        managementList.render(container, game, g, panelFont, disabledFont, shadowFont);
        financesList.render(container, game, g, panelFont, disabledFont, shadowFont);
    }
}
项目:awesome-game-store    文件:BuyGamesList.java   
/**
 * Override to render the Unlock Games Button too
 */
@Override
public void render(GameContainer container, StateBasedGame game, Graphics g, Font panelFont, Font disabledFont, Font shadowFont) throws SlickException {

    // Normal Super Class Rendering
    super.render(container, game, g, panelFont, disabledFont, shadowFont);
}
项目: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);

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

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

    // Renders the List Rows
    for(ListRow lr : listRows) {
        ((ManagementListRow)lr).render(container, game, g, ResourceLoader.getInstance().tinyGreenFont, ResourceLoader.getInstance().tinyRedFont, shadowFont);
    }
}
项目:awesome-game-store    文件:ListRow.java   
/**
 * Rendering
 * @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 {

    // Render the columns
    if(columns != null) {
        for(int i = 0; i < columns.length; i++) {
            columns[i].isAvailable = this.isAvailable;
            columns[i].render(container, game, g, panelFont, disabledFont, shadowFont);
        }
    }

    // Render the rectangle around if the user has the mouse over the row
    if(isAvailable) {
        if(isRectangleVisible) {
            g.setLineWidth(2f);
            Color previousColor = g.getColor();
            Color strokeColor = new Color(0, 0, 0);
            g.setColor(strokeColor);
            g.draw(rectangle);

            Color fillColor = new Color(0, 10, 100, 0.1f);
            g.setColor(fillColor);

            g.setColor(previousColor);

        }
    }
}
项目:awesome-game-store    文件:ViewGamesPanel.java   
public void render(GameContainer container, StateBasedGame game, Graphics g, Font panelFont, Font disabledFont, Font shadowFont) throws SlickException {

    // Let the Panel render
    super.render(container, game, g, panelFont, shadowFont);

    // Render the List, only if the Panel is visible
    if(visible) {
        viewGamesList.render(container, game, g, panelFont, disabledFont, shadowFont);
    }
}
项目:awesome-game-store    文件:ConsoleMiniPanel.java   
/**
 * Render!
 */
@Override
public void render(GameContainer container, StateBasedGame game, Graphics g, Font panelFont, Font shadowFont) throws SlickException {

    // Only if visible!
    if(visible) {

        // Super Class Render
        super.render(container, game, g, panelFont, shadowFont);

        // Title
        shadowFont.drawString(xPos + leftMargin + 1f, yPos + topHeaderMargin + 1f, console.getReferringMarketAsset().getName());
        panelFont.drawString(xPos + leftMargin + 1f, yPos + topHeaderMargin + 1f, console.getReferringMarketAsset().getName());

        // Play Price
        shadowFont.drawString(xPos + leftMargin + 1f, yPos + topBodyMargin + 1f, "Play price / hour: ");
        panelFont.drawString(xPos + leftMargin, yPos + topBodyMargin, "Play price / hour: ");
        shadowFont.drawString(decreasePriceButton.xPos + decreasePriceButton.width + 8f + 1f, yPos + topBodyMargin + 1f, GameSystem.printMoney(console.getReferringMarketConsole().getPlayPrice(), true));
        panelFont.drawString(decreasePriceButton.xPos + decreasePriceButton.width + 8f, yPos + topBodyMargin, GameSystem.printMoney(console.getReferringMarketConsole().getPlayPrice(), true));

        // Total Profit
        shadowFont.drawString(xPos + leftMargin + 1f, yPos + topBodyMargin + lineSize + 1f, "Total profit: $" + GameSystem.printMoney(console.getReferringMarketAsset().getTotalProfit(), false));
        panelFont.drawString(xPos + leftMargin, yPos + + topBodyMargin + lineSize, "Total profit: $" + GameSystem.printMoney(console.getReferringMarketAsset().getTotalProfit(), false));

        // Render Buttons!
        moveConsoleButton.render(container, game, g);
        sellConsoleButton.render(container, game, g);
        shadowFont.drawString(sellConsoleButton.getxPos() + sellConsoleButton.getWidth() + leftMargin + 1f, sellConsoleButton.getyPos() + 2f + 1f, "Sell for $ " + GameSystem.printMoney((int)(console.getReferringMarketAsset().getPrice() * 0.4), false));
        panelFont.drawString(sellConsoleButton.getxPos() + sellConsoleButton.getWidth() + leftMargin, sellConsoleButton.getyPos() + 2f, "Sell for $ " + GameSystem.printMoney((int)(console.getReferringMarketAsset().getPrice() * 0.4), false));
        increasePriceButton.render(container, game, g);
        decreasePriceButton.render(container, game, g);

    }
}
项目:awesome-game-store    文件:NewGamePanel.java   
@Override
public void render(GameContainer container, StateBasedGame game, Graphics g, Font panelFont, Font shadowFont) throws SlickException {

    if (visible) {

        super.render(container, game, g, panelFont, shadowFont);

        storeNameTextInput.render(container, game, g);
        difficultyRadioButtonGroup.render(container, game, g);
        mapSizeRadioButtonGroup.render(container, game, g);
        startGameTextButton.render(container, game, g);
        cancelTextButton.render(container, game, g);
    }
}
项目:awesome-game-store    文件:MiniPanel.java   
/**
 * Render!
 */
@Override
public void render(GameContainer container, StateBasedGame game, Graphics g, Font panelFont, Font shadowFont) throws SlickException {

    // Only renders the Mini Panel if it's visible
    if(visible) {

        // Save the previous Color
        Color previousColor = g.getColor();

        // Main Panel and Drop Shadow
        g.setLineWidth(8f);
        g.setColor(new Color(0.4f, 0.4f, 0.4f));
        g.draw(dropShadow);
        g.setColor(Color.black);
        g.draw(window);
        g.setColor(backgroundColor);
        g.fill(window);
        g.setColor(Color.black);
        g.draw(titleBar);
        g.setLineWidth(1/8f);
        g.setColor(titleBackgroundColor);
        g.fill(titleBar);

        // Revert back to previous Color
        g.setColor(previousColor);
    }
}
项目:awesome-game-store    文件:FloatingText.java   
public FloatingText(Font font, Font shadowFont, float xPos, float yPos, float xOffset, float yOffset,
        float entityWidth, float entityHeight, int displayTimeLimit) {

    // Basic attributes
    this.xPos = xPos;
    this.yPos = yPos;
    this.xOffset = xOffset;
    this.yOffset = yOffset;
    this.font = font;
    this.shadowFont = shadowFont;
    this.entityWidth = entityWidth;
    this.entityHeight = entityHeight;

    // Position, size
    width = 0f;
    height = 24f;
    leftMargin = 5f;
    localXOffset = 28f;     // 0f with Character Scale 1f
    localYOffset = -38f;    // -20f with Character Scale 1f

    // Creates the box
    box = new Rectangle(xPos + xOffset + localXOffset, yPos + yOffset + localYOffset, width, height);

    // Rendering properties
    lineColor = Color.black;
    backgroundColor = Color.white;

    // Visibility
    this.visible = false;
    this.displayTime = 0;
    this.displayTimeLimit = displayTimeLimit;
}
项目:awesome-game-store    文件:BuyConsolesPanel.java   
public void render(GameContainer container, StateBasedGame game, Graphics g, Font panelFont, Font disabledFont, Font shadowFont) throws SlickException {

    // Let the Panel render
    super.render(container, game, g, panelFont, shadowFont);

    // Render the List, only if the Panel is visible
    if(visible) {
        buyConsolesList.render(container, game, g, panelFont, disabledFont, shadowFont);
    }
}
项目:awesome-game-store    文件:Panel.java   
/**
 * Render
 * @param container
 * @param game
 * @param g
 * @throws SlickException
 */
public void render(GameContainer container, StateBasedGame game, Graphics g, Font panelFont, Font shadowFont) throws SlickException {

    // Only renders the Panel if it's visible
    if(visible) {

        Color previousColor = g.getColor();

        // Renders the geometry
        g.setColor(Color.gray);
        g.draw(dropShadow);
        g.setColor(Color.black);
        g.draw(window);
        g.draw(titleBar);

        // Fills the Panel with a solid color
        g.setColor(backgroundColor);
        g.fill(window);

        g.setColor(titleBackgroundColor);
        g.fill(titleBar);

        g.setColor(previousColor);

        // Renders the Title of the Panel
        shadowFont.drawString(OffsetUtil.getPreciseOffset(xPos) + 5f + 1f, OffsetUtil.getPreciseOffset(yPos) + 4f + 1f, title);
        panelFont.drawString(OffsetUtil.getPreciseOffset(xPos) + 5f, OffsetUtil.getPreciseOffset(yPos) + 4f, title);
    }
}
项目:awesome-game-store    文件:BuyFurnituresPanel.java   
public void render(GameContainer container, StateBasedGame game, Graphics g, Font panelFont, Font disabledFont, Font shadowFont) throws SlickException {

    // Let the Panel render
    super.render(container, game, g, panelFont, shadowFont);

    // Render the List, only if the Panel is visible
    if(visible) {
        buyFurnituresList.render(container, game, g, panelFont, disabledFont, shadowFont);
    }
}