Advertisement
Guest User

0001-Fix-for-256x256-game-icons-scaled-GUI-instances-to-3.pa

a guest
Sep 9th, 2014
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.17 KB | None | 0 0
  1. From fd97d181881b009f1762c6438807c59e9effaa16 Mon Sep 17 00:00:00 2001
  2. From: "Seth N. Hetu" <seth.hetu@gmail.com>
  3. Date: Tue, 9 Sep 2014 16:11:53 -0400
  4. Subject: [PATCH] Fix for 256x256 game icons; scaled GUI instances to 32x32 if
  5. larger than that.
  6.  
  7. ---
  8. org/lateralgm/file/iconio/BitmapDescriptor.java | 4 +++
  9. org/lateralgm/subframes/GameSettingFrame.java | 37 +++++++++++++++++++------
  10. 2 files changed, 33 insertions(+), 8 deletions(-)
  11.  
  12. diff --git a/org/lateralgm/file/iconio/BitmapDescriptor.java b/org/lateralgm/file/iconio/BitmapDescriptor.java
  13. index cc0a012..d1fe262 100644
  14. --- a/org/lateralgm/file/iconio/BitmapDescriptor.java
  15. +++ b/org/lateralgm/file/iconio/BitmapDescriptor.java
  16. @@ -51,6 +51,10 @@ public class BitmapDescriptor
  17. width = pDec.read();
  18. height = pDec.read();
  19. colorCount = pDec.read();
  20. +
  21. + //Fix for 256 w/h, which is specified in .ico files as 0.
  22. + if (width==0) { width=256; }
  23. + if (height==0) { height=256; }
  24.  
  25. reserved = pDec.read();
  26. planes = pDec.read2();
  27. diff --git a/org/lateralgm/subframes/GameSettingFrame.java b/org/lateralgm/subframes/GameSettingFrame.java
  28. index b6ff207..19aaf20 100644
  29. --- a/org/lateralgm/subframes/GameSettingFrame.java
  30. +++ b/org/lateralgm/subframes/GameSettingFrame.java
  31. @@ -16,9 +16,12 @@ import static java.lang.Integer.MAX_VALUE;
  32. import static javax.swing.GroupLayout.DEFAULT_SIZE;
  33. import static javax.swing.GroupLayout.PREFERRED_SIZE;
  34.  
  35. +import java.awt.Graphics2D;
  36. import java.awt.Image;
  37. +import java.awt.Point;
  38. import java.awt.event.ActionEvent;
  39. import java.awt.event.KeyEvent;
  40. +import java.awt.geom.AffineTransform;
  41. import java.awt.image.BufferedImage;
  42. import java.io.File;
  43. import java.io.FileInputStream;
  44. @@ -345,6 +348,28 @@ public class GameSettingFrame extends ResourceFrame<GameSettings,PGameSettings>
  45. public NumberField gameId;
  46. public JButton randomise;
  47. private CustomFileChooser iconFc;
  48. +
  49. + private static BufferedImage scale_image(BufferedImage src, int imgType, int destWidth, int destHeight) {
  50. + if(src == null) { return null; }
  51. + BufferedImage dest = new BufferedImage(destWidth, destHeight, imgType);
  52. + Graphics2D g = dest.createGraphics();
  53. + AffineTransform at = AffineTransform.getScaleInstance(destWidth/((float)src.getWidth()), destHeight/((float)src.getHeight()));
  54. + g.drawRenderedImage(src, at);
  55. + return dest;
  56. + }
  57. +
  58. + private void setIconPreviewToGameIcon() {
  59. + BufferedImage src = null;
  60. + if (gameIcon != null) {
  61. + src = (BufferedImage)gameIcon.getDisplayImage();
  62. + if (src!=null) {
  63. + if (src.getWidth()>32 || src.getHeight()>32) {
  64. + src = scale_image((BufferedImage)src, BufferedImage.TYPE_INT_ARGB, 32, 32);
  65. + }
  66. + }
  67. + }
  68. + iconPreview.setIcon(new ImageIcon(src));
  69. + }
  70.  
  71. private JPanel makeLoadingPane()
  72. {
  73. @@ -435,8 +460,8 @@ public class GameSettingFrame extends ResourceFrame<GameSettings,PGameSettings>
  74.  
  75. gameIcon = res.properties.get(PGameSettings.GAME_ICON);
  76. iconPreview = new JLabel(Messages.getString("GameSettingFrame.GAME_ICON")); //$NON-NLS-1$
  77. - if (gameIcon != null) iconPreview.setIcon(new ImageIcon(gameIcon.getDisplayImage()));
  78. -
  79. + setIconPreviewToGameIcon();
  80. +
  81. iconPreview.setHorizontalTextPosition(SwingConstants.LEFT);
  82. changeIcon = new JButton(Messages.getString("GameSettingFrame.CHANGE_ICON")); //$NON-NLS-1$
  83. changeIcon.addActionListener(this);
  84. @@ -795,7 +820,7 @@ public class GameSettingFrame extends ResourceFrame<GameSettings,PGameSettings>
  85. if (f.exists()) try
  86. {
  87. gameIcon = new ICOFile(new FileInputStream(f));
  88. - iconPreview.setIcon(new ImageIcon(gameIcon.getDisplayImage()));
  89. + setIconPreviewToGameIcon();
  90. imagesChanged = true;
  91. }
  92. catch (FileNotFoundException e1)
  93. @@ -842,11 +867,7 @@ public class GameSettingFrame extends ResourceFrame<GameSettings,PGameSettings>
  94. backLoadImage = g.get(PGameSettings.BACK_LOAD_BAR);
  95. frontLoadImage = g.get(PGameSettings.FRONT_LOAD_BAR);
  96. gameIcon = g.get(PGameSettings.GAME_ICON);
  97. - Image icoimg = gameIcon.getDisplayImage();
  98. - if (icoimg != null)
  99. - {
  100. - iconPreview.setIcon(new ImageIcon(icoimg));
  101. - }
  102. + setIconPreviewToGameIcon();
  103. imagesChanged = true;
  104. }
  105.  
  106. --
  107. 1.9.1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement