Some more changes to GUI to better support high screen resolutions.

This commit is contained in:
LevelX2 2016-02-13 02:30:05 +01:00
parent 1c2faaadde
commit 7ef0a0a7f0
31 changed files with 745 additions and 518 deletions

View file

@ -1,101 +0,0 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package mage.client.util;
import java.awt.Font;
import mage.client.MageFrame;
import mage.client.dialog.PreferencesDialog;
/**
*
* @author LevelX2
*/
public class FontSizeHelper {
public static String basicSymbolSize = "small";
public static int symbolCardSize = 15;
public static int symbolTooltipSize = 15;
public static int symbolPaySize = 15;
public static int symbolEditorSize = 15;
public static int tableHeaderHeight = 24;
public static int tableRowHeight = 20;
public static int dividerBarSize;
public static int scrollBarSize;
public static Font tooltipFont = new java.awt.Font("Arial", 0, 12);
public static Font menuFont = new java.awt.Font("Arial", 0, 12);
public static Font gameDialogAreaFontBig = new java.awt.Font("Arial", 0, 12);
public static Font gameDialogAreaFontSmall = new java.awt.Font("Arial", 0, 12);
public static Font getChatFont() {
int fontSize = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GUI_FONT_SIZE, 14);
return new java.awt.Font("Arial", 0, fontSize);
}
public static Font getTableFont() {
int fontSize = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GUI_FONT_SIZE, 14);
return new java.awt.Font("Arial", 0, fontSize);
}
public static Font getToolbarFont() {
int fontSize = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GUI_FONT_SIZE, 14);
return new java.awt.Font("Arial", 0, fontSize);
}
public static int getTableRowHeight() {
int fontSize = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GUI_FONT_SIZE, 14);
return fontSize + 6;
}
public static Font getTabFont() {
int fontSize = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GUI_FONT_SIZE, 14);
return new java.awt.Font("Arial", 0, fontSize);
}
public static void changeGUISize() {
calculateGUISizes();
MageFrame.getInstance().changeGUISize();
}
public static void calculateGUISizes() {
// Set basic symbol size
int fontSize = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GUI_FONT_SIZE, 14);
if (fontSize < 25) {
basicSymbolSize = "small";
} else if (fontSize < 45) {
basicSymbolSize = "medium";
} else {
basicSymbolSize = "large";
}
if (fontSize > 15) {
symbolTooltipSize = fontSize - 5;
symbolEditorSize = fontSize - 5;
symbolPaySize = fontSize - 5;
symbolCardSize = 15;
dividerBarSize = 10 + (fontSize / 4);
scrollBarSize = 14 + (fontSize / 4);
} else {
symbolTooltipSize = fontSize;
symbolEditorSize = fontSize;
symbolPaySize = fontSize;
symbolCardSize = 15;
dividerBarSize = 10;
scrollBarSize = 14;
}
tooltipFont = new java.awt.Font("Arial", 0, fontSize - 2);
// used for popup menus
menuFont = new java.awt.Font("Arial", 0, fontSize);
tableRowHeight = fontSize + 4;
tableHeaderHeight = fontSize + 10;
}
}

View file

@ -0,0 +1,117 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package mage.client.util;
import java.awt.Dimension;
import java.awt.Font;
import mage.client.MageFrame;
import mage.client.dialog.PreferencesDialog;
/**
*
* @author LevelX2
*/
public class GUISizeHelper {
// relate the native image card size to a value of the size scale
final static int CARD_IMAGE_WIDTH = 312;
final static int CARD_IMAGE_HEIGHT = 445;
final static int CARD_IMAG_VALUE = 42;
public static String basicSymbolSize = "small";
public static int symbolCardSize = 15;
public static int symbolTooltipSize = 15;
public static int symbolPaySize = 15;
public static int symbolEditorSize = 15;
public static int tableHeaderHeight = 24;
public static int tableRowHeight = 20;
public static int dividerBarSize;
public static int scrollBarSize;
public static int flagHeight;
public static Font chatFont = new java.awt.Font("Arial", 0, 12);
public static Font tableFont = new java.awt.Font("Arial", 0, 12);
public static Font tooltipFont = new java.awt.Font("Arial", 0, 12);
public static Font menuFont = new java.awt.Font("Arial", 0, 12);
public static Font gameDialogAreaFontBig = new java.awt.Font("Arial", 0, 12);
public static Font gameDialogAreaFontSmall = new java.awt.Font("Arial", 0, 12);
public static Dimension handCardDimension;
public static Font getToolbarFont() {
int fontSize = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GUI_TABLE_FONT_SIZE, 14);
return new java.awt.Font("Arial", 0, fontSize);
}
public static int getTableRowHeight() {
int fontSize = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GUI_TABLE_FONT_SIZE, 14);
return fontSize + 6;
}
public static Font getTabFont() {
int fontSize = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GUI_TABLE_FONT_SIZE, 14);
return new java.awt.Font("Arial", 0, fontSize);
}
public static void changeGUISize() {
calculateGUISizes();
MageFrame.getInstance().changeGUISize();
}
public static void calculateGUISizes() {
int tableFontSize = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GUI_TABLE_FONT_SIZE, 14);
tableFont = new java.awt.Font("Arial", 0, tableFontSize);
tableRowHeight = tableFontSize + 4;
tableHeaderHeight = tableFontSize + 10;
tooltipFont = new java.awt.Font("Arial", 0, tableFontSize - 2);
// used for popup menus
menuFont = new java.awt.Font("Arial", 0, tableFontSize);
int chatFontSize = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GUI_CHAT_FONT_SIZE, 14);
chatFont = new java.awt.Font("Arial", 0, chatFontSize);
// Set basic symbol size
if (tableFontSize > 24) {
flagHeight = tableFontSize - 4;
} else {
flagHeight = 11;
}
if (tableFontSize < 25) {
basicSymbolSize = "small";
} else if (tableFontSize < 45) {
basicSymbolSize = "medium";
} else {
basicSymbolSize = "large";
}
if (tableFontSize > 15) {
symbolTooltipSize = tableFontSize - 5;
symbolEditorSize = tableFontSize - 5;
symbolPaySize = tableFontSize - 5;
symbolCardSize = 15;
dividerBarSize = 10 + (tableFontSize / 4);
scrollBarSize = 14 + (tableFontSize / 4);
} else {
symbolTooltipSize = tableFontSize;
symbolEditorSize = tableFontSize;
symbolPaySize = tableFontSize;
symbolCardSize = 15;
dividerBarSize = 10;
scrollBarSize = 14;
}
int handCardSize = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GUI_CARD_HAND_SIZE, 14);
int width = CARD_IMAGE_WIDTH * handCardSize / 42;
int height = CARD_IMAGE_HEIGHT * handCardSize / 42;
handCardDimension = new Dimension(width, height);
}
}

View file

@ -24,8 +24,7 @@
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
*/
package mage.client.util;
import com.mortennobel.imagescaling.ResampleOp;
@ -37,6 +36,7 @@ import java.awt.Image;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.Transparency;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.awt.image.ImageObserver;
import java.awt.image.MemoryImageSource;
@ -58,6 +58,7 @@ import org.mage.card.arcane.UI;
* @author BetaSteward_at_googlemail.com
*/
public class ImageHelper {
protected static HashMap<String, BufferedImage> images = new HashMap<>();
protected static HashMap<String, BufferedImage> backgrounds = new HashMap<>();
@ -73,7 +74,8 @@ public class ImageHelper {
*
* @param ref - image name
* @param height - height after scaling
* @return a scaled image that preserves the original aspect ratio, with a specified height
* @return a scaled image that preserves the original aspect ratio, with a
* specified height
*/
public static BufferedImage loadImage(String ref, int height) {
BufferedImage image = loadImage(ref);
@ -104,7 +106,6 @@ public class ImageHelper {
return background;
}
public static BufferedImage scaleImage(BufferedImage image, int width, int height) {
BufferedImage scaledImage = image;
int w = image.getWidth();
@ -127,7 +128,7 @@ public class ImageHelper {
}
public static BufferedImage scaleImage(BufferedImage image, int height) {
double ratio = height / (double)image.getHeight();
double ratio = height / (double) image.getHeight();
int width = (int) (image.getWidth() * ratio);
return scaleImage(image, width, height);
}
@ -138,13 +139,12 @@ public class ImageHelper {
PixelGrabber grabber = new PixelGrabber(image, 0, 0, dimensions.frameWidth, dimensions.frameHeight, buffer, 0, dimensions.frameWidth);
try {
grabber.grabPixels();
}
catch(InterruptedException e) {
} catch (InterruptedException e) {
e.printStackTrace();
}
for(int y = 0; y < dimensions.frameHeight; y++) {
for(int x = 0; x < dimensions.frameWidth; x++) {
rotate[((dimensions.frameWidth - x - 1) *dimensions.frameHeight)+y] = buffer[(y*dimensions.frameWidth)+x];
for (int y = 0; y < dimensions.frameHeight; y++) {
for (int x = 0; x < dimensions.frameWidth; x++) {
rotate[((dimensions.frameWidth - x - 1) * dimensions.frameHeight) + y] = buffer[(y * dimensions.frameWidth) + x];
}
}
@ -155,7 +155,7 @@ public class ImageHelper {
public static BufferedImage rotate(BufferedImage image, double angle) {
double sin = Math.abs(Math.sin(angle)), cos = Math.abs(Math.cos(angle));
int w = image.getWidth(), h = image.getHeight();
int neww = (int)Math.floor(w*cos+h*sin), newh = (int)Math.floor(h*cos+w*sin);
int neww = (int) Math.floor(w * cos + h * sin), newh = (int) Math.floor(h * cos + w * sin);
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gs = ge.getDefaultScreenDevice();
@ -163,8 +163,8 @@ public class ImageHelper {
BufferedImage result = gc.createCompatibleImage(neww, newh, Transparency.TRANSLUCENT);
Graphics2D g = result.createGraphics();
g.translate((neww-w)/2, (newh-h)/2);
g.rotate(angle, w/2, h/2);
g.translate((neww - w) / 2, (newh - h) / 2);
g.rotate(angle, w / 2, h / 2);
g.drawRenderedImage(image, null);
g.dispose();
return result;
@ -184,6 +184,7 @@ public class ImageHelper {
/**
* Returns an image scaled to the size appropriate for the card picture
* panel
*
* @param original
* @param width
* @param height
@ -196,8 +197,8 @@ public class ImageHelper {
}
/**
* Returns an image scaled to fit width
* panel
* Returns an image scaled to fit width panel
*
* @param original
* @param width
* @return
@ -212,8 +213,32 @@ public class ImageHelper {
}
}
/**
* scale image
*
* @param sbi image to scale
* @param imageType type of image
* @param dWidth width of destination image
* @param dHeight height of destination image
* @return scaled image
*/
public static BufferedImage scale(BufferedImage sbi, int imageType, int dWidth, int dHeight) {
BufferedImage dbi = null;
if (sbi != null) {
double fWidth = dWidth / sbi.getWidth();
double fHeight = dHeight / sbi.getHeight();
dbi = new BufferedImage(dWidth, dHeight, imageType);
Graphics2D g = dbi.createGraphics();
AffineTransform at = AffineTransform.getScaleInstance(fWidth, fHeight);
g.drawRenderedImage(sbi, at);
g.dispose();
}
return dbi;
}
/**
* Returns an image scaled to the needed size
*
* @param original
* @param sizeNeed
* @return
@ -226,6 +251,7 @@ public class ImageHelper {
/**
* Get image using relative path in resources.
*
* @param path
* @return
*/

View file

@ -5,10 +5,13 @@
*/
package mage.client.util.gui.countryBox;
import java.net.URL;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.util.HashMap;
import java.util.Map;
import javax.swing.ImageIcon;
import mage.client.util.GUISizeHelper;
import mage.client.util.ImageHelper;
import org.apache.log4j.Logger;
/**
@ -17,33 +20,44 @@ import org.apache.log4j.Logger;
*/
public class CountryUtil {
private static final Logger logger = Logger.getLogger(CountryUtil.class);
private static final Map<String, ImageIcon> flagIconCache = new HashMap<>();
private static final Map<String, String> countryMap = new HashMap<>();
private static final Logger LOGGER = Logger.getLogger(CountryUtil.class);
private static final Map<String, ImageIcon> FLAG_ICON_CACHE = new HashMap<>();
private static final Map<String, String> COUNTRY_MAP = new HashMap<>();
public static ImageIcon getCountryFlagIcon(String countryCode) {
ImageIcon flagIcon = flagIconCache.get(countryCode);
ImageIcon flagIcon = FLAG_ICON_CACHE.get(countryCode);
if (flagIcon == null) {
URL url = CountryUtil.class.getResource("/flags/" + countryCode + (countryCode.endsWith(".png") ? "" : ".png"));
if (url != null) {
flagIcon = new javax.swing.ImageIcon(url);
// 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) {
int width = Math.round(GUISizeHelper.flagHeight * flagImage.getWidth(null) / flagImage.getHeight(null));
BufferedImage resized = ImageHelper.scale((BufferedImage) flagImage, BufferedImage.TYPE_4BYTE_ABGR, width, GUISizeHelper.flagHeight);
flagIcon = new ImageIcon(resized);
} else {
flagIcon = new ImageIcon(flagImage);
}
}
if (flagIcon == null || flagIcon.getImage() == null) {
logger.warn("Country flag resource not found: " + countryCode);
flagIconCache.put(countryCode, flagIcon);
LOGGER.warn("Country flag resource not found: " + countryCode);
FLAG_ICON_CACHE.put(countryCode, flagIcon);
} else {
flagIconCache.put(countryCode, flagIcon);
FLAG_ICON_CACHE.put(countryCode, flagIcon);
}
}
return flagIcon;
}
public static void changeGUISize() {
FLAG_ICON_CACHE.clear();
}
public static String getCountryName(String countryCode) {
if (countryMap.isEmpty()) {
if (COUNTRY_MAP.isEmpty()) {
for (int i = 0; i <= CountryComboBox.countryList.length - 1; i++) {
countryMap.put(CountryComboBox.countryList[i][1], CountryComboBox.countryList[i][0]);
COUNTRY_MAP.put(CountryComboBox.countryList[i][1], CountryComboBox.countryList[i][0]);
}
}
return countryMap.get(countryCode);
return COUNTRY_MAP.get(countryCode);
}
}