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

The following examples show how to use org.newdawn.slick.Image#getScaledCopy() . 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: ButtonMenu.java    From opsu-dance with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void revalidate() {
	super.revalidate();

	// initialize buttons
	Image button = GameImage.MENU_BUTTON_MID.getImage();
	button = button.getScaledCopy(width2, button.getHeight());
	Image buttonL = GameImage.MENU_BUTTON_LEFT.getImage();
	Image buttonR = GameImage.MENU_BUTTON_RIGHT.getImage();
	for (MenuState ms : MenuState.values()) {
		ms.revalidate(button, buttonL, buttonR);
	}
}
 
Example 2
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 3
Source File: ButtonMenu.java    From opsu with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void init(GameContainer container, StateBasedGame game)
		throws SlickException {
	this.container = container;
	this.game = game;
	this.input = container.getInput();

	// initialize buttons
	Image button = GameImage.MENU_BUTTON_MID.getImage();
	button = button.getScaledCopy(container.getWidth() / 2, button.getHeight());
	Image buttonL = GameImage.MENU_BUTTON_LEFT.getImage();
	Image buttonR = GameImage.MENU_BUTTON_RIGHT.getImage();
	for (MenuState ms : MenuState.values())
		ms.init(container, game, button, buttonL, buttonR);
}
 
Example 4
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 5
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 6
Source File: CanvasContainerTest.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
 */
public void init(GameContainer container) throws SlickException {
	image = tga = new Image("testdata/logo.tga");
	scaleMe = new Image("testdata/logo.tga", true, Image.FILTER_NEAREST);
	gif = new Image("testdata/logo.gif");
	scaled = gif.getScaledCopy(120, 120);
	subImage = image.getSubImage(200,0,70,260);
	rot = 0;
}
 
Example 7
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 8
Source File: MenuButton.java    From opsu with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Draw the button with a color filter at the given scale.
 * @param filter the color to filter with when drawing
 * @param scaleOverride the scale to use when drawing (only works for normal images)
 */
@SuppressWarnings("deprecation")
public void draw(Color filter, float scaleOverride) {
	// animations: get current frame
	Image image = this.img;
	if (image == null) {
		anim.updateNoDraw();
		image = anim.getCurrentFrame();
	}

	// normal images
	if (imgL == null) {
		float xScaleOffset = 0f, yScaleOffset = 0f;
		if (scaleOverride != 1f) {
			image = image.getScaledCopy(scaleOverride);
			xScaleOffset = image.getWidth() / 2f - xRadius;
			yScaleOffset = image.getHeight() / 2f - yRadius;
		}
		lastScale = scaleOverride;
		if (hoverEffect == 0)
			image.draw(x - xRadius, y - yRadius, filter);
		else {
			float oldAlpha = image.getAlpha();
			float oldAngle = image.getRotation();
			if ((hoverEffect & EFFECT_EXPAND) > 0) {
				if (scale.getValue() != 1f) {
					image = image.getScaledCopy(scale.getValue());
					image.setAlpha(oldAlpha);
					if (scaleOverride != 1f) {
						xScaleOffset = image.getWidth() / 2f - xRadius;
						yScaleOffset = image.getHeight() / 2f - yRadius;
					}
					lastScale *= scale.getValue();
				}
			}
			if ((hoverEffect & EFFECT_FADE) > 0)
				image.setAlpha(alpha.getValue());
			if ((hoverEffect & EFFECT_ROTATE) > 0)
				image.setRotation(angle.getValue());
			image.draw(x - xRadius - xScaleOffset, y - yRadius - yScaleOffset, filter);
			if (image == this.img) {
				image.setAlpha(oldAlpha);
				image.setRotation(oldAngle);
			}
		}
	}

	// 3-part images
	else {
		if (hoverEffect == 0) {
			image.draw(x - xRadius + imgL.getWidth(), y - yRadius, filter);
			imgL.draw(x - xRadius, y - yRadius, filter);
			imgR.draw(x + xRadius - imgR.getWidth(), y - yRadius, filter);
		} else if ((hoverEffect & EFFECT_FADE) > 0) {
			float a = image.getAlpha(), aL = imgL.getAlpha(), aR = imgR.getAlpha();
			float currentAlpha = alpha.getValue();
			image.setAlpha(currentAlpha);
			imgL.setAlpha(currentAlpha);
			imgR.setAlpha(currentAlpha);
			image.draw(x - xRadius + imgL.getWidth(), y - yRadius, filter);
			imgL.draw(x - xRadius, y - yRadius, filter);
			imgR.draw(x + xRadius - imgR.getWidth(), y - yRadius, filter);
			image.setAlpha(a);
			imgL.setAlpha(aL);
			imgR.setAlpha(aR);
		}
	}

	// text
	if (text != null)
		font.drawString(x - font.getWidth(text) / 2f, y - font.getLineHeight() / 2f, text, color);
}
 
Example 9
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);
			}
		}
	}
}