Java Code Examples for org.newdawn.slick.Graphics#setFont()

The following examples show how to use org.newdawn.slick.Graphics#setFont() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TextField.java    From opsu-dance with GNU General Public License v3.0 5 votes vote down vote up
public void render(Graphics g)
{
	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 (backgroundCol != null) {
		g.setColor(backgroundCol.multiply(clr));
		g.fillRect(x, y, width, height);
	}
	g.setColor(textCol.multiply(clr));
	Font temp = g.getFont();

	int cursorpos = font.getWidth(value);
	int tx = 0;
	if (cursorpos > width) {
		tx = width - cursorpos - font.getWidth("_");
	}

	g.translate(tx + 2, 0);
	g.setFont(font);
	g.drawString(value, x + 1, y + 1);

	if (focused) {
		g.drawString("|", x + cursorpos, y + 1);
	}

	g.translate(-tx - 2, 0);

	if (borderCol != null) {
		g.setColor(borderCol.multiply(clr));
		g.drawRect(x, y, width, height);
	}
	g.setColor(clr);
	g.setFont(temp);
	g.clearWorldClip();
	g.setClip(oldClip);
}
 
Example 2
Source File: TestState1.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * @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);
}
 
Example 3
Source File: TestState3.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * @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);
		}
	}
}
 
Example 4
Source File: TestState2.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * @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));
}
 
Example 5
Source File: TrueTypeFontPerformanceTest.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * @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);
		}
	}
}
 
Example 6
Source File: FontPerformanceTest.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * @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);
		}
	}
}
 
Example 7
Source File: GUITest.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * @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);
}
 
Example 8
Source File: TextField.java    From opsu with GNU General Public License v3.0 4 votes vote down vote up
/**
 * @see org.newdawn.slick.gui.AbstractComponent#render(org.newdawn.slick.gui.GUIContext,
 *      org.newdawn.slick.Graphics)
 */
@Override
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);
}
 
Example 9
Source File: TextField.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * @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);
}