public synchronized Image getBase(IHex hex, Component comp) { Image i = basesCache.get(hex); if (i == null) { Object[] pair = assignMatch(hex, comp); return (Image) pair[0]; } return i; }
@SuppressWarnings("unchecked") public synchronized List<Image> getSupers(IHex hex, Component comp) { List<Image> l = supersCache.get(hex); if (l == null) { Object[] pair = assignMatch(hex, comp); return (List<Image>) pair[1]; } return l; }
@SuppressWarnings("unchecked") public synchronized List<Image> getOrtho(IHex hex, Component comp) { List<Image> o = orthosCache.get(hex); if (o == null) { Object[] pair = assignMatch(hex, comp); return (List<Image>) pair[2]; } return o; }
BufferedImage createShadowMask(Image image) { int hashCode = image.hashCode(); BufferedImage mask = shadowImageCache.get(hashCode); if (mask != null) { return mask; } mask = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB); float opacity = 0.4f; Graphics2D g2d = mask.createGraphics(); g2d.drawImage(image, 0, 0, null); g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_IN, opacity)); g2d.setColor(Color.BLACK); g2d.fillRect(0, 0, image.getWidth(null), image.getHeight(null)); g2d.dispose(); shadowImageCache.put(hashCode, mask); return mask; }
/** * Adds all images associated with the hex to the specified tracker */ public synchronized void trackHexImages(IHex hex, MediaTracker tracker) { Image base = basesCache.get(hex); List<Image> superImgs = supersCache.get(hex); List<Image> orthoImgs = orthosCache.get(hex); // add base tracker.addImage(base, 1); // add superImgs if (superImgs != null) { for (Image img: superImgs) { tracker.addImage(img, 1); } } if (orthoImgs != null) { for (Image img: orthoImgs) { tracker.addImage(img, 1); } } }
private Image createBlurredShadow(Image orig) { if ((orig == null) || orig.getWidth(this) < 0 || orig.getHeight(this) < 0) { return null; } BufferedImage mask = shadowImageCache.get(orig.hashCode()); if (mask == null) { GraphicsConfiguration config = GraphicsEnvironment .getLocalGraphicsEnvironment().getDefaultScreenDevice() .getDefaultConfiguration(); // a slightly bigger image to give room for blurring mask = config.createCompatibleImage(orig.getWidth(this)+4, orig.getHeight(this)+4, Transparency.TRANSLUCENT); Graphics g = mask.getGraphics(); g.drawImage(orig,2,2,null); g.dispose(); mask = createShadowMask(mask); mask = blurOp.filter(mask, null); if (game.getPlanetaryConditions().getLight() != PlanetaryConditions.L_DAY) { mask = blurOp.filter(mask, null); } shadowImageCache.put(orig.hashCode(), mask); } return mask; }
if (useCache) { scaled = scaledImageCache.get(base.hashCode()); } else { scaled = null;
HexImageCacheEntry cacheEntry = hexImageCache.get(c); if ((cacheEntry != null) && !cacheEntry.needsUpdating) { boardGraph.drawImage(cacheEntry.hexImage, hexLoc.x, hexLoc.y, this);