Mercurial > hg > ristipolku
diff game/IDMButton.java @ 50:496e616ff09d
More work on IDMgui.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 22 Feb 2011 11:45:40 +0200 |
parents | e6da5c71be28 |
children | f81f76458b92 |
line wrap: on
line diff
--- a/game/IDMButton.java Tue Feb 22 10:52:08 2011 +0200 +++ b/game/IDMButton.java Tue Feb 22 11:45:40 2011 +0200 @@ -21,6 +21,7 @@ Font font; FontMetrics metrics; String text; + boolean active; public IDMButton(Point pos, int keyCode, Font font, String text) { @@ -30,6 +31,7 @@ this.keyCode = keyCode; this.text = text; state = State.NORMAL; + active = false; } public IDMButton(int x, int y, int keyCode, Font font, String text) @@ -71,7 +73,7 @@ if (state == State.PRESSED) { img = imgPressed; - xoffs = yoffs = 15; + xoffs = yoffs = 5; } else { @@ -88,8 +90,8 @@ g.setFont(font); g.setPaint(Color.black); g.drawString(text, - pos.x + xoffs + (img.getWidth() - textWidth) / 2, - pos.y + yoffs + (img.getHeight() - metrics.getHeight() / 2) / 2); + pos.x + xoffs * 2 + (img.getWidth() - textWidth) / 2, + pos.y + yoffs * 2 + (img.getHeight() / 2)); } public boolean contains(Point where) @@ -102,15 +104,26 @@ public void mousePressed(MouseEvent e) { state = State.PRESSED; + active = true; } public void mouseReleased(MouseEvent e) { super.mouseReleased(e); state = State.NORMAL; + active = false; } - public void clicked() + public void mouseEntered(MouseEvent e) { + if (active) + { + state = State.PRESSED; + } + } + + public void mouseExited(MouseEvent e) + { + state = State.NORMAL; } }