diff game/IDMButton.java @ 75:b586ce4f6d97

Large GUI code cleanup.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 03 Mar 2011 04:04:57 +0200
parents bca0112851d6
children 881deac2daf8
line wrap: on
line diff
--- a/game/IDMButton.java	Wed Mar 02 23:48:17 2011 +0200
+++ b/game/IDMButton.java	Thu Mar 03 04:04:57 2011 +0200
@@ -24,11 +24,14 @@
  
     public IDMButton(IDMPoint pos, int keyCode, Font font, String text)
     {
+        super(pos);
         loadImages();
-        this.pos = pos;
+        setSize(imgUp.getWidth(), imgUp.getHeight());
+
         this.font = font;
         this.keyCode = keyCode;
         this.text = text;
+
         state = State.NORMAL;
         active = false;
     }
@@ -82,39 +85,46 @@
         g.setFont(font);
         g.setPaint(Color.black);
         g.drawString(text,
-           getScaledX() + xoffs * 2 + (img.getWidth() - textWidth) / 2,
-           getScaledY() + yoffs * 2 + img.getHeight() / 2);
+           getScaledX() + xoffs + (getScaledWidth() - textWidth) / 2,
+           getScaledY() + yoffs + getScaledHeight() / 2);
     }
     
-    public boolean contains(Point where)
-    {
-        return (where.x >= getScaledX() && where.y >= getScaledY() &&
-                where.x < getScaledX() + imgUp.getWidth() &&
-                where.y < getScaledY() + imgUp.getHeight());
-    }
     
-    public void mousePressed(MouseEvent e)
+    public boolean mousePressed(MouseEvent e)
     {
         state = State.PRESSED;
         active = true;
+        return true;
     }
 
-    public void mouseReleased(MouseEvent e)
+    public boolean mouseReleased(MouseEvent e)
     {
+        boolean oldActive = active;
         super.mouseReleased(e);
         state = State.NORMAL;
         active = false;
+        return oldActive;
     }
 
-    public void mouseEntered(MouseEvent e)
+    public boolean mouseEntered(MouseEvent e)
     {
         if (active)
+        {
             state = State.PRESSED;
+            return true;
+        }
+        else
+            return false;
     }
 
-    public void mouseExited(MouseEvent e)
+    public boolean mouseExited(MouseEvent e)
     {
         if (active)
+        {
             state = State.NORMAL;
+            return true;
+        }
+        else
+            return false;
     }
 }