Skip to content

Commit 4df1e42

Browse files
arunjose696HeikoKlare
authored andcommitted
Automatic refactoring: move Win32DPIUtils.pointToPixel(size,zoom) to DPIUtils
The change is required to do pointToPixel conversions in GTK and MACOS which would be required in follow up PRs
1 parent d884e6b commit 4df1e42

File tree

34 files changed

+160
-165
lines changed

34 files changed

+160
-165
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,8 +1323,8 @@ int handleContextMenuRequested(long pView, long pArgs) {
13231323
// to PIXEL coordinates with the real native zoom value
13241324
// independent from the swt.autoScale property:
13251325
Point pt = new Point( //
1326-
Win32DPIUtils.pointToPixel(win32Point.x, DPIUtil.getNativeDeviceZoom()), //
1327-
Win32DPIUtils.pointToPixel(win32Point.y, DPIUtil.getNativeDeviceZoom()));
1326+
DPIUtil.pointToPixel(win32Point.x, DPIUtil.getNativeDeviceZoom()), //
1327+
DPIUtil.pointToPixel(win32Point.y, DPIUtil.getNativeDeviceZoom()));
13281328
// - then, scale back down from PIXEL to DISPLAY coordinates, taking
13291329
// swt.autoScale property into account
13301330
// which is also later considered in Menu#setLocation()

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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.pointToPixel(dragEvent.x, zoom);// To Pixels
542-
pt.y = Win32DPIUtils.pointToPixel(dragEvent.y, zoom);// To Pixels
541+
pt.x = DPIUtil.pointToPixel(dragEvent.x, zoom);// To Pixels
542+
pt.y = DPIUtil.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/common/org/eclipse/swt/internal/DPIUtil.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,6 @@
2424
/**
2525
* This class hold common constants and utility functions w.r.t. to SWT high DPI
2626
* functionality.
27-
* <p>
28-
* The {@code autoScaleUp(..)} methods convert from API coordinates (in
29-
* SWT points) to internal high DPI coordinates (in pixels) that interface with
30-
* native widgets.
31-
* </p>
32-
* <p>
33-
* The {@code autoScaleDown(..)} convert from high DPI pixels to API coordinates
34-
* (in SWT points).
35-
* </p>
3627
*
3728
* @since 3.105
3829
*/
@@ -257,6 +248,12 @@ public static void validateLinearScaling(ImageDataProvider provider) {
257248
}
258249
}
259250

251+
public static int pointToPixel(int size, int zoom) {
252+
if (zoom == 100 || size == SWT.DEFAULT) return size;
253+
float scaleFactor = getScalingFactor(zoom);
254+
return Math.round (size * scaleFactor);
255+
}
256+
260257
/**
261258
* Represents an element, such as some image data, at a specific zoom level.
262259
*

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -598,11 +598,11 @@ public HotspotAwareCursorHandleProvider(int hotspotX, int hotspotY) {
598598
}
599599

600600
protected final int getHotpotXInPixels(int zoom) {
601-
return Win32DPIUtils.pointToPixel(hotspotX, zoom);
601+
return DPIUtil.pointToPixel(hotspotX, zoom);
602602
}
603603

604604
protected final int getHotpotYInPixels(int zoom) {
605-
return Win32DPIUtils.pointToPixel(hotspotY, zoom);
605+
return DPIUtil.pointToPixel(hotspotY, zoom);
606606
}
607607

608608
protected static final void validateHotspotInsideImage(ImageData source, int hotspotX, int hotspotY) {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2320,8 +2320,8 @@ private ImageHandle createHandle(int zoom) {
23202320

23212321
private long initHandle(int zoom) {
23222322
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
2323-
int scaledWidth = Win32DPIUtils.pointToPixel (width, zoom);
2324-
int scaledHeight = Win32DPIUtils.pointToPixel (height, zoom);
2323+
int scaledWidth = DPIUtil.pointToPixel (width, zoom);
2324+
int scaledHeight = DPIUtil.pointToPixel (height, zoom);
23252325
long hDC = device.internal_new_GC(null);
23262326
long newHandle = OS.CreateCompatibleBitmap(hDC, scaledWidth, scaledHeight);
23272327
/*
@@ -2752,8 +2752,8 @@ protected ImageHandle newImageHandle(ZoomContext zoomContext) {
27522752
int gcStyle = drawer.getGcStyle();
27532753
Image image;
27542754
if ((gcStyle & SWT.TRANSPARENT) != 0) {
2755-
int scaledHeight = Win32DPIUtils.pointToPixel(height, targetZoom);
2756-
int scaledWidth = Win32DPIUtils.pointToPixel(width, targetZoom);
2755+
int scaledHeight = DPIUtil.pointToPixel(height, targetZoom);
2756+
int scaledWidth = DPIUtil.pointToPixel(width, targetZoom);
27572757
/* Create a 24 bit image data with alpha channel */
27582758
final ImageData resultData = new ImageData (scaledWidth, scaledHeight, 24, new PaletteData (0xFF, 0xFF00, 0xFF0000));
27592759
resultData.alphaData = new byte [scaledWidth * scaledHeight];

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,8 @@ public boolean contains (int x, int y) {
202202
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
203203
return applyUsingAnyHandle(regionHandle -> {
204204
int zoom = regionHandle.zoom();
205-
int xInPixels = Win32DPIUtils.pointToPixel(x, zoom);
206-
int yInPixels = Win32DPIUtils.pointToPixel(y, zoom);
205+
int xInPixels = DPIUtil.pointToPixel(x, zoom);
206+
int yInPixels = DPIUtil.pointToPixel(y, zoom);
207207
return containsInPixels(regionHandle.handle(), xInPixels, yInPixels);
208208
});
209209
}

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -379,9 +379,9 @@ void computeRuns (GC gc) {
379379
}
380380
SCRIPT_LOGATTR logAttr = new SCRIPT_LOGATTR();
381381
SCRIPT_PROPERTIES properties = new SCRIPT_PROPERTIES();
382-
int wrapIndentInPixels = Win32DPIUtils.pointToPixel(wrapIndent, getZoom(gc));
383-
int indentInPixels = Win32DPIUtils.pointToPixel(indent, getZoom(gc));
384-
int wrapWidthInPixels = Win32DPIUtils.pointToPixel(wrapWidth, getZoom(gc));
382+
int wrapIndentInPixels = DPIUtil.pointToPixel(wrapIndent, getZoom(gc));
383+
int indentInPixels = DPIUtil.pointToPixel(indent, getZoom(gc));
384+
int wrapWidthInPixels = DPIUtil.pointToPixel(wrapWidth, getZoom(gc));
385385
int[] tabsInPixels = Win32DPIUtils.pointToPixel(tabs, getZoom(gc));
386386
int lineWidth = indentInPixels, lineStart = 0, lineCount = 1;
387387
for (int i=0; i<allRuns.length - 1; i++) {
@@ -1896,8 +1896,8 @@ Rectangle getBoundsInPixels (int start, int end) {
18961896
}
18971897
left = Math.min(left, runLead);
18981898
right = Math.max(right, runTrail);
1899-
top = Math.min(top, Win32DPIUtils.pointToPixel(lineY[lineIndex], getZoom(null)));
1900-
bottom = Math.max(bottom, Win32DPIUtils.pointToPixel(lineY[lineIndex + 1] - lineSpacingInPoints, getZoom(null)));
1899+
top = Math.min(top, DPIUtil.pointToPixel(lineY[lineIndex], getZoom(null)));
1900+
bottom = Math.max(bottom, DPIUtil.pointToPixel(lineY[lineIndex + 1] - lineSpacingInPoints, getZoom(null)));
19011901
}
19021902
return new Rectangle(left, top, right - left, bottom - top + getScaledVerticalIndent());
19031903
}
@@ -2057,14 +2057,14 @@ int getLineIndent(int lineIndex) {
20572057
}
20582058

20592059
int getLineIndentInPixel (int lineIndex) {
2060-
int lineIndent = Win32DPIUtils.pointToPixel(wrapIndent, getZoom());
2060+
int lineIndent = DPIUtil.pointToPixel(wrapIndent, getZoom());
20612061
if (lineIndex == 0) {
2062-
lineIndent = Win32DPIUtils.pointToPixel(indent, getZoom());
2062+
lineIndent = DPIUtil.pointToPixel(indent, getZoom());
20632063
} else {
20642064
StyleItem[] previousLine = runs[lineIndex - 1];
20652065
StyleItem previousRun = previousLine[previousLine.length - 1];
20662066
if (previousRun.lineBreak && !previousRun.softBreak) {
2067-
lineIndent = Win32DPIUtils.pointToPixel(indent, getZoom());
2067+
lineIndent = DPIUtil.pointToPixel(indent, getZoom());
20682068
}
20692069
}
20702070
if (wrapWidth != -1) {
@@ -2078,8 +2078,8 @@ int getLineIndentInPixel (int lineIndex) {
20782078
if (partialLine) {
20792079
int lineWidth = this.lineWidthInPixels[lineIndex] + lineIndent;
20802080
switch (alignment) {
2081-
case SWT.CENTER: lineIndent += (Win32DPIUtils.pointToPixel(wrapWidth, getZoom()) - lineWidth) / 2; break;
2082-
case SWT.RIGHT: lineIndent += Win32DPIUtils.pointToPixel(wrapWidth, getZoom()) - lineWidth; break;
2081+
case SWT.CENTER: lineIndent += (DPIUtil.pointToPixel(wrapWidth, getZoom()) - lineWidth) / 2; break;
2082+
case SWT.RIGHT: lineIndent += DPIUtil.pointToPixel(wrapWidth, getZoom()) - lineWidth; break;
20832083
}
20842084
}
20852085
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,8 @@ public int getStyle () {
337337

338338
public long getHandle(int targetZoom) {
339339
if (!zoomToHandle.containsKey(targetZoom)) {
340-
int scaledWidth = Win32DPIUtils.pointToPixel(DPIUtil.pixelToPoint(width, this.zoom), targetZoom);
341-
int scaledHeight = Win32DPIUtils.pointToPixel(DPIUtil.pixelToPoint(height, this.zoom), targetZoom);
340+
int scaledWidth = DPIUtil.pointToPixel(DPIUtil.pixelToPoint(width, this.zoom), targetZoom);
341+
int scaledHeight = DPIUtil.pointToPixel(DPIUtil.pixelToPoint(height, this.zoom), targetZoom);
342342
long newImageListHandle = OS.ImageList_Create(scaledWidth, scaledHeight, flags, 16, 16);
343343
int count = OS.ImageList_GetImageCount (handle);
344344
for (int i = 0; i < count; i++) {

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

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -207,18 +207,9 @@ public static int[] pointToPixel(Drawable drawable, int[] pointArray, int zoom)
207207
return pointToPixel (pointArray, zoom);
208208
}
209209

210-
/**
211-
* Auto-scale up int dimensions to match the given zoom level
212-
*/
213-
public static int pointToPixel(int size, int zoom) {
214-
if (zoom == 100 || size == SWT.DEFAULT) return size;
215-
float scaleFactor = DPIUtil.getScalingFactor(zoom);
216-
return Math.round (size * scaleFactor);
217-
}
218-
219210
public static int pointToPixel(Drawable drawable, int size, int zoom) {
220211
if (drawable != null && !drawable.isAutoScalable()) return size;
221-
return pointToPixel (size, zoom);
212+
return DPIUtil.pointToPixel (size, zoom);
222213
}
223214

224215
public static float pointToPixel(float size, int zoom) {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -360,10 +360,10 @@ else if ((style & SWT.RIGHT) != 0) {
360360
Rectangle rect = Win32DPIUtils.scaleBounds(image.getBounds(), this.getZoom(), 100);
361361
width = rect.width;
362362
if (hasText && text.length () != 0) {
363-
width += Win32DPIUtils.pointToPixel(MARGIN * 2, getZoom());;
363+
width += DPIUtil.pointToPixel(MARGIN * 2, getZoom());;
364364
}
365365
height = rect.height;
366-
extra = Win32DPIUtils.pointToPixel(MARGIN * 2, getZoom());;
366+
extra = DPIUtil.pointToPixel(MARGIN * 2, getZoom());;
367367
}
368368
}
369369
if (hasText) {
@@ -377,7 +377,7 @@ else if ((style & SWT.RIGHT) != 0) {
377377
if (length == 0) {
378378
height = Math.max (height, lptm.tmHeight);
379379
} else {
380-
extra = Math.max (Win32DPIUtils.pointToPixel(MARGIN * 2, getZoom()), lptm.tmAveCharWidth);
380+
extra = Math.max (DPIUtil.pointToPixel(MARGIN * 2, getZoom()), lptm.tmAveCharWidth);
381381
char [] buffer = text.toCharArray ();
382382
RECT rect = new RECT ();
383383
int flags = OS.DT_CALCRECT | OS.DT_SINGLELINE;
@@ -1313,7 +1313,7 @@ private int getCheckboxTextOffset(long hdc) {
13131313
OS.GetThemePartSize(display.hButtonTheme(nativeZoom), hdc, OS.BP_CHECKBOX, OS.CBS_UNCHECKEDNORMAL, null, OS.TS_TRUE, size);
13141314
result += size.cx;
13151315
} else {
1316-
result += Win32DPIUtils.pointToPixel(13, nativeZoom);
1316+
result += DPIUtil.pointToPixel(13, nativeZoom);
13171317
}
13181318

13191319
// Windows uses half width of '0' as checkbox-to-text distance.

0 commit comments

Comments
 (0)