class GuiButton { String msg[]; String flag; boolean hot, down; float x, y; int s; boolean old; int id; Transition action; GuiButton(String m, float x, float y, int s) { this.x = x; this.y = y; this.s = s; this.msg = split(m,'|'); this.id = -1; this.flag = null; } GuiButton(String m, float x, float y, int s, int id, boolean old) { this.x = x; this.y = y; this.s = s; this.msg = split(m,'|'); this.id = id; this.old = old; this.flag = null; } GuiButton(String m, float x, float y, int s, Transition action) { this.x = x; this.y = y; this.s = s; this.msg = split(m,'|'); this.id = id; this.old = false; this.action = action; this.flag = null; } GuiButton(String m, float x, float y, int s, Transition action, String flag) { this.x = x; this.y = y; this.s = s; this.msg = split(m,'|'); this.id = id; this.old = false; this.action = action; this.flag = flag; } boolean isMouseOver() { for (int i = 0; i < msg.length; i++) { float yy = y + i * (font.h+1) * s; if (mouseX-x>=-s && mouseX-x<=msg[i].length()*font.w*s+s && mouseY-yy>=-s && mouseY-yy<=font.h*s+s) { return true; } } return false; } // returns true if button was clicked boolean Update() { boolean mouseOver = isMouseOver(); if (hot && down) { if (!(mousePressed)) { if (mouseOver) { down = false; if (flag != null) globalflags.add(flag); return true; } else { down = false; hot = mouseOver; } } } else if (!down) { hot = mouseOver && !(wasMousePressed); if (hot) { if (mousePressed) down = true; } } return false; } void Draw() { if (!hot && !down) { if (!old) font.Draw(x,y,msg,s); else fontGray.Draw(x,y,msg,s); } else if ((hot && !down)) { fontGray.Draw(x,y,msg,s); } else { if (isMouseOver()) fontGray.Draw(x+s,y+s,msg,s); else { if (!old) font.Draw(x+s,y+s,msg,s); else fontGray.Draw(x+s,y+s,msg,s); } } } }