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; }
/** * This assigns images to a hex based on the best matches it can find. * <p/> * First it assigns any images to be superimposed on a hex. These images must * have a match value of 1.0 to be added, and any time a match of this level is * achieved, any terrain involved in the match is removed from further * consideration. * <p/> * Any terrain left is used to match a base image for the hex. This time, a * match can be any value, and the first, best image is used. */ public synchronized Object[] assignMatch(IHex hex, Component comp) { IHex hexCopy = hex.duplicate(); List<Image> ortho = orthoFor(hexCopy, comp); List<Image> supers = supersFor(hexCopy, comp); Image base = baseFor(hexCopy, comp); Object[] pair = new Object[] { base, supers, ortho }; basesCache.put(hex, base); supersCache.put(hex, supers); orthosCache.put(hex, ortho); return pair; }
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; }
scaledImageCache.put(base.hashCode(), scaled);
hexImageCache.put(c, cacheEntry);