From d64bd1c1aff4616ed7e9f8d7bf9a1d04cabccb29 Mon Sep 17 00:00:00 2001 From: Tobias Schulte Date: Fri, 4 May 2018 09:26:52 +0200 Subject: [PATCH 1/2] allow transparent splash screens When defining a background color, it is now possible to define an alpha value as most significant byte. E.g. `80FF0000` would define a half transparent red background. This only works in combination with `ui.hide_decorations = true`. Closes #92 --- .../com/threerings/getdown/data/Application.java | 4 +++- .../threerings/getdown/launcher/GetdownApp.java | 15 +++++++++++++++ .../getdown/launcher/GetdownApplet.java | 1 + .../threerings/getdown/launcher/StatusPanel.java | 5 +---- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/threerings/getdown/data/Application.java b/src/main/java/com/threerings/getdown/data/Application.java index f759ef0..42d6858 100644 --- a/src/main/java/com/threerings/getdown/data/Application.java +++ b/src/main/java/com/threerings/getdown/data/Application.java @@ -1749,7 +1749,9 @@ public class Application { if (!StringUtil.isBlank(hexValue)) { try { - return new Color(Integer.parseInt(hexValue, 16)); + int rgba = Integer.parseInt(hexValue, 16); + boolean hasAlpha = hexValue.length() > 6; + return new Color(rgba, hasAlpha); } catch (NumberFormatException e) { log.warning("Ignoring invalid color", "hexValue", hexValue, "exception", e); } diff --git a/src/main/java/com/threerings/getdown/launcher/GetdownApp.java b/src/main/java/com/threerings/getdown/launcher/GetdownApp.java index 0dac4a1..e5f0386 100644 --- a/src/main/java/com/threerings/getdown/launcher/GetdownApp.java +++ b/src/main/java/com/threerings/getdown/launcher/GetdownApp.java @@ -5,7 +5,9 @@ package com.threerings.getdown.launcher; +import java.awt.Color; import java.awt.Container; +import java.awt.IllegalComponentStateException; import java.awt.Image; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; @@ -141,6 +143,13 @@ public class GetdownApp } }); _frame.setUndecorated(_ifc.hideDecorations); + try { + _frame.setBackground(_ifc.background); + } catch (UnsupportedOperationException e) { + log.warning("Failed to set background", e); + } catch (IllegalComponentStateException e) { + log.warning("Failed to set background", e); + } _frame.setResizable(false); } else { _frame.setTitle(title); @@ -226,6 +235,12 @@ public class GetdownApp // to allow the user to close the window if (_frame != null && _frame.isUndecorated()) { _frame.dispose(); + Color background = _frame.getBackground(); + if (background != null && background.getAlpha() < 255) { + // decorated windows do not allow alpha backgrounds + _frame.setBackground( + new Color(background.getRed(), background.getGreen(), background.getBlue())); + } _frame.setUndecorated(false); showContainer(); } diff --git a/src/main/java/com/threerings/getdown/launcher/GetdownApplet.java b/src/main/java/com/threerings/getdown/launcher/GetdownApplet.java index 8f10b96..8df73f3 100644 --- a/src/main/java/com/threerings/getdown/launcher/GetdownApplet.java +++ b/src/main/java/com/threerings/getdown/launcher/GetdownApplet.java @@ -104,6 +104,7 @@ public class GetdownApplet extends JApplet @Override protected Container createContainer () { getContentPane().removeAll(); + getContentPane().setBackground(_ifc.background); return getContentPane(); } @Override diff --git a/src/main/java/com/threerings/getdown/launcher/StatusPanel.java b/src/main/java/com/threerings/getdown/launcher/StatusPanel.java index 4fbb9be..ada90ed 100644 --- a/src/main/java/com/threerings/getdown/launcher/StatusPanel.java +++ b/src/main/java/com/threerings/getdown/launcher/StatusPanel.java @@ -189,10 +189,7 @@ public class StatusPanel extends JComponent super.paintComponent(g); Graphics2D gfx = (Graphics2D)g; - // always draw a background in case our image isn't ready yet - gfx.setColor(_ifc.background); - gfx.fillRect(0, 0, getWidth(), getHeight()); - // then attempt to draw a background image... + // attempt to draw a background image... Image img; if (_displayError) { img = _bg.getErrorImage(); From 44e45cb7013e160bbe1afbe96435d03bc80aef54 Mon Sep 17 00:00:00 2001 From: Tobias Schulte Date: Fri, 4 May 2018 09:06:56 +0200 Subject: [PATCH 2/2] set window to decorated even if error occurs during very early stage When the window is undecorated and an error occurs very early, e.g. during java version check, the order of the calls in the fail method is significant. super.fail() will call setStatusAsync, which will create the interface using EventQueue.invokeLater, if it does not exist yet. Therefore we must first call super.fail(), and then asynchronously make the window decorated again. Otherwise the window might not be created yet. Closes #57 --- .../getdown/launcher/GetdownApp.java | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/threerings/getdown/launcher/GetdownApp.java b/src/main/java/com/threerings/getdown/launcher/GetdownApp.java index e5f0386..050ba36 100644 --- a/src/main/java/com/threerings/getdown/launcher/GetdownApp.java +++ b/src/main/java/com/threerings/getdown/launcher/GetdownApp.java @@ -5,6 +5,7 @@ package com.threerings.getdown.launcher; +import java.awt.EventQueue; import java.awt.Color; import java.awt.Container; import java.awt.IllegalComponentStateException; @@ -22,7 +23,6 @@ import java.security.cert.CertificateFactory; import java.security.cert.X509Certificate; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.List; import javax.swing.JFrame; @@ -231,20 +231,25 @@ public class GetdownApp @Override protected void fail (String message) { - // if the frame was set to be undecorated, make window decoration available - // to allow the user to close the window - if (_frame != null && _frame.isUndecorated()) { - _frame.dispose(); - Color background = _frame.getBackground(); - if (background != null && background.getAlpha() < 255) { - // decorated windows do not allow alpha backgrounds - _frame.setBackground( - new Color(background.getRed(), background.getGreen(), background.getBlue())); - } - _frame.setUndecorated(false); - showContainer(); - } super.fail(message); + EventQueue.invokeLater(new Runnable() { + @Override + public void run() { + // if the frame was set to be undecorated, make window decoration available + // to allow the user to close the window + if (_frame != null && _frame.isUndecorated()) { + _frame.dispose(); + Color background = _frame.getBackground(); + if (background != null && background.getAlpha() < 255) { + // decorated windows do not allow alpha backgrounds + _frame.setBackground( + new Color(background.getRed(), background.getGreen(), background.getBlue())); + } + _frame.setUndecorated(false); + showContainer(); + } + } + }); } protected JFrame _frame;