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

The following examples show how to use org.newdawn.slick.Graphics#fillRoundRect() . 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
Source Project: opsu   File: UI.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Draws the volume bar on the middle right-hand side of the game container.
 * Only draws if the volume has recently been changed using with {@link #changeVolume(int)}.
 * @param g the graphics context
 */
public static void drawVolume(Graphics g) {
	if (volumeDisplay == -1)
		return;

	int width = container.getWidth(), height = container.getHeight();
	Image img = GameImage.VOLUME.getImage();

	// move image in/out
	float xOffset = 0;
	float ratio = (float) volumeDisplay / VOLUME_DISPLAY_TIME;
	if (ratio <= 0.1f)
		xOffset = img.getWidth() * (1 - (ratio * 10f));
	else if (ratio >= 0.9f)
		xOffset = img.getWidth() * (1 - ((1 - ratio) * 10f));

	img.drawCentered(width - img.getWidth() / 2f + xOffset, height / 2f);
	float barHeight = img.getHeight() * 0.9f;
	float volume = Options.getMasterVolume();
	g.setColor(Color.white);
	g.fillRoundRect(
			width - (img.getWidth() * 0.368f) + xOffset,
			(height / 2f) - (img.getHeight() * 0.47f) + (barHeight * (1 - volume)),
			img.getWidth() * 0.15f, barHeight * volume, 3
	);
}
 
Example 2
/**
 * @return x position where the next block can be drawn (right aligned)
 */
private int drawText(Graphics g, Color color, String text, int x, int y) {
	int width = Fonts.SMALL.getWidth(text) + 10;
	g.setColor(color);
	g.fillRoundRect(x - width, y, width, singleHeight + 6, 5, 25);
	Fonts.SMALL.drawString(x - width + 3, y + 3, text, Color.black);
	return x - width - 6;
}
 
Example 3
@Override
public void render(Graphics g) {
	int delta = renderDelta;

	// update animation
	expandProgress.update((expanded) ? delta : -delta * 2);

	// get parameters
	int idx = getIndexAt(mouseY);
	float t = expandProgress.getValue();
	if (expanded) {
		t = AnimationEquation.OUT_CUBIC.calc(t);
	}

	// background and border
	Color oldGColor = g.getColor();
	float oldLineWidth = g.getLineWidth();
	final int cornerRadius = 6;
	g.setLineWidth(1f);
	g.setColor((idx == -1) ? highlightColor : backgroundColor);
	g.fillRoundRect(x, y, width, baseHeight, cornerRadius);
	g.setColor(borderColor);
	g.drawRoundRect(x, y, width, baseHeight, cornerRadius);
	if (expanded || t >= 0.0001) {
		float oldBackgroundAlpha = backgroundColor.a;
		backgroundColor.a *= t;
		g.setColor(backgroundColor);
		g.fillRoundRect(x, y + offsetY, width, (height - offsetY) * t, cornerRadius);
		backgroundColor.a = oldBackgroundAlpha;
	}
	if (idx >= 0 && t >= 0.9999) {
		g.setColor(highlightColor);
		float yPos = y + offsetY + (offsetY * idx);
		int yOff = 0, hOff = 0;
		if (idx == 0 || idx == items.length - 1) {
			g.fillRoundRect(x, yPos, width, offsetY, cornerRadius);
			if (idx == 0)
				yOff = cornerRadius;
			hOff = cornerRadius;
		}
		g.fillRect(x, yPos + yOff, width, offsetY - hOff);
	}
	g.setColor(oldGColor);
	g.setLineWidth(oldLineWidth);

	// text
	chevronDown.draw(x + width - chevronDown.getWidth() - width * CHEVRON_X, y + (baseHeight - chevronDown.getHeight()) / 2f, chevronDownColor);
	fontNormal.drawString(x + (width * 0.03f), y + (fontNormal.getPaddingTop() + fontNormal.getPaddingBottom()) / 2f, itemNames[selectedItemIndex], textColor);
	float oldTextAlpha = textColor.a;
	textColor.a *= t;
	if (expanded || t >= 0.0001) {
		for (int i = 0; i < itemNames.length; i++) {
			Font f = (i == selectedItemIndex) ? fontSelected : fontNormal;
			if (i == idx && t >= 0.999)
				chevronRight.draw(x, y + offsetY + (offsetY * i) + (offsetY - chevronRight.getHeight()) / 2f, chevronRightColor);
			f.drawString(x + chevronRight.getWidth(), y + offsetY + (offsetY * i * t), itemNames[i], textColor);
		}
	}
	textColor.a = oldTextAlpha;
}
 
Example 4
Source Project: opsu-dance   File: UI.java    License: GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draws loading progress (OSZ unpacking, beatmap parsing, replay importing, sound loading)
 * at the bottom of the screen.
 * @param g the graphics context
 */
public static void drawLoadingProgress(Graphics g) {
	String text, file;
	int progress;

	// determine current action
	if ((file = oszunpacker.getCurrentFileName()) != null) {
		text = "Unpacking new beatmaps...";
		progress = oszunpacker.getUnpackerProgress();
	} else if ((file = beatmapParser.getCurrentFileName()) != null) {
		text = (beatmapParser.getStatus() == BeatmapParser.Status.INSERTING) ?
				"Updating database..." : "Loading beatmaps...";
		progress = beatmapParser.getParserProgress();
	} else if ((file = replayImporter.getCurrentFileName()) != null) {
		text = "Importing replays...";
		progress = replayImporter.getLoadingProgress();
	} else if ((file = SoundController.getCurrentFileName()) != null) {
		text = "Loading sounds...";
		progress = SoundController.getLoadingProgress();
	} else
		return;

	// draw loading info
	float marginX = width * 0.02f, marginY = height * 0.02f;
	float lineY = height - marginY;
	int lineOffsetY = Fonts.MEDIUM.getLineHeight();
	if (OPTION_LOAD_VERBOSE.state) {
		// verbose: display percentages and file names
		Fonts.MEDIUM.drawString(
				marginX, lineY - (lineOffsetY * 2),
				String.format("%s (%d%%)", text, progress), Color.white);
		Fonts.MEDIUM.drawString(marginX, lineY - lineOffsetY, file, Color.white);
	} else {
		// draw loading bar
		Fonts.MEDIUM.drawString(marginX, lineY - (lineOffsetY * 2), text, Color.white);
		g.setColor(Color.white);
		g.fillRoundRect(marginX, lineY - (lineOffsetY / 2f),
				(width - (marginX * 2f)) * progress / 100f, lineOffsetY / 4f, 4
		);
	}
}
 
Example 5
Source Project: opsu   File: UserButton.java    License: GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draws a user button.
 * @param g the graphics context
 * @param alpha the alpha multiplier
 */
public void draw(Graphics g, float alpha) {
	int padding = 4;
	int cx = x + padding, cy = y + padding;
	float t = bgAlpha.getValue();
	float oldWhiteAlpha = Colors.WHITE_FADE.a;
	Colors.WHITE_FADE.a = alpha;

	// rectangle
	Color bg;
	if (flashing) {
		bg = flashColor;
		bg.a = t * alpha;
	} else {
		bg = bgColor;
		bg.a = (0.5f * t) * alpha;
	}
	g.setColor(bg);
	g.fillRoundRect(cx, cy, buttonWidth - padding * 2, buttonHeight - padding * 2, 4);

	// no user?
	if (user == null && placeholderText != null) {
		Fonts.LARGE.drawString(
			x + (buttonWidth - Fonts.LARGE.getWidth(placeholderText)) / 2,
			y + (buttonHeight - Fonts.LARGE.getLineHeight()) / 2,
			placeholderText, Colors.WHITE_FADE
		);
		Colors.WHITE_FADE.a = oldWhiteAlpha;
		return;
	}

	// icon
	int iconSize = buttonHeight - padding * 4;
	Image img = getIconImage(user.getIconId());
	img.setAlpha(alpha);
	img.draw(cx + padding, cy + padding);

	// text
	int textX = cx + iconSize + padding * 3;
	int textY = cy + padding / 2;
	Fonts.MEDIUM.drawString(textX, textY, user.getName(), Colors.WHITE_FADE);
	textY += Fonts.MEDIUM.getLineHeight() - 3;
	Fonts.SMALL.drawString(textX, textY, String.format("Score: %,d", user.getScore()), Colors.WHITE_FADE);
	textY += Fonts.SMALL.getLineHeight() - 2;
	Fonts.SMALL.drawString(textX, textY, String.format("Accuracy: %.2f%%", user.getAccuracy()), Colors.WHITE_FADE);
	textY += Fonts.SMALL.getLineHeight() - 2;
	Fonts.SMALL.drawString(textX, textY, String.format("Lv%d", user.getLevel()), Colors.WHITE_FADE);

	// progress bar
	int barX = textX + Fonts.SMALL.getWidth("Lv#####");
	int barWidth = x + buttonWidth - padding - barX - 1;
	int barHeight = buttonHeight / 7;
	int barY = y + buttonHeight - padding - barHeight - 1;
	int barRadius = 8;
	float barAlpha = (0.75f + 0.25f * t) * alpha;
	barBgColor.a = barBorderColor.a = barFillColor.a = barAlpha;
	g.setColor(barBgColor);
	g.fillRoundRect(barX, barY, barWidth, barHeight, barRadius);
	g.setClip(barX, barY, (int) (barWidth * user.getNextLevelProgress()), barHeight);
	g.setColor(barFillColor);
	g.fillRoundRect(barX, barY, barWidth, barHeight, barRadius);
	g.clearClip();
	g.setAntiAlias(true);
	g.setColor(barBorderColor);
	g.setLineWidth(2f);
	g.drawRoundRect(barX, barY, barWidth, barHeight, barRadius);
	g.resetLineWidth();
	g.setAntiAlias(false);

	Colors.WHITE_FADE.a = oldWhiteAlpha;
}
 
Example 6
Source Project: opsu   File: DropdownMenu.java    License: GNU General Public License v3.0 4 votes vote down vote up
@Override
public void render(GUIContext container, Graphics g) throws SlickException {
	// update animation
	long time = container.getTime();
	if (lastUpdateTime > 0) {
		int delta = (int) (time - lastUpdateTime);
		expandProgress.update((expanded) ? delta : -delta * 2);
	}
	this.lastUpdateTime = time;

	// get parameters
	Input input = container.getInput();
	int idx = getIndexAt(input.getMouseX(), input.getMouseY());
	float t = expandProgress.getValue();
	if (expanded)
		t = AnimationEquation.OUT_CUBIC.calc(t);

	// background and border
	Color oldGColor = g.getColor();
	float oldLineWidth = g.getLineWidth();
	final int cornerRadius = 6;
	g.setLineWidth(1f);
	g.setColor((idx == -1) ? highlightColor : backgroundColor);
	g.fillRoundRect((int) x, (int) y, width, baseHeight, cornerRadius);
	g.setColor(borderColor);
	g.drawRoundRect((int) x, (int) y, width, baseHeight, cornerRadius);
	if (expanded || t >= 0.0001) {
		float oldBackgroundAlpha = backgroundColor.a;
		backgroundColor.a *= t;
		g.setColor(backgroundColor);
		g.fillRoundRect((int) x, (int) (y + offsetY), width, (height - offsetY) * t, cornerRadius);
		backgroundColor.a = oldBackgroundAlpha;
	}
	if (idx >= 0 && t >= 0.9999) {
		g.setColor(highlightColor);
		float yPos = y + offsetY + (offsetY * idx);
		int yOff = 0, hOff = 0;
		if (idx == 0 || idx == items.length - 1) {
			g.fillRoundRect((int) x, (int) yPos, width, offsetY, cornerRadius);
			if (idx == 0)
				yOff = cornerRadius;
			hOff = cornerRadius;
		}
		g.fillRect((int) x, (int) (yPos + yOff), width, offsetY - hOff);
	}
	g.setColor(oldGColor);
	g.setLineWidth(oldLineWidth);

	// text
	chevronDown.draw(x + width - chevronDown.getWidth() - width * CHEVRON_X, y + (baseHeight - chevronDown.getHeight()) / 2f, chevronDownColor);
	fontNormal.drawString(x + (width * 0.03f), y + (fontNormal.getPaddingTop() + fontNormal.getPaddingBottom()) / 2f, itemNames[itemIndex], textColor);
	float oldTextAlpha = textColor.a;
	textColor.a *= t;
	if (expanded || t >= 0.0001) {
		for (int i = 0; i < itemNames.length; i++) {
			Font f = (i == itemIndex) ? fontSelected : fontNormal;
			if (i == idx && t >= 0.999)
				chevronRight.draw(x, y + offsetY + (offsetY * i) + (offsetY - chevronRight.getHeight()) / 2f, chevronRightColor);
			f.drawString(x + chevronRight.getWidth(), y + offsetY + (offsetY * i * t), itemNames[i], textColor);
		}
	}
	textColor.a = oldTextAlpha;
}
 
Example 7
Source Project: opsu   File: UI.java    License: GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draws loading progress (OSZ unpacking, beatmap parsing, replay importing, sound loading)
 * at the bottom of the screen.
 * @param g the graphics context
 * @param alpha the text alpha level
 */
public static void drawLoadingProgress(Graphics g, float alpha) {
	String text, file;
	int progress;

	// determine current action
	if ((file = OszUnpacker.getCurrentFileName()) != null) {
		text = "Unpacking new beatmaps...";
		progress = OszUnpacker.getUnpackerProgress();
	} else if ((file = BeatmapParser.getCurrentFileName()) != null) {
		text = (BeatmapParser.getStatus() == BeatmapParser.Status.INSERTING) ?
				"Updating database..." : "Loading beatmaps...";
		progress = BeatmapParser.getParserProgress();
	} else if ((file = SkinUnpacker.getCurrentFileName()) != null) {
		text = "Unpacking new skins...";
		progress = SkinUnpacker.getUnpackerProgress();
	} else if ((file = ReplayImporter.getCurrentFileName()) != null) {
		text = "Importing replays...";
		progress = ReplayImporter.getLoadingProgress();
	} else if ((file = SoundController.getCurrentFileName()) != null) {
		text = "Loading sounds...";
		progress = SoundController.getLoadingProgress();
	} else
		return;

	// draw loading info
	float marginX = container.getWidth() * 0.02f, marginY = container.getHeight() * 0.02f;
	float lineY = container.getHeight() - marginY;
	int lineOffsetY = Fonts.MEDIUM.getLineHeight();
	float oldWhiteAlpha = Colors.WHITE_FADE.a;
	Colors.WHITE_FADE.a = alpha;
	if (Options.isLoadVerbose()) {
		// verbose: display percentages and file names
		Fonts.MEDIUM.drawString(
			marginX, lineY - (lineOffsetY * 2),
			String.format("%s (%d%%)", text, progress), Colors.WHITE_FADE
		);
		Fonts.MEDIUM.drawString(marginX, lineY - lineOffsetY, file, Colors.WHITE_FADE);
	} else {
		// draw loading bar
		Fonts.MEDIUM.drawString(marginX, lineY - (lineOffsetY * 2), text, Colors.WHITE_FADE);
		g.setColor(Colors.WHITE_FADE);
		g.fillRoundRect(
			marginX, lineY - (lineOffsetY / 2f),
			(container.getWidth() - (marginX * 2f)) * progress / 100f, lineOffsetY / 4f, 4
		);
	}
	Colors.WHITE_FADE.a = oldWhiteAlpha;
}
 
Example 8
/**
 * @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();
	}
}