當前位置: 首頁>>代碼示例>>Java>>正文


Java Graphics.setFont方法代碼示例

本文整理匯總了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));
	}
}
 
開發者ID:packetpirate,項目名稱:Generic-Zombie-Shooter-Redux,代碼行數:22,代碼來源:TooltipText.java

示例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());
	}
}
 
開發者ID:packetpirate,項目名稱:Generic-Zombie-Shooter-Redux,代碼行數:26,代碼來源:LoadingState.java

示例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);
}
 
開發者ID:SkidJava,項目名稱:BaseClient,代碼行數:32,代碼來源:UnicodeFontTest.java

示例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);
}
 
開發者ID:j-dong,項目名稱:trashjam2017,代碼行數:12,代碼來源:TestState1.java

示例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);
		}
	}
}
 
開發者ID:j-dong,項目名稱:trashjam2017,代碼行數:17,代碼來源:TestState3.java

示例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++;
		}
	}
}
 
開發者ID:packetpirate,項目名稱:Generic-Zombie-Shooter-Redux,代碼行數:36,代碼來源:Console.java

示例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;
	}
}
 
開發者ID:packetpirate,項目名稱:Generic-Zombie-Shooter-Redux,代碼行數:44,代碼來源:Calculate.java

示例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);
		}
	}
}
 
開發者ID:IngSW-unipv,項目名稱:Progetto-C,代碼行數:15,代碼來源:TrueTypeFontPerformanceTest.java

示例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);
		}
	}
}
 
開發者ID:IngSW-unipv,項目名稱:Progetto-C,代碼行數:13,代碼來源:FontPerformanceTest.java

示例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));
}
 
開發者ID:IngSW-unipv,項目名稱:Progetto-C,代碼行數:12,代碼來源:TestState2.java

示例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);
}
 
開發者ID:IngSW-unipv,項目名稱:Progetto-C,代碼行數:16,代碼來源:GUITest.java

示例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);
}
 
開發者ID:j-dong,項目名稱:trashjam2017,代碼行數:54,代碼來源:TextField.java


注:本文中的org.newdawn.slick.Graphics.setFont方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。