From f87c5bbbec578928b13102d2ee370d07239a90e2 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Sat, 27 Feb 2016 12:33:08 +0100 Subject: [PATCH] Fixed that the flag on avatar image could be to big. --- .../java/mage/client/game/PlayerPanelExt.java | 2 +- .../client/util/gui/countryBox/CountryUtil.java | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Mage.Client/src/main/java/mage/client/game/PlayerPanelExt.java b/Mage.Client/src/main/java/mage/client/game/PlayerPanelExt.java index 3ec1c661dd2..9bcbce7cff6 100644 --- a/Mage.Client/src/main/java/mage/client/game/PlayerPanelExt.java +++ b/Mage.Client/src/main/java/mage/client/game/PlayerPanelExt.java @@ -287,7 +287,7 @@ public class PlayerPanelExt extends javax.swing.JPanel { avatar.setText(this.player.getName()); if (!player.getUserData().getFlagName().equals(flagName)) { flagName = player.getUserData().getFlagName(); - this.avatar.setTopTextImage(CountryUtil.getCountryFlagIcon(flagName).getImage()); + this.avatar.setTopTextImage(CountryUtil.getCountryFlagIconSize(flagName, 11).getImage()); } // TODO: Add the wins to the tooltiptext of the avatar String countryname = CountryUtil.getCountryName(flagName); diff --git a/Mage.Client/src/main/java/mage/client/util/gui/countryBox/CountryUtil.java b/Mage.Client/src/main/java/mage/client/util/gui/countryBox/CountryUtil.java index 8fb2f4c2ed8..a76a4c508c2 100644 --- a/Mage.Client/src/main/java/mage/client/util/gui/countryBox/CountryUtil.java +++ b/Mage.Client/src/main/java/mage/client/util/gui/countryBox/CountryUtil.java @@ -27,7 +27,6 @@ public class CountryUtil { public static ImageIcon getCountryFlagIcon(String countryCode) { ImageIcon flagIcon = FLAG_ICON_CACHE.get(countryCode); if (flagIcon == null) { - // URL url = CountryUtil.class.getResource("/flags/" + countryCode + (countryCode.endsWith(".png") ? "" : ".png")); Image flagImage = ImageHelper.getImageFromResources("/flags/" + countryCode + (countryCode.endsWith(".png") ? "" : ".png")); if (flagImage != null) { if (GUISizeHelper.flagHeight > 11) { @@ -48,6 +47,22 @@ public class CountryUtil { return flagIcon; } + public static ImageIcon getCountryFlagIconSize(String countryCode, int height) { + ImageIcon flagIcon = null; + Image flagImage = ImageHelper.getImageFromResources("/flags/" + countryCode + (countryCode.endsWith(".png") ? "" : ".png")); + if (flagImage != null) { + + if (height > 11) { + int width = Math.round(height * flagImage.getWidth(null) / flagImage.getHeight(null)); + BufferedImage resized = ImageHelper.scale((BufferedImage) flagImage, BufferedImage.TYPE_4BYTE_ABGR, width, height); + flagIcon = new ImageIcon(resized); + } else { + flagIcon = new ImageIcon(flagImage); + } + } + return flagIcon; + } + public static void changeGUISize() { FLAG_ICON_CACHE.clear(); }