/* * This file is part of SpoutcraftPlugin. * * Copyright (c) 2011 SpoutcraftDev <http://spoutcraft.org//> * SpoutcraftPlugin is licensed under the GNU Lesser General Public License. * * SpoutcraftPlugin is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * SpoutcraftPlugin is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package org.getspout.spoutapi.gui; /** * Used to create a simple rectangle. */ public class Rectangle { int width, height, x, y; public Rectangle(int x, int y, int width, int height) { setX(x); setY(y); setWidth(width); setHeight(height); } public int getWidth() { return width; } public void setWidth(int width) { this.width = width; } public int getHeight() { return height; } public void setHeight(int height) { this.height = height; } public int getX() { return x; } public void setX(int x) { this.x = x; } public int getY() { return y; } public void setY(int y) { this.y = y; } public int getTop() { return getY(); } public int getLeft() { return getX(); } public int getBottom() { return getY() + getHeight(); } public int getRight() { return getX() + getWidth(); } /** * Shifts the position by given x and y. * @param x * @param y */ public void moveBy(int x, int y) { this.x += x; this.y += y; } /** * Resizes the rect with given width and height * @param width * @param height */ public void resize(int width, int height) { this.width = width; this.height = height; } /** * Moves rect to given x and y position. * @param x * @param y */ public void move(int x, int y) { this.x = x; this.y = y; } @Override public String toString() { return super.toString() + "{ x: " + x + " y: " + y + " width: " + width + " height: " + height + " }"; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + height; result = prime * result + width; result = prime * result + x; result = prime * result + y; return result; } @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } Rectangle other = (Rectangle) obj; if (height != other.height) { return false; } if (width != other.width) { return false; } if (x != other.x) { return false; } if (y != other.y) { return false; } return true; } }