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

The following examples show how to use org.newdawn.slick.Graphics#fillRect() . 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: TransformTest.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * @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
Source File: UI.java    From opsu-dance with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Draws a scroll bar.
 * @param g the graphics context
 * @param position the position in the virtual area
 * @param totalLength the total length of the virtual area
 * @param lengthShown the length of the virtual area shown
 * @param unitBaseX the base x coordinate
 * @param unitBaseY the base y coordinate
 * @param unitWidth the width of a unit
 * @param scrollAreaHeight the height of the scroll area
 * @param bgColor the scroll bar area background color (null if none)
 * @param scrollbarColor the scroll bar color
 * @param right whether or not to place the scroll bar on the right side of the unit
 */
public static void drawScrollbar(
		Graphics g, float position, float totalLength, float lengthShown,
		float unitBaseX, float unitBaseY, float unitWidth, float scrollAreaHeight,
		Color bgColor, Color scrollbarColor, boolean right
) {
	float scrollbarWidth = width * 0.00347f;
	float scrollbarHeight = scrollAreaHeight * lengthShown / totalLength;
	float offsetY = (scrollAreaHeight - scrollbarHeight) * (position / (totalLength - lengthShown));
	float scrollbarX = unitBaseX + unitWidth - ((right) ? scrollbarWidth : 0);
	if (bgColor != null) {
		g.setColor(bgColor);
		g.fillRect(scrollbarX, unitBaseY, scrollbarWidth, scrollAreaHeight);
	}
	g.setColor(scrollbarColor);
	g.fillRect(scrollbarX, unitBaseY + offsetY, scrollbarWidth, scrollbarHeight);
}
 
Example 3
Source File: RotateTransition.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * @see org.newdawn.slick.state.transition.Transition#postRender(org.newdawn.slick.state.StateBasedGame, org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
 */
public void postRender(StateBasedGame game, GameContainer container, Graphics g) throws SlickException {
	g.translate(container.getWidth()/2, container.getHeight()/2);
	g.scale(scale,scale);
	g.rotate(0, 0, ang);
	g.translate(-container.getWidth()/2, -container.getHeight()/2);
	if (background != null) {
		Color c = g.getColor();
		g.setColor(background);
		g.fillRect(0,0,container.getWidth(),container.getHeight());
		g.setColor(c);
	}
	prev.render(container, game, g);
	g.translate(container.getWidth()/2, container.getHeight()/2);
	g.rotate(0, 0, -ang);
	g.scale(1/scale,1/scale);
	g.translate(-container.getWidth()/2, -container.getHeight()/2);
}
 
Example 4
Source File: CopyAreaAlphaTest.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * @see org.newdawn.slick.Game#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
 */
public void render(GameContainer container, Graphics g)
		throws SlickException {
	g.clearAlphaMap();
	g.setDrawMode(Graphics.MODE_NORMAL);
	g.setColor(Color.white);
	g.fillOval(100,100,150,150);
	textureMap.draw(10,50);
	
	g.copyArea(copy, 100,100);
	g.setColor(Color.red);
	g.fillRect(300,100,200,200);
	copy.draw(350,150);
}
 
Example 5
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 6
Source File: ClipTest.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * @see org.newdawn.slick.Game#render(org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
 */
public void render(GameContainer container, Graphics g)
		throws SlickException {
	g.setColor(Color.white);
	g.drawString("1 - No Clipping", 100, 10);
	g.drawString("2 - Screen Clipping", 100, 30);
	g.drawString("3 - World Clipping", 100, 50);
	
	if (world) {
		g.drawString("WORLD CLIPPING ENABLED", 200, 80);
	} 
	if (clip) {
		g.drawString("SCREEN CLIPPING ENABLED", 200, 80);
	}
	
	g.rotate(400, 400, ang);
	if (world) {
		g.setWorldClip(350,302,100,196);
	}
	if (clip) {
		g.setClip(350,302,100,196);
	}
	g.setColor(Color.red);
	g.fillOval(300,300,200,200);
	g.setColor(Color.blue);
	g.fillRect(390,200,20,400);
	
	g.clearClip();
	g.clearWorldClip();
}
 
Example 7
Source File: UserSelectOverlay.java    From opsu with GNU General Public License v3.0 5 votes vote down vote up
/** Renders the user selection menu. */
private void renderUserSelect(Graphics g, float alpha) {
	COLOR_WHITE.a = alpha;

	// title
	String title = "User Select";
	Fonts.XLARGE.drawString(
		x + (width - Fonts.XLARGE.getWidth(title)) / 2,
		(int) (y + titleY - scrolling.getPosition()),
		title, COLOR_WHITE
	);

	// users
	int cx = (int) (x + usersStartX);
	int cy = (int) (y + -scrolling.getPosition() + usersStartY);
	for (UserButton button : userButtons) {
		button.setPosition(cx, cy);
		if (cy < height)
			button.draw(g, alpha);
		cy += UserButton.getHeight() + usersPaddingY;
	}

	// scrollbar
	int scrollbarWidth = 10, scrollbarHeight = 45;
	float scrollbarX = x + width - scrollbarWidth;
	float scrollbarY = y + (scrolling.getPosition() / maxScrollOffset) * (height - scrollbarHeight);
	g.setColor(COLOR_WHITE);
	g.fillRect(scrollbarX, scrollbarY, scrollbarWidth, scrollbarHeight);
}
 
Example 8
Source File: SimpleButton.java    From opsu-dance with GNU General Public License v3.0 5 votes vote down vote up
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 9
Source File: FadeOutTransition.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * @see org.newdawn.slick.state.transition.Transition#postRender(org.newdawn.slick.state.StateBasedGame, org.newdawn.slick.GameContainer, org.newdawn.slick.Graphics)
 */
public void postRender(StateBasedGame game, GameContainer container, Graphics g) {
	Color old = g.getColor();
	g.setColor(color);
	g.fillRect(0, 0, container.getWidth() * 2, container.getHeight() * 2);
	g.setColor(old);
}
 
Example 10
Source File: Spinner.java    From opsu with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void draw(Graphics g, int trackPosition) {
	// only draw spinners shortly before start time
	int timeDiff = hitObject.getTime() - trackPosition;
	final int fadeInTime = game.getFadeInTime();
	if (timeDiff - fadeInTime > 0)
		return;

	boolean spinnerComplete = (rotations >= rotationsNeeded);
	float alpha = Utils.clamp(1 - (float) timeDiff / fadeInTime, 0f, 1f);

	// darken screen
	if (Options.getSkin().isSpinnerFadePlayfield()) {
		float oldAlpha = Colors.BLACK_ALPHA.a;
		if (timeDiff > 0)
			Colors.BLACK_ALPHA.a *= alpha;
		g.setColor(Colors.BLACK_ALPHA);
		g.fillRect(0, 0, width, height);
		Colors.BLACK_ALPHA.a = oldAlpha;
	}

	// rpm
	Image rpmImg = GameImage.SPINNER_RPM.getImage();
	rpmImg.setAlpha(alpha);
	rpmImg.drawCentered(width / 2f, height - rpmImg.getHeight() / 2f);
	if (timeDiff < 0)
		data.drawSymbolString(Integer.toString(drawnRPM), (width + rpmImg.getWidth() * 0.95f) / 2f,
				height - data.getScoreSymbolImage('0').getHeight() * 1.025f, 1f, 1f, true);

	// spinner meter (subimage)
	Image spinnerMetre = GameImage.SPINNER_METRE.getImage();
	int spinnerMetreY = (spinnerComplete) ? 0 : (int) (spinnerMetre.getHeight() * (1 - (rotations / rotationsNeeded)));
	Image spinnerMetreSub = spinnerMetre.getSubImage(
			0, spinnerMetreY,
			spinnerMetre.getWidth(), spinnerMetre.getHeight() - spinnerMetreY
	);
	spinnerMetreSub.setAlpha(alpha);
	spinnerMetreSub.draw(0, height - spinnerMetreSub.getHeight());

	// main spinner elements
	GameImage.SPINNER_CIRCLE.getImage().setAlpha(alpha);
	GameImage.SPINNER_CIRCLE.getImage().setRotation(drawRotation * 360f);
	GameImage.SPINNER_CIRCLE.getImage().drawCentered(width / 2, height / 2);
	if (!GameMod.HIDDEN.isActive()) {
		float approachScale = 1 - Utils.clamp(((float) timeDiff / (hitObject.getTime() - hitObject.getEndTime())), 0f, 1f);
		Image approachCircleScaled = GameImage.SPINNER_APPROACHCIRCLE.getImage().getScaledCopy(approachScale);
		approachCircleScaled.setAlpha(alpha);
		approachCircleScaled.drawCentered(width / 2, height / 2);
	}
	GameImage.SPINNER_SPIN.getImage().setAlpha(alpha);
	GameImage.SPINNER_SPIN.getImage().drawCentered(width / 2, height * 3 / 4);

	if (spinnerComplete) {
		GameImage.SPINNER_CLEAR.getImage().drawCentered(width / 2, height / 4);
		int extraRotations = (int) (rotations - rotationsNeeded);
		if (extraRotations > 0)
			data.drawSymbolNumber(extraRotations * 1000, width / 2, height * 2 / 3, 1f, 1f);
	}
}
 
Example 11
Source File: ScoreData.java    From opsu-dance with 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.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 File: Spinner.java    From opsu-dance with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void draw(Graphics g, int trackPosition, float mirrorAngle) {
	if (mirrorAngle != 0f) {
		return;
	}
	// only draw spinners shortly before start time
	int timeDiff = hitObject.getTime() - trackPosition;
	final int fadeInTime = gameState.getFadeInTime();
	if (timeDiff - fadeInTime > 0)
		return;

	boolean spinnerComplete = (rotations >= rotationsNeeded);
	float alpha = Utils.clamp(1 - (float) timeDiff / fadeInTime, 0f, 1f);

	// darken screen
	if (SkinService.skin.isSpinnerFadePlayfield()) {
		float oldAlpha = Colors.BLACK_ALPHA.a;
		if (timeDiff > 0)
			Colors.BLACK_ALPHA.a *= alpha;
		g.setColor(Colors.BLACK_ALPHA);
		g.fillRect(0, 0, width, height);
		Colors.BLACK_ALPHA.a = oldAlpha;
	}

	// rpm
	Image rpmImg = GameImage.SPINNER_RPM.getImage();
	rpmImg.setAlpha(alpha);
	rpmImg.drawCentered(width2, height - rpmImg.getHeight() / 2f);
	if (timeDiff < 0)
		data.drawSymbolString(Integer.toString(drawnRPM), (width + rpmImg.getWidth() * 0.95f) / 2f,
				height - data.getScoreSymbolImage('0').getHeight() * 1.025f, 1f, 1f, true);

	// spinner meter (subimage)
	Image spinnerMetre = GameImage.SPINNER_METRE.getImage();
	int spinnerMetreY = (spinnerComplete) ? 0 : (int) (spinnerMetre.getHeight() * (1 - (rotations / rotationsNeeded)));
	Image spinnerMetreSub = spinnerMetre.getSubImage(
			0, spinnerMetreY,
			spinnerMetre.getWidth(), spinnerMetre.getHeight() - spinnerMetreY
	);
	spinnerMetreSub.setAlpha(alpha);
	spinnerMetreSub.draw(0, height - spinnerMetreSub.getHeight());

	// main spinner elements
	GameImage.SPINNER_CIRCLE.getImage().setAlpha(alpha);
	GameImage.SPINNER_CIRCLE.getImage().setRotation(drawRotation * 360f);
	GameImage.SPINNER_CIRCLE.getImage().drawCentered(width2, height2);
	if (!GameMod.HIDDEN.isActive()) {
		float approachScale = 1 - Utils.clamp(((float) timeDiff / (hitObject.getTime() - hitObject.getEndTime())), 0f, 1f);
		Image approachCircleScaled = GameImage.SPINNER_APPROACHCIRCLE.getImage().getScaledCopy(approachScale);
		approachCircleScaled.setAlpha(alpha);
		approachCircleScaled.drawCentered(width2, height2);
	}
	GameImage.SPINNER_SPIN.getImage().setAlpha(alpha);
	GameImage.SPINNER_SPIN.getImage().drawCentered(width2, height * 3 / 4);

	if (spinnerComplete) {
		GameImage.SPINNER_CLEAR.getImage().drawCentered(width2, height / 4);
		int extraRotations = (int) (rotations - rotationsNeeded);
		if (extraRotations > 0)
			data.drawSymbolNumber(extraRotations * 1000, width2, height * 2 / 3, 1f, 1f);
	}
}
 
Example 13
Source File: GeomTest.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 4 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.setColor(Color.white);
	g.drawString("Red indicates a collision, green indicates no collision", 50, 420);
       g.drawString("White are the targets", 50, 435);

       g.pushTransform();
       g.translate(100,100);
       g.pushTransform();
       g.translate(-50,-50);
       g.scale(10, 10);
       g.setColor(Color.red);
       g.fillRect(0,0,5,5);
       g.setColor(Color.white);
       g.drawRect(0,0,5,5);
       g.popTransform();
       g.setColor(Color.green);
       g.fillRect(20,20,50,50);
       g.popTransform();
       
	g.setColor(Color.white);
	g.draw(rect);
	g.draw(circle);
	
	g.setColor(rect1.intersects(rect) ? Color.red : Color.green);
	g.draw(rect1);
	g.setColor(rect2.intersects(rect) ? Color.red : Color.green);
	g.draw(rect2);
       g.setColor(roundRect.intersects(rect) ? Color.red : Color.green);
       g.draw(roundRect);
	g.setColor(circle1.intersects(rect) ? Color.red : Color.green);
	g.draw(circle1);
	g.setColor(circle2.intersects(rect) ? Color.red : Color.green);
	g.draw(circle2);
	g.setColor(circle3.intersects(circle) ? Color.red : Color.green);
	g.fill(circle3);
	g.setColor(circle4.intersects(circle) ? Color.red : Color.green);
	g.draw(circle4);

       g.fill(roundRect2);
	g.setColor(Color.blue);
       g.draw(roundRect2);
	g.setColor(Color.blue);
	g.draw(new Circle(100,100,50));
	g.drawRect(50,50,100,100);
       
}
 
Example 14
Source File: DummyMenuScrollState.java    From nullpomino with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void drawMenuList (Graphics graphics)
{
	int maxentry = minentry + pageHeight - 1;
	if (maxentry >= list.length)
		maxentry = list.length-1;

	for(int i = minentry, y = 0; i <= maxentry; i++, y++) {
		if(i < list.length) {
			NormalFontSlick.printFontGrid(2, 3 + y, list[i].toUpperCase(), (cursor == i));
			if(cursor == i) NormalFontSlick.printFontGrid(1, 3 + y, "b", NormalFontSlick.COLOR_RED);
		}
	}

	int sbHeight = 16*(pageHeight - 2) - (LINE_WIDTH << 1);
	//Draw scroll bar
	NormalFontSlick.printFontGrid(SB_TEXT_X, 3, "k", SB_TEXT_COLOR);
	NormalFontSlick.printFontGrid(SB_TEXT_X, 2 + pageHeight, "n", SB_TEXT_COLOR);
	//Draw shadow
	graphics.setColor(SB_SHADOW_COLOR);
	graphics.fillRect(SB_MIN_X+SB_WIDTH, SB_MIN_Y+LINE_WIDTH, LINE_WIDTH, sbHeight);
	graphics.fillRect(SB_MIN_X+LINE_WIDTH, SB_MIN_Y+sbHeight, SB_WIDTH, LINE_WIDTH);
	//Draw border
	graphics.setColor(SB_BORDER_COLOR);
	graphics.fillRect(SB_MIN_X, SB_MIN_Y, SB_WIDTH, sbHeight);
	//Draw inside
	int insideHeight = sbHeight-(LINE_WIDTH << 1);
	int insideWidth = SB_WIDTH-(LINE_WIDTH << 1);
	int fillMinY = ((insideHeight*minentry)/list.length);
	int fillHeight = (((maxentry-minentry+1)*insideHeight+list.length-1)/list.length);
	if (fillHeight < LINE_WIDTH)
	{
		fillHeight = LINE_WIDTH;
		fillMinY = (((insideHeight-fillHeight+1)*minentry)/(list.length-pageHeight+1));
	}
	graphics.setColor(SB_BACK_COLOR);
	graphics.fillRect(SB_MIN_X+LINE_WIDTH, SB_MIN_Y+LINE_WIDTH, insideWidth, insideHeight);
	graphics.setColor(SB_FILL_COLOR);
	graphics.fillRect(SB_MIN_X+LINE_WIDTH, SB_MIN_Y+LINE_WIDTH+fillMinY, insideWidth, fillHeight);
	graphics.setColor(Color.white);

	//Update coordinates
	pUpMinY = SB_MIN_Y+LINE_WIDTH;
	pUpMaxY = pUpMinY+fillMinY;
	pDownMinY = pUpMaxY+fillHeight;
	pDownMaxY = SB_MIN_Y+LINE_WIDTH+insideHeight;
}
 
Example 15
Source File: ImageGraphicsTest.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 4 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) 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 16
Source File: RenderUtils.java    From opsu-dance with GNU General Public License v3.0 4 votes vote down vote up
public static void fillCenteredRect(Graphics g, float x, float y, float radius) {
	float totalLength = radius * 2f + 1f;
	g.fillRect(x - radius, y - radius, totalLength, totalLength);
}
 
Example 17
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 18
Source File: DownloadNode.java    From opsu with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draws the download result as a rectangular button.
 * @param g the graphics context
 * @param position the index (to offset the button from the topmost button)
 * @param hover true if the mouse is hovering over this button
 * @param focus true if the button is focused
 * @param previewing true if the beatmap is currently being previewed
 */
public void drawResult(Graphics g, float position, boolean hover, boolean focus, boolean previewing) {
	float textX = buttonBaseX + buttonWidth * 0.001f;
	float edgeX = buttonBaseX + buttonWidth * 0.985f;
	float y = buttonBaseY + position;
	float marginY = buttonHeight * 0.04f;
	Download dl = DownloadList.get().getDownload(beatmapSetID);

	// rectangle outline
	g.setColor((focus) ? Colors.BLACK_BG_FOCUS : (hover) ? Colors.BLACK_BG_HOVER : Colors.BLACK_BG_NORMAL);
	g.fillRect(buttonBaseX, y, buttonWidth, buttonHeight);

	// map is already loaded
	if (BeatmapSetList.get().containsBeatmapSetID(beatmapSetID)) {
		g.setColor(Colors.BLUE_BUTTON);
		g.fillRect(buttonBaseX, y, buttonWidth, buttonHeight);
	}

	// download progress
	if (dl != null) {
		float progress = dl.getProgress();
		if (progress > 0f) {
			g.setColor(Colors.GREEN);
			g.fillRect(buttonBaseX, y, buttonWidth * progress / 100f, buttonHeight);
		}
	}

	// preview button
	Image img = (previewing) ? GameImage.MUSIC_PAUSE.getImage() : GameImage.MUSIC_PLAY.getImage();
	img.drawCentered(textX + img.getWidth() / 2, y + buttonHeight / 2f);
	textX += img.getWidth() + buttonWidth * 0.001f;

	// text
	// TODO: if the title/artist line is too long, shorten it (e.g. add "...") instead of just clipping
	if (Options.useUnicodeMetadata()) {  // load glyphs
		Fonts.loadGlyphs(Fonts.BOLD, getTitle());
		Fonts.loadGlyphs(Fonts.BOLD, getArtist());
	}
	// TODO can't set clip again or else old clip will be cleared
	//g.setClip((int) textX, (int) (y + marginY), (int) (edgeX - textX - Fonts.DEFAULT.getWidth(creator)), Fonts.BOLD.getLineHeight());
	Fonts.BOLD.drawString(
			textX, y + marginY,
			String.format("%s - %s%s", getArtist(), getTitle(),
					(dl != null) ? String.format(" [%s]", dl.getStatus().getName()) : ""), Color.white);
	//g.clearClip();
	Fonts.DEFAULT.drawString(
			textX, y + marginY + Fonts.BOLD.getLineHeight(),
			String.format("Last updated: %s", date), Color.white);
	Fonts.DEFAULT.drawString(
			edgeX - Fonts.DEFAULT.getWidth(creator), y + marginY,
			creator, Color.white);
}
 
Example 19
Source File: GraphicsTest.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 4 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) 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 20
Source File: ScoreData.java    From opsu with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draws the score data as a rectangular button.
 * @param g the graphics context
 * @param position the index (to offset the button from the topmost button)
 * @param rank the score rank
 * @param prevScore the previous (lower) score, or -1 if none
 * @param focus whether the button is focused
 * @param t the animation progress [0,1]
 */
public void draw(Graphics g, float position, int rank, long prevScore, boolean focus, float t) {
	float x = baseX - buttonWidth * (1 - AnimationEquation.OUT_BACK.calc(t)) / 2.5f;
	float rankX = x + buttonWidth * 0.04f;
	float edgeX = x + buttonWidth * 0.98f;
	float y = baseY + position;
	float midY = y + buttonHeight / 2f;
	float marginY = Fonts.DEFAULT.getLineHeight() * 0.01f;
	Color c = Colors.WHITE_FADE;
	float alpha = t;
	float oldAlpha = c.a;
	c.a = alpha;

	// rectangle outline
	g.setLineWidth(1f);
	Color rectColor = (focus) ? Colors.BLACK_BG_HOVER : Colors.BLACK_BG_NORMAL;
	float oldRectAlpha = rectColor.a;
	rectColor.a *= AnimationEquation.IN_QUAD.calc(alpha);
	g.setColor(rectColor);
	g.fillRect(x + 1, y + 1, buttonWidth - 1, buttonHeight - 1);
	rectColor.a *= 1.25f;
	g.setColor(rectColor);
	g.drawRect(x, y, buttonWidth, buttonHeight);
	rectColor.a = oldRectAlpha;

	// rank
	if (focus) {
		Fonts.LARGE.drawString(
			rankX, y + (buttonHeight - Fonts.LARGE.getLineHeight()) / 2f,
			Integer.toString(rank + 1), c
		);
	}

	// grade image
	float gradeX = rankX + Fonts.LARGE.getWidth("###");
	Image img = getGrade().getMenuImage();
	img.setAlpha(alpha);
	img.draw(gradeX, midY - img.getHeight() / 2f);
	img.setAlpha(1f);

	// player
	float textX = gradeX + img.getWidth() * 1.2f;
	float textOffset = (buttonHeight - Fonts.LARGE.getLineHeight() - Fonts.MEDIUM.getLineHeight()) / 2f;
	if (playerName != null)
		Fonts.LARGE.drawString(textX, y + textOffset, playerName);
	textOffset += Fonts.LARGE.getLineHeight() - 4;

	// score
	Fonts.MEDIUM.drawString(
		textX, y + textOffset,
		String.format("Score: %s (%dx)", NumberFormat.getNumberInstance().format(score), combo), c
	);

	// mods
	StringBuilder sb = new StringBuilder();
	for (GameMod mod : GameMod.values()) {
		if ((mod.getBit() & mods) > 0) {
			sb.append(mod.getAbbreviation());
			sb.append(',');
		}
	}
	if (sb.length() > 0) {
		sb.setLength(sb.length() - 1);
		String modString = sb.toString();
		Fonts.DEFAULT.drawString(edgeX - Fonts.DEFAULT.getWidth(modString), y + marginY, modString, c);
	}

	// accuracy
	String accuracy = String.format("%.2f%%", getScorePercent());
	Fonts.DEFAULT.drawString(edgeX - Fonts.DEFAULT.getWidth(accuracy), y + marginY + Fonts.DEFAULT.getLineHeight(), accuracy, c);

	// score difference
	String diff = (prevScore < 0 || score < prevScore) ?
		"-" : String.format("+%s", NumberFormat.getNumberInstance().format(score - prevScore));
	Fonts.DEFAULT.drawString(edgeX - Fonts.DEFAULT.getWidth(diff), y + marginY + Fonts.DEFAULT.getLineHeight() * 2, diff, c);

	// time since
	if (getTimeSince() != null) {
		Image clock = GameImage.HISTORY.getImage();
		clock.drawCentered(x + buttonWidth * 1.02f + clock.getWidth() / 2f, midY);
		Fonts.DEFAULT.drawString(
			x + buttonWidth * 1.03f + clock.getWidth(),
			midY - Fonts.DEFAULT.getLineHeight() / 2f,
			getTimeSince(), c
		);
	}

	c.a = oldAlpha;
}