package kku.cs.fgl.gui;
import java.awt.AWTEvent;
import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;
public class TButton extends TComponent {
private Image image;
private Image hover;
private String caption;
public TButton() {
this(0,0);
}
public TButton(float x, float y) {
this(x,y,60,30);
}
public TButton(float x, float y, int width, int height) {
super(x, y, width, height);
try {
image = new Image("gui/button-black.png");
hover = new Image("gui/button-black-hover.png");
} catch (SlickException e) {
e.printStackTrace();
}
}
@Override
public void paint(Graphics g) {
//super.paint(g);
Image img = image;
if(isMouseEnterState() && hover != null)
img=hover;
if(img!=null){
int iw = img.getWidth();
int ih = img.getHeight();
g.drawImage(img,0,0,getWidth(),getHeight(),0,0,iw,ih,bcolor);
}
int h = getFont().getLineHeight();
h = (getHeight()-h)/2;
getFont().drawString(10,h,caption);
}
Color bcolor = Color.white;
@Override
public void mouseClicked(int button) {
super.mouseClicked(button);
if(button==0){
bcolor = Color.yellow;
fireActionEvent(100);
}
}
int ctime=0;
@Override
public void update(int time) {
super.update(time);
ctime+=time;
if(ctime>100){
if(bcolor!=Color.white)bcolor = Color.white;
ctime=0;
}
}
public Color getBcolor() {
return bcolor;
}
public void setBcolor(Color bcolor) {
this.bcolor = bcolor;
}
public String getCaption() {
return caption;
}
public void setCaption(String caption) {
this.caption = caption;
}
public Image getHover() {
return hover;
}
public void setHover(Image hover) {
this.hover = hover;
}
public Image getImage() {
return image;
}
public void setImage(Image image) {
this.image = image;
}
}