本文整理汇总了Java中org.newdawn.slick.Graphics.setFont方法的典型用法代码示例。如果您正苦于以下问题:Java Graphics.setFont方法的具体用法?Java Graphics.setFont怎么用?Java Graphics.setFont使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.newdawn.slick.Graphics
的用法示例。
在下文中一共展示了Graphics.setFont方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: render
import org.newdawn.slick.Graphics; //导入方法依赖的package包/类
@Override
public void render(Graphics g, long cTime) {
// Draw the text as normal.
g.setColor(color);
g.setFont(ttf);
g.drawString(text, pos.x, pos.y);
// If the mouse cursor is hovering over the text, display the tooltip.
if(isMouseInside()) {
float mx = Globals.mouse.getPosition().x;
float my = Globals.mouse.getPosition().y;
float txtWidth = ttf.getWidth(tooltip);
g.setColor(Color.gray);
g.fillRect(mx, my, (txtWidth + 10.0f), (ttf.getHeight() + 10.0f));
g.setColor(Color.white);
g.drawRect(mx, my, (txtWidth + 10.0f), (ttf.getHeight() + 10.0f));
g.setColor(Color.black);
g.drawString(tooltip, (mx + 5.0f), (my + 5.0f));
}
}
示例2: render
import org.newdawn.slick.Graphics; //导入方法依赖的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());
}
}
示例3: render
import org.newdawn.slick.Graphics; //导入方法依赖的package包/类
/**
* @see org.newdawn.slick.Game#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
*/
public void render(GameContainer container, Graphics g) {
g.setColor(Color.white);
String text = "This is UnicodeFont!\nIt rockz. Kerning: T,";
unicodeFont.drawString(10, 33, text);
// unicodeFont.drawString(10, 33, text, Color.red, 8, 19);
g.setColor(Color.red);
g.drawRect(10, 33, unicodeFont.getWidth(text), unicodeFont.getLineHeight());
g.setColor(Color.blue);
int yOffset = unicodeFont.getYOffset(text);
g.drawRect(10, 33 + yOffset, unicodeFont.getWidth(text), unicodeFont.getHeight(text) - yOffset);
String tst = "width comparison, ,";
g.setFont(unicodeFont);
g.setColor(Color.green);
g.drawString(tst,10,300);
g.drawString(tst,10,350);
g.drawRect(10, 300, unicodeFont.getLogicalWidth(tst), unicodeFont.getLineHeight());
g.setColor(Color.red);
g.drawRect(10, 350, unicodeFont.getWidth(tst), unicodeFont.getLineHeight());
// font.drawString(10, 73, "\u6880\u6881\u6882 (...) \u6883\u6884\u6885\u6886\u6887 hi?");
unicodeFont.addGlyphs("[email protected]!#!#$%___--");
// Cypriot Syllabary glyphs (Everson Mono font): \uD802\uDC02\uD802\uDC03\uD802\uDC12 == 0x10802, 0x10803, s0x10812
// g.drawLine(0, container.getHeight() - 512, container.getWidth(), container.getHeight() - 512);
}
示例4: render
import org.newdawn.slick.Graphics; //导入方法依赖的package包/类
/**
* @see org.newdawn.slick.state.BasicGameState#render(org.newdawn.slick.GameContainer, org.newdawn.slick.state.StateBasedGame, org.newdawn.slick.Graphics)
*/
public void render(GameContainer container, StateBasedGame game, Graphics g) {
g.setFont(font);
g.setColor(Color.white);
g.drawString("State Based Game Test", 100, 100);
g.drawString("Numbers 1-3 will switch between states.", 150, 300);
g.setColor(Color.red);
g.drawString("This is State 1", 200, 50);
}
示例5: render
import org.newdawn.slick.Graphics; //导入方法依赖的package包/类
/**
* @see org.newdawn.slick.state.BasicGameState#render(org.newdawn.slick.GameContainer, org.newdawn.slick.state.StateBasedGame, org.newdawn.slick.Graphics)
*/
public void render(GameContainer container, StateBasedGame game, Graphics g) {
g.setFont(font);
g.setColor(Color.blue);
g.drawString("This is State 3", 200, 50);
g.setColor(Color.white);
for (int i=0;i<options.length;i++) {
g.drawString(options[i], 400 - (font.getWidth(options[i])/2), 200+(i*50));
if (selected == i) {
g.drawRect(200,190+(i*50),400,50);
}
}
}
示例6: render
import org.newdawn.slick.Graphics; //导入方法依赖的package包/类
@Override
public void render(Graphics g, long cTime) {
// Draw the container window.
g.setColor(CONSOLE_BACKGROUND);
g.fillRect(10.0f, (Globals.HEIGHT - 232.0f), (Globals.WIDTH - 20.0f), 222.0f);
g.setColor(CONSOLE_BORDER);
g.drawRect(10.0f, (Globals.HEIGHT - 232.0f), (Globals.WIDTH - 20.0f), 222.0f);
// Draw the input box.
g.setColor(CONSOLE_TEXTBOX);
g.fillRect(15.0f, (Globals.HEIGHT - 34.0f), (Globals.WIDTH - 30.0f), 19.0f);
g.setColor(CONSOLE_TEXTBORDER);
g.drawRect(15.0f, (Globals.HEIGHT - 34.0f), (Globals.WIDTH - 30.0f), 19.0f);
// Draw the current command.
g.setColor(CONSOLE_TEXT);
g.setFont(CONSOLE_FONT);
g.drawString(currentCommand, 20.0f, (Globals.HEIGHT - 30.0f));
// Draw the cursor next to the last character of the current command.
g.fillRect((20.0f + CONSOLE_FONT.getWidth(currentCommand)), (Globals.HEIGHT - 30.0f), 2.0f, CONSOLE_FONT.getHeight());
// Display the previous commands.
if(!pastCommands.isEmpty()) {
int command = (pastCommands.size() > 10) ? (pastCommands.size() - 10) : 0;
g.setColor(CONSOLE_PASTTEXT);
for(int i = 0; i < Math.min(pastCommands.size(), 10); i++) {
float x = 20.0f;
float y = (Globals.HEIGHT - 39.0f - (19.0f * Math.min(pastCommands.size(), 10))) + (i * 19.0f);
g.drawString(pastCommands.get(command), x, (y + 4.0f));
command++;
}
}
}
示例7: TextWrap
import org.newdawn.slick.Graphics; //导入方法依赖的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;
}
}
示例8: render
import org.newdawn.slick.Graphics; //导入方法依赖的package包/类
/**
* @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer,
* org.newdawn.slick.Graphics)
*/
public void render(GameContainer container, Graphics g) {
g.setFont(font);
if (visible) {
for (int i = 0; i < lines.size(); i++) {
font.drawString(10, 50 + (i * 20), (String) lines.get(i),
i > 10 ? Color.red : Color.green);
}
}
}
示例9: render
import org.newdawn.slick.Graphics; //导入方法依赖的package包/类
/**
* @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
*/
public void render(GameContainer container, Graphics g) {
g.setFont(font);
if (visible) {
for (int i=0;i<lines.size();i++) {
font.drawString(10, 50+(i*20),(String) lines.get(i),i > 10 ? Color.red : Color.green);
}
}
}
示例10: render
import org.newdawn.slick.Graphics; //导入方法依赖的package包/类
/**
* @see org.newdawn.slick.state.BasicGameState#render(org.newdawn.slick.GameContainer, org.newdawn.slick.state.StateBasedGame, org.newdawn.slick.Graphics)
*/
public void render(GameContainer container, StateBasedGame game, Graphics g) {
g.setFont(font);
g.setColor(Color.green);
g.drawString("This is State 2", 200, 50);
g.rotate(400,300,ang);
g.drawImage(image,400-(image.getWidth()/2),300-(image.getHeight()/2));
}
示例11: render
import org.newdawn.slick.Graphics; //导入方法依赖的package包/类
/**
* @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
*/
public void render(GameContainer container, Graphics g) {
background.draw(0, 0, 800, 500);
for (int i=0;i<4;i++) {
areas[i].render(container, g);
}
field.render(container, g);
field2.render(container, g);
g.setFont(font);
g.drawString(message, 200, 550);
}
示例12: render
import org.newdawn.slick.Graphics; //导入方法依赖的package包/类
/**
* @see org.newdawn.slick.gui.AbstractComponent#render(org.newdawn.slick.gui.GUIContext,
* org.newdawn.slick.Graphics)
*/
public void render(GUIContext container, Graphics g) {
if (lastKey != -1) {
if (input.isKeyDown(lastKey)) {
if (repeatTimer < System.currentTimeMillis()) {
repeatTimer = System.currentTimeMillis() + KEY_REPEAT_INTERVAL;
keyPressed(lastKey, lastChar);
}
} else {
lastKey = -1;
}
}
Rectangle oldClip = g.getClip();
g.setWorldClip(x,y,width, height);
// Someone could have set a color for me to blend...
Color clr = g.getColor();
if (background != null) {
g.setColor(background.multiply(clr));
g.fillRect(x, y, width, height);
}
g.setColor(text.multiply(clr));
Font temp = g.getFont();
int cpos = font.getWidth(value.substring(0, cursorPos));
int tx = 0;
if (cpos > width) {
tx = width - cpos - font.getWidth("_");
}
g.translate(tx + 2, 0);
g.setFont(font);
g.drawString(value, x + 1, y + 1);
if (hasFocus() && visibleCursor) {
g.drawString("_", x + 1 + cpos + 2, y + 1);
}
g.translate(-tx - 2, 0);
if (border != null) {
g.setColor(border.multiply(clr));
g.drawRect(x, y, width, height);
}
g.setColor(clr);
g.setFont(temp);
g.clearWorldClip();
g.setClip(oldClip);
}