Skip to content

Commit ed71087

Browse files
committed
[win32] Scale up bounds as rectangle in GC
This commit adresses render artifacts visible when drawing on a GC with monitor-specific scaling enabled e.g. on 175%. Reason is that scaling up all attributes of bounds separately can lead to rounding errors e.g. between y and height (one being scaled up, the other one not). Scaling them together as a rectangle solves this limitation.
1 parent 413426e commit ed71087

File tree

1 file changed

+29
-78
lines changed
  • bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics

1 file changed

+29
-78
lines changed

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/GC.java

Lines changed: 29 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -512,14 +512,10 @@ public void copyArea (int srcX, int srcY, int width, int height, int destX, int
512512
* @since 3.1
513513
*/
514514
public void copyArea (int srcX, int srcY, int width, int height, int destX, int destY, boolean paint) {
515-
int deviceZoom = getZoom();
516-
srcX = DPIUtil.scaleUp(drawable, srcX, deviceZoom);
517-
srcY = DPIUtil.scaleUp(drawable, srcY, deviceZoom);
518-
width = DPIUtil.scaleUp(drawable, width, deviceZoom);
519-
height = DPIUtil.scaleUp(drawable, height, deviceZoom);
520-
destX = DPIUtil.scaleUp(drawable, destX, deviceZoom);
521-
destY = DPIUtil.scaleUp(drawable, destY, deviceZoom);
522-
copyAreaInPixels(srcX, srcY, width, height, destX, destY, paint);
515+
int zoom = getZoom();
516+
Rectangle sourceRect = DPIUtil.scaleUp(drawable, new Rectangle(srcX, srcY, width, height), zoom);
517+
Rectangle destRect = DPIUtil.scaleUp(drawable, new Rectangle(destX, destY, width, height), zoom);
518+
copyAreaInPixels(sourceRect.x, sourceRect.y, sourceRect.width, sourceRect.height, destRect.x, destRect.y, paint);
523519
}
524520

525521
void copyAreaInPixels(int srcX, int srcY, int width, int height, int destX, int destY, boolean paint) {
@@ -759,12 +755,8 @@ void disposeGdip() {
759755
* </ul>
760756
*/
761757
public void drawArc (int x, int y, int width, int height, int startAngle, int arcAngle) {
762-
int deviceZoom = getZoom();
763-
x = DPIUtil.scaleUp(drawable, x, deviceZoom);
764-
y = DPIUtil.scaleUp(drawable, y, deviceZoom);
765-
width = DPIUtil.scaleUp(drawable, width, deviceZoom);
766-
height = DPIUtil.scaleUp(drawable, height, deviceZoom);
767-
drawArcInPixels(x, y, width, height, startAngle, arcAngle);
758+
Rectangle rect = DPIUtil.scaleUp(drawable, new Rectangle(x, y, width, height), getZoom());
759+
drawArcInPixels(rect.x, rect.y, rect.width, rect.height, startAngle, arcAngle);
768760
}
769761

770762
void drawArcInPixels (int x, int y, int width, int height, int startAngle, int arcAngle) {
@@ -843,12 +835,8 @@ void drawArcInPixels (int x, int y, int width, int height, int startAngle, int a
843835
* @see #drawRectangle(int, int, int, int)
844836
*/
845837
public void drawFocus (int x, int y, int width, int height) {
846-
int deviceZoom = getZoom();
847-
x = DPIUtil.scaleUp (drawable, x, deviceZoom);
848-
y = DPIUtil.scaleUp (drawable, y, deviceZoom);
849-
width = DPIUtil.scaleUp (drawable, width, deviceZoom);
850-
height = DPIUtil.scaleUp (drawable, height, deviceZoom);
851-
drawFocusInPixels(x, y, width, height);
838+
Rectangle rect = DPIUtil.scaleUp(drawable, new Rectangle(x, y, width, height), getZoom());
839+
drawFocusInPixels(rect.x, rect.y, rect.width, rect.height);
852840
}
853841

854842
void drawFocusInPixels (int x, int y, int width, int height) {
@@ -1696,12 +1684,8 @@ void drawLineInPixels (int x1, int y1, int x2, int y2) {
16961684
* </ul>
16971685
*/
16981686
public void drawOval (int x, int y, int width, int height) {
1699-
int deviceZoom = getZoom();
1700-
x = DPIUtil.scaleUp (drawable, x, deviceZoom);
1701-
y = DPIUtil.scaleUp (drawable, y, deviceZoom);
1702-
width = DPIUtil.scaleUp (drawable, width, deviceZoom);
1703-
height = DPIUtil.scaleUp (drawable, height, deviceZoom);
1704-
drawOvalInPixels(x, y, width, height);
1687+
Rectangle rect = DPIUtil.scaleUp(drawable, new Rectangle(x, y, width, height), getZoom());
1688+
drawOvalInPixels(rect.x, rect.y, rect.width, rect.height);
17051689
}
17061690

17071691
void drawOvalInPixels (int x, int y, int width, int height) {
@@ -1910,12 +1894,7 @@ void drawPolylineInPixels(int[] pointArray) {
19101894
* </ul>
19111895
*/
19121896
public void drawRectangle (int x, int y, int width, int height) {
1913-
int deviceZoom = getZoom();
1914-
x = DPIUtil.scaleUp (drawable, x, deviceZoom);
1915-
y = DPIUtil.scaleUp (drawable, y, deviceZoom);
1916-
width = DPIUtil.scaleUp (drawable, width, deviceZoom);
1917-
height = DPIUtil.scaleUp (drawable, height, deviceZoom);
1918-
drawRectangleInPixels(x, y, width, height);
1897+
drawRectangle(new Rectangle(x, y, width, height));
19191898
}
19201899

19211900
void drawRectangleInPixels (int x, int y, int width, int height) {
@@ -1996,14 +1975,11 @@ public void drawRectangle (Rectangle rect) {
19961975
* </ul>
19971976
*/
19981977
public void drawRoundRectangle (int x, int y, int width, int height, int arcWidth, int arcHeight) {
1999-
int deviceZoom = getZoom();
2000-
x = DPIUtil.scaleUp (drawable, x, deviceZoom);
2001-
y = DPIUtil.scaleUp (drawable, y, deviceZoom);
2002-
width = DPIUtil.scaleUp (drawable, width, deviceZoom);
2003-
height = DPIUtil.scaleUp (drawable, height, deviceZoom);
2004-
arcWidth = DPIUtil.scaleUp (drawable, arcWidth, deviceZoom);
2005-
arcHeight = DPIUtil.scaleUp (drawable, arcHeight, deviceZoom);
2006-
drawRoundRectangleInPixels(x, y, width, height, arcWidth, arcHeight);
1978+
int zoom = getZoom();
1979+
Rectangle rect = DPIUtil.scaleUp(drawable, new Rectangle(x, y, width, height), zoom);
1980+
arcWidth = DPIUtil.scaleUp (drawable, arcWidth, zoom);
1981+
arcHeight = DPIUtil.scaleUp (drawable, arcHeight, zoom);
1982+
drawRoundRectangleInPixels(rect.x, rect.y, rect.width, rect.height, arcWidth, arcHeight);
20071983
}
20081984

20091985
void drawRoundRectangleInPixels (int x, int y, int width, int height, int arcWidth, int arcHeight) {
@@ -2687,12 +2663,8 @@ public boolean equals (Object object) {
26872663
* @see #drawArc
26882664
*/
26892665
public void fillArc (int x, int y, int width, int height, int startAngle, int arcAngle) {
2690-
int deviceZoom = getZoom();
2691-
x = DPIUtil.scaleUp (drawable, x, deviceZoom);
2692-
y = DPIUtil.scaleUp (drawable, y, deviceZoom);
2693-
width = DPIUtil.scaleUp (drawable, width, deviceZoom);
2694-
height = DPIUtil.scaleUp (drawable, height, deviceZoom);
2695-
fillArcInPixels(x, y, width, height, startAngle, arcAngle);
2666+
Rectangle rect = DPIUtil.scaleUp(drawable, new Rectangle(x, y, width, height), getZoom());
2667+
fillArcInPixels(rect.x, rect.y, rect.width, rect.height, startAngle, arcAngle);
26962668
}
26972669

26982670
void fillArcInPixels (int x, int y, int width, int height, int startAngle, int arcAngle) {
@@ -2767,12 +2739,8 @@ void fillArcInPixels (int x, int y, int width, int height, int startAngle, int a
27672739
* @see #drawRectangle(int, int, int, int)
27682740
*/
27692741
public void fillGradientRectangle (int x, int y, int width, int height, boolean vertical) {
2770-
int deviceZoom = getZoom();
2771-
x = DPIUtil.scaleUp (drawable, x, deviceZoom);
2772-
y = DPIUtil.scaleUp (drawable, y, deviceZoom);
2773-
width = DPIUtil.scaleUp (drawable, width, deviceZoom);
2774-
height = DPIUtil.scaleUp (drawable, height, deviceZoom);
2775-
fillGradientRectangleInPixels(x, y, width, height, vertical);
2742+
Rectangle rect = DPIUtil.scaleUp(drawable, new Rectangle(x, y, width, height), getZoom());
2743+
fillGradientRectangleInPixels(rect.x, rect.y, rect.width, rect.height, vertical);
27762744
}
27772745

27782746
void fillGradientRectangleInPixels(int x, int y, int width, int height, boolean vertical) {
@@ -2886,12 +2854,8 @@ void fillGradientRectangleInPixels(int x, int y, int width, int height, boolean
28862854
* @see #drawOval
28872855
*/
28882856
public void fillOval (int x, int y, int width, int height) {
2889-
int deviceZoom = getZoom();
2890-
x = DPIUtil.scaleUp (drawable, x, deviceZoom);
2891-
y = DPIUtil.scaleUp (drawable, y, deviceZoom);
2892-
width = DPIUtil.scaleUp (drawable, width, deviceZoom);
2893-
height = DPIUtil.scaleUp (drawable, height, deviceZoom);
2894-
fillOvalInPixels(x, y, width, height);
2857+
Rectangle rect = DPIUtil.scaleUp(drawable, new Rectangle(x, y, width, height), getZoom());
2858+
fillOvalInPixels(rect.x, rect.y, rect.width, rect.height);
28952859
}
28962860

28972861
void fillOvalInPixels (int x, int y, int width, int height) {
@@ -3010,12 +2974,7 @@ void fillPolygonInPixels (int[] pointArray) {
30102974
* @see #drawRectangle(int, int, int, int)
30112975
*/
30122976
public void fillRectangle (int x, int y, int width, int height) {
3013-
int deviceZoom = getZoom();
3014-
x = DPIUtil.scaleUp (drawable, x, deviceZoom);
3015-
y = DPIUtil.scaleUp (drawable, y, deviceZoom);
3016-
width = DPIUtil.scaleUp (drawable, width, deviceZoom);
3017-
height = DPIUtil.scaleUp (drawable, height, deviceZoom);
3018-
fillRectangleInPixels(x, y, width, height);
2977+
fillRectangle(new Rectangle(x, y, width, height));
30192978
}
30202979

30212980
void fillRectangleInPixels (int x, int y, int width, int height) {
@@ -3076,14 +3035,11 @@ public void fillRectangle (Rectangle rect) {
30763035
* @see #drawRoundRectangle
30773036
*/
30783037
public void fillRoundRectangle (int x, int y, int width, int height, int arcWidth, int arcHeight) {
3079-
int deviceZoom = getZoom();
3080-
x = DPIUtil.scaleUp (drawable, x, deviceZoom);
3081-
y = DPIUtil.scaleUp (drawable, y, deviceZoom);
3082-
width = DPIUtil.scaleUp (drawable, width, deviceZoom);
3083-
height = DPIUtil.scaleUp (drawable, height, deviceZoom);
3084-
arcWidth = DPIUtil.scaleUp (drawable, arcWidth, deviceZoom);
3085-
arcHeight = DPIUtil.scaleUp (drawable, arcHeight, deviceZoom);
3086-
fillRoundRectangleInPixels(x, y, width, height, arcWidth, arcHeight);
3038+
int zoom = getZoom();
3039+
Rectangle rect = DPIUtil.scaleUp(drawable, new Rectangle(x, y, width, height), zoom);
3040+
arcWidth = DPIUtil.scaleUp (drawable, arcWidth, zoom);
3041+
arcHeight = DPIUtil.scaleUp (drawable, arcHeight, zoom);
3042+
fillRoundRectangleInPixels(rect.x, rect.y, rect.width, rect.height, arcWidth, arcHeight);
30873043
}
30883044

30893045
void fillRoundRectangleInPixels (int x, int y, int width, int height, int arcWidth, int arcHeight) {
@@ -4281,12 +4237,7 @@ void setClipping(long clipRgn) {
42814237
* </ul>
42824238
*/
42834239
public void setClipping (int x, int y, int width, int height) {
4284-
int deviceZoom = getZoom();
4285-
x = DPIUtil.scaleUp(drawable, x, deviceZoom);
4286-
y = DPIUtil.scaleUp(drawable, y, deviceZoom);
4287-
width = DPIUtil.scaleUp(drawable, width, deviceZoom);
4288-
height = DPIUtil.scaleUp(drawable, height, deviceZoom);
4289-
setClippingInPixels(x, y, width, height);
4240+
setClipping(new Rectangle(x, y, width, height));
42904241
}
42914242

42924243
void setClippingInPixels (int x, int y, int width, int height) {

0 commit comments

Comments
 (0)