Skip to content

Commit 95b46b6

Browse files
ShahzaibIbrahimfedejeanne
authored andcommitted
[Refactor DPIUtil] rename scaleUp/Down
renaming scaleDown and ScaleUp methods to pixelToPoint and pointToPixel respectively
1 parent cb16f62 commit 95b46b6

File tree

61 files changed

+568
-568
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+568
-568
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ public static Frame new_Frame (final Composite parent) {
250250

251251
parent.getDisplay().asyncExec(() -> {
252252
if (parent.isDisposed()) return;
253-
final Rectangle clientArea = Win32DPIUtils.scaleUp(parent.getClientArea(), DPIUtil.getZoomForAutoscaleProperty(parent.nativeZoom)); // To Pixels
253+
final Rectangle clientArea = Win32DPIUtils.pointToPixel(parent.getClientArea(), DPIUtil.getZoomForAutoscaleProperty(parent.nativeZoom)); // To Pixels
254254
EventQueue.invokeLater(() -> {
255255
frame.setSize (clientArea.width, clientArea.height);
256256
frame.validate ();
@@ -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.scaleDown(new Point(dim.width, dim.height), DPIUtil.getDeviceZoom())); // To Points
296+
shell.setSize(Win32DPIUtils.pixelToPoint(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/Edge.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,14 +1254,14 @@ int handleContextMenuRequested(long pView, long pArgs) {
12541254
// to PIXEL coordinates with the real native zoom value
12551255
// independent from the swt.autoScale property:
12561256
Point pt = new Point( //
1257-
Win32DPIUtils.scaleUp(win32Point.x, DPIUtil.getNativeDeviceZoom()), //
1258-
Win32DPIUtils.scaleUp(win32Point.y, DPIUtil.getNativeDeviceZoom()));
1257+
Win32DPIUtils.pointToPixel(win32Point.x, DPIUtil.getNativeDeviceZoom()), //
1258+
Win32DPIUtils.pointToPixel(win32Point.y, DPIUtil.getNativeDeviceZoom()));
12591259
// - then, scale back down from PIXEL to DISPLAY coordinates, taking
12601260
// swt.autoScale property into account
12611261
// which is also later considered in Menu#setLocation()
12621262
pt = new Point( //
1263-
DPIUtil.scaleDown(pt.x, DPIUtil.getZoomForAutoscaleProperty(browser.getShell().nativeZoom)), //
1264-
DPIUtil.scaleDown(pt.y, DPIUtil.getZoomForAutoscaleProperty(browser.getShell().nativeZoom)));
1263+
DPIUtil.pixelToPoint(pt.x, DPIUtil.getZoomForAutoscaleProperty(browser.getShell().nativeZoom)), //
1264+
DPIUtil.pixelToPoint(pt.y, DPIUtil.getZoomForAutoscaleProperty(browser.getShell().nativeZoom)));
12651265
// - finally, translate the POINT from widget-relative
12661266
// to DISPLAY-relative coordinates
12671267
pt = browser.toDisplay(pt.x, pt.y);

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.scaleDown(new Point(screenX, screenY), DPIUtil.getDeviceZoom()); // To Points
1883+
Point position = Win32DPIUtils.pixelToPoint(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 Browser/win32/org/eclipse/swt/browser/WebSite.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,8 @@ int ShowContextMenu(int dwID, long ppt, long pcmdtReserved, long pdispReserved)
320320
Event event = new Event();
321321
POINT pt = new POINT();
322322
OS.MoveMemory(pt, ppt, POINT.sizeof);
323-
pt.x = DPIUtil.scaleDown(pt.x, DPIUtil.getDeviceZoom()); // To Points
324-
pt.y = DPIUtil.scaleDown(pt.y, DPIUtil.getDeviceZoom()); // To Points
323+
pt.x = DPIUtil.pixelToPoint(pt.x, DPIUtil.getDeviceZoom()); // To Points
324+
pt.y = DPIUtil.pixelToPoint(pt.y, DPIUtil.getDeviceZoom()); // To Points
325325
event.x = pt.x;
326326
event.y = pt.y;
327327
browser.notifyListeners(SWT.MenuDetect, event);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ private void drag(Event dragEvent) {
510510
int offsetX = event.offsetX;
511511
hwndDrag = topControl.handle;
512512
if ((topControl.getStyle() & SWT.RIGHT_TO_LEFT) != 0) {
513-
offsetX = Win32DPIUtils.scaleUp(image.getBounds(), zoom).width - offsetX;
513+
offsetX = Win32DPIUtils.pointToPixel(image.getBounds(), zoom).width - offsetX;
514514
RECT rect = new RECT ();
515515
OS.GetClientRect (topControl.handle, rect);
516516
hwndDrag = OS.CreateWindowEx (
@@ -538,8 +538,8 @@ private void drag(Event dragEvent) {
538538
int flags = OS.RDW_UPDATENOW | OS.RDW_ALLCHILDREN;
539539
OS.RedrawWindow (topControl.handle, null, 0, flags);
540540
POINT pt = new POINT ();
541-
pt.x = Win32DPIUtils.scaleUp(dragEvent.x, zoom);// To Pixels
542-
pt.y = Win32DPIUtils.scaleUp(dragEvent.y, zoom);// To Pixels
541+
pt.x = Win32DPIUtils.pointToPixel(dragEvent.x, zoom);// To Pixels
542+
pt.y = Win32DPIUtils.pointToPixel(dragEvent.y, zoom);// To Pixels
543543
OS.MapWindowPoints (control.handle, 0, pt, 1);
544544
RECT rect = new RECT ();
545545
OS.GetWindowRect (hwndDrag, rect);

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.scaleDown(new Point(xInPixels, yInPixels), zoom);
413+
return Win32DPIUtils.pixelToPoint(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.scaleDown(new Point (pt.x, pt.y), zoom);
422+
Point p = Win32DPIUtils.pixelToPoint(new Point (pt.x, pt.y), zoom);
423423
return this.control.toDisplay(p);
424424
}
425425

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public void dragOver(DropTargetEvent event) {
151151
int effect = checkEffect(event.feedback);
152152
long handle = table.handle;
153153
Point coordinates = new Point(event.x, event.y);
154-
coordinates = Win32DPIUtils.scaleUp(table.toControl(coordinates), DPIUtil.getZoomForAutoscaleProperty(table.nativeZoom)); // To Pixels
154+
coordinates = Win32DPIUtils.pointToPixel(table.toControl(coordinates), DPIUtil.getZoomForAutoscaleProperty(table.nativeZoom)); // To Pixels
155155
LVHITTESTINFO pinfo = new LVHITTESTINFO();
156156
pinfo.x = coordinates.x;
157157
pinfo.y = coordinates.y;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public void dragOver(DropTargetEvent event) {
165165
int effect = checkEffect(event.feedback);
166166
long handle = tree.handle;
167167
Point coordinates = new Point(event.x, event.y);
168-
coordinates = Win32DPIUtils.scaleUp(tree.toControl(coordinates), DPIUtil.getZoomForAutoscaleProperty(tree.nativeZoom)); // To Pixels
168+
coordinates = Win32DPIUtils.pointToPixel(tree.toControl(coordinates), DPIUtil.getZoomForAutoscaleProperty(tree.nativeZoom)); // To Pixels
169169
TVHITTESTINFO lpht = new TVHITTESTINFO ();
170170
lpht.x = coordinates.x;
171171
lpht.y = coordinates.y;

bundles/org.eclipse.swt/Eclipse SWT OLE Win32/win32/org/eclipse/swt/ole/win32/OleClientSite.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,7 @@ protected int GetWindow(long phwnd) {
810810
return COM.S_OK;
811811
}
812812
RECT getRect() {
813-
Rectangle area = Win32DPIUtils.scaleUp(getClientArea(), DPIUtil.getZoomForAutoscaleProperty(nativeZoom)); // To Pixels
813+
Rectangle area = Win32DPIUtils.pointToPixel(getClientArea(), DPIUtil.getZoomForAutoscaleProperty(nativeZoom)); // To Pixels
814814
RECT rect = new RECT();
815815
rect.left = area.x;
816816
rect.top = area.y;
@@ -987,14 +987,14 @@ private int OnInPlaceDeactivate() {
987987
return COM.S_OK;
988988
}
989989
private int OnPosRectChange(long lprcPosRect) {
990-
Point size = Win32DPIUtils.scaleUp(getSize(), DPIUtil.getZoomForAutoscaleProperty(nativeZoom)); // To Pixels
990+
Point size = Win32DPIUtils.pointToPixel(getSize(), DPIUtil.getZoomForAutoscaleProperty(nativeZoom)); // To Pixels
991991
setExtent(size.x, size.y);
992992
return COM.S_OK;
993993
}
994994
private void onPaint(Event e) {
995995
if (state == STATE_RUNNING || state == STATE_INPLACEACTIVE) {
996996
SIZE size = getExtent();
997-
Rectangle area = Win32DPIUtils.scaleUp(getClientArea(), DPIUtil.getZoomForAutoscaleProperty(nativeZoom)); // To Pixels
997+
Rectangle area = Win32DPIUtils.pointToPixel(getClientArea(), DPIUtil.getZoomForAutoscaleProperty(nativeZoom)); // To Pixels
998998
RECT rect = new RECT();
999999
if (getProgramID().startsWith("Excel.Sheet")) { //$NON-NLS-1$
10001000
rect.left = area.x; rect.right = area.x + (area.height * size.cx / size.cy);
@@ -1370,11 +1370,11 @@ void setBorderSpace(RECT newBorderwidth) {
13701370
}
13711371
void setBounds() {
13721372
int zoom = DPIUtil.getZoomForAutoscaleProperty(nativeZoom);
1373-
Rectangle area = Win32DPIUtils.scaleUp(frame.getClientArea(), zoom); // To Pixels
1374-
setBounds(DPIUtil.scaleDown(borderWidths.left, zoom),
1375-
DPIUtil.scaleDown(borderWidths.top, zoom),
1376-
DPIUtil.scaleDown(area.width - borderWidths.left - borderWidths.right, zoom),
1377-
DPIUtil.scaleDown(area.height - borderWidths.top - borderWidths.bottom, zoom));
1373+
Rectangle area = Win32DPIUtils.pointToPixel(frame.getClientArea(), zoom); // To Pixels
1374+
setBounds(DPIUtil.pixelToPoint(borderWidths.left, zoom),
1375+
DPIUtil.pixelToPoint(borderWidths.top, zoom),
1376+
DPIUtil.pixelToPoint(area.width - borderWidths.left - borderWidths.right, zoom),
1377+
DPIUtil.pixelToPoint(area.height - borderWidths.top - borderWidths.bottom, zoom));
13781378
setObjectRects();
13791379
}
13801380
private void setExtent(int width, int height){

bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Image.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1822,27 +1822,27 @@ public String toString () {
18221822
* @noreference This method is not intended to be referenced by clients.
18231823
*/
18241824
public static void drawScaled(GC gc, Image original, int width, int height, float scaleFactor) {
1825-
gc.drawImage (original, 0, 0, CocoaDPIUtil.autoScaleDown (width), CocoaDPIUtil.autoScaleDown (height),
1825+
gc.drawImage (original, 0, 0, CocoaDPIUtil.pixelToPoint (width), CocoaDPIUtil.pixelToPoint (height),
18261826
/* E.g. destWidth here is effectively DPIUtil.autoScaleDown (scaledWidth), but avoiding rounding errors.
18271827
* Nevertheless, we still have some rounding errors due to the point-based API GC#drawImage(..).
18281828
*/
1829-
0, 0, Math.round (CocoaDPIUtil.autoScaleDown (width * scaleFactor)), Math.round (CocoaDPIUtil.autoScaleDown (height * scaleFactor)));
1829+
0, 0, Math.round (CocoaDPIUtil.pixelToPoint (width * scaleFactor)), Math.round (CocoaDPIUtil.pixelToPoint (height * scaleFactor)));
18301830
}
18311831

18321832
private final class CocoaDPIUtil {
18331833

18341834
/**
18351835
* Auto-scale down int dimensions.
18361836
*/
1837-
public static int autoScaleDown(int size) {
1838-
return DPIUtil.scaleDown(size, DPIUtil.getDeviceZoom());
1837+
public static int pixelToPoint(int size) {
1838+
return DPIUtil.pixelToPoint(size, DPIUtil.getDeviceZoom());
18391839
}
18401840

18411841
/**
18421842
* Auto-scale down float dimensions.
18431843
*/
1844-
public static float autoScaleDown(float size) {
1845-
return DPIUtil.scaleDown(size, DPIUtil.getDeviceZoom());
1844+
public static float pixelToPoint(float size) {
1845+
return DPIUtil.pixelToPoint(size, DPIUtil.getDeviceZoom());
18461846
}
18471847
}
18481848

0 commit comments

Comments
 (0)