mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 12:18:00 +00:00
Support fixing rotation of plane card art
This commit is contained in:
1
.gitattributes
vendored
1
.gitattributes
vendored
@@ -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
|
||||
|
||||
60
forge-gui-mobile/src/forge/assets/FRotatedImage.java
Normal file
60
forge-gui-mobile/src/forge/assets/FRotatedImage.java
Normal file
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user