Update RetroCardRenderer

* adjusted values for better scaling
* fix artifact background overriding card color
This commit is contained in:
jmlundeen 2025-04-29 08:47:32 -05:00
parent 7a3a86017c
commit e9b6712915
2 changed files with 48 additions and 36 deletions

View file

@ -105,21 +105,25 @@ public class RetroCardRenderer extends CardRenderer {
// = cardWidth - 2 x totalContentInset // = cardWidth - 2 x totalContentInset
protected int contentWidth; protected int contentWidth;
// Width of art / text box // dimensions of art / text box
protected int innerContentWidth; protected int innerContentWidth;
// X position of inside content protected int artHeight;
private int innerContentStart;
// How tall the name / type lines and P/T box are // How tall the name / type lines and P/T box are
protected static final float BOX_HEIGHT_FRAC = 0.065f; // x cardHeight protected static final float BOX_HEIGHT_FRAC = 0.051f; // x cardHeight
protected static final int BOX_HEIGHT_MIN = 16; protected static final float PT_BOX_HEIGHT_FRAC = 0.065f; // x cardHeight
protected static final int BOX_HEIGHT_MIN = 8;
protected int boxHeight; protected int boxHeight;
protected int ptBoxHeight;
// How far down the card is the type line placed? // How far down the card is the type line placed?
protected static final float TYPE_LINE_Y_FRAC = 0.52f; // x cardHeight protected static final float TYPE_LINE_Y_FRAC = 0.525f; // x cardHeight
protected int typeLineY; protected int typeLineY;
// The left and right frame inset
protected static final float INSET_WIDTH_FRAC = .055f;
protected int insetWidth;
// Possible sizes of rules text font // Possible sizes of rules text font
protected static final int[] RULES_TEXT_FONT_SIZES = {24, 18, 15, 12, 9}; protected static final int[] RULES_TEXT_FONT_SIZES = {24, 18, 15, 12, 9};
@ -156,14 +160,18 @@ public class RetroCardRenderer extends CardRenderer {
borderWidth = (int) Math.max( borderWidth = (int) Math.max(
BORDER_WIDTH_MIN, BORDER_WIDTH_MIN,
0.042 * cardWidth); 0.048 * cardWidth);
frameInset = (int) Math.max( frameInset = (int) Math.max(
BORDER_WIDTH_MIN, BORDER_WIDTH_MIN,
0.012 * cardWidth); 0.012 * cardWidth);
insetWidth = (int) Math.max(
BORDER_WIDTH_MIN,
INSET_WIDTH_FRAC * cardWidth);
// Content inset, just equal to border width // Content inset, just equal to border width
contentInset = borderWidth - frameInset; contentInset = borderWidth + insetWidth;
// Total content inset helper // Total content inset helper
totalContentInset = borderWidth + contentInset; totalContentInset = borderWidth + contentInset;
@ -175,14 +183,20 @@ public class RetroCardRenderer extends CardRenderer {
boxHeight = (int) Math.max( boxHeight = (int) Math.max(
BOX_HEIGHT_MIN, BOX_HEIGHT_MIN,
BOX_HEIGHT_FRAC * cardHeight); BOX_HEIGHT_FRAC * cardHeight);
ptBoxHeight = (int) Math.max(
// Art / text box size BOX_HEIGHT_MIN * 2,
innerContentWidth = (int) (cardWidth * 0.81f); PT_BOX_HEIGHT_FRAC * cardHeight);
innerContentStart = (int) (cardWidth * 0.095f);
// Type line at // Type line at
typeLineY = (int) (TYPE_LINE_Y_FRAC * cardHeight); typeLineY = (int) (TYPE_LINE_Y_FRAC * cardHeight);
// Art / text box size
innerContentWidth = (int) (cardWidth * .8f);
if (innerContentWidth < 160) {
innerContentWidth += 2;
}
artHeight = typeLineY - (borderWidth + boxHeight);
// Box text height // Box text height
boxTextHeight = getTextHeightForBoxHeight(boxHeight); boxTextHeight = getTextHeightForBoxHeight(boxHeight);
boxTextOffset = (boxHeight - boxTextHeight) / 2; boxTextOffset = (boxHeight - boxTextHeight) / 2;
@ -190,8 +204,8 @@ public class RetroCardRenderer extends CardRenderer {
boxTextFontNarrow = new Font("Arial Narrow", Font.PLAIN, boxTextHeight); boxTextFontNarrow = new Font("Arial Narrow", Font.PLAIN, boxTextHeight);
// Box text height // Box text height
ptTextHeight = getPTTextHeightForLineHeight(boxHeight); ptTextHeight = getPTTextHeightForLineHeight(ptBoxHeight);
ptTextOffset = (boxHeight - ptTextHeight) / 2; ptTextOffset = (ptBoxHeight - ptTextHeight) / 2;
ptTextFont = new Font("Arial", Font.BOLD, ptTextHeight); ptTextFont = new Font("Arial", Font.BOLD, ptTextHeight);
// Inset Frame Colors // Inset Frame Colors
@ -251,7 +265,7 @@ public class RetroCardRenderer extends CardRenderer {
protected void drawArt(Graphics2D g) { protected void drawArt(Graphics2D g) {
if (artImage != null) { if (artImage != null) {
boolean shouldPreserveAspect = false; boolean shouldPreserveAspect = true;
Rectangle2D sourceRect = ArtRect.RETRO.rect; Rectangle2D sourceRect = ArtRect.RETRO.rect;
if (cardView.getFrameStyle() != FrameStyle.RETRO) { if (cardView.getFrameStyle() != FrameStyle.RETRO) {
sourceRect = new Rectangle2D.Double(sourceRect.getX(), sourceRect.getY() + .01, sourceRect.getWidth(), sourceRect.getHeight()); sourceRect = new Rectangle2D.Double(sourceRect.getX(), sourceRect.getY() + .01, sourceRect.getWidth(), sourceRect.getHeight());
@ -266,8 +280,8 @@ public class RetroCardRenderer extends CardRenderer {
// Normal drawing of art from a source part of the card frame into the rect // Normal drawing of art from a source part of the card frame into the rect
drawArtIntoRect(g, drawArtIntoRect(g,
innerContentStart + frameInset, innerContentStart + frameInset * 2, contentInset + frameInset, borderWidth + boxHeight + frameInset,
innerContentWidth - frameInset * 2, typeLineY - borderWidth * 2 - frameInset, innerContentWidth - frameInset * 2, artHeight - frameInset * 2,
sourceRect, shouldPreserveAspect); sourceRect, shouldPreserveAspect);
} }
@ -291,24 +305,24 @@ public class RetroCardRenderer extends CardRenderer {
// Draw the textbox fill // Draw the textbox fill
drawTextboxBackground(g, textboxPaint, frameColors, borderPaint, isOriginalDualLand()); drawTextboxBackground(g, textboxPaint, frameColors, borderPaint, isOriginalDualLand());
drawInsetFrame(g, innerContentStart, innerContentStart + frameInset, drawInsetFrame(g, contentInset, borderWidth + boxHeight,
innerContentWidth, typeLineY - borderWidth * 2 + frameInset, borderPaint, cardView.getCardTypes().contains(CardType.LAND)); innerContentWidth, artHeight, borderPaint, cardView.getCardTypes().contains(CardType.LAND));
drawTypeLine(g, attribs, getCardTypeLine(), drawTypeLine(g, attribs, getCardTypeLine(),
innerContentStart, typeLineY + frameInset, contentInset, typeLineY,
innerContentWidth, boxHeight + frameInset); innerContentWidth, boxHeight);
// Draw the transform circle // Draw the transform circle
int nameOffset = drawTransformationCircle(g, attribs, borderPaint); int nameOffset = drawTransformationCircle(g, attribs, borderPaint);
// Draw the name line // Draw the name line
drawNameLine(g, attribs, cardView.getDisplayName(), manaCostString, drawNameLine(g, attribs, cardView.getDisplayName(), manaCostString,
innerContentStart + nameOffset, totalContentInset / 2 - frameInset, contentInset + nameOffset, borderWidth,
contentWidth - nameOffset - borderWidth); innerContentWidth);
// Draw the textbox rules // Draw the textbox rules
drawRulesText(g, textboxKeywords, textboxRules, drawRulesText(g, textboxKeywords, textboxRules,
innerContentStart + 2, typeLineY + boxHeight + 2, contentInset + 2, typeLineY + boxHeight + 2,
innerContentWidth - 4, (int) ((cardHeight - borderWidth * 2) * 0.32f)); innerContentWidth - 4, (int) ((cardHeight - borderWidth * 2) * 0.32f));
// Draw the bottom right stuff // Draw the bottom right stuff
@ -390,7 +404,7 @@ public class RetroCardRenderer extends CardRenderer {
private void drawTextboxBackground(Graphics2D g, Paint textboxPaint, ObjectColor frameColors, Paint borderPaint, boolean isOriginalDual) { private void drawTextboxBackground(Graphics2D g, Paint textboxPaint, ObjectColor frameColors, Paint borderPaint, boolean isOriginalDual) {
g.setPaint(textboxPaint); g.setPaint(textboxPaint);
int x = innerContentStart; int x = contentInset;
int backgroundHeight = (int) ((cardHeight - borderWidth * 2) * 0.33f); int backgroundHeight = (int) ((cardHeight - borderWidth * 2) * 0.33f);
if (cardView.getCardTypes().contains(CardType.LAND)) { if (cardView.getCardTypes().contains(CardType.LAND)) {
@ -532,6 +546,8 @@ public class RetroCardRenderer extends CardRenderer {
return; return;
} }
int contentInset = borderWidth - frameInset;
// Where to start drawing the things // Where to start drawing the things
int curY = cardHeight - (int) (0.03f * cardHeight); int curY = cardHeight - (int) (0.03f * cardHeight);
@ -559,8 +575,8 @@ public class RetroCardRenderer extends CardRenderer {
// Draw PT box // Draw PT box
CardRendererUtils.drawRoundedBox(g, CardRendererUtils.drawRoundedBox(g,
x, curY - boxHeight, x, curY - ptBoxHeight,
partBoxWidth, boxHeight, partBoxWidth, ptBoxHeight,
contentInset, contentInset,
borderPaint, borderPaint,
isVehicle ? BOX_VEHICLE : fill); isVehicle ? BOX_VEHICLE : fill);
@ -998,11 +1014,7 @@ public class RetroCardRenderer extends CardRenderer {
// Get the text height for a given box height // Get the text height for a given box height
protected static int getTextHeightForBoxHeight(int h) { protected static int getTextHeightForBoxHeight(int h) {
if (h < 15) { return Math.max(10, (int) Math.ceil(.95 * h));
return h - 3;
} else {
return (int) Math.ceil(.6 * h);
}
} }
protected static int getPTTextHeightForLineHeight(int h) { protected static int getPTTextHeightForLineHeight(int h) {
@ -1056,8 +1068,6 @@ public class RetroCardRenderer extends CardRenderer {
protected static BufferedImage getBackgroundTexture(ObjectColor colors, Collection<CardType> types) { protected static BufferedImage getBackgroundTexture(ObjectColor colors, Collection<CardType> types) {
if (types.contains(CardType.LAND)) { if (types.contains(CardType.LAND)) {
return BG_IMG_LAND; return BG_IMG_LAND;
} else if (types.contains(CardType.ARTIFACT)) {
return BG_IMG_ARTIFACT;
} else if (colors.isMulticolored()) { } else if (colors.isMulticolored()) {
return BG_IMG_GOLD; return BG_IMG_GOLD;
} else if (colors.isWhite()) { } else if (colors.isWhite()) {
@ -1070,6 +1080,8 @@ public class RetroCardRenderer extends CardRenderer {
return BG_IMG_RED; return BG_IMG_RED;
} else if (colors.isGreen()) { } else if (colors.isGreen()) {
return BG_IMG_GREEN; return BG_IMG_GREEN;
} else if (types.contains(CardType.ARTIFACT)) {
return BG_IMG_ARTIFACT;
} else { } else {
// Colorless // Colorless
return BG_IMG_COLORLESS; return BG_IMG_COLORLESS;

View file

@ -7,7 +7,7 @@ import java.awt.geom.Rectangle2D;
*/ */
public enum ArtRect { public enum ArtRect {
NORMAL(new Rectangle2D.Double(.079f, .11f, .84f, .42f)), NORMAL(new Rectangle2D.Double(.079f, .11f, .84f, .42f)),
RETRO(new Rectangle2D.Double(.12f, .11f, .77f, .43f)), RETRO(new Rectangle2D.Double(.12f, .11f, .76f, .43f)),
AFTERMATH_TOP(new Rectangle2D.Double(0.075, 0.113, 0.832, 0.227)), AFTERMATH_TOP(new Rectangle2D.Double(0.075, 0.113, 0.832, 0.227)),
AFTERMATH_BOTTOM(new Rectangle2D.Double(0.546, 0.562, 0.272, 0.346)), AFTERMATH_BOTTOM(new Rectangle2D.Double(0.546, 0.562, 0.272, 0.346)),
SPLIT_LEFT(new Rectangle2D.Double(0.152, 0.539, 0.386, 0.400)), SPLIT_LEFT(new Rectangle2D.Double(0.152, 0.539, 0.386, 0.400)),