1 21 package proguard.gui.splash; 22 23 import java.awt.*; 24 import java.awt.image.BufferedImage ; 25 26 31 public class BufferedSprite implements Sprite 32 { 33 private int bufferX; 34 private int bufferY; 35 private Image bufferImage; 36 private Color backgroundColor; 37 private Sprite sprite; 38 private VariableInt x; 39 private VariableInt y; 40 41 private long cachedTime = -1; 42 43 44 55 public BufferedSprite(int bufferX, 56 int bufferY, 57 int width, 58 int height, 59 Sprite sprite, 60 VariableInt x, 61 VariableInt y) 62 { 63 64 this(bufferX, 65 bufferY, 66 new BufferedImage (width, height, BufferedImage.TYPE_4BYTE_ABGR), 67 null, 68 sprite, 69 x, 70 y); 71 } 72 73 74 86 public BufferedSprite(int bufferX, 87 int bufferY, 88 Image bufferImage, 89 Color backgroundColor, 90 Sprite sprite, 91 VariableInt x, 92 VariableInt y) 93 { 94 this.bufferX = bufferX; 95 this.bufferY = bufferY; 96 this.bufferImage = bufferImage; 97 this.backgroundColor = backgroundColor; 98 this.sprite = sprite; 99 this.x = x; 100 this.y = y; 101 } 102 103 104 106 public void paint(Graphics graphics, long time) 107 { 108 if (time != cachedTime) 109 { 110 Graphics bufferGraphics = bufferImage.getGraphics(); 111 112 if (backgroundColor != null) 114 { 115 Graphics2D bufferGraphics2D = (Graphics2D)bufferGraphics; 116 bufferGraphics2D.setComposite(AlphaComposite.Clear); 117 bufferGraphics.fillRect(0, 0, bufferImage.getWidth(null), bufferImage.getHeight(null)); 118 bufferGraphics2D.setComposite(AlphaComposite.Src); 119 } 120 else 121 { 122 bufferGraphics.setColor(backgroundColor); 123 bufferGraphics.fillRect(0, 0, bufferImage.getWidth(null), bufferImage.getHeight(null)); 124 } 125 126 bufferGraphics.translate(-bufferX, -bufferY); 128 bufferGraphics.setColor(graphics.getColor()); 129 bufferGraphics.setFont(graphics.getFont()); 130 131 sprite.paint(bufferGraphics, time); 133 134 bufferGraphics.dispose(); 135 136 cachedTime = time; 137 } 138 139 graphics.drawImage(bufferImage, 141 bufferX + x.getInt(time), 142 bufferY + y.getInt(time), 143 null); 144 } 145 } 146 | Popular Tags |