Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- From fd97d181881b009f1762c6438807c59e9effaa16 Mon Sep 17 00:00:00 2001
- From: "Seth N. Hetu" <seth.hetu@gmail.com>
- Date: Tue, 9 Sep 2014 16:11:53 -0400
- Subject: [PATCH] Fix for 256x256 game icons; scaled GUI instances to 32x32 if
- larger than that.
- ---
- org/lateralgm/file/iconio/BitmapDescriptor.java | 4 +++
- org/lateralgm/subframes/GameSettingFrame.java | 37 +++++++++++++++++++------
- 2 files changed, 33 insertions(+), 8 deletions(-)
- diff --git a/org/lateralgm/file/iconio/BitmapDescriptor.java b/org/lateralgm/file/iconio/BitmapDescriptor.java
- index cc0a012..d1fe262 100644
- --- a/org/lateralgm/file/iconio/BitmapDescriptor.java
- +++ b/org/lateralgm/file/iconio/BitmapDescriptor.java
- @@ -51,6 +51,10 @@ public class BitmapDescriptor
- width = pDec.read();
- height = pDec.read();
- colorCount = pDec.read();
- +
- + //Fix for 256 w/h, which is specified in .ico files as 0.
- + if (width==0) { width=256; }
- + if (height==0) { height=256; }
- reserved = pDec.read();
- planes = pDec.read2();
- diff --git a/org/lateralgm/subframes/GameSettingFrame.java b/org/lateralgm/subframes/GameSettingFrame.java
- index b6ff207..19aaf20 100644
- --- a/org/lateralgm/subframes/GameSettingFrame.java
- +++ b/org/lateralgm/subframes/GameSettingFrame.java
- @@ -16,9 +16,12 @@ import static java.lang.Integer.MAX_VALUE;
- import static javax.swing.GroupLayout.DEFAULT_SIZE;
- import static javax.swing.GroupLayout.PREFERRED_SIZE;
- +import java.awt.Graphics2D;
- import java.awt.Image;
- +import java.awt.Point;
- import java.awt.event.ActionEvent;
- import java.awt.event.KeyEvent;
- +import java.awt.geom.AffineTransform;
- import java.awt.image.BufferedImage;
- import java.io.File;
- import java.io.FileInputStream;
- @@ -345,6 +348,28 @@ public class GameSettingFrame extends ResourceFrame<GameSettings,PGameSettings>
- public NumberField gameId;
- public JButton randomise;
- private CustomFileChooser iconFc;
- +
- + private static BufferedImage scale_image(BufferedImage src, int imgType, int destWidth, int destHeight) {
- + if(src == null) { return null; }
- + BufferedImage dest = new BufferedImage(destWidth, destHeight, imgType);
- + Graphics2D g = dest.createGraphics();
- + AffineTransform at = AffineTransform.getScaleInstance(destWidth/((float)src.getWidth()), destHeight/((float)src.getHeight()));
- + g.drawRenderedImage(src, at);
- + return dest;
- + }
- +
- + private void setIconPreviewToGameIcon() {
- + BufferedImage src = null;
- + if (gameIcon != null) {
- + src = (BufferedImage)gameIcon.getDisplayImage();
- + if (src!=null) {
- + if (src.getWidth()>32 || src.getHeight()>32) {
- + src = scale_image((BufferedImage)src, BufferedImage.TYPE_INT_ARGB, 32, 32);
- + }
- + }
- + }
- + iconPreview.setIcon(new ImageIcon(src));
- + }
- private JPanel makeLoadingPane()
- {
- @@ -435,8 +460,8 @@ public class GameSettingFrame extends ResourceFrame<GameSettings,PGameSettings>
- gameIcon = res.properties.get(PGameSettings.GAME_ICON);
- iconPreview = new JLabel(Messages.getString("GameSettingFrame.GAME_ICON")); //$NON-NLS-1$
- - if (gameIcon != null) iconPreview.setIcon(new ImageIcon(gameIcon.getDisplayImage()));
- -
- + setIconPreviewToGameIcon();
- +
- iconPreview.setHorizontalTextPosition(SwingConstants.LEFT);
- changeIcon = new JButton(Messages.getString("GameSettingFrame.CHANGE_ICON")); //$NON-NLS-1$
- changeIcon.addActionListener(this);
- @@ -795,7 +820,7 @@ public class GameSettingFrame extends ResourceFrame<GameSettings,PGameSettings>
- if (f.exists()) try
- {
- gameIcon = new ICOFile(new FileInputStream(f));
- - iconPreview.setIcon(new ImageIcon(gameIcon.getDisplayImage()));
- + setIconPreviewToGameIcon();
- imagesChanged = true;
- }
- catch (FileNotFoundException e1)
- @@ -842,11 +867,7 @@ public class GameSettingFrame extends ResourceFrame<GameSettings,PGameSettings>
- backLoadImage = g.get(PGameSettings.BACK_LOAD_BAR);
- frontLoadImage = g.get(PGameSettings.FRONT_LOAD_BAR);
- gameIcon = g.get(PGameSettings.GAME_ICON);
- - Image icoimg = gameIcon.getDisplayImage();
- - if (icoimg != null)
- - {
- - iconPreview.setIcon(new ImageIcon(icoimg));
- - }
- + setIconPreviewToGameIcon();
- imagesChanged = true;
- }
- --
- 1.9.1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement