diff --git a/.gitattributes b/.gitattributes index 0f9c18d57e5..bf7b7625288 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1220,6 +1220,7 @@ forge-gui-mobile/src/forge/assets/FBufferedImage.java -text forge-gui-mobile/src/forge/assets/FDelayLoadImage.java -text forge-gui-mobile/src/forge/assets/FImage.java -text forge-gui-mobile/src/forge/assets/FImageComplex.java -text +forge-gui-mobile/src/forge/assets/FRotatedImage.java -text forge-gui-mobile/src/forge/assets/FSkin.java -text forge-gui-mobile/src/forge/assets/FSkinBorder.java -text forge-gui-mobile/src/forge/assets/FSkinColor.java -text diff --git a/forge-gui-mobile/src/forge/assets/FRotatedImage.java b/forge-gui-mobile/src/forge/assets/FRotatedImage.java new file mode 100644 index 00000000000..cf12c654f3f --- /dev/null +++ b/forge-gui-mobile/src/forge/assets/FRotatedImage.java @@ -0,0 +1,60 @@ +package forge.assets; + +import com.badlogic.gdx.graphics.Texture; +import forge.Graphics; + +public class FRotatedImage extends FImageComplex { + private final Texture texture; + private final int srcX, srcY, srcWidth, srcHeight; + private final boolean clockwise; + + public FRotatedImage(Texture texture0, int srcX0, int srcY0, int srcWidth0, int srcHeight0, boolean clockwise0) { + texture = texture0; + srcX = srcX0; + srcY = srcY0; + srcWidth = srcWidth0; + srcHeight = srcHeight0; + clockwise = clockwise0; + } + + @Override + public float getWidth() { + return srcHeight; //width and height are swapped since image rotated + } + + @Override + public float getHeight() { + return srcWidth; + } + + @Override + public Texture getTexture() { + return texture; + } + + @Override + public int getRegionX() { + return srcX; + } + + @Override + public int getRegionY() { + return srcY; + } + + @Override + public void draw(Graphics g, float x, float y, float w, float h) { + float originX, originY, rotation; + if (clockwise) { + originX = x + w / 2; + originY = y + w / 2; + rotation = -90; + } + else { + originX = x + h / 2; + originY = y + h / 2; + rotation = 90; + } + g.drawRotatedImage(texture, x, y, h, w, originX, originY, srcX, srcY, srcWidth, srcHeight, rotation); + } +} diff --git a/forge-gui-mobile/src/forge/card/CardRenderer.java b/forge-gui-mobile/src/forge/card/CardRenderer.java index 0823613064c..5769f3aa9e0 100644 --- a/forge-gui-mobile/src/forge/card/CardRenderer.java +++ b/forge-gui-mobile/src/forge/card/CardRenderer.java @@ -15,6 +15,7 @@ import com.badlogic.gdx.graphics.g2d.TextureRegion; import forge.Graphics; import forge.ImageKeys; import forge.assets.FImageComplex; +import forge.assets.FRotatedImage; import forge.assets.FSkinColor; import forge.assets.FSkinFont; import forge.assets.FSkinImage; @@ -106,14 +107,24 @@ public class CardRenderer { w *= 106f / 250f; } else if (isHorizontalCard) { //allow rotated image for horizontal cards - if (h > w) { //rotate image if its not the correct orientation - w = h; - h = image.getWidth(); + float artX = 40f, artY = 40f; + float artW = 350f, artH = 156f; + float srcW = 430f, srcH = 300f; + if (w > h) { + x = w * 40f / 430f; + y = h * 40f / srcH; + w *= artW / srcW; + h *= artH / srcH; + } + else { //rotate art clockwise if its not the correct orientation + x = w * artY / srcH; + y = h * (srcW - artW - artX) / srcW; + w *= artH / srcH; + h *= artW / srcW; + cardArt = new FRotatedImage(image, Math.round(x), Math.round(y), Math.round(w), Math.round(h), true); + cardArtCache.put(imageKey, cardArt); + return cardArt; } - x = w * 40f / 430f; - y = h * 40f / 300f; - w *= 349f / 430f; - h *= 156f / 300f; } else { x = w * 0.1f;