From 268c327ebda39f9a392fd20fcc4a1e478cb40484 Mon Sep 17 00:00:00 2001 From: Ray Greenwell Date: Fri, 16 Mar 2012 14:10:00 +0000 Subject: [PATCH] Parse a background color from getdown.txt, or figure out a sensible one. Always fill the component with that, in case there's trouble with the background image. --- .../threerings/getdown/data/Application.java | 19 +++++++++++++++---- .../getdown/launcher/StatusPanel.java | 7 ++++--- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/threerings/getdown/data/Application.java b/src/main/java/com/threerings/getdown/data/Application.java index c8fd1e3..c416476 100644 --- a/src/main/java/com/threerings/getdown/data/Application.java +++ b/src/main/java/com/threerings/getdown/data/Application.java @@ -137,6 +137,9 @@ public class Application /** The human readable name of this application. */ public String name; + /** A background color, just in case. */ + public Color background; + /** Background image specifiers for {@link RotatingBackgrounds}. */ public String[] rotatingBackgrounds; @@ -188,10 +191,10 @@ public class Application @Override public String toString () { - return "[name=" + name + ", bg=" + backgroundImage + ", pi=" + progressImage + - ", prect=" + progress + ", pt=" + progressText + ", pb=" + progressBar + - ", srect=" + status + ", st=" + statusText + ", shadow=" + textShadow + - ", err=" + installError + ", nrect=" + patchNotes + + return "[name=" + name + ", bg=" + background + ", bg=" + backgroundImage + + ", pi=" + progressImage + ", prect=" + progress + ", pt=" + progressText + + ", pb=" + progressBar + ", srect=" + status + ", st=" + statusText + + ", shadow=" + textShadow + ", err=" + installError + ", nrect=" + patchNotes + ", notes=" + patchNotesUrl + ", stepPercentages=" + stepPercentages + "]"; } @@ -656,6 +659,14 @@ public class Application if (ui.backgroundImage == null) { // support legacy format ui.backgroundImage = (String)cdata.get("ui.background"); } + // and now ui.background can refer to the background color, but fall back to black + // or white, depending on the brightness of the progressText + Color defaultBackground = (.5f < Color.RGBtoHSB( + ui.progressText.getRed(), ui.progressText.getGreen(), ui.progressText.getBlue(), + null)[2]) + ? Color.BLACK + : Color.WHITE; + ui.background = parseColor(cdata, "ui.background", defaultBackground); ui.progressImage = (String)cdata.get("ui.progress_image"); ui.rotatingBackgrounds = ConfigUtil.getMultiValue(cdata, "ui.rotating_background"); ui.iconImages = ConfigUtil.getMultiValue(cdata, "ui.icon"); diff --git a/src/main/java/com/threerings/getdown/launcher/StatusPanel.java b/src/main/java/com/threerings/getdown/launcher/StatusPanel.java index d91d210..bd42ca1 100644 --- a/src/main/java/com/threerings/getdown/launcher/StatusPanel.java +++ b/src/main/java/com/threerings/getdown/launcher/StatusPanel.java @@ -184,6 +184,10 @@ 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... Image img; if (_displayError) { img = _bg.getErrorImage(); @@ -192,9 +196,6 @@ public class StatusPanel extends JComponent } if (img != null) { gfx.drawImage(img, 0, 0, this); - } else { - gfx.setColor(getBackground()); - gfx.fillRect(0, 0, getWidth(), getHeight()); } Object oalias = SwingUtil.activateAntiAliasing(gfx);