Skip to content

Commit 9973218

Browse files
committed
Using eclipse Automatic refactoring to move Win32DPIUtils.pointToPixel(size,zoom) to DPIUtils
1 parent 2ac13c9 commit 9973218

File tree

33 files changed

+126
-125
lines changed

33 files changed

+126
-125
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
@@ -1256,8 +1256,8 @@ int handleContextMenuRequested(long pView, long pArgs) {
12561256
// to PIXEL coordinates with the real native zoom value
12571257
// independent from the swt.autoScale property:
12581258
Point pt = new Point( //
1259-
Win32DPIUtils.pointToPixel(win32Point.x, DPIUtil.getNativeDeviceZoom()), //
1260-
Win32DPIUtils.pointToPixel(win32Point.y, DPIUtil.getNativeDeviceZoom()));
1259+
DPIUtil.pointToPixel(win32Point.x, DPIUtil.getNativeDeviceZoom()), //
1260+
DPIUtil.pointToPixel(win32Point.y, DPIUtil.getNativeDeviceZoom()));
12611261
// - then, scale back down from PIXEL to DISPLAY coordinates, taking
12621262
// swt.autoScale property into account
12631263
// 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/graphics/ImageData.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2617,8 +2617,8 @@ static void fillGradientRectangle(GC gc, Device device,
26172617
int redBits, int greenBits, int blueBits, int zoom) {
26182618
/* Create the bitmap and tile it */
26192619
ImageDataProvider imageDataProvider = imageZoom -> {
2620-
int scaledWidth = Win32DPIUtils.pointToPixel(width, imageZoom);
2621-
int scaledHeight = Win32DPIUtils.pointToPixel(height, imageZoom);
2620+
int scaledWidth = DPIUtil.pointToPixel(width, imageZoom);
2621+
int scaledHeight = DPIUtil.pointToPixel(height, imageZoom);
26222622
return createGradientBand(scaledWidth, scaledHeight, vertical, fromRGB, toRGB, redBits, greenBits,
26232623
blueBits);
26242624
};

bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/DPIUtil.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,21 @@ public static int mapZoomToDPI (int zoom) {
223223
return roundedDpi;
224224
}
225225

226+
/**
227+
* Auto-scale up int dimensions to match the given zoom level
228+
*/
229+
public static int pointToPixel(int size, int zoom) {
230+
if (zoom == 100 || size == SWT.DEFAULT) return size;
231+
float scaleFactor = getScalingFactor(zoom);
232+
return Math.round (size * scaleFactor);
233+
}
234+
235+
public static float pointToPixel(float size, int zoom) {
236+
if (zoom == 100 || size == SWT.DEFAULT) return size;
237+
float scaleFactor = getScalingFactor(zoom);
238+
return (size * scaleFactor);
239+
}
240+
226241
/**
227242
* Represents an element, such as some image data, at a specific zoom level.
228243
*

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
@@ -2199,8 +2199,8 @@ private ImageHandle createHandle(int zoom) {
21992199

22002200
private long initHandle(int zoom) {
22012201
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
2202-
int scaledWidth = Win32DPIUtils.pointToPixel (width, zoom);
2203-
int scaledHeight = Win32DPIUtils.pointToPixel (height, zoom);
2202+
int scaledWidth = DPIUtil.pointToPixel (width, zoom);
2203+
int scaledHeight = DPIUtil.pointToPixel (height, zoom);
22042204
long hDC = device.internal_new_GC(null);
22052205
long newHandle = OS.CreateCompatibleBitmap(hDC, scaledWidth, scaledHeight);
22062206
/*
@@ -2598,8 +2598,8 @@ protected ImageHandle newImageHandle(int zoom) {
25982598
int gcStyle = drawer.getGcStyle();
25992599
Image image;
26002600
if ((gcStyle & SWT.TRANSPARENT) != 0) {
2601-
int scaledHeight = Win32DPIUtils.pointToPixel(height, zoom);
2602-
int scaledWidth = Win32DPIUtils.pointToPixel(width, zoom);
2601+
int scaledHeight = DPIUtil.pointToPixel(height, zoom);
2602+
int scaledWidth = DPIUtil.pointToPixel(width, zoom);
26032603
/* Create a 24 bit image data with alpha channel */
26042604
final ImageData resultData = new ImageData (scaledWidth, scaledHeight, 24, new PaletteData (0xFF, 0xFF00, 0xFF0000));
26052605
resultData.alphaData = new byte [scaledWidth * scaledHeight];

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,10 +261,10 @@ public BasePatternHandle(int zoom) {
261261
@Override
262262
long createHandle(int zoom) {
263263
long handle;
264-
float x1 = Win32DPIUtils.pointToPixel(baseX1, zoom);
265-
float y1 = Win32DPIUtils.pointToPixel(baseY1, zoom);
266-
float x2 = Win32DPIUtils.pointToPixel(baseX2, zoom);
267-
float y2 = Win32DPIUtils.pointToPixel(baseY2, zoom);
264+
float x1 = DPIUtil.pointToPixel(baseX1, zoom);
265+
float y1 = DPIUtil.pointToPixel(baseY1, zoom);
266+
float x2 = DPIUtil.pointToPixel(baseX2, zoom);
267+
float y2 = DPIUtil.pointToPixel(baseY2, zoom);
268268
if (color1 == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
269269
if (color1.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
270270
if (color2 == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);

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/graphics/Transform.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ public MultiplyOperation(Transform matrix) {
428428
public void apply(TransformHandle transformHandle) {
429429
long handle = transformHandle.handle;
430430
int zoom = transformHandle.zoom;
431-
long newHandle = Gdip.Matrix_new(elements[0], elements[1], elements[2], elements[3], Win32DPIUtils.pointToPixel(elements[4], zoom), Win32DPIUtils.pointToPixel(elements[5], zoom));
431+
long newHandle = Gdip.Matrix_new(elements[0], elements[1], elements[2], elements[3], DPIUtil.pointToPixel(elements[4], zoom), DPIUtil.pointToPixel(elements[5], zoom));
432432
if (newHandle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
433433
try {
434434
Gdip.Matrix_Multiply(handle, newHandle, Gdip.MatrixOrderPrepend);

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
@@ -332,8 +332,8 @@ public int getStyle () {
332332

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

0 commit comments

Comments
 (0)