From a748358d5830383ebe1cd874577193e61d87308e Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Mon, 27 Feb 2006 00:34:12 +0000 Subject: [PATCH] Added support for rendering an image as the progress bar. --- .../threerings/getdown/data/Application.java | 15 ++++++--- .../threerings/getdown/launcher/Getdown.java | 31 ++++++++++++------- .../getdown/launcher/StatusPanel.java | 23 +++++++++----- 3 files changed, 46 insertions(+), 23 deletions(-) diff --git a/src/java/com/threerings/getdown/data/Application.java b/src/java/com/threerings/getdown/data/Application.java index 8687829..366618b 100644 --- a/src/java/com/threerings/getdown/data/Application.java +++ b/src/java/com/threerings/getdown/data/Application.java @@ -60,6 +60,12 @@ public class Application /** The human readable name of this application. */ public String name; + /** The path (relative to the appdir) to the background image. */ + public String backgroundImage; + + /** The path (relative to the appdir) to the progress bar image. */ + public String progressImage; + /** The dimensions of the progress bar. */ public Rectangle progress = new Rectangle(5, 5, 300, 15); @@ -75,9 +81,6 @@ public class Application /** The color of the status text. */ public Color statusText = Color.black; - /** The path (relative to the appdir) to the background image. */ - public String background; - /** The color of the text shadow. */ public Color textShadow; } @@ -326,7 +329,11 @@ public class Application ui.status = parseRect(cdata, "ui.status", ui.status); ui.statusText = parseColor(cdata, "ui.status_text", ui.statusText); ui.textShadow = parseColor(cdata, "ui.text_shadow", ui.textShadow); - ui.background = (String)cdata.get("ui.background"); + ui.backgroundImage = (String)cdata.get("ui.background_image"); + if (ui.backgroundImage == null) { // support legacy format + ui.backgroundImage = (String)cdata.get("ui.background"); + } + ui.progressImage = (String)cdata.get("ui.progress_image"); return ui; } diff --git a/src/java/com/threerings/getdown/launcher/Getdown.java b/src/java/com/threerings/getdown/launcher/Getdown.java index 14295d3..e0db3f7 100644 --- a/src/java/com/threerings/getdown/launcher/Getdown.java +++ b/src/java/com/threerings/getdown/launcher/Getdown.java @@ -514,17 +514,9 @@ public class Getdown extends Thread return; } - // if we have a background image, load it up - BufferedImage bgimg = null; - if (!StringUtil.isBlank(_ifc.background)) { - File bgpath = _app.getLocalPath(_ifc.background); - try { - bgimg = ImageIO.read(bgpath); - } catch (IOException ioe) { - Log.warning("Failed to read UI background [path=" + bgpath + - ", error=" + ioe + "]."); - } - } + // load up our background and progress bar images + BufferedImage bgimg = loadImage(_ifc.backgroundImage); + BufferedImage barimg = loadImage(_ifc.progressImage); // create our user interface, and display it String title = StringUtil.isBlank(_ifc.name) ? "" : _ifc.name; @@ -553,7 +545,7 @@ public class Getdown extends Thread _frame.getContentPane().removeAll(); } _frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); - _status = new StatusPanel(_msgs, _ifc, bgimg); + _status = new StatusPanel(_msgs, _ifc, bgimg, barimg); _frame.getContentPane().add(_status, BorderLayout.CENTER); _frame.pack(); SwingUtil.centerWindow(_frame); @@ -581,6 +573,21 @@ public class Getdown extends Thread } } + protected BufferedImage loadImage (String path) + { + if (StringUtil.isBlank(path)) { + return null; + } + File imgpath = _app.getLocalPath(path); + try { + return ImageIO.read(imgpath); + } catch (IOException ioe) { + Log.warning("Failed to load image [path=" + imgpath + + ", error=" + ioe + "]."); + return null; + } + } + public static void main (String[] args) { // maybe they specified the appdir in a system property diff --git a/src/java/com/threerings/getdown/launcher/StatusPanel.java b/src/java/com/threerings/getdown/launcher/StatusPanel.java index c66f1d2..d55b4b0 100644 --- a/src/java/com/threerings/getdown/launcher/StatusPanel.java +++ b/src/java/com/threerings/getdown/launcher/StatusPanel.java @@ -1,5 +1,5 @@ // -// $Id: StatusPanel.java,v 1.13 2004/07/28 06:01:58 mdb Exp $ +// $Id$ package com.threerings.getdown.launcher; @@ -32,7 +32,7 @@ import com.threerings.getdown.data.Application.UpdateInterface; public class StatusPanel extends JComponent { public StatusPanel (ResourceBundle msgs, UpdateInterface ifc, - BufferedImage bgimg) + BufferedImage bgimg, BufferedImage barimg) { _msgs = msgs; _ifc = ifc; @@ -44,6 +44,7 @@ public class StatusPanel extends JComponent } else { _psize = new Dimension(bgimg.getWidth(), bgimg.getHeight()); } + _barimg = barimg; } /** @@ -133,10 +134,18 @@ public class StatusPanel extends JComponent _newplab = null; } - gfx.setColor(_ifc.progressBar); - gfx.fillRect(_ifc.progress.x, _ifc.progress.y, - _progress * _ifc.progress.width / 100, - _ifc.progress.height); + if (_barimg != null) { + gfx.setClip(_ifc.progress.x, _ifc.progress.y, + _progress * _ifc.progress.width / 100, + _ifc.progress.height); + gfx.drawImage(_barimg, _ifc.progress.x, _ifc.progress.y, null); + gfx.setClip(null); + } else { + gfx.setColor(_ifc.progressBar); + gfx.fillRect(_ifc.progress.x, _ifc.progress.y, + _progress * _ifc.progress.width / 100, + _ifc.progress.height); + } if (_plabel != null) { int xmarg = (_ifc.progress.width - _plabel.getSize().width)/2; @@ -228,7 +237,7 @@ public class StatusPanel extends JComponent } } - protected BufferedImage _bgimg; + protected BufferedImage _bgimg, _barimg; protected Dimension _psize; protected ResourceBundle _msgs;