MCPcopy Create free account
hub / github.com/Card-Forge/forge / draw

Method draw

forge-gui-mobile/src/forge/card/CardAvatarImage.java:32–59  ·  view source on GitHub ↗
(Graphics g, float x, float y, float w, float h)

Source from the content-addressed store, hash-verified

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}

Callers

nothing calls this directly

Calls 6

getCardArtMethod · 0.95
endClipMethod · 0.80
getWidthMethod · 0.65
getHeightMethod · 0.65
drawMethod · 0.65
startClipMethod · 0.45

Tested by

no test coverage detected