Improve card zoom rendering size

This commit is contained in:
drdev
2014-05-04 02:59:32 +00:00
parent 7904f2bb76
commit 8f5d27e24b
4 changed files with 32 additions and 40 deletions

View File

@@ -355,17 +355,11 @@ public enum FSkinImage implements FImage {
} }
public float getNearestHQWidth(float baseWidth) { public float getNearestHQWidth(float baseWidth) {
return getNearestHQSize(baseWidth, w); return ImageUtil.getNearestHQSize(baseWidth, w);
} }
public float getNearestHQHeight(float baseHeight) { public float getNearestHQHeight(float baseHeight) {
return getNearestHQSize(baseHeight, h); return ImageUtil.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;
} }
@Override @Override

View File

@@ -21,8 +21,6 @@ import forge.card.CardDetailUtil.DetailColors;
import forge.card.mana.ManaCost; import forge.card.mana.ManaCost;
import forge.game.card.Card; import forge.game.card.Card;
import forge.item.PaperCard; import forge.item.PaperCard;
import forge.model.FModel;
import forge.properties.ForgePreferences.FPref;
import forge.screens.match.FControl; import forge.screens.match.FControl;
import forge.toolbox.FCardPanel; import forge.toolbox.FCardPanel;
import forge.toolbox.FDialog; import forge.toolbox.FDialog;
@@ -47,40 +45,38 @@ public class CardRenderer {
} }
public static void drawZoom(Graphics g, Card card, float width, float height) { public static void drawZoom(Graphics g, Card card, float width, float height) {
float x = FDialog.INSETS; float w = width - 2 * FDialog.INSETS;
float y = x; float h = height - 2 * FDialog.INSETS;
float w = width - 2 * x;
float h = height - 2 * y;
Texture image = ImageCache.getImage(card); Texture image = ImageCache.getImage(card);
float imageWidth = image.getWidth();
float imageHeight = image.getHeight();
float ratio = h / w; if (imageWidth > w || imageHeight > h) {
float imageRatio = (float)image.getHeight() / (float)image.getWidth(); //use image ratio rather than normal aspect ratio so it looks better //scale down until image fits on screen
float widthRatio = w / imageWidth;
float heightRatio = h / imageHeight;
if (ratio > imageRatio) { if (widthRatio < heightRatio) {
float oldHeight = h; imageWidth *= widthRatio;
h = w * imageRatio; imageHeight *= widthRatio;
y += (oldHeight - h) / 2;
} }
else { else {
float oldWidth = w; imageWidth *= heightRatio;
w = h / imageRatio; imageHeight *= heightRatio;
x += (oldWidth - w) / 2;
} }
}
//prevent scaling image larger if preference turned off else {
if (w > image.getWidth() || h > image.getHeight()) { //scale up as long as image fits on screen
if (!FModel.getPreferences().getPrefBoolean(FPref.UI_SCALE_LARGER)) { float minWidth = w / 2;
float oldWidth = w; float minHeight = h / 2;
float oldHeight = h; while (imageWidth < minWidth && imageHeight < minHeight) {
w = image.getWidth(); imageWidth *= 2;
h = image.getHeight(); imageHeight *= 2;
x += (oldWidth - w) / 2;
y += (oldHeight - h) / 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) { public static void drawDetails(Graphics g, Card card, float width, float height) {

View File

@@ -121,10 +121,6 @@ public class SettingsScreen extends FScreen {
"Randomize Card Art", "Randomize Card Art",
"Generates cards with random art in generated limited mode card pools."), "Generates cards with random art in generated limited mode card pools."),
4); 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, lstSettings.addItem(new BooleanSetting(FPref.UI_HIDE_REMINDER_TEXT,
"Hide Reminder Text", "Hide Reminder Text",
"Hide reminder text in Card Detail pane."), "Hide reminder text in Card Detail pane."),

View File

@@ -13,9 +13,15 @@ import forge.properties.ForgePreferences.FPref;
import forge.util.Base64Coder; import forge.util.Base64Coder;
public class ImageUtil { 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) { public static PaperCard getPaperCardFromImageKey(String key) {
if( key == null ) if ( key == null ) {
return null; return null;
}
PaperCard cp = StaticData.instance().getCommonCards().getCard(key); PaperCard cp = StaticData.instance().getCommonCards().getCard(key);
if ( cp == null ) if ( cp == null )