org.newdawn.slick.Image Java Examples

The following examples show how to use org.newdawn.slick.Image. 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: Slider.java    From opsu-dance with GNU General Public License v3.0 7 votes vote down vote up
/**
 * Initializes the Slider data type with images and dimensions.
 * @param circleDiameter the circle diameter
 * @param beatmap the associated beatmap
 */
public static void init(float circleDiameter, Beatmap beatmap) {
	followRadius = circleDiameter / 2 * 3f;
	int diameterInt = (int) circleDiameter;

	// slider ball
	if (GameImage.SLIDER_BALL.hasBeatmapSkinImages() ||
	    (!GameImage.SLIDER_BALL.hasBeatmapSkinImage() && GameImage.SLIDER_BALL.getImages() != null))
		sliderBallImages = GameImage.SLIDER_BALL.getImages();
	else
		sliderBallImages = new Image[]{ GameImage.SLIDER_BALL.getImage() };
	for (int i = 0; i < sliderBallImages.length; i++)
		sliderBallImages[i] = sliderBallImages[i].getScaledCopy(diameterInt, diameterInt);

	GameImage.SLIDER_FOLLOWCIRCLE.setImage(GameImage.SLIDER_FOLLOWCIRCLE.getImage().getScaledCopy(diameterInt * 259 / 128, diameterInt * 259 / 128));
	GameImage.REVERSEARROW.setImage(GameImage.REVERSEARROW.getImage().getScaledCopy(diameterInt, diameterInt));
	GameImage.SLIDER_TICK.setImage(GameImage.SLIDER_TICK.getImage().getScaledCopy(diameterInt / 4, diameterInt / 4));

	sliderMultiplier = beatmap.sliderMultiplier;
	sliderTickRate = beatmap.sliderTickRate;
}
 
Example #2
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 #3
Source File: ResourceHolderSlick.java    From nullpomino with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Load line clear effect images.
 */
public static void loadLineClearEffectImages() {
	String skindir = NullpoMinoSlick.propConfig.getProperty("custom.skin.directory", "res");

	if(imgBreak == null) {
		imgBreak = new Image[BLOCK_BREAK_MAX][BLOCK_BREAK_SEGMENTS];

		for(int i = 0; i < BLOCK_BREAK_MAX; i++) {
			for(int j = 0; j < BLOCK_BREAK_SEGMENTS; j++) {
				imgBreak[i][j] = loadImage(skindir + "/graphics/break" + i + "_" + j + ".png");
			}
		}
	}
	if(imgPErase == null) {
		imgPErase = new Image[PERASE_MAX];

		for(int i = 0; i < imgPErase.length; i++) {
			imgPErase[i] = loadImage(skindir + "/graphics/perase" + i + ".png");
		}
	}
}
 
Example #4
Source File: MenuButton.java    From opsu with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Set x and y radius of the button based on current scale factor
 * and expansion direction.
 */
private void setHoverRadius() {
	Image image = this.img;
	if (image == null)
		image = anim.getCurrentFrame();

	int xOffset = 0, yOffset = 0;
	float currentScale = scale.getValue();
	if (dir != Expand.CENTER) {
		// offset by difference between normal/scaled image dimensions
		xOffset = (int) ((currentScale - 1f) * image.getWidth());
		yOffset = (int) ((currentScale - 1f) * image.getHeight());
		if (dir == Expand.UP || dir == Expand.DOWN)
			xOffset = 0;    // no horizontal offset
		if (dir == Expand.RIGHT || dir == Expand.LEFT)
			yOffset = 0;    // no vertical offset
		if (dir == Expand.RIGHT || dir == Expand.DOWN_RIGHT || dir == Expand.UP_RIGHT)
			xOffset *= -1;  // flip x for right
		if (dir == Expand.DOWN ||  dir == Expand.DOWN_LEFT || dir == Expand.DOWN_RIGHT)
			yOffset *= -1;  // flip y for down
	}
	this.xRadius = ((image.getWidth() * currentScale) + xOffset) / 2f;
	this.yRadius = ((image.getHeight() * currentScale) + yOffset) / 2f;
}
 
Example #5
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 #6
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 #7
Source File: GradientImageTest.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
 */
public void init(GameContainer container) throws SlickException {
	this.container = container;
	
	image1 = new Image("testdata/grass.png");
	image2 = new Image("testdata/rocks.png");
	
	fill = new GradientFill(-64,0,new Color(1,1,1,1f),64,0,new Color(0,0,0,0));
	shape = new Rectangle(336,236,128,128);
    poly = new Polygon();
	poly.addPoint(320,220);
	poly.addPoint(350,200);
	poly.addPoint(450,200);
	poly.addPoint(480,220);
	poly.addPoint(420,400);
	poly.addPoint(400,390);
}
 
Example #8
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 #9
Source File: GraphicsFactory.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/** 
 * Create an underlying graphics context for the given image
 * 
 * @param image The image we want to render to
 * @return The graphics context created
 * @throws SlickException
 */
private static Graphics createGraphics(Image image) throws SlickException {
	init();
	
	if (fbo) {
		try {
			return new FBOGraphics(image);
		} catch (Exception e) {
			fbo = false;
			Log.warn("FBO failed in use, falling back to PBuffer");
		}
	}
	
	if (pbuffer) {
		if (pbufferRT) {
			return new PBufferGraphics(image);
		} else {
			return new PBufferUniqueGraphics(image);
		}
	}
	
	throw new SlickException("Failed to create offscreen buffer even though the card reports it's possible");
}
 
Example #10
Source File: MouseOverArea.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Create a new mouse over area
 * 
 * @param container
 *            The container displaying the mouse over area
 * @param image
 *            The normalImage to display
 * @param shape
 *            The shape defining the area of the mouse sensitive zone
 */
public MouseOverArea(GUIContext container, Image image, Shape shape) {
	super(container);

	area = shape;
	normalImage = image;
	currentImage = image;
	mouseOverImage = image;
	mouseDownImage = image;

	currentColor = normalColor;

	state = NORMAL;
	Input input = container.getInput();
	over = area.contains(input.getMouseX(), input.getMouseY());
	mouseDown = input.isMouseButtonDown(0);
	updateImage();
}
 
Example #11
Source File: TileSet.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Set the image to use for this sprite sheet image to use for this tileset
 * 
 * @param image
 *            The image to use for this tileset
 */
public void setTileSetImage(Image image) {
	tiles = new SpriteSheet(image, tileWidth, tileHeight, tileSpacing,
			tileMargin);
	tilesAcross = tiles.getHorizontalCount();
	tilesDown = tiles.getVerticalCount();

	if (tilesAcross <= 0) {
		tilesAcross = 1;
	}
	if (tilesDown <= 0) {
		tilesDown = 1;
	}

	lastGID = (tilesAcross * tilesDown) + firstGID - 1;
}
 
Example #12
Source File: Slider.java    From opsu with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Initializes the Slider data type with images and dimensions.
 * @param container the game container
 * @param circleDiameter the circle diameter
 * @param beatmap the associated beatmap
 */
public static void init(GameContainer container, float circleDiameter, Beatmap beatmap) {
	containerWidth = container.getWidth();
	containerHeight = container.getHeight();

	diameter = circleDiameter * HitObject.getXMultiplier();  // convert from Osupixels (640x480)
	int diameterInt = (int) diameter;

	followRadius = diameter / 2 * 3f;

	// slider ball
	if (GameImage.SLIDER_BALL.hasBeatmapSkinImages() ||
	    (!GameImage.SLIDER_BALL.hasBeatmapSkinImage() && GameImage.SLIDER_BALL.getImages() != null))
		sliderBallImages = GameImage.SLIDER_BALL.getImages();
	else
		sliderBallImages = new Image[]{ GameImage.SLIDER_BALL.getImage() };
	for (int i = 0; i < sliderBallImages.length; i++)
		sliderBallImages[i] = sliderBallImages[i].getScaledCopy(diameterInt * 118 / 128, diameterInt * 118 / 128);

	GameImage.SLIDER_FOLLOWCIRCLE.setImage(GameImage.SLIDER_FOLLOWCIRCLE.getImage().getScaledCopy(diameterInt * 259 / 128, diameterInt * 259 / 128));
	GameImage.REVERSEARROW.setImage(GameImage.REVERSEARROW.getImage().getScaledCopy(diameterInt, diameterInt));
	GameImage.SLIDER_TICK.setImage(GameImage.SLIDER_TICK.getImage().getScaledCopy(diameterInt / 4, diameterInt / 4));

	sliderMultiplier = beatmap.sliderMultiplier;
	sliderTickRate = beatmap.sliderTickRate;
}
 
Example #13
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 #14
Source File: LegacyCurveRenderState.java    From opsu with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Reads the first row of the slider gradient texture and upload it as
 * a 1D texture to OpenGL if it hasn't already been done.
 */
public void initGradient() {
	if (gradientTexture == 0) {
		Image slider = GameImage.SLIDER_GRADIENT_EXPERIMENTAL.getImage().getScaledCopy(1.0f / GameImage.getUIscale());
		staticState.gradientTexture = GL11.glGenTextures();
		ByteBuffer buff = BufferUtils.createByteBuffer(slider.getWidth() * 4);
		for (int i = 0; i < slider.getWidth(); ++i) {
			Color col = slider.getColor(i, 0);
			buff.put((byte) (255 * col.r));
			buff.put((byte) (255 * col.g));
			buff.put((byte) (255 * col.b));
			buff.put((byte) (255 * col.a));
		}
		buff.flip();
		GL11.glBindTexture(GL11.GL_TEXTURE_1D, gradientTexture);
		GL11.glTexImage1D(GL11.GL_TEXTURE_1D, 0, GL11.GL_RGBA, slider.getWidth(), 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buff);
		EXTFramebufferObject.glGenerateMipmapEXT(GL11.GL_TEXTURE_1D);
	}
}
 
Example #15
Source File: CurveRenderState.java    From opsu with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Reads the first row of the slider gradient texture and upload it as
 * a 1D texture to OpenGL if it hasn't already been done.
 */
public void initGradient() {
	if (gradientTexture == 0) {
		Image slider = GameImage.SLIDER_GRADIENT.getImage().getScaledCopy(1.0f / GameImage.getUIscale());
		staticState.gradientTexture = GL11.glGenTextures();
		ByteBuffer buff = BufferUtils.createByteBuffer(slider.getWidth() * 4);
		for (int i = 0; i < slider.getWidth(); ++i) {
			Color col = slider.getColor(i, 0);
			buff.put((byte) (255 * col.r));
			buff.put((byte) (255 * col.g));
			buff.put((byte) (255 * col.b));
			buff.put((byte) (255 * col.a));
		}
		buff.flip();
		GL11.glBindTexture(GL11.GL_TEXTURE_1D, gradientTexture);
		GL11.glTexImage1D(GL11.GL_TEXTURE_1D, 0, GL11.GL_RGBA, slider.getWidth(), 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buff);
		ContextCapabilities capabilities = GLContext.getCapabilities();
		if (capabilities.OpenGL30) {
			GL30.glGenerateMipmap(GL11.GL_TEXTURE_1D);
		} else if (capabilities.GL_EXT_framebuffer_object) {
			EXTFramebufferObject.glGenerateMipmapEXT(GL11.GL_TEXTURE_1D);
		} else {
			GL11.glTexParameteri(GL11.GL_TEXTURE_1D, GL14.GL_GENERATE_MIPMAP, GL11.GL_TRUE);
		}
	}
}
 
Example #16
Source File: ParticleTest.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
 */
public void init(GameContainer container) throws SlickException {
	Image image = new Image("testdata/particle.tga", true);
	system = new ParticleSystem(image);
	
	system.addEmitter(new FireEmitter(400,300,45));
	system.addEmitter(new FireEmitter(200,300,60));
	system.addEmitter(new FireEmitter(600,300,30));
	
	//system.setUsePoints(true);
}
 
Example #17
Source File: CanvasContainerTest.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) {
	image.draw(0,0);
	image.draw(500,0,200,100);
	scaleMe.draw(500,100,200,100);
	scaled.draw(400,500);
	Image flipped = scaled.getFlippedCopy(true, false);
	flipped.draw(520,500);
	Image flipped2 = flipped.getFlippedCopy(false, true);
	flipped2.draw(520,380);
	Image flipped3 = flipped2.getFlippedCopy(true, false);
	flipped3.draw(400,380);
	
	for (int i=0;i<3;i++) {
		subImage.draw(200+(i*30),300);
	}
	
	g.translate(500, 200);
	g.rotate(50, 50, rot);
	g.scale(0.3f,0.3f);
	image.draw();
	g.resetTransform();
}
 
Example #18
Source File: PBufferUniqueGraphics.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Create a new graphics context around a pbuffer
 * 
 * @param image The image we're rendering to
 * @throws SlickException Indicates a failure to use pbuffers
 */
public PBufferUniqueGraphics(Image image) throws SlickException {
	super(image.getTexture().getTextureWidth(), image.getTexture().getTextureHeight());
	this.image = image;
	
	Log.debug("Creating pbuffer(unique) "+image.getWidth()+"x"+image.getHeight());
	if ((Pbuffer.getCapabilities() & Pbuffer.PBUFFER_SUPPORTED) == 0) {
		throw new SlickException("Your OpenGL card does not support PBuffers and hence can't handle the dynamic images required for this application.");
	}

	init();
}
 
Example #19
Source File: ResourceHolderSlick.java    From nullpomino with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Load image
 * @param filename Filename
 * @return Image data
 */
public static Image loadImage(String filename) {
	if(NullpoMinoSlick.useBigImageTextureLoad) {
		return (Image)loadBigImage(filename);
	}
	return loadNormalImage(filename);
}
 
Example #20
Source File: LameTest.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 {
	poly.addPoint(100, 100);
	poly.addPoint(120, 100);
	poly.addPoint(120, 120);
	poly.addPoint(100, 120);

	image = new Image("testdata/rocks.png");
}
 
Example #21
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 #22
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 #23
Source File: ImageTest.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 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.drawRect(0,0,image.getWidth(),image.getHeight());
	image.draw(0,0);
	image.draw(500,0,200,100);
	scaleMe.draw(500,100,200,100);
	scaled.draw(400,500);
	Image flipped = scaled.getFlippedCopy(true, false);
	flipped.draw(520,500);
	Image flipped2 = flipped.getFlippedCopy(false, true);
	flipped2.draw(520,380);
	Image flipped3 = flipped2.getFlippedCopy(true, false);
	flipped3.draw(400,380);
	
	for (int i=0;i<3;i++) {
		subImage.draw(200+(i*30),300);
	}
	
	g.translate(500, 200);
	g.rotate(50, 50, rot);
	g.scale(0.3f,0.3f);
	image.draw();
	g.resetTransform();
       
       rotImage.setRotation(rot);
       rotImage.draw(100, 200);
}
 
Example #24
Source File: GraphicsFactory.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Release any graphics context that is assocaited with the given image
 * 
 * @param image The image to release
 * @throws SlickException Indicates a failure to release the context
 */
public static void releaseGraphicsForImage(Image image) throws SlickException {
	Graphics g = (Graphics) graphics.remove(image.getTexture());
	
	if (g != null) {
		g.destroy();
	}
}
 
Example #25
Source File: ImageGraphicsTest.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 {
	testImage = new Image("testdata/logo.png");
	preloaded = new Image("testdata/logo.png");
	testFont = new AngelCodeFont("testdata/hiero.fnt","testdata/hiero.png");
	target = new Image(400,300);
	cut = new Image(100,100);
	gTarget = target.getGraphics();
	offscreenPreload = preloaded.getGraphics();
	
	offscreenPreload.drawString("Drawing over a loaded image", 5, 15);
	offscreenPreload.setLineWidth(5);
	offscreenPreload.setAntiAlias(true);
	offscreenPreload.setColor(Color.blue.brighter());
	offscreenPreload.drawOval(200, 30, 50, 50);
	offscreenPreload.setColor(Color.white);
	offscreenPreload.drawRect(190,20,70,70);
	offscreenPreload.flush();
	
	if (GraphicsFactory.usingFBO()) {
		using = "FBO (Frame Buffer Objects)";
	} else if (GraphicsFactory.usingPBuffer()) {
		using = "Pbuffer (Pixel Buffers)";
	}
	
	System.out.println(preloaded.getColor(50,50));
}
 
Example #26
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 #27
Source File: Game.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;
	input = container.getInput();

	int width = container.getWidth();
	int height = container.getHeight();

	// create offscreen graphics
	offscreen = new Image(width, height);
	gOffscreen = offscreen.getGraphics();
	gOffscreen.setBackground(Color.black);

	// initialize music position bar location
	musicBarX = width * 0.01f;
	musicBarY = height * 0.05f;
	musicBarWidth = Math.max(width * 0.005f, 7);
	musicBarHeight = height * 0.9f;

	// initialize scoreboard star stream
	scoreboardStarStream = new StarStream(0, height * 2f / 3f, width / 4, 0, 0);
	scoreboardStarStream.setPositionSpread(height / 20f);
	scoreboardStarStream.setDirectionSpread(10f);
	scoreboardStarStream.setDurationSpread(700, 100);

	// create the associated GameData object
	data = new GameData(width, height);
}
 
Example #28
Source File: ButtonMenu.java    From opsu with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Initializes the menu state.
 * @param container the game container
 * @param game the game
 * @param button the center button image
 * @param buttonL the left button image
 * @param buttonR the right button image
 */
public void init(GameContainer container, StateBasedGame game, Image button, Image buttonL, Image buttonR) {
	float center = container.getWidth() / 2f;
	float baseY = getBaseY(container, game);
	float offsetY = button.getHeight() * 1.25f;

	menuButtons = new MenuButton[buttons.length];
	for (int i = 0; i < buttons.length; i++) {
		MenuButton b = new MenuButton(button, buttonL, buttonR, center, baseY + (i * offsetY));
		b.setText(String.format("%d. %s", i + 1, buttons[i].getText()), Fonts.XLARGE, Color.white);
		b.setHoverFade();
		menuButtons[i] = b;
	}
}
 
Example #29
Source File: MenuButton.java    From opsu with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a new button from an Image.
 * @param img the image
 * @param x the center x coordinate
 * @param y the center y coordinate
 */
public MenuButton(Image img, float x, float y) {
	this.img = img;
	this.x = x;
	this.y = y;
	this.xRadius = img.getWidth() / 2f;
	this.yRadius = img.getHeight() / 2f;
}
 
Example #30
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);
}