Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved unit image scaling in the lobby #2915

Merged
merged 3 commits into from
Jun 9, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import megamek.common.force.*;
import megamek.common.icons.Camouflage;
import megamek.common.options.OptionsConstants;
import megamek.common.util.ImageUtil;
import megamek.common.util.fileUtils.MegaMekFile;

/** A specialized renderer for the Mek Force tree. */
Expand Down Expand Up @@ -124,8 +125,9 @@ public String getToolTipText(MouseEvent event) {
return null;
}

private void setIcon(Image image, int size) {
setIcon(new ImageIcon(image.getScaledInstance(-1, size, Image.SCALE_SMOOTH)));
private void setIcon(Image image, int height) {
int width = height * image.getWidth(null) / image.getHeight(null);
setIcon(new ImageIcon(ImageUtil.getScaledImage(image, width, height)));
SJuliez marked this conversation as resolved.
Show resolved Hide resolved
}

MekForceTreeRenderer(ChatLounge cl) {
Expand Down
16 changes: 10 additions & 6 deletions megamek/src/megamek/client/ui/swing/lobby/MekTableModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import megamek.common.icons.Camouflage;
import megamek.common.icons.Portrait;
import megamek.common.options.*;
import megamek.common.util.ImageUtil;
import megamek.common.util.fileUtils.MegaMekFile;

import static megamek.client.ui.swing.util.UIUtil.*;
Expand Down Expand Up @@ -317,13 +318,11 @@ public Component getTableCellRendererComponent(final JTable table,
setToolTipText(null);
if (column == COLS.UNIT.ordinal()) {
if (!compact) {
Image image = getToolkit().getImage(UNKNOWN_UNIT);
setIcon(new ImageIcon(image.getScaledInstance(-1, size, Image.SCALE_SMOOTH)));
setIcon(getToolkit().getImage(UNKNOWN_UNIT), size);
}
} else if (column == COLS.PILOT.ordinal()) {
if (!compact) {
Image image = getToolkit().getImage(DEF_PORTRAIT);
setIcon(new ImageIcon(image.getScaledInstance(-1, size, Image.SCALE_SMOOTH)));
setIcon(getToolkit().getImage(DEF_PORTRAIT), size);
}
}
} else {
Expand All @@ -332,10 +331,10 @@ public Component getTableCellRendererComponent(final JTable table,
final Camouflage camouflage = entity.getCamouflageOrElse(entity.getOwner().getCamouflage());
final Image icon = clientGui.bv.getTilesetManager().loadPreviewImage(entity, camouflage, this);
if (!compact) {
setIcon(new ImageIcon(icon.getScaledInstance(-1, size, Image.SCALE_SMOOTH)));
setIcon(icon, size);
setIconTextGap(UIUtil.scaleForGUI(10));
} else {
setIcon(new ImageIcon(icon.getScaledInstance(-1, size/3, Image.SCALE_SMOOTH)));
setIcon(icon, size / 3);
setIconTextGap(UIUtil.scaleForGUI(5));
}
} else if (column == COLS.PILOT.ordinal()) {
Expand All @@ -357,8 +356,13 @@ public Component getTableCellRendererComponent(final JTable table,
return this;
}

private void setIcon(Image image, int height) {
int width = height * image.getWidth(null) / image.getHeight(null);
setIcon(new ImageIcon(ImageUtil.getScaledImage(image, width, height)));
}
}


@Override
public int getColumnCount() {
return N_COL;
Expand Down