Skip to content
Permalink
ccf5f5084b
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
77 lines (56 sloc) 1.63 KB
package game.menus;
import java.awt.Rectangle;
import org.lwjgl.opengl.GL11;
import game.input.Mouse;
public class Button {
int xPos, yPos, width, height;
String text;
boolean clickable = true;
boolean visible = true;
private Mouse mouse;
private Rectangle collisionRect;
public Button(int xPos, int yPos, int width, int height, String text, Mouse mouse) {
this.xPos = xPos;
this.yPos = yPos;
this.width = width;
this.height = height;
this.text = text;
this.mouse = mouse;
collisionRect = new Rectangle();
collisionRect.x = xPos;
collisionRect.y = yPos;
collisionRect.height = height;
collisionRect.width = width;
}
public void draw() {
if (visible) {
if (mouseOver() && clickable) {
GL11.glColor3f(.7f, .7f, .7f);
GL11.glBegin(GL11.GL_QUADS);
GL11.glVertex2d(xPos - 1, yPos + 1);
GL11.glVertex2d(xPos + width + 1, yPos + 1);
GL11.glVertex2d(xPos + width + 1, yPos + height - 1);
GL11.glVertex2d(xPos - 1, yPos + height - 1);
GL11.glEnd();
GL11.glBegin(GL11.GL_QUADS);
GL11.glVertex2d(xPos + 1, yPos - 1);
GL11.glVertex2d(xPos + width - 1, yPos - 1);
GL11.glVertex2d(xPos + width - 1, yPos + height + 1);
GL11.glVertex2d(xPos + 1, yPos + height + 1);
GL11.glEnd();
}
}
}
public boolean clicked() {
return collisionRect.contains(mouse.getX(), mouse.getY()) && mouse.leftClicked();
}
public boolean mouseOver() {
return collisionRect.contains(mouse.getX(), mouse.getY());
}
public void setClickable(boolean clickable) {
this.clickable = clickable;
}
public void setVisible(boolean visible) {
this.visible = visible;
}
}