Java Code Examples for org.newdawn.slick.Image#drawCentered()

The following examples show how to use org.newdawn.slick.Image#drawCentered() . 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: InputOverlayKey.java    From opsu with GNU General Public License v3.0 7 votes vote down vote up
/**
 * Renders this key.
 * @param g the graphics context
 * @param x the x position
 * @param y the y position
 * @param baseImage the key image
 */
public void render(Graphics g, int x, int y, Image baseImage) {
	g.pushTransform();
	float scale = 1f;
	if (downtime > 0) {
		float progress = downtime / (float) ANIMATION_TIME;
		scale -= (1f - ACTIVE_SCALE) * progress;
		g.scale(scale, scale);
		x /= scale;
		y /= scale;
	}
	baseImage.drawCentered(x, y, down ? activeColor : Color.white);
	x -= Fonts.MEDIUMBOLD.getWidth(text) / 2;
	y -= Fonts.MEDIUMBOLD.getLineHeight() / 2;
	/*
	// shadow (TODO)
	g.pushTransform();
	g.scale(1.1f, 1.1f);
	float shadowx = x / 1.1f - Fonts.MEDIUMBOLD.getWidth(text) * 0.05f;
	float shadowy = y / 1.1f - Fonts.MEDIUMBOLD.getLineHeight() * 0.05f;
	Fonts.MEDIUMBOLD.drawString(shadowx, shadowy, text, Color.black);
	g.popTransform();
	*/
	Fonts.MEDIUMBOLD.drawString(x, y, text, Options.getSkin().getInputOverlayText());
	g.popTransform();
}
 
Example 2
Source File: Curve.java    From opsu-dance with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Draws the curve in the range [0, t] (where the full range is [0, 1]) to the graphics context.
 * @param color the color filter
 * @param from index to draw from
 * @param to index to draw to (exclusive)
 */
public void draw(Color color, int from, int to) {
	if (curve == null)
		return;

	if (OPTION_FALLBACK_SLIDERS.state || SkinService.skin.getSliderStyle() == Skin.STYLE_PEPPYSLIDER || !mmsliderSupported) {
		// peppysliders
		Image hitCircle = GameImage.HITCIRCLE.getImage();
		Image hitCircleOverlay = GameImage.HITCIRCLE_OVERLAY.getImage();
		for (int i = from; i < to; i++)
			hitCircleOverlay.drawCentered(curve[i].x, curve[i].y, Colors.WHITE_FADE);
		float a = fallbackSliderColor.a;
		fallbackSliderColor.a = color.a;
		for (int i = from; i < to; i++)
			hitCircle.drawCentered(curve[i].x, curve[i].y, fallbackSliderColor);
		fallbackSliderColor.a = a;
	} else {
		// mmsliders
		if (renderState == null)
			renderState = new CurveRenderState(hitObject, curve, false);
		renderState.draw(color, borderColor, from, to);
	}
}
 
Example 3
Source File: GameData.java    From opsu-dance with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Draws a number with defaultSymbols.
 * @param n the number to draw
 * @param x the center x coordinate
 * @param y the center y coordinate
 * @param scale the scale to apply
 * @param alpha the alpha level
 */
public void drawSymbolNumber(int n, float x, float y, float scale, float alpha) {
	int length = (int) (Math.log10(n) + 1);
	float digitWidth = getDefaultSymbolImage(0).getWidth();
	if (digitWidth <= 1f) {
		return;
	}
	digitWidth = (digitWidth - SkinService.skin.getHitCircleFontOverlap()) * scale;
	float cx = x + ((length - 1) * (digitWidth / 2));

	for (int i = 0; i < length; i++) {
		Image digit = getDefaultSymbolImage(n % 10).getScaledCopy(scale);
		digit.setAlpha(alpha);
		digit.drawCentered(cx, y);
		cx -= digitWidth;
		n /= 10;
	}
}
 
Example 4
Source File: UI.java    From opsu with 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 5
Source File: UI.java    From opsu with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Draws a tab image and text centered at a location.
 * @param x the center x coordinate
 * @param y the center y coordinate
 * @param text the text to draw inside the tab
 * @param selected whether the tab is selected (white) or not (red)
 * @param isHover whether to include a hover effect (unselected only)
 */
public static void drawTab(float x, float y, String text, boolean selected, boolean isHover) {
	Image tabImage = GameImage.MENU_TAB.getImage();
	float tabTextX = x - (Fonts.MEDIUM.getWidth(text) / 2);
	float tabTextY = y - (tabImage.getHeight() / 2);
	Color filter, textColor;
	if (selected) {
		filter = Color.white;
		textColor = Color.black;
	} else {
		filter = (isHover) ? Colors.RED_HOVER : Color.red;
		textColor = Color.white;
	}
	tabImage.drawCentered(x, y, filter);
	Fonts.MEDIUM.drawString(tabTextX, tabTextY, text, textColor);
}
 
Example 6
Source File: Curve.java    From opsu with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Draws the curve in the range [0, t] (where the full range is [0, 1]) to the graphics context.
 * @param color the color filter
 * @param t set the curve interval to [0, t]
 */
public void draw(Color color, float t) {
	if (curve == null)
		return;

	t = Utils.clamp(t, 0f, 1f);

	// peppysliders
	if (Options.getSkin().getSliderStyle() == Skin.STYLE_PEPPYSLIDER || !mmsliderSupported) {
		int drawUpTo = (int) (curve.length * t);
		Image hitCircle = GameImage.HITCIRCLE.getImage();
		Image hitCircleOverlay = GameImage.HITCIRCLE_OVERLAY.getImage();
		for (int i = 0; i < drawUpTo; i++)
			hitCircleOverlay.drawCentered(curve[i].x, curve[i].y, Colors.WHITE_FADE);
		for (int i = 0; i < drawUpTo; i++)
			hitCircle.drawCentered(curve[i].x, curve[i].y, color);
	}

	// mmsliders
	else {
		if (renderState == null)
			renderState = new CurveRenderState(hitObject, curve);
		renderState.draw(color, borderColor, t);
	}
}
 
Example 7
Source File: Beatmap.java    From opsu with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Draws the beatmap background image.
 * @param width the container width
 * @param height the container height
 * @param offsetX the x offset (from the screen center)
 * @param offsetY the y offset (from the screen center)
 * @param alpha the alpha value
 * @param stretch if true, stretch to screen dimensions; otherwise, maintain aspect ratio
 * @return true if successful, false if any errors were produced
 */
public boolean drawBackground(int width, int height, float offsetX, float offsetY, float alpha, boolean stretch) {
	if (bg == null)
		return false;

	ImageLoader imageLoader = bgImageCache.get(bg);
	if (imageLoader == null)
		return false;

	Image bgImage = imageLoader.getImage();
	if (bgImage == null)
		return true;

	int swidth = width;
	int sheight = height;
	if (!stretch) {
		// fit image to screen
		if (bgImage.getWidth() / (float) bgImage.getHeight() > width / (float) height)  // x > y
			sheight = (int) (width * bgImage.getHeight() / (float) bgImage.getWidth());
		else
			swidth = (int) (height * bgImage.getWidth() / (float) bgImage.getHeight());
	} else {
		// fill screen while maintaining aspect ratio
		if (bgImage.getWidth() / (float) bgImage.getHeight() > width / (float) height)  // x > y
			swidth = (int) (height * bgImage.getWidth() / (float) bgImage.getHeight());
		else
			sheight = (int) (width * bgImage.getHeight() / (float) bgImage.getWidth());
	}
	if (Options.isParallaxEnabled()) {
		swidth = (int) (swidth * GameImage.PARALLAX_SCALE);
		sheight = (int) (sheight * GameImage.PARALLAX_SCALE);
	}
	bgImage = bgImage.getScaledCopy(swidth, sheight);
	bgImage.setAlpha(alpha);
	if (!Options.isParallaxEnabled() && offsetX == 0f && offsetY == 0f)
		bgImage.drawCentered(width / 2, height / 2);
	else
		bgImage.drawCentered(width / 2 + offsetX, height / 2 + offsetY);
	return true;
}
 
Example 8
Source File: Beatmap.java    From opsu-dance with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Draws the beatmap background image.
 * @param width the container width
 * @param height the container height
 * @param alpha the alpha value
 * @param stretch if true, stretch to screen dimensions; otherwise, maintain aspect ratio
 * @return true if successful, false if any errors were produced
 */
public boolean drawBackground(int width, int height, float alpha, boolean stretch) {
	if (bg == null) {
		return false;
	}

	ImageLoader imageLoader = bgImageCache.get(bg);
	if (imageLoader == null)
		return false;

	Image bgImage = imageLoader.getImage();
	if (bgImage == null)
		return true;

	int swidth = width;
	int sheight = height;
	if (!stretch) {
		// fit image to screen
		if (bgImage.getWidth() / (float) bgImage.getHeight() > width / (float) height)  // x > y
			sheight = (int) (width * bgImage.getHeight() / (float) bgImage.getWidth());
		else
			swidth = (int) (height * bgImage.getWidth() / (float) bgImage.getHeight());
	} else {
		// fill screen while maintaining aspect ratio
		if (bgImage.getWidth() / (float) bgImage.getHeight() > width / (float) height)  // x > y
			swidth = (int) (height * bgImage.getWidth() / (float) bgImage.getHeight());
		else
			sheight = (int) (width * bgImage.getHeight() / (float) bgImage.getWidth());
	}
	bgImage = bgImage.getScaledCopy(swidth, sheight);
	bgImage.setAlpha(alpha);
	bgImage.drawCentered(width / 2, height / 2);
	return true;
}
 
Example 9
Source File: GameRanking.java    From opsu with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void render(GameContainer container, StateBasedGame game, Graphics g)
		throws SlickException {
	int width = container.getWidth();
	int height = container.getHeight();
	int mouseX = input.getMouseX(), mouseY = input.getMouseY();

	Beatmap beatmap = MusicController.getBeatmap();

	// background
	float parallaxX = 0, parallaxY = 0;
	if (Options.isParallaxEnabled()) {
		int offset = (int) (height * (GameImage.PARALLAX_SCALE - 1f));
		parallaxX = -offset / 2f * (mouseX - width / 2) / (width / 2);
		parallaxY = -offset / 2f * (mouseY - height / 2) / (height / 2);
	}
	if (!beatmap.drawBackground(width, height, parallaxX, parallaxY, 0.5f, true)) {
		Image bg = GameImage.MENU_BG.getImage();
		if (Options.isParallaxEnabled()) {
			bg = bg.getScaledCopy(GameImage.PARALLAX_SCALE);
			bg.setAlpha(0.5f);
			bg.drawCentered(width / 2 + parallaxX, height / 2 + parallaxY);
		} else {
			bg.setAlpha(0.5f);
			bg.drawCentered(width / 2, height / 2);
			bg.setAlpha(1f);
		}
	}

	// ranking screen elements
	data.drawRankingElements(g, beatmap, animationProgress.getTime());

	// buttons
	replayButton.draw();
	if (data.isGameplay() && !GameMod.AUTO.isActive())
		retryButton.draw();
	UI.getBackButton().draw(g);

	UI.draw(g);
}
 
Example 10
Source File: GameData.java    From opsu with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Draws a number with defaultSymbols.
 * @param n the number to draw
 * @param x the center x coordinate
 * @param y the center y coordinate
 * @param scale the scale to apply
 * @param alpha the alpha level
 */
public void drawSymbolNumber(int n, float x, float y, float scale, float alpha) {
	int length = (int) (Math.log10(n) + 1);
	float digitWidth = getDefaultSymbolImage(0).getWidth() * scale;
	float cx = x + ((length - 1) * (digitWidth / 2));

	for (int i = 0; i < length; i++) {
		Image digit = getDefaultSymbolImage(n % 10).getScaledCopy(scale);
		digit.setAlpha(alpha);
		digit.drawCentered(cx, y);
		cx -= digitWidth;
		n /= 10;
	}
}
 
Example 11
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 12
Source File: BeatmapSetNode.java    From opsu with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draws the button.
 * @param x the x coordinate
 * @param y the y coordinate
 * @param grade the highest grade, if any
 * @param focus true if this is the focused node
 */
public void draw(float x, float y, Grade grade, boolean focus) {
	Image bg = GameImage.MENU_BUTTON_BG.getImage();
	boolean expanded = (beatmapIndex > -1);
	Beatmap beatmap = beatmapSet.get(expanded ? beatmapIndex : 0);
	bg.setAlpha(0.9f);
	Color bgColor;
	Color textColor = Options.getSkin().getSongSelectInactiveTextColor();

	// get drawing parameters
	if (expanded) {
		x -= bg.getWidth() / 10f;
		if (focus) {
			bgColor = Color.white;
			textColor = Options.getSkin().getSongSelectActiveTextColor();
		} else
			bgColor = Colors.BLUE_BUTTON;
	} else if (beatmapSet.isPlayed())
		bgColor = Colors.ORANGE_BUTTON;
	else
		bgColor = Colors.PINK_BUTTON;
	bg.draw(x, y, bgColor);

	float cx = x + (bg.getWidth() * 0.043f);
	float cy = y + (bg.getHeight() * 0.18f) - 3;

	// draw grade
	if (grade != Grade.NULL) {
		Image gradeImg = grade.getMenuImage();
		gradeImg.drawCentered(cx - bg.getWidth() * 0.01f + gradeImg.getWidth() / 2f, y + bg.getHeight() / 2.2f);
		cx += gradeImg.getWidth();
	}

	// draw text
	if (Options.useUnicodeMetadata()) {  // load glyphs
		Fonts.loadGlyphs(Fonts.MEDIUM, beatmap.titleUnicode);
		Fonts.loadGlyphs(Fonts.DEFAULT, beatmap.artistUnicode);
	}
	Fonts.MEDIUM.drawString(cx, cy, beatmap.getTitle(), textColor);
	Fonts.DEFAULT.drawString(cx, cy + Fonts.MEDIUM.getLineHeight() - 3,
			String.format("%s // %s", beatmap.getArtist(), beatmap.creator), textColor);
	if (expanded || beatmapSet.size() == 1)
		Fonts.BOLD.drawString(cx, cy + Fonts.MEDIUM.getLineHeight() + Fonts.DEFAULT.getLineHeight() - 6,
				beatmap.version, textColor);

	// draw stars
	// (note: in osu!, stars are also drawn for beatmap sets of size 1)
	if (expanded) {
		if (beatmap.starRating >= 0) {
			Image star = GameImage.STAR.getImage();
			float starOffset = star.getWidth() * 1.25f;
			float starX = cx + starOffset * 0.02f;
			float starY = cy + Fonts.MEDIUM.getLineHeight() + Fonts.DEFAULT.getLineHeight() * 2 - 6f * GameImage.getUIscale();
			float starCenterY = starY + star.getHeight() / 2f;
			final float baseAlpha = focus ? 1f : 0.8f;
			final float smallStarScale = 0.4f;
			final int maxStars = 10;
			star.setAlpha(baseAlpha);
			int i = 1;
			for (; i < beatmap.starRating && i <= maxStars; i++) {
				if (focus)
					star.drawFlash(starX + (i - 1) * starOffset, starY, star.getWidth(), star.getHeight(), textColor);
				else
					star.draw(starX + (i - 1) * starOffset, starY);
			}
			if (i <= maxStars) {
				float partialStarScale = smallStarScale + (float) (beatmap.starRating - i + 1) * (1f - smallStarScale);
				Image partialStar = star.getScaledCopy(partialStarScale);
				partialStar.setAlpha(baseAlpha);
				float partialStarY = starCenterY - partialStar.getHeight() / 2f;
				if (focus)
					partialStar.drawFlash(starX + (i - 1) * starOffset, partialStarY, partialStar.getWidth(), partialStar.getHeight(), textColor);
				else
					partialStar.draw(starX + (i - 1) * starOffset, partialStarY);
			}
			if (++i <= maxStars) {
				Image smallStar = star.getScaledCopy(smallStarScale);
				smallStar.setAlpha(0.5f);
				float smallStarY = starCenterY - smallStar.getHeight() / 2f;
				for (; i <= maxStars; i++)
					smallStar.draw(starX + (i - 1) * starOffset, smallStarY);
			}
		}
	}
}
 
Example 13
Source File: BackButton.java    From opsu with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draws the backbutton.
 */
public void draw(Graphics g) {
	if (backButton != null) {
		backButton.draw();
		return;
	}

	// calculate chevron size
	Float beatProgress = MusicController.getBeatProgress();
	if (beatProgress == null)
		beatProgress = 0f;
	else if (beatProgress < 0.2f)
		beatProgress = AnimationEquation.IN_QUINT.calc(beatProgress * 5f);
	else
		beatProgress = 1f - AnimationEquation.OUT_QUAD.calc((beatProgress - 0.2f) * 1.25f);
	int chevronSize = (int) (chevronBaseSize - (isHovered ? 6f : 3f) * beatProgress);

	// calculate button sizes
	AnimationEquation anim = isHovered ? AnimationEquation.OUT_ELASTIC : AnimationEquation.IN_ELASTIC;
	float progress = anim.calc((float) animationTime / ANIMATION_TIME);
	float firstWidth = firstButtonWidth + (firstButtonWidth - slopeImageSlopeWidth * 2) * progress;
	float secondWidth = secondButtonWidth + secondButtonWidth * 0.25f * progress;
	realButtonWidth = (int) (firstWidth + secondWidth);

	// right part
	g.setColor(COLOR_PINK);
	g.fillRect(0, buttonYpos, firstWidth + secondWidth - slopeImageSlopeWidth, slopeImageSize);
	slopeImage.draw(firstWidth + secondWidth - slopeImageSize, buttonYpos, COLOR_PINK);

	// left part
	Color hoverColor = new Color(0f, 0f, 0f);
	hoverColor.r = COLOR_PINK.r + (COLOR_DARKPINK.r - COLOR_PINK.r) * progress;
	hoverColor.g = COLOR_PINK.g + (COLOR_DARKPINK.g - COLOR_PINK.g) * progress;
	hoverColor.b = COLOR_PINK.b + (COLOR_DARKPINK.b - COLOR_PINK.b) * progress;
	g.setColor(hoverColor);
	g.fillRect(0, buttonYpos, firstWidth - slopeImageSlopeWidth, slopeImageSize);
	slopeImage.draw(firstWidth - slopeImageSize, buttonYpos, hoverColor);

	// chevron
	Image chevron = GameImage.MENU_BACK_CHEVRON.getImage().getScaledCopy(chevronSize, chevronSize);
	chevron.drawCentered((firstWidth - slopeImageSlopeWidth / 2) / 2, buttonYpos + paddingY * 1.5f);

	// text
	float textY = buttonYpos + paddingY - textOffset;
	float textX = firstWidth + (secondWidth - paddingX * 2 - textWidth) / 2;
	Fonts.MEDIUM.drawString(textX, textY + 1, BUTTON_TEXT, Color.black);
	Fonts.MEDIUM.drawString(textX, textY, BUTTON_TEXT, Color.white);
}
 
Example 14
Source File: ScoreData.java    From opsu-dance 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 textX = x + buttonWidth * 0.24f;
	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
	Color rectColor = (focus) ? Colors.BLACK_BG_FOCUS : Colors.BLACK_BG_NORMAL;
	float oldRectAlpha = rectColor.a;
	rectColor.a *= AnimationEquation.IN_QUAD.calc(alpha);
	g.setColor(rectColor);
	g.fillRect(x, y, buttonWidth, buttonHeight);
	rectColor.a = oldRectAlpha;

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

	// grade image
	Image img = getGrade().getMenuImage();
	img.setAlpha(alpha);
	img.drawCentered(x + buttonWidth * 0.15f, midY);
	img.setAlpha(1f);

	// score
	float textOffset = (buttonHeight - Fonts.MEDIUM.getLineHeight() - Fonts.SMALL.getLineHeight()) / 2f;
	Fonts.MEDIUM.drawString(textX, y + textOffset,
			String.format("Score: %s (%dx)", NumberFormat.getNumberInstance().format(score), combo), c);

	// hit counts (custom: osu! shows user instead, above score)
	String player = (playerName == null) ? "" : String.format("  (%s)", playerName);
	Fonts.SMALL.drawString(textX, y + textOffset + Fonts.MEDIUM.getLineHeight(),
			String.format("300:%d  100:%d  50:%d  Miss:%d%s", hit300, hit100, hit50, miss, player), 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 15
Source File: Slider.java    From opsu with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draws slider ticks.
 * @param trackPosition the track position
 * @param curveAlpha the curve alpha level
 * @param decorationsAlpha the decorations alpha level
 */
private void drawSliderTicks(int trackPosition, float curveAlpha, float decorationsAlpha) {
	// don't draw if the slider would be completely finished (occurs when game is in losing state)
	if (trackPosition > hitObject.getTime() + sliderTimeTotal) {
		return;
	}

	float tickScale = 0.5f + 0.5f * AnimationEquation.OUT_BACK.calc(decorationsAlpha);
	Image tick = GameImage.SLIDER_TICK.getImage().getScaledCopy(tickScale);

	// calculate which ticks need to be drawn (don't draw if sliderball crossed it)
	int min = 0;
	int max = ticksT.length;
	if (trackPosition > hitObject.getTime()) {
		for (int i = 0; i < ticksT.length; ) {
			if (((trackPosition - hitObject.getTime()) % sliderTime) / sliderTime < ticksT[i]) {
				break;
			}
			min = ++i;
		}
	}
	if (currentRepeats % 2 == 1) {
		max -= min;
		min = 0;
	}

	// calculate the tick alpha level
	float sliderTickAlpha;
	if (currentRepeats == 0) {
		sliderTickAlpha = decorationsAlpha;
	} else {
		float t = getT(trackPosition, false);
		if (currentRepeats % 2 == 1) {
			t = 1f - t;
		}
		sliderTickAlpha = Utils.clamp(t * ticksT.length * 2, 0f, 1f);
	}

	// draw ticks
	Colors.WHITE_FADE.a = Math.min(curveAlpha, sliderTickAlpha);
	for (int i = min; i < max; i++) {
		Vec2f c = curve.pointAt(ticksT[i]);
		tick.drawCentered(c.x, c.y, Colors.WHITE_FADE);
	}
}
 
Example 16
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 17
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 18
Source File: PauseOverlay.java    From opsu-dance with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void render(Graphics g)
{
	if (this.fadeInTime < 0) {
		return;
	}

	if (this.readyToResume) {
		// draw glowing hit select circle and pulse effect
		Image cursorCircle = HITCIRCLE_SELECT.absScale(HITCIRCLE.getWidth());
		cursorCircle.setAlpha(1.0f);
		cursorCircle.drawCentered(this.mousePauseX, this.mousePauseY);
		final float pulseScale = 1f + this.pausePulseTiming;
		Image cursorCirclePulse = cursorCircle.getScaledCopy(pulseScale);
		cursorCirclePulse.setAlpha(1f - this.pausePulseTiming);
		cursorCirclePulse.drawCentered(this.mousePauseX, this.mousePauseY);
		return;
	}

	final float fadein = clamp((float) this.fadeInTime / LOSE_FADEIN_TIME, 0f, 1f);
	glDisable(GL_TEXTURE_2D);
	glColor4f(0f, 0f, 0f, .6f * fadein);
	glBegin(GL_QUADS);
	glVertex2f(0, 0);
	glVertex2f(width, 0);
	glVertex2f(width, height);
	glVertex2f(0, height);
	glEnd();
	glEnable(GL_TEXTURE_2D);

	glColor4f(1f, 1f, 1f, fadein);
	this.background.draw(0, 0, null);

	if (!this.isLose) {
		glColor4f(1f, 1f, 1f, fadein);
		this.continueButton.draw(null);
	}
	glColor4f(1f, 1f, 1f, fadein);
	this.retryButton.draw(null);
	glColor4f(1f, 1f, 1f, fadein);
	this.backButton.draw(null);
}
 
Example 19
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 20
Source File: Slider.java    From opsu-dance with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draws slider ticks.
 * @param g graphics
 * @param trackPosition the track position
 * @param curveAlpha the curve alpha level
 * @param decorationsAlpha the decorations alpha level
 */
private void drawSliderTicks(Graphics g, int trackPosition, float curveAlpha, float decorationsAlpha, float mirrorAngle) {
	float tickScale = 0.5f + 0.5f * AnimationEquation.OUT_BACK.calc(decorationsAlpha);
	Image tick = GameImage.SLIDER_TICK.getImage().getScaledCopy(tickScale);

	// calculate which ticks need to be drawn (don't draw if sliderball crossed it)
	int min = 0;
	int max = ticksT.length;
	if (trackPosition > getTime()) {
		for (int i = 0; i < ticksT.length; ) {
			if (((trackPosition - getTime()) % sliderTime) / sliderTime < ticksT[i]) {
				break;
			}
			min = ++i;
		}
	}
	if (currentRepeats % 2 == 1) {
		max -= min;
		min = 0;
	}

	// calculate the tick alpha level
	float sliderTickAlpha;
	if (currentRepeats == 0) {
		sliderTickAlpha = decorationsAlpha;
	} else {
		float t = getT(trackPosition, false);
		if (currentRepeats % 2 == 1) {
			t = 1f - t;
		}
		sliderTickAlpha = Utils.clamp(t * ticksT.length * 2, 0f, 1f);
	}

	// draw ticks
	Colors.WHITE_FADE.a = Math.min(curveAlpha, sliderTickAlpha);
	for (int i = min; i < max; i++) {
		Vec2f c = curve.pointAt(ticksT[i]);
		g.pushTransform();
		if (mirrorAngle != 0f) {
			g.rotate(c.x, c.y, mirrorAngle);
		}
		tick.drawCentered(c.x, c.y, Colors.WHITE_FADE);
		g.popTransform();
	}
}