Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package rainet; import java.io.IOException; import org.lwjgl.opengl.GL11; import org.newdawn.slick.opengl.Texture; import org.newdawn.slick.opengl.TextureLoader; import org.newdawn.slick.util.ResourceLoader; /** * * @author NTicknor19 */ public class Button { Texture bTex; public boolean isVisible, upsd = false; public float width, height, sx, sy; public Button(String s, float x, float y, float w, float h, boolean v) throws IOException { bTex = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("res/" + s + ".png")); width = w; height = h; isVisible = v; sx = x; sy = y; } public Button(String s, float x, float y, float w, float h, boolean v, boolean u) throws IOException { bTex = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("res/" + s + ".png")); width = w; height = h; isVisible = v; sx = x; sy = y; upsd = u; } public void show() { isVisible = true; } public void hide() { isVisible = false; } public void setVisible(boolean v) { isVisible = v; } public boolean gotClicked(float mx, float my) { // System.out.println("X: "+sx+" "+mx+" "+(sx+width)); // System.out.println("Y: "+sy+" "+my+" "+(sy+height)); // System.out.println(mx>sx&&mx<(sx+width)&&my>sy&&my<(sy+height)); return mx > sx && mx < (sx + width) && my > sy && my < (sy + height); } public void draw() throws IOException { if (isVisible) { bTex.bind(); GL11.glBegin(GL11.GL_QUADS); GL11.glTexCoord2f(upsd ? 1 : 0, upsd ? 1 : 0); GL11.glVertex2f(sx, sy); GL11.glTexCoord2f(upsd ? 0 : 1, upsd ? 1 : 0); GL11.glVertex2f(sx + width, sy); GL11.glTexCoord2f(upsd ? 0 : 1, upsd ? 0 : 1); GL11.glVertex2f(sx + width, sy + height); GL11.glTexCoord2f(upsd ? 1 : 0, upsd ? 0 : 1); GL11.glVertex2f(sx, sy + height); GL11.glEnd(); } } }