Skip to content

Commit 1926a71

Browse files
Revision 2.0
1 parent a4d689b commit 1926a71

File tree

22 files changed

+77
-73
lines changed

22 files changed

+77
-73
lines changed

bundles/org.eclipse.swt/Eclipse SWT AWT/win32/org/eclipse/swt/awt/SWT_AWT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ public void componentResized (ComponentEvent e) {
293293
display.syncExec (() -> {
294294
if (shell.isDisposed()) return;
295295
Dimension dim = parent.getSize ();
296-
shell.setSize(Win32DPIUtils.pixelToPoint(new Point(dim.width, dim.height), DPIUtil.getDeviceZoom())); // To Points
296+
shell.setSize(Win32DPIUtils.pixelToPointAsSize(new Point(dim.width, dim.height), DPIUtil.getDeviceZoom())); // To Points
297297
});
298298
}
299299
};

bundles/org.eclipse.swt/Eclipse SWT Browser/win32/org/eclipse/swt/browser/IE.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1880,7 +1880,7 @@ void handleDOMEvent (OleEvent e) {
18801880
int screenY = pVarResult.getInt();
18811881
pVarResult.dispose();
18821882

1883-
Point position = Win32DPIUtils.pixelToPoint(new Point(screenX, screenY), DPIUtil.getDeviceZoom()); // To Points
1883+
Point position = Win32DPIUtils.pixelToPointAsLocation(new Point(screenX, screenY), DPIUtil.getDeviceZoom()); // To Points
18841884
position = browser.getDisplay().map(null, browser, position);
18851885
newEvent.x = position.x; newEvent.y = position.y;
18861886

bundles/org.eclipse.swt/Eclipse SWT Drag and Drop/win32/org/eclipse/swt/dnd/DropTarget.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ private Point convertPixelToPoint(int xInPixels, int yInPixels) {
410410
if (this.control == null) {
411411
// If there is no control for context, the behavior remains as before
412412
int zoom = DPIUtil.getZoomForAutoscaleProperty(this.nativeZoom);
413-
return Win32DPIUtils.pixelToPoint(new Point(xInPixels, yInPixels), zoom);
413+
return Win32DPIUtils.pixelToPointAsLocation(new Point(xInPixels, yInPixels), zoom);
414414
}
415415
int zoom = DPIUtil.getZoomForAutoscaleProperty(this.control.nativeZoom);
416416
// There is no API to convert absolute values in pixels to display relative
@@ -419,7 +419,7 @@ private Point convertPixelToPoint(int xInPixels, int yInPixels) {
419419
POINT pt = new POINT ();
420420
pt.x = xInPixels; pt.y = yInPixels;
421421
OS.ScreenToClient (this.control.handle, pt);
422-
Point p = Win32DPIUtils.pixelToPoint(new Point (pt.x, pt.y), zoom);
422+
Point p = Win32DPIUtils.pixelToPointAsLocation(new Point (pt.x, pt.y), zoom);
423423
return this.control.toDisplay(p);
424424
}
425425

bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Point.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
import java.io.*;
1818

19-
import org.eclipse.swt.internal.*;
2019
import org.eclipse.swt.widgets.*;
2120

2221
/**
@@ -139,8 +138,8 @@ public static sealed class OfFloat extends Point permits Point.WithMonitor {
139138

140139
private static final long serialVersionUID = -1862062276431597053L;
141140

142-
private float residualX, residualY;
143-
private RoundingMode roundingMode;
141+
public float residualX, residualY;
142+
public RoundingMode roundingMode;
144143

145144
public OfFloat(int x, int y) {
146145
super(x, y);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ public Point getDPI () {
526526
int dpiX = OS.GetDeviceCaps (hDC, OS.LOGPIXELSX);
527527
int dpiY = OS.GetDeviceCaps (hDC, OS.LOGPIXELSY);
528528
internal_dispose_GC (hDC, null);
529-
return Win32DPIUtils.pixelToPoint(new Point (dpiX, dpiY), DPIUtil.getZoomForAutoscaleProperty(getDeviceZoom()));
529+
return Win32DPIUtils.pixelToPointAsLocation(new Point (dpiX, dpiY), DPIUtil.getZoomForAutoscaleProperty(getDeviceZoom()));
530530
}
531531

532532
/**

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,7 +1056,7 @@ private class DrawImageOperation extends ImageOperation {
10561056

10571057
@Override
10581058
void apply() {
1059-
drawImageInPixels(getImage(), Win32DPIUtils.pointToPixel(drawable, this.location, getZoom()));
1059+
drawImageInPixels(getImage(), Win32DPIUtils.pointToPixelAsLocation(drawable, this.location, getZoom()));
10601060
}
10611061

10621062
private void drawImageInPixels(Image image, Point location) {
@@ -1868,8 +1868,8 @@ private class DrawLineOperation extends Operation {
18681868
@Override
18691869
void apply() {
18701870
int deviceZoom = getZoom();
1871-
Point startInPixels = Win32DPIUtils.pointToPixel (drawable, start, deviceZoom);
1872-
Point endInPixels = Win32DPIUtils.pointToPixel (drawable, end, deviceZoom);
1871+
Point startInPixels = Win32DPIUtils.pointToPixelAsLocation (drawable, start, deviceZoom);
1872+
Point endInPixels = Win32DPIUtils.pointToPixelAsLocation (drawable, end, deviceZoom);
18731873
drawLineInPixels(startInPixels.x, startInPixels.y, endInPixels.x, endInPixels.y);
18741874
}
18751875
}
@@ -2457,7 +2457,7 @@ private class DrawStringOperation extends Operation {
24572457

24582458
@Override
24592459
void apply() {
2460-
Point scaledLocation = Win32DPIUtils.pointToPixel(drawable, location, getZoom());
2460+
Point scaledLocation = Win32DPIUtils.pointToPixelAsLocation(drawable, location, getZoom());
24612461
drawStringInPixels(string, scaledLocation.x, scaledLocation.y, isTransparent);
24622462
}
24632463
}
@@ -2643,7 +2643,7 @@ private class DrawTextOperation extends Operation {
26432643

26442644
@Override
26452645
void apply() {
2646-
Point scaledLocation = Win32DPIUtils.pointToPixel(drawable, location, getZoom());
2646+
Point scaledLocation = Win32DPIUtils.pointToPixelAsLocation(drawable, location, getZoom());
26472647
drawTextInPixels(string, scaledLocation.x, scaledLocation.y, flags);
26482648
}
26492649
}
@@ -5736,7 +5736,7 @@ void apply() {
57365736
*/
57375737
public Point stringExtent (String string) {
57385738
if (string == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
5739-
return Win32DPIUtils.pixelToPoint(drawable, stringExtentInPixels(string), getZoom());
5739+
return Win32DPIUtils.pixelToPointAsSize(drawable, stringExtentInPixels(string), getZoom());
57405740
}
57415741

57425742
Point stringExtentInPixels (String string) {
@@ -5781,7 +5781,7 @@ Point stringExtentInPixels (String string) {
57815781
* </ul>
57825782
*/
57835783
public Point textExtent (String string) {
5784-
return Win32DPIUtils.pixelToPoint(drawable, textExtentInPixels(string, SWT.DRAW_DELIMITER | SWT.DRAW_TAB), getZoom());
5784+
return Win32DPIUtils.pixelToPointAsSize(drawable, textExtentInPixels(string, SWT.DRAW_DELIMITER | SWT.DRAW_TAB), getZoom());
57855785
}
57865786

57875787
/**
@@ -5816,7 +5816,7 @@ public Point textExtent (String string) {
58165816
* </ul>
58175817
*/
58185818
public Point textExtent (String string, int flags) {
5819-
return Win32DPIUtils.pixelToPoint(drawable, textExtentInPixels(string, flags), getZoom());
5819+
return Win32DPIUtils.pixelToPointAsSize(drawable, textExtentInPixels(string, flags), getZoom());
58205820
}
58215821

58225822
Point textExtentInPixels(String string, int flags) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2199,7 +2199,7 @@ public int[] getLineOffsets () {
21992199
*/
22002200
public Point getLocation (int offset, boolean trailing) {
22012201
checkLayout();
2202-
return Win32DPIUtils.pixelToPoint(getDevice(), getLocationInPixels(offset, trailing), getZoom());
2202+
return Win32DPIUtils.pixelToPointAsLocation(getDevice(), getLocationInPixels(offset, trailing), getZoom());
22032203
}
22042204

22052205
Point getLocationInPixels (int offset, boolean trailing) {
@@ -2409,7 +2409,7 @@ int _getOffset(int offset, int movement, boolean forward) {
24092409
*/
24102410
public int getOffset (Point point, int[] trailing) {
24112411
checkLayout();
2412-
if (point == null) SWT.error (SWT.ERROR_NULL_ARGUMENT); return getOffsetInPixels(Win32DPIUtils.pointToPixel(getDevice(), point, getZoom()), trailing);
2412+
if (point == null) SWT.error (SWT.ERROR_NULL_ARGUMENT); return getOffsetInPixels(Win32DPIUtils.pointToPixelAsLocation(getDevice(), point, getZoom()), trailing);
24132413
}
24142414

24152415
int getOffsetInPixels (Point point, int[] trailing) {

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/ImageList.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ private void addPlaceholderImageToImageList(long imageListHandle, int bitmapWidt
371371
public Point getImageSize() {
372372
int [] cx = new int [1], cy = new int [1];
373373
OS.ImageList_GetIconSize (handle, cx, cy);
374-
return Win32DPIUtils.pixelToPoint(new Point (cx [0], cy [0]), zoom);
374+
return Win32DPIUtils.pixelToPointAsSize(new Point (cx [0], cy [0]), zoom);
375375
}
376376

377377
public int indexOf (Image image) {

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/Win32DPIUtils.java

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,14 @@ public static float pixelToPoint(Drawable drawable, float size, int zoom) {
113113
return DPIUtil.pixelToPoint (size, zoom);
114114
}
115115

116-
public static Point pixelToPoint(Point point, int zoom) {
117-
//TODO actually all callers should explicitly state what mode the want!
118-
return pixelToPoint(point, zoom, RoundingMode.ROUND);
116+
public static Point pixelToPointAsSize(Drawable drawable, Point point, int zoom) {
117+
if (drawable != null && !drawable.isAutoScalable()) return point;
118+
return pixelToPointAsSize (point, zoom);
119+
}
120+
121+
public static Point pixelToPointAsLocation(Drawable drawable, Point point, int zoom) {
122+
if (drawable != null && !drawable.isAutoScalable()) return point;
123+
return pixelToPointAsLocation (point, zoom);
119124
}
120125

121126
public static Point pixelToPointAsSize(Point point, int zoom) {
@@ -126,7 +131,7 @@ public static Point pixelToPointAsLocation(Point point, int zoom) {
126131
return pixelToPoint(point, zoom, RoundingMode.ROUND);
127132
}
128133

129-
public static Point pixelToPoint(Point point, int zoom, RoundingMode mode) {
134+
private static Point pixelToPoint(Point point, int zoom, RoundingMode mode) {
130135
if (zoom == 100 || point == null) return point;
131136
Point.OfFloat fPoint = Point.OfFloat.from(point);
132137
float scaleFactor = DPIUtil.getScalingFactor(zoom);
@@ -135,17 +140,12 @@ public static Point pixelToPoint(Point point, int zoom, RoundingMode mode) {
135140
return new Point.OfFloat(scaledX, scaledY, mode);
136141
}
137142

138-
public static Point pixelToPoint(Drawable drawable, Point point, int zoom) {
139-
if (drawable != null && !drawable.isAutoScalable()) return point;
140-
return pixelToPoint (point, zoom);
141-
}
142-
143143
public static Rectangle pixelToPoint(Rectangle rect, int zoom) {
144144
if (zoom == 100 || rect == null) return rect;
145145
if (rect instanceof Rectangle.OfFloat rectOfFloat) return pixelToPoint(rectOfFloat, zoom);
146146
Rectangle scaledRect = new Rectangle.OfFloat (0,0,0,0);
147-
Point scaledTopLeft = pixelToPoint(new Point (rect.x, rect.y), zoom);
148-
Point scaledBottomRight = pixelToPoint(new Point (rect.x + rect.width, rect.y + rect.height), zoom);
147+
Point scaledTopLeft = pixelToPointAsLocation(new Point (rect.x, rect.y), zoom);
148+
Point scaledBottomRight = pixelToPointAsLocation(new Point (rect.x + rect.width, rect.y + rect.height), zoom);
149149

150150
scaledRect.x = scaledTopLeft.x;
151151
scaledRect.y = scaledTopLeft.y;
@@ -232,7 +232,7 @@ public static float pointToPixel(Drawable drawable, float size, int zoom) {
232232
return pointToPixel (size, zoom);
233233
}
234234

235-
public static Point pointToPixel(Point point, int zoom, RoundingMode mode) {
235+
private static Point pointToPixel(Point point, int zoom, RoundingMode mode) {
236236
if (zoom == 100 || point == null) return point;
237237
Point.OfFloat fPoint = Point.OfFloat.from(point);
238238
float scaleFactor = DPIUtil.getScalingFactor(zoom);
@@ -241,6 +241,16 @@ public static Point pointToPixel(Point point, int zoom, RoundingMode mode) {
241241
return new Point.OfFloat(scaledX, scaledY, mode);
242242
}
243243

244+
public static Point pointToPixelAsSize(Drawable drawable, Point point, int zoom) {
245+
if (drawable != null && !drawable.isAutoScalable()) return point;
246+
return pointToPixelAsSize(point, zoom);
247+
}
248+
249+
public static Point pointToPixelAsLocation(Drawable drawable, Point point, int zoom) {
250+
if (drawable != null && !drawable.isAutoScalable()) return point;
251+
return pointToPixelAsLocation(point, zoom);
252+
}
253+
244254
public static Point pointToPixelAsSize(Point point, int zoom) {
245255
return pointToPixel(point, zoom, RoundingMode.UP);
246256
}
@@ -249,17 +259,12 @@ public static Point pointToPixelAsLocation(Point point, int zoom) {
249259
return pointToPixel(point, zoom, RoundingMode.ROUND);
250260
}
251261

252-
public static Point pointToPixel(Drawable drawable, Point point, int zoom) {
253-
if (drawable != null && !drawable.isAutoScalable()) return point;
254-
return pointToPixel (point, zoom, RoundingMode.ROUND);
255-
}
256-
257262
public static Rectangle pointToPixel(Rectangle rect, int zoom) {
258263
if (zoom == 100 || rect == null) return rect;
259264
if (rect instanceof Rectangle.OfFloat rectOfFloat) return pointToPixel(rectOfFloat, zoom);
260265
Rectangle scaledRect = new Rectangle.OfFloat(0,0,0,0);
261-
Point scaledTopLeft = pointToPixel (new Point(rect.x, rect.y), zoom, RoundingMode.ROUND);
262-
Point scaledBottomRight = pointToPixel (new Point(rect.x + rect.width, rect.y + rect.height), zoom, RoundingMode.ROUND);
266+
Point scaledTopLeft = pointToPixelAsLocation (new Point(rect.x, rect.y), zoom);
267+
Point scaledBottomRight = pointToPixelAsLocation (new Point(rect.x + rect.width, rect.y + rect.height), zoom);
263268

264269
scaledRect.x = scaledTopLeft.x;
265270
scaledRect.y = scaledTopLeft.y;

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Caret.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ public Canvas getParent () {
223223
*/
224224
public Point getSize () {
225225
checkWidget();
226-
return Win32DPIUtils.pixelToPoint(getSizeInPixels(), getZoom());
226+
return Win32DPIUtils.pixelToPointAsSize(getSizeInPixels(), getZoom());
227227
}
228228

229229
Point getSizeInPixels () {

0 commit comments

Comments
 (0)