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

The following examples show how to use org.newdawn.slick.Graphics#setLineWidth() . 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: GradientTest.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 container, Graphics g) {
	
	g.rotate(400, 300, ang);
	g.fill(rect, gradient);
	g.fill(round, gradient);
	g.fill(poly, gradient2);
	g.fill(center, gradient4);

	g.setAntiAlias(true);
	g.setLineWidth(10);
	g.draw(round2, gradient2);
	g.setLineWidth(2);
	g.draw(poly, gradient);
	g.setAntiAlias(false);
	
	g.fill(center, gradient4);
	g.setAntiAlias(true);
	g.setColor(Color.black);
	g.draw(center);
	g.setAntiAlias(false);
}
 
Example 2
Source File: LineRenderTest.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 6 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.setAntiAlias(antialias);
		g.setLineWidth(50);
		g.setColor(Color.red);
		g.draw(path);
		
//		g.setColor(Color.red);
//		TextureImpl.bindNone();
//		g.setLineWidth(width);
//		g.setAntiAlias(true);
//		for (int i=0;i<10;i++) {
//			g.translate(35,35);
//			g.draw(polygon);
//		}
//		g.translate(-350,-350);
//		
//		g.setColor(Color.white);
//		g.setLineWidth(1);
//		g.setAntiAlias(false);
//		g.draw(polygon);
	}
 
Example 3
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 4
Source File: OptionsOverlay.java    From opsu with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Renders a slider option.
 * @param g the graphics context
 * @param option the game option
 * @param cy the y coordinate
 */
private void renderSliderOption(Graphics g, GameOption option, int cy) {
	// draw option name and value
	final int padding = 10;
	String value = option.getValueString();
	int nameWidth = Fonts.MEDIUM.getWidth(option.getName());
	int valueWidth = Fonts.MEDIUM.getWidth(value);
	Fonts.MEDIUM.drawString(x + optionStartX, cy + optionTextOffsetY, option.getName(), COLOR_WHITE);
	Fonts.MEDIUM.drawString(x + optionStartX + optionWidth - valueWidth, cy + optionTextOffsetY, value, COLOR_BLUE);

	// calculate slider positions
	int sliderWidth = optionWidth - nameWidth - padding - padding - valueWidth;
	if (sliderWidth <= 1)
		return;  // menu hasn't slid in far enough to need to draw the slider
	int sliderStartX = (int) (x + optionStartX + nameWidth + padding);
	if (hoverOption == option) {
		sliderOptionStartX = sliderStartX;
		if (!isAdjustingSlider)
			sliderOptionWidth = sliderWidth;
		else
			sliderWidth = sliderOptionWidth;
	}
	int sliderEndX = sliderStartX + sliderWidth;

	// draw slider
	float sliderValue = (float) (option.getIntegerValue() - option.getMinValue()) / (option.getMaxValue() - option.getMinValue());
	float sliderBallPos = sliderStartX + (int) ((sliderWidth - controlImageSize) * sliderValue);
	g.setLineWidth(3f);
	g.setColor(COLOR_PINK);
	if (sliderValue > 0.0001f)
		g.drawLine(sliderStartX, cy + optionHeight / 2, sliderBallPos, cy + optionHeight / 2);
	sliderBallImg.draw(sliderBallPos, cy + controlImagePadding, COLOR_PINK);
	if (sliderValue < 0.999f) {
		float oldAlpha = COLOR_PINK.a;
		COLOR_PINK.a *= 0.45f;
		g.setColor(COLOR_PINK);
		g.drawLine(sliderBallPos + controlImageSize + 1, cy + optionHeight / 2, sliderEndX, cy + optionHeight / 2);
		COLOR_PINK.a = oldAlpha;
	}
}
 
Example 5
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 6
Source File: DropdownMenu.java    From opsu-dance with GNU General Public License v3.0 4 votes vote down vote up
@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 7
Source File: UI.java    From opsu-dance with 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 8
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;
}
 
Example 9
Source File: ScoreData.java    From opsu 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.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 10
Source File: UserButton.java    From opsu with 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 11
Source File: UserSelectOverlay.java    From opsu with GNU General Public License v3.0 4 votes vote down vote up
/** Renders the user creation menu. */
private void renderUserCreate(Graphics g, float alpha) {
	COLOR_WHITE.a = COLOR_RED.a = alpha;
	COLOR_GRAY.a = alpha * 0.8f;

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

	// user button
	int cy = (int) (y + usersStartY);
	String caption = "Click the profile below to create it.";
	Fonts.MEDIUM.drawString(x + (width - Fonts.MEDIUM.getWidth(caption)) / 2, cy, caption, COLOR_WHITE);
	cy += Fonts.MEDIUM.getLineHeight();
	newUserButton.draw(g, alpha);
	cy += UserButton.getHeight() + Fonts.MEDIUMBOLD.getLineHeight();

	// user name
	String nameHeader = "Name";
	Fonts.MEDIUMBOLD.drawString(x + (width - Fonts.MEDIUMBOLD.getWidth(nameHeader)) / 2, cy, nameHeader, COLOR_WHITE);
	cy += Fonts.MEDIUMBOLD.getLineHeight();
	Color textColor = COLOR_WHITE;
	String name = newUser.getName();
	if (name.isEmpty()) {
		name = "Type a name...";
		textColor = COLOR_GRAY;
	} else if (!UserList.get().isValidUserName(name))
		textColor = COLOR_RED;
	int textWidth = Fonts.LARGE.getWidth(name);
	int searchTextX = (int) (x + (width - textWidth) / 2);
	Fonts.LARGE.drawString(searchTextX, cy, name, textColor);
	cy += Fonts.LARGE.getLineHeight();
	g.setColor(textColor);
	g.setLineWidth(2f);
	g.drawLine(searchTextX, cy, searchTextX + textWidth, cy);
	cy += Fonts.MEDIUMBOLD.getLineHeight();

	// user icons
	renderUserIcons(g, newUser.getIconId(), "Icon", cy, alpha);
}
 
Example 12
Source File: DropdownMenu.java    From opsu with 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 13
Source File: UI.java    From opsu with 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 14
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();
	}
}