1 21 package proguard.gui.splash; 22 23 import java.awt.*; 24 25 30 public class ShadowedSprite implements Sprite 31 { 32 private VariableInt xOffset; 33 private VariableInt yOffset; 34 private VariableDouble alpha; 35 private VariableInt blur; 36 private Sprite sprite; 37 38 private float cachedAlpha = -1.0f; 39 private Color cachedColor; 40 41 42 51 public ShadowedSprite(VariableInt xOffset, 52 VariableInt yOffset, 53 VariableDouble alpha, 54 VariableInt blur, 55 Sprite sprite) 56 { 57 this.xOffset = xOffset; 58 this.yOffset = yOffset; 59 this.alpha = alpha; 60 this.blur = blur; 61 this.sprite = sprite; 62 } 63 64 65 67 public void paint(Graphics graphics, long time) 68 { 69 double l = alpha.getDouble(time); 70 int b = blur.getInt(time) + 1; 71 72 float a = 1.0f - (float)Math.pow(1.0 - l, 1.0/(b*b)); 73 if (a != cachedAlpha) 74 { 75 cachedAlpha = a; 76 cachedColor = new Color(0f, 0f, 0f, a); 77 } 78 79 83 Color actualColor = graphics.getColor(); 85 graphics.setColor(cachedColor); 86 87 int xo = xOffset.getInt(time) - b/2; 88 int yo = yOffset.getInt(time) - b/2; 89 90 for (int x = 0; x < b; x++) 92 { 93 for (int y = 0; y < b; y++) 94 { 95 int xt = xo + x; 96 int yt = yo + y; 97 graphics.translate(xt, yt); 98 sprite.paint(graphics, time); 99 graphics.translate(-xt, -yt); 100 } 101 } 102 103 graphics.setColor(actualColor); 105 106 sprite.paint(graphics, time); 108 } 109 } 110 | Popular Tags |