Fixes issue where tiles wouldn't be rendered on the first draw call, due to multiple draw calls happening in very quick succession.
@@ -48,6 +48,8 @@ public class Screen {
private boolean isInFullScreenExclusiveMode = false;
+ private boolean hasFirstRenderCompleted = false;
+
/**
* Constructs a new 80x40 Screen with the 18pt DejaVu Sans Mono font.
*
@@ -172,18 +174,24 @@ public class Screen {
frame.addComponentListener(new ComponentListener() {
@Override
public void componentResized(final ComponentEvent e) {
+ if (hasFirstRenderCompleted) {
draw();
}
+ }
@Override
public void componentMoved(final ComponentEvent e) {
+ if (hasFirstRenderCompleted) {
draw();
}
+ }
@Override
public void componentShown(final ComponentEvent e) {
+ if (hasFirstRenderCompleted) {
draw();
}
+ }
@Override
public void componentHidden(final ComponentEvent e) {}
@@ -192,8 +200,10 @@ public class Screen {
frame.addWindowFocusListener(new WindowFocusListener() {
@Override
public void windowGainedFocus(final WindowEvent e) {
+ if (hasFirstRenderCompleted) {
draw();
}
+ }
@Override
public void windowLostFocus(final WindowEvent e) {}
@@ -202,8 +212,10 @@ public class Screen {
frame.addWindowListener(new WindowListener() {
@Override
public void windowOpened(final WindowEvent e) {
+ if (hasFirstRenderCompleted) {
draw();
}
+ }
@Override
public void windowClosing(final WindowEvent e) {}
@@ -216,13 +228,17 @@ public class Screen {
@Override
public void windowDeiconified(final WindowEvent e) {
+ if (hasFirstRenderCompleted) {
draw();
}
+ }
@Override
public void windowActivated(final WindowEvent e) {
+ if (hasFirstRenderCompleted) {
draw();
}
+ }
@Override
public void windowDeactivated(final WindowEvent e) {}
@@ -409,7 +425,7 @@ public class Screen {
final boolean hashChanged = (positionHashes_previous[x][y] != positionHashes_current[x][y]);
final boolean notYetRendered = (positionHashes_previous[x][y] == 0);
- if (notYetRendered || hashChanged) {
+ if (hasFirstRenderCompleted == false || notYetRendered || hashChanged) {
tiles.getTileAt(x, y).draw(gc, imageCache, xPosition, yPosition);
// Draw all of component tiles that overlap the current position.
@@ -452,6 +468,8 @@ public class Screen {
bs.show();
} while (bs.contentsLost()); // Repeat render if drawing buffer was lost.
+
+ hasFirstRenderCompleted = true;
}
/**
