changeset 198:b88440f4431a

Allow no-text (null text) buttons.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 24 Apr 2019 14:53:27 +0300
parents f3302a2d7815
children 2e7b28b058a7
files game/IDMButton.java
diffstat 1 files changed, 13 insertions(+), 9 deletions(-) [+]
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);
+        }
     }