Skip to content

Commit

Permalink
#38 Fixing scrolled/scaled rendering issue
Browse files Browse the repository at this point in the history
  • Loading branch information
defano committed Apr 20, 2019
1 parent 82ea313 commit 24ade4e
Showing 1 changed file with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ public void setScale(double scale) {
@Override
public void repaint(Rectangle r) {

// Sub-region repainting not available when scanlines are rendered; must repaint entire surface
if (r == null || isScanlinesVisible()) {
// Sub-region repainting not available zoomed in
if (r == null || getScale() > 1) {
super.repaint();
}

Expand Down Expand Up @@ -235,6 +235,12 @@ public void paintComponent(Graphics g) {
Rectangle clip = g.getClipBounds();
if (clip != null && !clip.isEmpty() && isVisible()) {

// Draw the surface background
if (getCanvasBackground() != null) {
((Graphics2D) g).setPaint(getCanvasBackground());
g.fillRect(clip.x, clip.y, clip.width, clip.height);
}

// Draw visible portion of this surface's image into a buffer (does not modify this graphics context)
BufferedImage buffer = new BufferedImage(clip.width, clip.height, BufferedImage.TYPE_INT_ARGB);
GraphicsContext g2d = new AwtGraphicsContext(buffer.createGraphics());
Expand All @@ -244,12 +250,6 @@ public void paintComponent(Graphics g) {
paintScanlines(g2d, getScaledSurfaceDimension());
g2d.dispose();

// Draw the surface background
if (getCanvasBackground() != null) {
((Graphics2D) g).setPaint(getCanvasBackground());
g.fillRect(clip.x, clip.y, clip.width, clip.height);
}

// Draw the paint image
g.drawImage(buffer, clip.x, clip.y, clip.width, clip.height, null);
}
Expand Down

0 comments on commit 24ade4e

Please sign in to comment.