From 7feb237c069872c8eb1458beccef8d1aa13b5c52 Mon Sep 17 00:00:00 2001 From: Mark Langen Date: Fri, 16 Sep 2016 16:38:45 -0600 Subject: [PATCH] Fixed card stacking offset in Editor / Library / etc. * Rather than respecting the spacing setting from Preferences, the spacing is now calculated from the card size if characteristic based rendering is enabled, since from the renderer we know exactly what spacing is actually needed. --- .../java/mage/client/util/GUISizeHelper.java | 19 +++++++++--- .../org/mage/card/arcane/CardRenderer.java | 29 +++++++++++++++++-- 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/Mage.Client/src/main/java/mage/client/util/GUISizeHelper.java b/Mage.Client/src/main/java/mage/client/util/GUISizeHelper.java index 9dccd138897..885d6daca90 100644 --- a/Mage.Client/src/main/java/mage/client/util/GUISizeHelper.java +++ b/Mage.Client/src/main/java/mage/client/util/GUISizeHelper.java @@ -13,6 +13,9 @@ import javax.swing.JMenuItem; import javax.swing.JPopupMenu; import mage.client.MageFrame; import mage.client.dialog.PreferencesDialog; +import mage.sets.avacynrestored.GuiseOfFire; +import org.apache.log4j.Logger; +import org.mage.card.arcane.CardRenderer; /** * @@ -140,10 +143,14 @@ public class GUISizeHelper { int otherZonesCardSize = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GUI_CARD_OTHER_ZONES_SIZE, 14); otherZonesCardDimension = new Dimension(CARD_IMAGE_WIDTH * otherZonesCardSize / 42, CARD_IMAGE_HEIGHT * otherZonesCardSize / 42); - if (otherZonesCardSize > 29) { - otherZonesCardVerticalOffset = otherZonesCardDimension.height / 8; + if (PreferencesDialog.getCachedValue(PreferencesDialog.KEY_CARD_RENDERING_FALLBACK, "false").equals("false")) { + otherZonesCardVerticalOffset = CardRenderer.getCardTopHeight(otherZonesCardDimension.width); } else { - otherZonesCardVerticalOffset = otherZonesCardDimension.height / 10; + if (otherZonesCardSize > 29) { + otherZonesCardVerticalOffset = otherZonesCardDimension.height / 8; + } else { + otherZonesCardVerticalOffset = otherZonesCardDimension.height / 10; + } } int battlefieldCardMinSize = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GUI_CARD_BATTLEFIELD_MIN_SIZE, 10); @@ -153,7 +160,11 @@ public class GUISizeHelper { int editorCardSize = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GUI_CARD_EDITOR_SIZE, 14); editorCardDimension = new Dimension(CARD_IMAGE_WIDTH * editorCardSize / 42, CARD_IMAGE_HEIGHT * editorCardSize / 42); - editorCardOffsetSize = 2 * PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GUI_CARD_OFFSET_SIZE, 14) - 10; + if (PreferencesDialog.getCachedValue(PreferencesDialog.KEY_CARD_RENDERING_FALLBACK, "false").equals("false")) { + editorCardOffsetSize = CardRenderer.getCardTopHeight(editorCardDimension.width); + } else { + editorCardOffsetSize = 2 * PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GUI_CARD_OFFSET_SIZE, 14) - 10; + } enlargedImageHeight = 25 * PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GUI_ENLARGED_IMAGE_SIZE, 20); } diff --git a/Mage.Client/src/main/java/org/mage/card/arcane/CardRenderer.java b/Mage.Client/src/main/java/org/mage/card/arcane/CardRenderer.java index 3236c785957..3e29d6f30ce 100644 --- a/Mage.Client/src/main/java/org/mage/card/arcane/CardRenderer.java +++ b/Mage.Client/src/main/java/org/mage/card/arcane/CardRenderer.java @@ -149,6 +149,12 @@ public abstract class CardRenderer { } } + private static int getBorderWidth(int cardWidth) { + return (int) Math.max( + BORDER_WIDTH_MIN, + BORDER_WIDTH_FRAC * cardWidth); + } + // Layout operation // Calculate common layout metrics that will be used by several // of the operations in the template method. @@ -162,9 +168,26 @@ public abstract class CardRenderer { CORNER_RADIUS_MIN, CORNER_RADIUS_FRAC * cardWidth); - borderWidth = (int) Math.max( - BORDER_WIDTH_MIN, - BORDER_WIDTH_FRAC * cardWidth); + borderWidth = getBorderWidth(cardWidth); + } + + /** + * How far does a card have to be spaced down from + * a rendered card to show it's entire name line? + * This function is a bit of a hack, as different card faces need + * slightly different spacing, but we need it in a static context + * so that spacing is consistent in GY / deck views etc. + * @return + */ + public static int getCardTopHeight(int cardWidth) { + // Constants copied over from ModernCardRenderer and tweaked + float BOX_HEIGHT_FRAC = 0.065f; // x cardHeight + int BOX_HEIGHT_MIN = 16; + int boxHeight = (int) Math.max( + BOX_HEIGHT_MIN, + BOX_HEIGHT_FRAC * cardWidth * 1.4f); + int borderWidth = getBorderWidth(cardWidth); + return 2*borderWidth + boxHeight; } // The Draw Method