org.newdawn.slick.geom.Rectangle Java Examples

The following examples show how to use org.newdawn.slick.geom.Rectangle. 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: RectProcessor.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * @see org.newdawn.slick.svg.inkscape.ElementProcessor#process(org.newdawn.slick.svg.Loader, org.w3c.dom.Element, org.newdawn.slick.svg.Diagram, org.newdawn.slick.geom.Transform)
 */
public void process(Loader loader, Element element, Diagram diagram, Transform t) throws ParsingException {
	Transform transform = Util.getTransform(element);
    transform = new Transform(t, transform); 
	
	float width = Float.parseFloat(element.getAttribute("width"));
	float height = Float.parseFloat(element.getAttribute("height"));
	float x = Float.parseFloat(element.getAttribute("x"));
	float y = Float.parseFloat(element.getAttribute("y"));
	
	Rectangle rect = new Rectangle(x,y,width+1,height+1);
	Shape shape = rect.transform(transform);
	
	NonGeometricData data = Util.getNonGeometricData(element);
	data.addAttribute("width", ""+width);
	data.addAttribute("height", ""+height);
	data.addAttribute("x", ""+x);
	data.addAttribute("y", ""+y);
	
	diagram.addFigure(new Figure(Figure.RECTANGLE, shape, data, transform));
}
 
Example #2
Source File: ShapeTest.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 {
    shapes = new ArrayList();
    rect = new Rectangle(10, 10, 100, 80);
    shapes.add(rect);
    roundRect = new RoundedRectangle(150, 10, 60, 80, 20);
    shapes.add(roundRect);
    ellipse = new Ellipse(350, 40, 50, 30);
    shapes.add(ellipse);
    circle = new Circle(470, 60, 50);
    shapes.add(circle);
    polygon = new Polygon(new float[]{550, 10, 600, 40, 620, 100, 570, 130});
    shapes.add(polygon);
    
    keys = new boolean[256];
    lastChar = new char[256];
    createPoly(200,200);
}
 
Example #3
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 #4
Source File: Graphics.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Set clipping that controls which areas of the world will be drawn to.
 * Note that world clip is different from standard screen clip in that it's
 * defined in the space of the current world coordinate - i.e. it's affected
 * by translate, rotate, scale etc.
 * 
 * @param x
 *            The x coordinate of the top left corner of the allowed area
 * @param y
 *            The y coordinate of the top left corner of the allowed area
 * @param width
 *            The width of the allowed area
 * @param height
 *            The height of the allowed area
 */
public void setWorldClip(float x, float y, float width, float height) {
	predraw();
	worldClipRecord = new Rectangle(x, y, width, height);
	
	GL.glEnable(SGL.GL_CLIP_PLANE0);
	worldClip.put(1).put(0).put(0).put(-x).flip();
	GL.glClipPlane(SGL.GL_CLIP_PLANE0, worldClip);
	GL.glEnable(SGL.GL_CLIP_PLANE1);
	worldClip.put(-1).put(0).put(0).put(x + width).flip();
	GL.glClipPlane(SGL.GL_CLIP_PLANE1, worldClip);

	GL.glEnable(SGL.GL_CLIP_PLANE2);
	worldClip.put(0).put(1).put(0).put(-y).flip();
	GL.glClipPlane(SGL.GL_CLIP_PLANE2, worldClip);
	GL.glEnable(SGL.GL_CLIP_PLANE3);
	worldClip.put(0).put(-1).put(0).put(y + height).flip();
	GL.glClipPlane(SGL.GL_CLIP_PLANE3, worldClip);
	postdraw();
}
 
Example #5
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#init(org.newdawn.slick.GameContainer)
 */
public void init(GameContainer container) throws SlickException {
	this.container = container;

	rect = new Rectangle(400,100,200,150);
	round = new RoundedRectangle(150,100,200,150,50);
	round2 = new RoundedRectangle(150,300,200,150,50);
	center = new Rectangle(350,250,100,100);
	
	poly = new Polygon();
	poly.addPoint(400,350);
	poly.addPoint(550,320);
	poly.addPoint(600,380);
	poly.addPoint(620,450);
	poly.addPoint(500,450);
	
	gradient = new GradientFill(0,-75,Color.red,0,75,Color.yellow,true);
	gradient2 = new GradientFill(0,-75,Color.blue,0,75,Color.white,true);
	gradient4 = new GradientFill(-50,-40,Color.green,50,40,Color.cyan,true);
}
 
Example #6
Source File: Graphics.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Tile a rectangle with a pattern specifing the offset from the top corner
 * that one tile should match
 * 
 * @param x
 *            The x coordinate of the rectangle
 * @param y
 *            The y coordinate of the rectangle
 * @param width
 *            The width of the rectangle
 * @param height
 *            The height of the rectangle
 * @param pattern
 *            The image to tile across the rectangle
 * @param offX
 *            The offset on the x axis from the top left corner
 * @param offY
 *            The offset on the y axis from the top left corner
 */
public void fillRect(float x, float y, float width, float height,
		Image pattern, float offX, float offY) {
	int cols = ((int) Math.ceil(width / pattern.getWidth())) + 2;
	int rows = ((int) Math.ceil(height / pattern.getHeight())) + 2;

	Rectangle preClip = getWorldClip();
	setWorldClip(x, y, width, height);

	predraw();
	// Draw all the quads we need
	for (int c = 0; c < cols; c++) {
		for (int r = 0; r < rows; r++) {
			pattern.draw(c * pattern.getWidth() + x - offX, r
					* pattern.getHeight() + y - offY);
		}
	}
	postdraw();

	setWorldClip(preClip);
}
 
Example #7
Source File: TextField.java    From opsu-dance with GNU General Public License v3.0 5 votes vote down vote up
public void render(Graphics g)
{
	Rectangle oldClip = g.getClip();
	g.setWorldClip(x,y,width, height);
	
	// Someone could have set a color for me to blend...
	Color clr = g.getColor();

	if (backgroundCol != null) {
		g.setColor(backgroundCol.multiply(clr));
		g.fillRect(x, y, width, height);
	}
	g.setColor(textCol.multiply(clr));
	Font temp = g.getFont();

	int cursorpos = font.getWidth(value);
	int tx = 0;
	if (cursorpos > width) {
		tx = width - cursorpos - font.getWidth("_");
	}

	g.translate(tx + 2, 0);
	g.setFont(font);
	g.drawString(value, x + 1, y + 1);

	if (focused) {
		g.drawString("|", x + cursorpos, y + 1);
	}

	g.translate(-tx - 2, 0);

	if (borderCol != null) {
		g.setColor(borderCol.multiply(clr));
		g.drawRect(x, y, width, height);
	}
	g.setColor(clr);
	g.setFont(temp);
	g.clearWorldClip();
	g.setClip(oldClip);
}
 
Example #8
Source File: GeomUtilTest.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Perform the cut
 */
public void init() {
	Polygon source = new Polygon();
	source.addPoint(100,100);
	source.addPoint(150,80);
	source.addPoint(210,120);
	source.addPoint(340,150);
	source.addPoint(150,200);
	source.addPoint(120,250);
	this.source = source;
	
	circle = new Circle(0,0,50);
	rect = new Rectangle(-100,-40,200,80);
	star = new Polygon();
	
	float dis = 40;
	for (int i=0;i<360;i+=30) {
		dis = dis == 40 ? 60 : 40;
		double x = (Math.cos(Math.toRadians(i)) * dis);
		double y = (Math.sin(Math.toRadians(i)) * dis);
		star.addPoint((float) x, (float) y);
	}
	
	this.cut = circle;
	cut.setLocation(203,78);
	xp = (int) cut.getCenterX();
	yp = (int) cut.getCenterY();
	makeBoolean();
}
 
Example #9
Source File: Graphics.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Set the world clip to be applied
 * 
 * @see #setWorldClip(float, float, float, float)
 * @param clip
 *            The area still visible
 */
public void setWorldClip(Rectangle clip) {
	if (clip == null) {
		clearWorldClip();
	} else {
		setWorldClip(clip.getX(), clip.getY(), clip.getWidth(), clip
				.getHeight());
	}
}
 
Example #10
Source File: MorphShapeTest.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * @see BasicGame#init(GameContainer)
 */
public void init(GameContainer container) throws SlickException {
	a = new Rectangle(100,100,50,200);
	a = a.transform(Transform.createRotateTransform(0.1f,100,100));
	b = new Rectangle(200,100,50,200);
	b = b.transform(Transform.createRotateTransform(-0.6f,100,100));
	c = new Rectangle(300,100,50,200);
	c = c.transform(Transform.createRotateTransform(-0.2f,100,100));
	
	morph = new MorphShape(a);
	morph.addShape(b);
	morph.addShape(c);
	
	container.setVSync(true);
}
 
Example #11
Source File: Graphics.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Set the clipping to apply to the drawing. Note that this clipping takes
 * no note of the transforms that have been applied to the context and is
 * always in absolute screen space coordinates.
 * 
 * @param rect
 *            The rectangle describing the clipped area in screen
 *            coordinates
 */
public void setClip(Rectangle rect) {
	if (rect == null) {
		clearClip();
		return;
	}

	setClip((int) rect.getX(), (int) rect.getY(), (int) rect.getWidth(),
			(int) rect.getHeight());
}
 
Example #12
Source File: TextField.java    From opsu with GNU General Public License v3.0 4 votes vote down vote up
/**
 * @see org.newdawn.slick.gui.AbstractComponent#render(org.newdawn.slick.gui.GUIContext,
 *      org.newdawn.slick.Graphics)
 */
@Override
public void render(GUIContext container, Graphics g) {
	if (lastKey != -1) {
		if (input.isKeyDown(lastKey)) {
			if (repeatTimer < System.currentTimeMillis()) {
				repeatTimer = System.currentTimeMillis() + KEY_REPEAT_INTERVAL;
				keyPressed(lastKey, lastChar);
			}
		} else {
			lastKey = -1;
		}
	}
	Rectangle oldClip = g.getClip();
	g.setWorldClip(x,y,width, height);
	
	// Someone could have set a color for me to blend...
	Color clr = g.getColor();

	if (background != null) {
		g.setColor(background.multiply(clr));
		g.fillRect(x, y, width, height);
	}
	g.setColor(text.multiply(clr));
	Font temp = g.getFont();

	int cpos = font.getWidth(value.substring(0, cursorPos));
	int tx = 0;
	if (cpos > width) {
		tx = width - cpos - font.getWidth("_");
	}

	g.translate(tx + 2, 0);
	g.setFont(font);
	g.drawString(value, x + 1, y + 1);

	if (hasFocus() && visibleCursor) {
		g.drawString("_", x + 1 + cpos + 2, y + 1);
	}

	g.translate(-tx - 2, 0);

	if (border != null) {
		g.setColor(border.multiply(clr));
		g.drawRect(x, y, width, height);
	}
	g.setColor(clr);
	g.setFont(temp);
	g.clearWorldClip();
	g.setClip(oldClip);
}
 
Example #13
Source File: TextField.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * @see org.newdawn.slick.gui.AbstractComponent#render(org.newdawn.slick.gui.GUIContext,
 *      org.newdawn.slick.Graphics)
 */
public void render(GUIContext container, Graphics g) {
	if (lastKey != -1) {
		if (input.isKeyDown(lastKey)) {
			if (repeatTimer < System.currentTimeMillis()) {
				repeatTimer = System.currentTimeMillis() + KEY_REPEAT_INTERVAL;
				keyPressed(lastKey, lastChar);
			}
		} else {
			lastKey = -1;
		}
	}
	Rectangle oldClip = g.getClip();
	g.setWorldClip(x,y,width, height);
	
	// Someone could have set a color for me to blend...
	Color clr = g.getColor();

	if (background != null) {
		g.setColor(background.multiply(clr));
		g.fillRect(x, y, width, height);
	}
	g.setColor(text.multiply(clr));
	Font temp = g.getFont();

	int cpos = font.getWidth(value.substring(0, cursorPos));
	int tx = 0;
	if (cpos > width) {
		tx = width - cpos - font.getWidth("_");
	}

	g.translate(tx + 2, 0);
	g.setFont(font);
	g.drawString(value, x + 1, y + 1);

	if (hasFocus() && visibleCursor) {
		g.drawString("_", x + 1 + cpos + 2, y + 1);
	}

	g.translate(-tx - 2, 0);

	if (border != null) {
		g.setColor(border.multiply(clr));
		g.drawRect(x, y, width, height);
	}
	g.setColor(clr);
	g.setFont(temp);
	g.clearWorldClip();
	g.setClip(oldClip);
}
 
Example #14
Source File: Graphics.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * Return the currently applied clipping rectangle
 * 
 * @return The current applied clipping rectangle or null if no clipping is
 *         applied
 */
public Rectangle getClip() {
	return clip;
}
 
Example #15
Source File: Graphics.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * Get the last set world clip or null of the world clip isn't set
 * 
 * @return The last set world clip rectangle
 */
public Rectangle getWorldClip() {
	return worldClipRecord;
}
 
Example #16
Source File: AbstractComponent.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * Gives the focus to this component with a click of the mouse.
 * 
 * @see org.newdawn.slick.gui.AbstractComponent#mouseReleased(int, int, int)
 */
public void mouseReleased(int button, int x, int y) {
	setFocus(Rectangle.contains(x, y, getX(), getY(), getWidth(),
			getHeight()));
}
 
Example #17
Source File: MouseOverArea.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 2 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 x
 *            The position of the area
 * @param y
 *            the position of the area
 * @param width
 *            The width of the area
 * @param height
 *            The height of the area
 */
public MouseOverArea(GUIContext container, Image image, int x, int y,
		int width, int height) {
	this(container,image,new Rectangle(x,y,width,height));
}