From 8f5d27e24bb85c386cbbced74fa10359ab9d4432 Mon Sep 17 00:00:00 2001 From: drdev Date: Sun, 4 May 2014 02:59:32 +0000 Subject: [PATCH] Improve card zoom rendering size --- .../src/forge/assets/FSkinImage.java | 10 +--- .../src/forge/card/CardRenderer.java | 50 +++++++++---------- .../screens/settings/SettingsScreen.java | 4 -- .../src/main/java/forge/assets/ImageUtil.java | 8 ++- 4 files changed, 32 insertions(+), 40 deletions(-) diff --git a/forge-gui-mobile/src/forge/assets/FSkinImage.java b/forge-gui-mobile/src/forge/assets/FSkinImage.java index 9739cde3f4a..013b0922d01 100644 --- a/forge-gui-mobile/src/forge/assets/FSkinImage.java +++ b/forge-gui-mobile/src/forge/assets/FSkinImage.java @@ -355,17 +355,11 @@ public enum FSkinImage implements FImage { } public float getNearestHQWidth(float baseWidth) { - return getNearestHQSize(baseWidth, w); + return ImageUtil.getNearestHQSize(baseWidth, w); } public float getNearestHQHeight(float baseHeight) { - return getNearestHQSize(baseHeight, h); - } - - private float getNearestHQSize(float baseSize, float actualSize) { - //get nearest power of actualSize to baseSize so that the image renders good - float nearestSize = (float)Math.round(actualSize) * (float)Math.pow(2, (double)Math.round(Math.log((double)(baseSize / actualSize)) / Math.log(2))); - return nearestSize; + return ImageUtil.getNearestHQSize(baseHeight, h); } @Override diff --git a/forge-gui-mobile/src/forge/card/CardRenderer.java b/forge-gui-mobile/src/forge/card/CardRenderer.java index 5b49552d75e..794edc10012 100644 --- a/forge-gui-mobile/src/forge/card/CardRenderer.java +++ b/forge-gui-mobile/src/forge/card/CardRenderer.java @@ -21,8 +21,6 @@ import forge.card.CardDetailUtil.DetailColors; import forge.card.mana.ManaCost; import forge.game.card.Card; import forge.item.PaperCard; -import forge.model.FModel; -import forge.properties.ForgePreferences.FPref; import forge.screens.match.FControl; import forge.toolbox.FCardPanel; import forge.toolbox.FDialog; @@ -47,40 +45,38 @@ public class CardRenderer { } public static void drawZoom(Graphics g, Card card, float width, float height) { - float x = FDialog.INSETS; - float y = x; - float w = width - 2 * x; - float h = height - 2 * y; + float w = width - 2 * FDialog.INSETS; + float h = height - 2 * FDialog.INSETS; Texture image = ImageCache.getImage(card); + float imageWidth = image.getWidth(); + float imageHeight = image.getHeight(); - float ratio = h / w; - float imageRatio = (float)image.getHeight() / (float)image.getWidth(); //use image ratio rather than normal aspect ratio so it looks better + if (imageWidth > w || imageHeight > h) { + //scale down until image fits on screen + float widthRatio = w / imageWidth; + float heightRatio = h / imageHeight; - if (ratio > imageRatio) { - float oldHeight = h; - h = w * imageRatio; - y += (oldHeight - h) / 2; + if (widthRatio < heightRatio) { + imageWidth *= widthRatio; + imageHeight *= widthRatio; + } + else { + imageWidth *= heightRatio; + imageHeight *= heightRatio; + } } else { - float oldWidth = w; - w = h / imageRatio; - x += (oldWidth - w) / 2; - } - - //prevent scaling image larger if preference turned off - if (w > image.getWidth() || h > image.getHeight()) { - if (!FModel.getPreferences().getPrefBoolean(FPref.UI_SCALE_LARGER)) { - float oldWidth = w; - float oldHeight = h; - w = image.getWidth(); - h = image.getHeight(); - x += (oldWidth - w) / 2; - y += (oldHeight - h) / 2; + //scale up as long as image fits on screen + float minWidth = w / 2; + float minHeight = h / 2; + while (imageWidth < minWidth && imageHeight < minHeight) { + imageWidth *= 2; + imageHeight *= 2; } } - g.drawImage(image, x, y, w, h); + g.drawImage(image, (width - imageWidth) / 2, (height - imageHeight) / 2, imageWidth, imageHeight); } public static void drawDetails(Graphics g, Card card, float width, float height) { diff --git a/forge-gui-mobile/src/forge/screens/settings/SettingsScreen.java b/forge-gui-mobile/src/forge/screens/settings/SettingsScreen.java index 0c598a56456..4565030bfeb 100644 --- a/forge-gui-mobile/src/forge/screens/settings/SettingsScreen.java +++ b/forge-gui-mobile/src/forge/screens/settings/SettingsScreen.java @@ -121,10 +121,6 @@ public class SettingsScreen extends FScreen { "Randomize Card Art", "Generates cards with random art in generated limited mode card pools."), 4); - lstSettings.addItem(new BooleanSetting(FPref.UI_SCALE_LARGER, - "Scale Image Larger", - "Allows card pictures to be expanded larger than their original size."), - 4); lstSettings.addItem(new BooleanSetting(FPref.UI_HIDE_REMINDER_TEXT, "Hide Reminder Text", "Hide reminder text in Card Detail pane."), diff --git a/forge-gui/src/main/java/forge/assets/ImageUtil.java b/forge-gui/src/main/java/forge/assets/ImageUtil.java index 675a8ce1a89..87ad6c20744 100644 --- a/forge-gui/src/main/java/forge/assets/ImageUtil.java +++ b/forge-gui/src/main/java/forge/assets/ImageUtil.java @@ -13,9 +13,15 @@ import forge.properties.ForgePreferences.FPref; import forge.util.Base64Coder; public class ImageUtil { + public static float getNearestHQSize(float baseSize, float actualSize) { + //get nearest power of actualSize to baseSize so that the image renders good + return (float)Math.round(actualSize) * (float)Math.pow(2, (double)Math.round(Math.log((double)(baseSize / actualSize)) / Math.log(2))); + } + public static PaperCard getPaperCardFromImageKey(String key) { - if( key == null ) + if ( key == null ) { return null; + } PaperCard cp = StaticData.instance().getCommonCards().getCard(key); if ( cp == null )