mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 19:58:00 +00:00
Improve card zoom rendering size
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
float oldWidth = w;
|
||||
w = h / imageRatio;
|
||||
x += (oldWidth - w) / 2;
|
||||
imageWidth *= heightRatio;
|
||||
imageHeight *= heightRatio;
|
||||
}
|
||||
|
||||
//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;
|
||||
}
|
||||
else {
|
||||
//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) {
|
||||
|
||||
@@ -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."),
|
||||
|
||||
@@ -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 )
|
||||
|
||||
Reference in New Issue
Block a user