Skip to content

Commit

Permalink
Area viewer: Fixed several issues
Browse files Browse the repository at this point in the history
- fixed some graphical glitches when running low on memory
- added work-around for known Java bug in Swing's layout managers
  • Loading branch information
Argent77 committed Mar 9, 2014
1 parent 85116bb commit 15f1b01
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
6 changes: 6 additions & 0 deletions src/infinity/NearInfinity.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@

public final class NearInfinity extends JFrame implements ActionListener, ViewableContainer
{
static {
// XXX: Works around a known bug in Java's Swing layouts when using FocusTraversalPolicy
// Note: Required for Area Viewer's JTree control; must be set before executing main()
System.setProperty("java.util.Arrays.useLegacyMergeSort", "true");
}

private static final int[] JAVA_VERSION = {1, 6}; // the minimum java version supported

private static final JTextArea consoletext = new JTextArea();
Expand Down
6 changes: 0 additions & 6 deletions src/infinity/gui/layeritem/AnimatedLayerItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,6 @@
* Represents a game resource structure visually as a bitmap animation.
* @author argent77
*/
/*
* TODO: Add proper support for mirrored animations (mirrored on Y axis)
* - sprites are already mirrored correctly
* - center position has yet to be mirrored
* Example map using mirrored animationsL AR3016
*/
public class AnimatedLayerItem extends AbstractLayerItem implements LayerItemListener, ActionListener
{
// lookup table for alpha transparency on blended animations
Expand Down
31 changes: 20 additions & 11 deletions src/infinity/resource/are/viewer/TilesetRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsEnvironment;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferInt;
Expand Down Expand Up @@ -493,6 +495,21 @@ public void reload(boolean force)
updateDisplay(b || force);
}

@Override
public void paint(Graphics g)
{
// checking whether VolatileImage instance needs to be updated
if (getImage() != null && getImage() instanceof VolatileImage) {
VolatileImage image = (VolatileImage)getImage();
GraphicsConfiguration gc =
GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
if (image.validate(gc) == VolatileImage.IMAGE_RESTORED) {
updateDisplay(true);
}
}
super.paint(g);
}

protected void updateSize()
{
if (isInitialized()) {
Expand Down Expand Up @@ -536,17 +553,9 @@ protected void paintCanvas(Graphics g)
private boolean updateImageSize()
{
if (isInitialized()) {
Image curImg = getImage();
if (curImg == null || curImg.getWidth(null) != getMapWidth(false) ||
curImg.getHeight(null) != getMapHeight(false)) {
if (curImg != null) {
curImg = null;
}
Image newImg = ColorConvert.createVolatileImage(getMapWidth(false), getMapHeight(false), false);
if (newImg == null) {
return false;
}
setImage(newImg);
if (getImage() == null || getImage().getWidth(null) != getMapWidth(false) ||
getImage().getHeight(null) != getMapHeight(false)) {
setImage(ColorConvert.createVolatileImage(getMapWidth(false), getMapHeight(false), false));
}
updateSize();
return true;
Expand Down

0 comments on commit 15f1b01

Please sign in to comment.