Fix rendering of scaled images

This commit is contained in:
drdev
2013-09-04 00:18:06 +00:00
parent 9f6f9ce7bb
commit fc5230a9b9
2 changed files with 21 additions and 15 deletions

View File

@@ -365,10 +365,6 @@ public class FLabel extends JLabel implements ILocalRepaint {
} }
}; };
public void setIcon(FSkin.SkinImage icon) {
this.skin.setIcon(icon);
}
//========== Methods //========== Methods
/** @param b0   boolean */ /** @param b0   boolean */
// Must be public. // Must be public.
@@ -447,22 +443,32 @@ public class FLabel extends JLabel implements ILocalRepaint {
return this.cmdRightClick; return this.cmdRightClick;
} }
public void setIcon(FSkin.SkinImage icon) {
this.skin.setIcon(icon);
}
@Override @Override
// Must be public. // Must be public.
public void setIcon(final Icon i0) { public void setIcon(final Icon i0) {
if (i0 == null) { this.img = null; return; }
// Will need image (not icon) for scaled and non-scaled. // Will need image (not icon) for scaled and non-scaled.
if (iconInBackground) { this.img = ((ImageIcon) i0).getImage(); }
// Will need image if not in background, but scaled. // Will need image if not in background, but scaled.
else if (iconScaleAuto) { this.img = ((ImageIcon) i0).getImage(); } if (iconInBackground || iconScaleAuto) {
// If not in background, not scaled, can use original icon. if (i0 != null) {
else { super.setIcon(i0); } img = ((ImageIcon) i0).getImage();
if (img != null) {
iw = img.getWidth(null); iw = img.getWidth(null);
ih = img.getHeight(null); ih = img.getHeight(null);
iar = ((double) iw) / ((double) ih); iar = ((double) iw) / ((double) ih);
} }
else {
img = null;
iw = 0;
ih = 0;
iar = 0;
}
}
else { // If not in background, not scaled, can use original icon.
super.setIcon(i0);
}
} }
/** @param c0   {@link forge.Command} on click */ /** @param c0   {@link forge.Command} on click */

View File

@@ -855,7 +855,7 @@ public enum FSkin {
final Graphics2D g2d = resizedImage.createGraphics(); final Graphics2D g2d = resizedImage.createGraphics();
g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g2d.drawImage(baseImage.image, 0, 0, w0, h0, 0, 0, baseImage.getWidth(), baseImage.getHeight(), null); g2d.drawImage(baseImage.image, 0, 0, w, h, 0, 0, baseImage.getWidth(), baseImage.getHeight(), null);
g2d.dispose(); g2d.dispose();
this.changeImage(resizedImage, null); this.changeImage(resizedImage, null);