Cache inset offsets used to translate Graphics2D object.

This commit is contained in:
Jan Philipp Timme 2014-11-12 11:20:27 +01:00
parent 61b80ff49e
commit c5b76fbdf9
1 changed files with 17 additions and 1 deletions

View File

@ -38,6 +38,17 @@ public class GameFrame extends JFrame {
*/
private long frameTime;
/**
* Amount of pixels taken away from window decoration on the left side.
*/
private int insetLeft;
/**
* Amount of pixels taken away from window decoration on the top side.
*/
private int insetTop;
/**
* Default constructor.
*/
@ -78,6 +89,11 @@ public class GameFrame extends JFrame {
//prepare the buffered strategy
this.createBufferStrategy(2);
this.bufferStrategy = this.getBufferStrategy();
//Measure and cache inset offsets for continuous use in the draw() method.
//This way, we translate our 0x0 to the first top left pixel that is actually visible.
this.insetLeft = this.getInsets().left;
this.insetTop = this.getInsets().top;
}
/**
@ -121,7 +137,7 @@ public class GameFrame extends JFrame {
this.applyRenderingHints(bufferedGraphics);
//Apply translation since different platforms use different window decorations that mess
//up our coordinates. The new origin shall be the first usable pixel in the top left corner.
bufferedGraphics.translate(this.getInsets().left, this.getInsets().top);
bufferedGraphics.translate(this.insetLeft, this.insetTop);
this.superScreen.doPaint(bufferedGraphics); //Trigger the actual paint routines.
} catch (Exception e) {
System.err.println("Exception in GameFrame.draw() gefangen:");