Skip to content

Commit 59b68e6

Browse files
Revision 2.0
1 parent bbb5abc commit 59b68e6

File tree

21 files changed

+75
-70
lines changed

21 files changed

+75
-70
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/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) {
@@ -1865,8 +1865,8 @@ private class DrawLineOperation extends Operation {
18651865
@Override
18661866
void apply() {
18671867
int deviceZoom = getZoom();
1868-
Point startInPixels = Win32DPIUtils.pointToPixel (drawable, start, deviceZoom);
1869-
Point endInPixels = Win32DPIUtils.pointToPixel (drawable, end, deviceZoom);
1868+
Point startInPixels = Win32DPIUtils.pointToPixelAsLocation (drawable, start, deviceZoom);
1869+
Point endInPixels = Win32DPIUtils.pointToPixelAsLocation (drawable, end, deviceZoom);
18701870
drawLineInPixels(startInPixels.x, startInPixels.y, endInPixels.x, endInPixels.y);
18711871
}
18721872
}
@@ -2454,7 +2454,7 @@ private class DrawStringOperation extends Operation {
24542454

24552455
@Override
24562456
void apply() {
2457-
Point scaledLocation = Win32DPIUtils.pointToPixel(drawable, location, getZoom());
2457+
Point scaledLocation = Win32DPIUtils.pointToPixelAsLocation(drawable, location, getZoom());
24582458
drawStringInPixels(string, scaledLocation.x, scaledLocation.y, isTransparent);
24592459
}
24602460
}
@@ -2640,7 +2640,7 @@ private class DrawTextOperation extends Operation {
26402640

26412641
@Override
26422642
void apply() {
2643-
Point scaledLocation = Win32DPIUtils.pointToPixel(drawable, location, getZoom());
2643+
Point scaledLocation = Win32DPIUtils.pointToPixelAsLocation(drawable, location, getZoom());
26442644
drawTextInPixels(string, scaledLocation.x, scaledLocation.y, flags);
26452645
}
26462646
}
@@ -5733,7 +5733,7 @@ void apply() {
57335733
*/
57345734
public Point stringExtent (String string) {
57355735
if (string == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
5736-
return Win32DPIUtils.pixelToPoint(drawable, stringExtentInPixels(string), getZoom());
5736+
return Win32DPIUtils.pixelToPointAsSize(drawable, stringExtentInPixels(string), getZoom());
57375737
}
57385738

57395739
Point stringExtentInPixels (String string) {
@@ -5778,7 +5778,7 @@ Point stringExtentInPixels (String string) {
57785778
* </ul>
57795779
*/
57805780
public Point textExtent (String string) {
5781-
return Win32DPIUtils.pixelToPoint(drawable, textExtentInPixels(string, SWT.DRAW_DELIMITER | SWT.DRAW_TAB), getZoom());
5781+
return Win32DPIUtils.pixelToPointAsSize(drawable, textExtentInPixels(string, SWT.DRAW_DELIMITER | SWT.DRAW_TAB), getZoom());
57825782
}
57835783

57845784
/**
@@ -5813,7 +5813,7 @@ public Point textExtent (String string) {
58135813
* </ul>
58145814
*/
58155815
public Point textExtent (String string, int flags) {
5816-
return Win32DPIUtils.pixelToPoint(drawable, textExtentInPixels(string, flags), getZoom());
5816+
return Win32DPIUtils.pixelToPointAsSize(drawable, textExtentInPixels(string, flags), getZoom());
58175817
}
58185818

58195819
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
@@ -227,7 +227,7 @@ public Canvas getParent () {
227227
*/
228228
public Point getSize () {
229229
checkWidget();
230-
return Win32DPIUtils.pixelToPoint(getSizeInPixels(), getZoom());
230+
return Win32DPIUtils.pixelToPointAsSize(getSizeInPixels(), getZoom());
231231
}
232232

233233
Point getSizeInPixels () {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,7 @@ boolean dragDetect (long hwnd, int x, int y, boolean filter, boolean [] detect,
911911
*/
912912
public Point getCaretLocation () {
913913
checkWidget ();
914-
return Win32DPIUtils.pixelToPoint(getCaretLocationInPixels(), getZoom());
914+
return Win32DPIUtils.pixelToPointAsLocation(getCaretLocationInPixels(), getZoom());
915915
}
916916

917917
Point getCaretLocationInPixels () {

0 commit comments

Comments
 (0)