Skip to content

Commit

Permalink
Scroll redraw on Windows lead to drawing artifacts
Browse files Browse the repository at this point in the history
The reworked scrolling of the FigureCanvas didn't correctly calculated
the exposure areas which need to be redrawn after scrolling. This led to
drawing artifacts.
  • Loading branch information
azoitl committed Apr 10, 2024
1 parent 838d9d5 commit 8fafd3c
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions org.eclipse.draw2d/src/org/eclipse/draw2d/FigureCanvas.java
Original file line number Diff line number Diff line change
Expand Up @@ -411,24 +411,20 @@ private void performScroll(int hOffset, int vOffset) {
int dy = -vOffset + getViewport().getViewLocation().y;
Rectangle clientArea = getViewport().getBounds().getShrinked(getViewport().getInsets());
Rectangle blit = clientArea.getResized(-Math.abs(dx), -Math.abs(dy));
Rectangle expose = clientArea.getCopy();
Point dest = clientArea.getTopLeft();

expose.width = Math.abs(dx);
blit.width = Math.max(blit.width, 0);
blit.height = Math.max(blit.height, 0);

if (dx < 0) { // Moving left?
blit.translate(-dx, 0); // Move blit area to the right
expose.x = dest.x + blit.width;
} else {
// Moving right
} else { // Moving right
dest.x += dx; // Move expose area to the right
}

expose.height = Math.abs(dy);
if (dy < 0) { // Moving up?
blit.translate(0, -dy); // Move blit area down
expose.y = dest.y + blit.height; // Move expose area down
} else {
// Moving down
} else { // Moving down
dest.y += dy;
}

Expand All @@ -438,7 +434,7 @@ private void performScroll(int hOffset, int vOffset) {
getViewport().setHorizontalLocation(hOffset);
getViewport().setVerticalLocation(vOffset);
getViewport().setIgnoreScroll(false);
redraw(expose.x, expose.y, expose.width, expose.height, true);
scrollRedraw(dx, dy, clientArea, blit);
}

private void scrollChildren(int dx, int dy, Rectangle blit, Point dest) {
Expand All @@ -462,6 +458,26 @@ private void scrollChildren(int dx, int dy, Rectangle blit, Point dest) {
}
}

private void scrollRedraw(int dx, int dy, Rectangle clientArea, Rectangle blit) {
Rectangle expose = clientArea.getCopy();
if (dx != 0) {
expose.width = Math.abs(dx);
if (dx < 0) { // Moving left?
expose.x += blit.width; // Move expose area right
}
redraw(expose.x, expose.y, expose.width, expose.height, true);
}
if (dy != 0) {
expose.x = clientArea.x;
expose.width = clientArea.width;
expose.height = Math.abs(dy);
if (dy < 0) { // Moving up?
expose.y += blit.height; // Move expose area down
}
redraw(expose.x, expose.y, expose.width, expose.height, true);
}
}

/**
* Sets the given border on the LightweightSystem's root figure.
*
Expand Down

0 comments on commit 8fafd3c

Please sign in to comment.