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

The following examples show how to use org.newdawn.slick.Graphics#drawRect() . These examples are extracted from open source projects. 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
/**
 * @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
 */
public void render(GameContainer contiainer, Graphics g) {
	g.translate(320,240);
	g.scale(scale, scale);

	g.setColor(Color.red);
	for (int x=0;x<10;x++) {
		for (int y=0;y<10;y++) {
			g.fillRect(-500+(x*100), -500+(y*100), 80, 80);
		}
	}
	
	g.setColor(new Color(1,1,1,0.5f));
	g.fillRect(-320,-240,640,480);
	g.setColor(Color.white);
	g.drawRect(-320,-240,640,480);
}
 
Example 2
/**
 * @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
 */
public void render(GameContainer container, Graphics g) {
	g.drawString("T - TGA Snapshot", 10,50);
	g.drawString("J - JPG Snapshot", 10,70);
	g.drawString("P - PNG Snapshot", 10,90);

	g.setDrawMode(Graphics.MODE_ADD);
	g.drawImage(copy, 200, 300);
	g.setDrawMode(Graphics.MODE_NORMAL);
	
	g.drawString(message, 10,400);
	g.drawRect(200,0,400,300);
	g.translate(400, 250);
	fire.render();
	this.g = g;
}
 
Example 3
/**
 * @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
 */
public void render(GameContainer container, Graphics g) {
	font.drawString(80, 5, "A Font Example", Color.red);
	font.drawString(100, 32, "We - AV - Here is a more complete line that hopefully");
	font.drawString(100, 36 + font.getHeight("We Here is a more complete line that hopefully"), 
			             "will show some kerning.");
	
	font2.drawString(80, 85, "A Font Example", Color.red);
	font2.drawString(100, 132, "We - AV - Here is a more complete line that hopefully");
	font2.drawString(100, 136 + font2.getHeight("We - Here is a more complete line that hopefully"), 
			             "will show some kerning.");
	image.draw(100,400);
	
	String testStr = "Testing Font";
	font2.drawString(100, 300, testStr);
	g.setColor(Color.white);
	g.drawRect(100,300+font2.getYOffset(testStr),font2.getWidth(testStr),font2.getHeight(testStr)-font2.getYOffset(testStr));
	font.drawString(500, 300, testStr);
	g.setColor(Color.white);
	g.drawRect(500,300+font.getYOffset(testStr),font.getWidth(testStr),font.getHeight(testStr)-font.getYOffset(testStr));
}
 
Example 4
/**
 * @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
 */
public void render(GameContainer container, Graphics g) {
	if (nextResource != null) {
		g.drawString("Loading: "+nextResource.getDescription(), 100, 100);
	}
	
	int total = LoadingList.get().getTotalResources();
	int loaded = LoadingList.get().getTotalResources() - LoadingList.get().getRemainingResources();
	
	float bar = loaded / (float) total;
	g.fillRect(100,150,loaded*40,20);
	g.drawRect(100,150,total*40,20);
	
	if (started) {
		image.draw(100,200);
		font.drawString(100,500,"LOADING COMPLETE");
	}
}
 
Example 5
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 6
public void render(Graphics g) {
	g.setLineWidth(2f);
	g.setColor(bg);
	g.fillRect(hitbox.x, hitbox.y, hitbox.width, hitbox.height);
	g.setColor(fg);
	font.drawString(hitbox.x + 5, textY, text);
	if (isHovered) {
		g.setColor(hoverBorder);
	} else {
		g.setColor(border);
	}
	g.drawRect(hitbox.x, hitbox.y, hitbox.width, hitbox.height);
}
 
Example 7
/**
 * @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
 */
public void render(GameContainer container, Graphics g) {
	original.draw(0,0,new Color(1,1,1,0.4f));
	
	image.draw(x,y);
	imageX.draw(x+400,y);
	imageY.draw(x,y+300);
	scaledSub.draw(x+300,y+300);
	
	bigSheet.getSprite(7, 5).draw(50,10);
	g.setColor(Color.white);
	g.drawRect(50,10,64,64);
	g.rotate(x+400, y+165, ang);
	g.drawImage(sub, x+300, y+100);
}
 
Example 8
/**
 * @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 9
/**
 * @see org.newdawn.slick.Game#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
 */
public void render(GameContainer container, Graphics g)
		throws SlickException {
	String text = "abc";
	font.drawString(610,100,text);
	
	GL11.glDisable(GL11.GL_BLEND);
	GL11.glEnable(GL11.GL_ALPHA_TEST);
	GL11.glAlphaFunc(GL11.GL_GEQUAL, 0.5f);
	font.drawString(610,150,text);
	GL11.glDisable(GL11.GL_ALPHA_TEST);
	GL11.glEnable(GL11.GL_BLEND);
	
	g.translate(-50,-130);
	g.scale(10,10);
	font.drawString(0,0,text);

	GL11.glDisable(GL11.GL_BLEND);
	GL11.glEnable(GL11.GL_ALPHA_TEST);
	GL11.glAlphaFunc(GL11.GL_GEQUAL, 0.5f);
	font.drawString(0,26,text);
	GL11.glDisable(GL11.GL_ALPHA_TEST);
	GL11.glEnable(GL11.GL_BLEND);
	
	g.resetTransform();
	g.setColor(Color.lightGray);
	g.drawString("Original Size on Sheet", 620, 210);
	g.drawString("10x Scale Up", 40, 575);
	
	g.setColor(Color.darkGray);
	g.drawRect(40, 40, 560,530);
	g.drawRect(610, 105, 150,100);

	g.setColor(Color.white);
	g.drawString("512x512 Font Sheet", 620, 300);
	g.drawString("NEHE Charset", 620, 320);
	g.drawString("4096x4096 (8x) Source Image", 620, 340);
	g.drawString("ScanSize = 20", 620, 360);
}
 
Example 10
/**
 * @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
 */
public void render(GameContainer container, Graphics g) {
	g.drawRect(0,0,image.getWidth(),image.getHeight());
	image.draw(0,0);
	image.draw(500,0,200,100);
	scaleMe.draw(500,100,200,100);
	scaled.draw(400,500);
	Image flipped = scaled.getFlippedCopy(true, false);
	flipped.draw(520,500);
	Image flipped2 = flipped.getFlippedCopy(false, true);
	flipped2.draw(520,380);
	Image flipped3 = flipped2.getFlippedCopy(true, false);
	flipped3.draw(400,380);
	
	for (int i=0;i<3;i++) {
		subImage.draw(200+(i*30),300);
	}
	
	g.translate(500, 200);
	g.rotate(50, 50, rot);
	g.scale(0.3f,0.3f);
	image.draw();
	g.resetTransform();
       
       rotImage.setRotation(rot);
       rotImage.draw(100, 200);
}
 
Example 11
/**
 * Draws the score in-game (smaller and with less information).
 * @param g the current graphics context
 * @param vPos the base y position of the scoreboard
 * @param rank the current rank of this score
 * @param position the animated position offset
 * @param data an instance of GameData to draw rank number
 * @param alpha the transparency of the score
 * @param isActive if this score is the one currently played
 */
public void drawSmall(Graphics g, int vPos, int rank, float position, GameData data, float alpha, boolean isActive) {
	int rectWidth = (int) (145 * GameImage.getUIscale());  //135
	int rectHeight = data.getScoreSymbolImage('0').getHeight();
	int vertDistance = rectHeight + 10;
	int yPos = (int) (vPos + position * vertDistance - rectHeight / 2);
	int xPaddingLeft = Math.max(4, (int) (rectWidth * 0.04f));
	int xPaddingRight = Math.max(2, (int) (rectWidth * 0.02f));
	int yPadding = Math.max(2, (int) (rectHeight * 0.02f));
	String scoreString = String.format(Locale.US, "%,d", score);
	String comboString = String.format("%dx", combo);
	String rankString = String.format("%d", rank);

	Color white = Colors.WHITE_ALPHA, blue = Colors.BLUE_SCOREBOARD, black = Colors.BLACK_ALPHA;
	float oldAlphaWhite = white.a, oldAlphaBlue = blue.a, oldAlphaBlack = black.a;

	// rectangle background
	Color rectColor = isActive ? white : blue;
	rectColor.a = alpha * 0.2f;
	g.setColor(rectColor);
	g.fillRect(0, yPos, rectWidth, rectHeight);
	black.a = alpha * 0.2f;
	g.setColor(black);
	float oldLineWidth = g.getLineWidth();
	g.setLineWidth(1f);
	g.drawRect(0, yPos, rectWidth, rectHeight);
	g.setLineWidth(oldLineWidth);

	// rank
	data.drawSymbolString(rankString, rectWidth, yPos, 1.0f, alpha * 0.2f, true);

	white.a = blue.a = alpha * 0.75f;

	// player name
	if (playerName != null)
		Fonts.MEDIUMBOLD.drawString(xPaddingLeft, yPos + yPadding, playerName, white);

	// score
	Fonts.DEFAULT.drawString(
		xPaddingLeft, yPos + rectHeight - Fonts.DEFAULT.getLineHeight() - yPadding, scoreString, white
	);

	// combo
	Fonts.DEFAULT.drawString(
		rectWidth - Fonts.DEFAULT.getWidth(comboString) - xPaddingRight,
		yPos + rectHeight - Fonts.DEFAULT.getLineHeight() - yPadding,
		comboString, blue
	);

	white.a = oldAlphaWhite;
	blue.a = oldAlphaBlue;
	black.a = oldAlphaBlack;
}
 
Example 12
Source Project: opsu-dance   File: UI.java    License: GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draws a tooltip, if any, near the current mouse coordinates,
 * bounded by the container dimensions.
 * @param g the graphics context
 */
public static void drawTooltip(Graphics g) {
	if (tooltipAlpha.getTime() == 0 || tooltip == null)
		return;

	int margin = width / 100, textMarginX = 2;
	int lineHeight = Fonts.SMALL.getLineHeight();
	int textWidth = textMarginX * 2, textHeight = lineHeight;
	if (tooltipNewlines) {
		String[] lines = tooltip.split("\\n");
		int maxWidth = Fonts.SMALL.getWidth(lines[0]);
		for (int i = 1; i < lines.length; i++) {
			int w = Fonts.SMALL.getWidth(lines[i]);
			if (w > maxWidth)
				maxWidth = w;
		}
		textWidth += maxWidth;
		textHeight += lineHeight * (lines.length - 1);
	} else
		textWidth += Fonts.SMALL.getWidth(tooltip);

	// get drawing coordinates
	int offset = (int) (tooltipOffset * Options.OPTION_CURSOR_SIZE.val / 100.0f);
	int x = mouseX + offset;
	int y = mouseY + offset;
	if (x + textWidth > width - margin)
		x = width - margin - textWidth;
	else if (x < margin)
		x = margin;
	if (y + textHeight > height - margin)
		y = height - margin - textHeight;
	else if (y < margin)
		y = margin;

	// draw tooltip text inside a filled rectangle
	float alpha = tooltipAlpha.getValue();
	float oldAlpha = Colors.BLACK_ALPHA.a;
	Colors.BLACK_ALPHA.a = alpha;
	g.setColor(Colors.BLACK_ALPHA);
	Colors.BLACK_ALPHA.a = oldAlpha;
	g.fillRect(x, y, textWidth, textHeight);
	oldAlpha = Colors.DARK_GRAY.a;
	Colors.DARK_GRAY.a = alpha;
	g.setColor(Colors.DARK_GRAY);
	g.setLineWidth(1);
	g.drawRect(x, y, textWidth, textHeight);
	Colors.DARK_GRAY.a = oldAlpha;
	oldAlpha = Colors.WHITE_ALPHA.a;
	Colors.WHITE_ALPHA.a = alpha;
	Fonts.SMALL.drawString(x + textMarginX, y, tooltip, Colors.WHITE_ALPHA);
	Colors.WHITE_ALPHA.a = oldAlpha;
}
 
Example 13
Source Project: opsu   File: TextField.java    License: 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 14
Source Project: opsu   File: ScoreData.java    License: GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draws the score in-game (smaller and with less information).
 * @param g the current graphics context
 * @param vPos the base y position of the scoreboard
 * @param rank the current rank of this score
 * @param position the animated position offset
 * @param data an instance of GameData to draw rank number
 * @param alpha the transparency of the score
 * @param isActive if this score is the one currently played
 */
public void drawSmall(Graphics g, int vPos, int rank, float position, GameData data, float alpha, boolean isActive) {
	int rectWidth = (int) (145 * GameImage.getUIscale());  //135
	int rectHeight = data.getScoreSymbolImage('0').getHeight();
	int vertDistance = rectHeight + 10;
	int yPos = (int) (vPos + position * vertDistance - rectHeight / 2);
	int xPaddingLeft = Math.max(4, (int) (rectWidth * 0.04f));
	int xPaddingRight = Math.max(2, (int) (rectWidth * 0.02f));
	int yPadding = Math.max(2, (int) (rectHeight * 0.02f));
	String scoreString = String.format(Locale.US, "%,d", score);
	String comboString = String.format("%dx", combo);
	String rankString = String.format("%d", rank);

	Color white = Colors.WHITE_ALPHA, blue = Colors.BLUE_SCOREBOARD, black = Colors.BLACK_ALPHA;
	float oldAlphaWhite = white.a, oldAlphaBlue = blue.a, oldAlphaBlack = black.a;

	// rectangle background
	Color rectColor = isActive ? white : blue;
	rectColor.a = alpha * 0.2f;
	g.setColor(rectColor);
	g.fillRect(0, yPos, rectWidth, rectHeight);
	black.a = alpha * 0.2f;
	g.setColor(black);
	float oldLineWidth = g.getLineWidth();
	g.setLineWidth(1f);
	g.drawRect(0, yPos, rectWidth, rectHeight);
	g.setLineWidth(oldLineWidth);

	// rank
	data.drawSymbolString(rankString, rectWidth, yPos, 1.0f, alpha * 0.2f, true);

	white.a = blue.a = alpha * 0.75f;

	// player name
	if (playerName != null)
		Fonts.MEDIUM.drawString(xPaddingLeft, yPos + yPadding, playerName, white);

	// score
	Fonts.DEFAULT.drawString(
		xPaddingLeft, yPos + rectHeight - Fonts.DEFAULT.getLineHeight() - yPadding, scoreString, white
	);

	// combo
	Fonts.DEFAULT.drawString(
		rectWidth - Fonts.DEFAULT.getWidth(comboString) - xPaddingRight,
		yPos + rectHeight - Fonts.DEFAULT.getLineHeight() - yPadding,
		comboString, blue
	);

	white.a = oldAlphaWhite;
	blue.a = oldAlphaBlue;
	black.a = oldAlphaBlack;
}
 
Example 15
Source Project: opsu   File: UI.java    License: GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draws a tooltip, if any, near the current mouse coordinates,
 * bounded by the container dimensions.
 * @param g the graphics context
 */
public static void drawTooltip(Graphics g) {
	if (tooltipAlpha.getTime() == 0 || tooltip == null || tooltip.isEmpty())
		return;

	int containerWidth = container.getWidth(), containerHeight = container.getHeight();
	int margin = containerWidth / 100, textMarginX = 2;
	int offset = GameImage.CURSOR_MIDDLE.getImage().getWidth() / 2;
	int lineHeight = Fonts.SMALL.getLineHeight();
	int textWidth = textMarginX * 2, textHeight = lineHeight;
	if (tooltipNewlines) {
		String[] lines = tooltip.split("\\n");
		int maxWidth = Fonts.SMALL.getWidth(lines[0]);
		for (int i = 1; i < lines.length; i++) {
			int w = Fonts.SMALL.getWidth(lines[i]);
			if (w > maxWidth)
				maxWidth = w;
		}
		textWidth += maxWidth;
		textHeight += lineHeight * (lines.length - 1);
	} else
		textWidth += Fonts.SMALL.getWidth(tooltip);

	// get drawing coordinates
	int x = input.getMouseX() + offset, y = input.getMouseY() + offset;
	if (x + textWidth > containerWidth - margin)
		x = containerWidth - margin - textWidth;
	else if (x < margin)
		x = margin;
	if (y + textHeight > containerHeight - margin)
		y = containerHeight - margin - textHeight;
	else if (y < margin)
		y = margin;

	// draw tooltip text inside a filled rectangle
	float alpha = tooltipAlpha.getValue();
	float oldAlpha = Colors.BLACK_ALPHA.a;
	Colors.BLACK_ALPHA.a = alpha;
	g.setColor(Colors.BLACK_ALPHA);
	Colors.BLACK_ALPHA.a = oldAlpha;
	g.fillRect(x, y, textWidth, textHeight);
	oldAlpha = Colors.DARK_GRAY.a;
	Colors.DARK_GRAY.a = alpha;
	g.setColor(Colors.DARK_GRAY);
	g.setLineWidth(1);
	g.drawRect(x, y, textWidth, textHeight);
	Colors.DARK_GRAY.a = oldAlpha;
	oldAlpha = Colors.WHITE_ALPHA.a;
	Colors.WHITE_ALPHA.a = alpha;
	Fonts.SMALL.drawString(x + textMarginX, y, tooltip, Colors.WHITE_ALPHA);
	Colors.WHITE_ALPHA.a = oldAlpha;
}
 
Example 16
/**
 * @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);
}
 
Example 17
/**
 * @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
 */
public void render(GameContainer container, Graphics g) throws SlickException {
	g.setColor(Color.white);
	
	g.setAntiAlias(true);
	for (int x=0;x<360;x+=10) {
		g.drawLine(700,100,(int) (700+(Math.cos(Math.toRadians(x))*100)),
						   (int) (100+(Math.sin(Math.toRadians(x))*100)));
	}
	g.setAntiAlias(false);
	
	g.setColor(Color.yellow);
	g.drawString("The Graphics Test!", 300, 50);
	g.setColor(Color.white);
	g.drawString("Space - Toggles clipping", 400, 80);
	g.drawString("Frame rate capped to 100", 400, 120);
	
	if (clip) {
		g.setColor(Color.gray);
		g.drawRect(100,260,400,100);
		g.setClip(100,260,400,100);
	}

	g.setColor(Color.yellow);
	g.translate(100, 120);
	g.fill(poly);
	g.setColor(Color.blue);
	g.setLineWidth(3);
	g.draw(poly);
	g.setLineWidth(1);
	g.translate(0, 230);
	g.draw(poly);
	g.resetTransform();
	
	g.setColor(Color.magenta);
	g.drawRoundRect(10, 10, 100, 100, 10);
	g.fillRoundRect(10, 210, 100, 100, 10);
	
	g.rotate(400, 300, ang);
	g.setColor(Color.green);
	g.drawRect(200,200,200,200);
	g.setColor(Color.blue);
	g.fillRect(250,250,100,100);

	g.drawImage(image, 300,270);
	
	g.setColor(Color.red);
	g.drawOval(100,100,200,200);
	g.setColor(Color.red.darker());
	g.fillOval(300,300,150,100);
	g.setAntiAlias(true);
	g.setColor(Color.white);
	g.setLineWidth(5.0f);
	g.drawOval(300,300,150,100);
	g.setAntiAlias(true);
	g.resetTransform();
	
	if (clip) {
		g.clearClip();
	}
}
 
Example 18
/**
 * Render the game - in this case render the map and diagnostic data
 * 
 * @param container The container we're running the game in
 * @param g The graphics context on which to render
 */
public void render(GameContainer container, Graphics g)
		throws SlickException {
	g.translate(50,50);
	for (int x=0;x<50;x++) {
		for (int y=0;y<50;y++) {
			if (dataMap.blocked(this, x, y)) {
				g.setColor(Color.gray);
				g.fillRect((x*10)+1,(y*10)+1,8,8);
			}
		}
	}
	
	if (showSpaces) {
		for (int i=0;i<navMesh.getSpaceCount();i++) {
			Space space = navMesh.getSpace(i);
			if (builder.clear(dataMap, space)) {
				g.setColor(new Color(1,1,0,0.5f));
				g.fillRect(space.getX()*10, space.getY()*10, space.getWidth()*10, space.getHeight()*10);
			}
			g.setColor(Color.yellow);
			g.drawRect(space.getX()*10, space.getY()*10, space.getWidth()*10, space.getHeight()*10);

			if (showLinks) {
				int links = space.getLinkCount();
				for (int j=0;j<links;j++) {
					Link link = space.getLink(j);
					g.setColor(Color.red);
					g.fillRect((link.getX()*10)-2, (link.getY()*10)-2,5,5);
				}
			}
		}
	}
	
	if (path != null) {
		g.setColor(Color.white);
		for (int i=0;i<path.length()-1;i++) {
			g.drawLine(path.getX(i)*10, path.getY(i)*10, path.getX(i+1)*10, path.getY(i+1)*10);
		}
	}
}
 
Example 19
/**
 * @see org.newdawn.slick.BasicGame#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
 */
public void render(GameContainer container, Graphics g) throws SlickException {

	// RENDERING TO AN IMAGE AND THEN DRAWING IT TO THE DISPLAY
	// Draw graphics and text onto our graphics context from the Image target
	gTarget.setBackground(new Color(0,0,0,0));
	gTarget.clear();
	gTarget.rotate(200,160,ang);
	gTarget.setFont(testFont);
	gTarget.fillRect(10, 10, 50, 50);
	gTarget.drawString("HELLO WORLD",10,10);

	gTarget.drawImage(testImage,100,150);
	gTarget.drawImage(testImage,100,50);
	gTarget.drawImage(testImage,50,75);
	
	// Note we started by clearing the offscreen graphics area and then end
	// by calling flush
	gTarget.flush(); 

	g.setColor(Color.red);
	g.fillRect(250, 50, 200, 200);
	// The image has been updated using its graphics context, so now draw the image
	// to the screen a few times
	target.draw(300,100);
	target.draw(300,410,200,150);
	target.draw(505,410,100,75);
	
	// Draw some text on the screen to indicate what we did and put some
	// nice boxes around the three areas
	g.setColor(Color.white);
	g.drawString("Testing On Offscreen Buffer", 300, 80);
	g.setColor(Color.green);
	g.drawRect(300, 100, target.getWidth(), target.getHeight());
	g.drawRect(300, 410, target.getWidth()/2, target.getHeight()/2);
	g.drawRect(505, 410, target.getWidth()/4, target.getHeight()/4);
	
	// SCREEN COPY EXAMPLE
	// Put some text and simple graphics on the screen to test copying
	// from the screen to a target image
	g.setColor(Color.white);
	g.drawString("Testing Font On Back Buffer", 10, 100);
	g.drawString("Using: "+using, 10, 580);
	g.setColor(Color.red);
	g.fillRect(10,120,200,5);
	
	// Copy the screen area into a destination image
	int xp = (int) (60 + (Math.sin(ang / 60) * 50));
	g.copyArea(cut,xp,50);
	
	// Draw the copied image to the screen and put some nice
	// boxes around the source and the destination
	cut.draw(30,250);
	g.setColor(Color.white);
	g.drawRect(30, 250, cut.getWidth(), cut.getHeight());
	g.setColor(Color.gray);
	g.drawRect(xp, 50, cut.getWidth(), cut.getHeight());
	
	// ALTERING A LOADED IMAGE EXAMPLE
	// Draw the image we loaded in the init method and then modified
	// by drawing some text and simple geometry on it
	preloaded.draw(2,400);
	g.setColor(Color.blue);
	g.drawRect(2,400,preloaded.getWidth(),preloaded.getHeight());
}
 
Example 20
/**
 * Draw a marker for a given point
 * 
 * @param g The graphics context on which to draw
 * @param p The point to draw
 */
private void drawMarker(Graphics g, Vector2f p) {
	g.drawRect(p.x-5, p.y-5,10,10);
}