| 6 | import forge.item.PaperCard; |
| 7 | |
| 8 | public class CardAvatarImage implements FImage { |
| 9 | private final String imageKey; |
| 10 | private FImage image; |
| 11 | |
| 12 | public CardAvatarImage(PaperCard card0) { |
| 13 | this(card0.getImageKey(false)); |
| 14 | } |
| 15 | public CardAvatarImage(String imageKey0) { |
| 16 | imageKey = imageKey0; |
| 17 | } |
| 18 | |
| 19 | @Override |
| 20 | public float getWidth() { |
| 21 | return getHeight(); //image will be drawn at its height |
| 22 | } |
| 23 | |
| 24 | @Override |
| 25 | public float getHeight() { |
| 26 | if (image != null) { |
| 27 | return image.getHeight(); |
| 28 | } |
| 29 | return ImageCache.getInstance().getDefaultImage().getHeight() * CardRenderer.CARD_ART_HEIGHT_PERCENTAGE; |
| 30 | } |
| 31 | |
| 32 | @Override |
| 33 | public void draw(Graphics g, float x, float y, float w, float h) { |
| 34 | //force to get the avatar since the the cardartcache & loadingcache is always cleared on screen change or the battle bar will display black |
| 35 | image = CardRenderer.getCardArt(imageKey, false, false, false, false, false, false, false, false, true, false); |
| 36 | if (image == null) { |
| 37 | return; //can't draw anything if can't be loaded yet |
| 38 | } |
| 39 | |
| 40 | //draw scaled image into clipped region so it fills box while maintain aspect ratio |
| 41 | g.startClip(x, y, w, h); |
| 42 | |
| 43 | float aspectRatio = w / h; |
| 44 | float imageAspectRatio = image.getWidth() / image.getHeight(); |
| 45 | if (imageAspectRatio > aspectRatio) { |
| 46 | float w0 = w * imageAspectRatio / aspectRatio; |
| 47 | x -= (w0 - w) / 2; |
| 48 | w = w0; |
| 49 | } |
| 50 | else { |
| 51 | float h0 = h * aspectRatio / imageAspectRatio; |
| 52 | y -= (h0 - h) / 2; |
| 53 | h = h0; |
| 54 | } |
| 55 | |
| 56 | image.draw(g, x, y, w, h); |
| 57 | |
| 58 | g.endClip(); |
| 59 | } |
| 60 | } |
nothing calls this directly
no outgoing calls
no test coverage detected