diff game/IDMButton.java @ 198:b88440f4431a

Allow no-text (null text) buttons.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 24 Apr 2019 14:53:27 +0300
parents 8dbaa093c562
children
line wrap: on
line diff
--- a/game/IDMButton.java	Wed Apr 24 12:55:54 2019 +0300
+++ b/game/IDMButton.java	Wed Apr 24 14:53:27 2019 +0300
@@ -112,16 +112,20 @@
             img = imgUnpressed;
         }
 
-        if (metrics == null)
-            metrics = g.getFontMetrics(font);
+        g.drawImage(img, getScaledX() + xoffs, getScaledY() + yoffs, null);
+
+        if (text != null)
+        {
+            if (metrics == null)
+                metrics = g.getFontMetrics(font);
 
-        int textWidth = metrics.stringWidth(text);
-        g.drawImage(img, getScaledX() + xoffs, getScaledY() + yoffs, null);
-        g.setFont(font);
-        g.setPaint(Color.black);
-        g.drawString(text,
-           getScaledX() + xoffs + (getScaledWidth() - textWidth) / 2,
-           getScaledY() + yoffs + getScaledHeight() / 2);
+            int textWidth = metrics.stringWidth(text);
+            g.setFont(font);
+            g.setPaint(Color.black);
+            g.drawString(text,
+               getScaledX() + xoffs + (getScaledWidth() - textWidth) / 2,
+               getScaledY() + yoffs + getScaledHeight() / 2);
+        }
     }