本文整理汇总了Java中org.newdawn.slick.util.FontUtils.drawCenter方法的典型用法代码示例。如果您正苦于以下问题:Java FontUtils.drawCenter方法的具体用法?Java FontUtils.drawCenter怎么用?Java FontUtils.drawCenter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.newdawn.slick.util.FontUtils
的用法示例。
在下文中一共展示了FontUtils.drawCenter方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: render
import org.newdawn.slick.util.FontUtils; //导入方法依赖的package包/类
@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());
}
}
示例2: TextWrap
import org.newdawn.slick.util.FontUtils; //导入方法依赖的package包/类
/**
* 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;
}
}
示例3: render
import org.newdawn.slick.util.FontUtils; //导入方法依赖的package包/类
@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);
}
}
示例4: render
import org.newdawn.slick.util.FontUtils; //导入方法依赖的package包/类
@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);
}
示例5: render
import org.newdawn.slick.util.FontUtils; //导入方法依赖的package包/类
@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);
}
示例6: render
import org.newdawn.slick.util.FontUtils; //导入方法依赖的package包/类
@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);
}