ClipSprite.java revision b72c5c2e5482cf10117b2b25f642f7616b2326c3
1b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato/* 2b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * ProGuard -- shrinking, optimization, obfuscation, and preverification 3b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * of Java bytecode. 4b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * 5b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * Copyright (c) 2002-2009 Eric Lafortune (eric@graphics.cornell.edu) 6b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * 7b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * This program is free software; you can redistribute it and/or modify it 8b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * under the terms of the GNU General Public License as published by the Free 9b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * Software Foundation; either version 2 of the License, or (at your option) 10b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * any later version. 11b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * 12b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * This program is distributed in the hope that it will be useful, but WITHOUT 13b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 15b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * more details. 16b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * 17b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * You should have received a copy of the GNU General Public License along 18b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * with this program; if not, write to the Free Software Foundation, Inc., 19b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato */ 21b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratopackage proguard.gui.splash; 22b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 23b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratoimport java.awt.*; 24b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 25b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato/** 26b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * This Sprite encapsulates another Sprite, which is clipped by a clip Sprite. 27b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * 28b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * @author Eric Lafortune 29b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato */ 30b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onoratopublic class ClipSprite implements Sprite 31b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato{ 32b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato private final VariableColor insideClipColor; 33b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato private final VariableColor outsideClipColor; 34b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato private final Sprite clipSprite; 35b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato private final Sprite sprite; 36b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 37b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 38b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato /** 39b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * Creates a new ClipSprite. 40b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * @param insideClipColor the background color inside the clip sprite. 41b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * @param outsideClipColor the background color outside the clip sprite. 42b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * @param clipSprite the clip Sprite. 43b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato * @param sprite the clipped Sprite. 44b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato */ 45b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public ClipSprite(VariableColor insideClipColor, 46b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato VariableColor outsideClipColor, 47b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato Sprite clipSprite, 48b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato Sprite sprite) 49b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato { 50b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato this.insideClipColor = insideClipColor; 51b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato this.outsideClipColor = outsideClipColor; 52b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato this.clipSprite = clipSprite; 53b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato this.sprite = sprite; 54b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato } 55b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 56b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 57b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato // Implementation for Sprite. 58b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 59b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato public void paint(Graphics graphics, long time) 60b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato { 61b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato // Clear the background. 62b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato Color outsideColor = outsideClipColor.getColor(time); 63b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato Rectangle clip = graphics.getClipBounds(); 64b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato graphics.setPaintMode(); 65b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato graphics.setColor(outsideColor); 66b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato graphics.fillRect(0, 0, clip.width, clip.height); 67b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 68b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato // Draw the sprite in XOR mode. 69b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato OverrideGraphics2D g = new OverrideGraphics2D((Graphics2D)graphics); 70b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato Color insideColor = insideClipColor.getColor(time); 71b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato g.setOverrideXORMode(insideColor); 72b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato sprite.paint(g, time); 73b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato g.setOverrideXORMode(null); 74b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 75b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato // Clear the clip area. 76b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato g.setOverrideColor(insideColor); 77b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato clipSprite.paint(g, time); 78b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato g.setOverrideColor(null); 79b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato 80b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato // Draw the sprite in XOR mode. 81b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato g.setOverrideXORMode(insideColor); 82b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato sprite.paint(g, time); 83b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato g.setOverrideXORMode(null); 84b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato } 85b72c5c2e5482cf10117b2b25f642f7616b2326c3Joe Onorato} 86