Skip to content

Commit e10ef48

Browse files
ShahzaibIbrahimfedejeanne
authored andcommitted
Refactor: Replace autoScale calls with scaleUp/Down
Removing all autoScale method from DPIUtil and replace it usages with scaleDown/Up method and pass the zoom from the caller side
1 parent 756e8d8 commit e10ef48

File tree

10 files changed

+43
-269
lines changed

10 files changed

+43
-269
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
@@ -294,7 +294,7 @@ public void componentResized (ComponentEvent e) {
294294
display.syncExec (() -> {
295295
if (shell.isDisposed()) return;
296296
Dimension dim = parent.getSize ();
297-
shell.setSize(DPIUtil.autoScaleDown(new Point(dim.width, dim.height))); // To Points
297+
shell.setSize(DPIUtil.scaleDown(new Point(dim.width, dim.height), DPIUtil.getDeviceZoom())); // To Points
298298
});
299299
}
300300
};

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 = DPIUtil.autoScaleDown(new Point(screenX, screenY)); // To Points
1883+
Point position = DPIUtil.scaleDown(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.autoScaleDown(pt.x); // To Points
324-
pt.y = DPIUtil.autoScaleDown(pt.y); // To Points
323+
pt.x = DPIUtil.scaleDown(pt.x, DPIUtil.getDeviceZoom()); // To Points
324+
pt.y = DPIUtil.scaleDown(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/common/org/eclipse/swt/graphics/ImageData.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2609,35 +2609,36 @@ static void buildDitheredGradientChannel(int from, int to, int steps,
26092609
* @param redBits the number of significant red bits, 0 for palette modes
26102610
* @param greenBits the number of significant green bits, 0 for palette modes
26112611
* @param blueBits the number of significant blue bits, 0 for palette modes
2612+
* @param zoom the zoom of gc drawer used
26122613
*/
26132614
static void fillGradientRectangle(GC gc, Device device,
26142615
int x, int y, int width, int height, boolean vertical,
26152616
RGB fromRGB, RGB toRGB,
2616-
int redBits, int greenBits, int blueBits) {
2617+
int redBits, int greenBits, int blueBits, int zoom) {
26172618
/* Create the bitmap and tile it */
26182619
ImageData band = createGradientBand(width, height, vertical,
26192620
fromRGB, toRGB, redBits, greenBits, blueBits);
26202621
Image image = new Image(device, band);
26212622
if ((band.width == 1) || (band.height == 1)) {
2622-
gc.drawImage(image, 0, 0, DPIUtil.autoScaleDown(band.width), DPIUtil.autoScaleDown(band.height),
2623-
DPIUtil.autoScaleDown(x), DPIUtil.autoScaleDown(y), DPIUtil.autoScaleDown(width),
2624-
DPIUtil.autoScaleDown(height));
2623+
gc.drawImage(image, 0, 0, DPIUtil.scaleDown(band.width, zoom), DPIUtil.scaleDown(band.height, zoom),
2624+
DPIUtil.scaleDown(x, zoom), DPIUtil.scaleDown(y, zoom), DPIUtil.scaleDown(width, zoom),
2625+
DPIUtil.scaleDown(height, zoom));
26252626
} else {
26262627
if (vertical) {
26272628
for (int dx = 0; dx < width; dx += band.width) {
26282629
int blitWidth = width - dx;
26292630
if (blitWidth > band.width) blitWidth = band.width;
2630-
gc.drawImage(image, 0, 0, DPIUtil.autoScaleDown(blitWidth), DPIUtil.autoScaleDown(band.height),
2631-
DPIUtil.autoScaleDown(dx + x), DPIUtil.autoScaleDown(y), DPIUtil.autoScaleDown(blitWidth),
2632-
DPIUtil.autoScaleDown(band.height));
2631+
gc.drawImage(image, 0, 0, DPIUtil.scaleDown(blitWidth, zoom), DPIUtil.scaleDown(band.height, zoom),
2632+
DPIUtil.scaleDown(dx + x, zoom), DPIUtil.scaleDown(y, zoom), DPIUtil.scaleDown(blitWidth, zoom),
2633+
DPIUtil.scaleDown(band.height, zoom));
26332634
}
26342635
} else {
26352636
for (int dy = 0; dy < height; dy += band.height) {
26362637
int blitHeight = height - dy;
26372638
if (blitHeight > band.height) blitHeight = band.height;
2638-
gc.drawImage(image, 0, 0, DPIUtil.autoScaleDown(band.width), DPIUtil.autoScaleDown(blitHeight),
2639-
DPIUtil.autoScaleDown(x), DPIUtil.autoScaleDown(dy + y), DPIUtil.autoScaleDown(band.width),
2640-
DPIUtil.autoScaleDown(blitHeight));
2639+
gc.drawImage(image, 0, 0, DPIUtil.scaleDown(band.width, zoom), DPIUtil.scaleDown(blitHeight, zoom),
2640+
DPIUtil.scaleDown(x, zoom), DPIUtil.scaleDown(dy + y, zoom), DPIUtil.scaleDown(band.width, zoom),
2641+
DPIUtil.scaleDown(blitHeight, zoom));
26412642
}
26422643
}
26432644
}

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

Lines changed: 0 additions & 158 deletions
Original file line numberDiff line numberDiff line change
@@ -116,37 +116,6 @@ public static Optional<AutoScaleMethod> forString(String s) {
116116
autoScaleMethod = AUTO_SCALE_METHOD_SETTING != AutoScaleMethod.AUTO ? AUTO_SCALE_METHOD_SETTING : AutoScaleMethod.NEAREST;
117117
}
118118

119-
/**
120-
* Auto-scale down ImageData
121-
*/
122-
public static ImageData autoScaleDown (Device device, final ImageData imageData) {
123-
if (deviceZoom == 100 || imageData == null || (device != null && !device.isAutoScalable())) return imageData;
124-
float scaleFactor = 1.0f / getScalingFactor (deviceZoom);
125-
return autoScaleImageData(device, imageData, scaleFactor);
126-
}
127-
128-
public static int[] autoScaleDown(int[] pointArray) {
129-
if (deviceZoom == 100 || pointArray == null) return pointArray;
130-
float scaleFactor = getScalingFactor (deviceZoom);
131-
int [] returnArray = new int[pointArray.length];
132-
for (int i = 0; i < pointArray.length; i++) {
133-
returnArray [i] = Math.round (pointArray [i] / scaleFactor);
134-
}
135-
return returnArray;
136-
}
137-
138-
public static int[] autoScaleDown(Drawable drawable, int[] pointArray) {
139-
if (drawable != null && !drawable.isAutoScalable ()) return pointArray;
140-
return autoScaleDown (pointArray);
141-
}
142-
143-
/**
144-
* Auto-scale down float array dimensions.
145-
*/
146-
public static float[] autoScaleDown(float size[]) {
147-
return scaleDown(size, deviceZoom);
148-
}
149-
150119
public static float[] scaleDown(float size[], int zoom) {
151120
if (zoom == 100 || size == null) return size;
152121
float scaleFactor = getScalingFactor (zoom);
@@ -157,75 +126,33 @@ public static float[] scaleDown(float size[], int zoom) {
157126
return scaledSize;
158127
}
159128

160-
/**
161-
* Auto-scale down float array dimensions if enabled for Drawable class.
162-
*/
163-
public static float[] autoScaleDown(Drawable drawable, float size[]) {
164-
return scaleDown(drawable, size, deviceZoom);
165-
}
166-
167129
public static float[] scaleDown(Drawable drawable, float size[], int zoom) {
168130
if (drawable != null && !drawable.isAutoScalable()) return size;
169131
return scaleDown(size, zoom);
170132
}
171133

172-
/**
173-
* Auto-scale down int dimensions.
174-
*/
175-
public static int autoScaleDown(int size) {
176-
return scaleDown(size, deviceZoom);
177-
}
178-
179134
public static int scaleDown(int size, int zoom) {
180135
if (zoom == 100 || size == SWT.DEFAULT) return size;
181136
float scaleFactor = getScalingFactor (zoom);
182137
return Math.round (size / scaleFactor);
183138
}
184139

185-
/**
186-
* Auto-scale down int dimensions if enabled for Drawable class.
187-
*/
188-
public static int autoScaleDown(Drawable drawable, int size) {
189-
return scaleDown(drawable, size, deviceZoom);
190-
}
191-
192140
public static int scaleDown(Drawable drawable, int size, int zoom) {
193141
if (drawable != null && !drawable.isAutoScalable()) return size;
194142
return scaleDown (size, zoom);
195143
}
196144

197-
/**
198-
* Auto-scale down float dimensions.
199-
*/
200-
public static float autoScaleDown(float size) {
201-
return scaleDown(size, deviceZoom);
202-
}
203-
204145
public static float scaleDown(float size, int zoom) {
205146
if (zoom == 100 || size == SWT.DEFAULT) return size;
206147
float scaleFactor = getScalingFactor (zoom);
207148
return (size / scaleFactor);
208149
}
209150

210-
/**
211-
* Auto-scale down float dimensions if enabled for Drawable class.
212-
*/
213-
public static float autoScaleDown(Drawable drawable, float size) {
214-
return scaleDown (drawable, size, deviceZoom);
215-
}
216-
217151
public static float scaleDown(Drawable drawable, float size, int zoom) {
218152
if (drawable != null && !drawable.isAutoScalable()) return size;
219153
return scaleDown (size, zoom);
220154
}
221155

222-
/**
223-
* Returns a new scaled down Point.
224-
*/
225-
public static Point autoScaleDown(Point point) {
226-
return scaleDown(point, deviceZoom);
227-
}
228-
229156
public static Point scaleDown(Point point, int zoom) {
230157
if (zoom == 100 || point == null) return point;
231158
Point.OfFloat fPoint = FloatAwareGeometryFactory.createFrom(point);
@@ -235,35 +162,14 @@ public static Point scaleDown(Point point, int zoom) {
235162
return new Point.OfFloat(scaledX, scaledY);
236163
}
237164

238-
/**
239-
* Returns a new scaled down Point if enabled for Drawable class.
240-
*/
241-
public static Point autoScaleDown(Drawable drawable, Point point) {
242-
return scaleDown(drawable, point, deviceZoom);
243-
}
244-
245165
public static Point scaleDown(Drawable drawable, Point point, int zoom) {
246166
if (drawable != null && !drawable.isAutoScalable()) return point;
247167
return scaleDown (point, zoom);
248168
}
249169

250-
/**
251-
* Returns a new scaled down Rectangle.
252-
*/
253-
public static Rectangle autoScaleDown(Rectangle rect) {
254-
return scaleDown(rect, deviceZoom);
255-
}
256-
257170
public static Rectangle scaleDown(Rectangle rect, int zoom) {
258171
return scaleBounds(rect, 100, zoom);
259172
}
260-
/**
261-
* Returns a new scaled down Rectangle if enabled for Drawable class.
262-
*/
263-
public static Rectangle autoScaleDown(Drawable drawable, Rectangle rect) {
264-
if (drawable != null && !drawable.isAutoScalable()) return rect;
265-
return scaleDown(rect, deviceZoom);
266-
}
267173

268174
public static Rectangle scaleDown(Drawable drawable, Rectangle rect, int zoom) {
269175
if (drawable != null && !drawable.isAutoScalable()) return rect;
@@ -342,17 +248,6 @@ public static ImageData autoScaleImageData (Device device, final ImageData image
342248
return autoScaleImageData(device, imageData, scaleFactor);
343249
}
344250

345-
/**
346-
* Auto-scale up ImageData to device zoom that is at 100%.
347-
*/
348-
public static ImageData autoScaleUp (Device device, final ImageData imageData) {
349-
return autoScaleImageData(device, imageData, 100);
350-
}
351-
352-
public static int[] autoScaleUp(int[] pointArray) {
353-
return scaleUp(pointArray, deviceZoom);
354-
}
355-
356251
public static int[] scaleUp(int[] pointArray, int zoom) {
357252
if (zoom == 100 || pointArray == null) return pointArray;
358253
float scaleFactor = getScalingFactor(zoom);
@@ -363,20 +258,10 @@ public static int[] scaleUp(int[] pointArray, int zoom) {
363258
return returnArray;
364259
}
365260

366-
public static int[] autoScaleUp(Drawable drawable, int[] pointArray) {
367-
return scaleUp(drawable, pointArray, deviceZoom);
368-
}
369-
370261
public static int[] scaleUp(Drawable drawable, int[] pointArray, int zoom) {
371262
if (drawable != null && !drawable.isAutoScalable()) return pointArray;
372263
return scaleUp (pointArray, zoom);
373264
}
374-
/**
375-
* Auto-scale up int dimensions.
376-
*/
377-
public static int autoScaleUp(int size) {
378-
return scaleUp(size, deviceZoom);
379-
}
380265

381266
/**
382267
* Auto-scale up int dimensions to match the given zoom level
@@ -387,44 +272,22 @@ public static int scaleUp(int size, int zoom) {
387272
return Math.round (size * scaleFactor);
388273
}
389274

390-
/**
391-
* Auto-scale up int dimensions if enabled for Drawable class.
392-
*/
393-
public static int autoScaleUp(Drawable drawable, int size) {
394-
return scaleUp(drawable, size, deviceZoom);
395-
}
396-
397275
public static int scaleUp(Drawable drawable, int size, int zoom) {
398276
if (drawable != null && !drawable.isAutoScalable()) return size;
399277
return scaleUp (size, zoom);
400278
}
401279

402-
public static float autoScaleUp(float size) {
403-
return scaleUp(size, deviceZoom);
404-
}
405-
406280
public static float scaleUp(float size, int zoom) {
407281
if (zoom == 100 || size == SWT.DEFAULT) return size;
408282
float scaleFactor = getScalingFactor(zoom);
409283
return (size * scaleFactor);
410284
}
411285

412-
public static float autoScaleUp(Drawable drawable, float size) {
413-
return scaleUp(drawable, size, deviceZoom);
414-
}
415-
416286
public static float scaleUp(Drawable drawable, float size, int zoom) {
417287
if (drawable != null && !drawable.isAutoScalable()) return size;
418288
return scaleUp (size, zoom);
419289
}
420290

421-
/**
422-
* Returns a new scaled up Point.
423-
*/
424-
public static Point autoScaleUp(Point point) {
425-
return scaleUp(point, deviceZoom);
426-
}
427-
428291
public static Point scaleUp(Point point, int zoom) {
429292
if (zoom == 100 || point == null) return point;
430293
Point.OfFloat fPoint = FloatAwareGeometryFactory.createFrom(point);
@@ -434,36 +297,15 @@ public static Point scaleUp(Point point, int zoom) {
434297
return new Point.OfFloat(scaledX, scaledY);
435298
}
436299

437-
/**
438-
* Returns a new scaled up Point if enabled for Drawable class.
439-
*/
440-
public static Point autoScaleUp(Drawable drawable, Point point) {
441-
return scaleUp (drawable, point, deviceZoom);
442-
}
443-
444300
public static Point scaleUp(Drawable drawable, Point point, int zoom) {
445301
if (drawable != null && !drawable.isAutoScalable()) return point;
446302
return scaleUp (point, zoom);
447303
}
448304

449-
/**
450-
* Returns a new scaled up Rectangle.
451-
*/
452-
public static Rectangle autoScaleUp(Rectangle rect) {
453-
return scaleUp(rect, deviceZoom);
454-
}
455-
456305
public static Rectangle scaleUp(Rectangle rect, int zoom) {
457306
return scaleBounds(rect, zoom, 100);
458307
}
459308

460-
/**
461-
* Returns a new scaled up Rectangle if enabled for Drawable class.
462-
*/
463-
public static Rectangle autoScaleUp(Drawable drawable, Rectangle rect) {
464-
return scaleUp(drawable, rect, deviceZoom);
465-
}
466-
467309
public static Rectangle scaleUp(Drawable drawable, Rectangle rect, int zoom) {
468310
if (drawable != null && !drawable.isAutoScalable()) return rect;
469311
return scaleUp (rect, zoom);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3089,11 +3089,11 @@ private class FillGradientRectangleOperation extends FillRectangleOperation {
30893089
@Override
30903090
void apply() {
30913091
Rectangle rect = DPIUtil.scaleUp(drawable, rectangle, getZoom());
3092-
fillGradientRectangleInPixels(rect.x, rect.y, rect.width, rect.height, vertical);
3092+
fillGradientRectangleInPixels(rect.x, rect.y, rect.width, rect.height, vertical, getZoom());
30933093
}
30943094
}
30953095

3096-
private void fillGradientRectangleInPixels(int x, int y, int width, int height, boolean vertical) {
3096+
private void fillGradientRectangleInPixels(int x, int y, int width, int height, boolean vertical, int zoom) {
30973097
if (width == 0 || height == 0) return;
30983098

30993099
RGB backgroundRGB, foregroundRGB;
@@ -3183,7 +3183,7 @@ private void fillGradientRectangleInPixels(int x, int y, int width, int height,
31833183
final int bitResolution = (depth >= 24) ? 8 : (depth >= 15) ? 5 : 0;
31843184
ImageData.fillGradientRectangle(this, data.device,
31853185
x, y, width, height, vertical, fromRGB, toRGB,
3186-
bitResolution, bitResolution, bitResolution);
3186+
bitResolution, bitResolution, bitResolution, zoom);
31873187
}
31883188

31893189
/**

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,7 +1592,7 @@ public Menu getMenuBar () {
15921592
@Override
15931593
public Rectangle getBounds() {
15941594
checkDevice ();
1595-
return DPIUtil.autoScaleDown(getBoundsInPixels());
1595+
return DPIUtil.scaleDown(getBoundsInPixels(), DPIUtil.getDeviceZoom());
15961596
}
15971597

15981598
Rectangle getBoundsInPixels () {
@@ -1665,7 +1665,7 @@ int getClickCount (int type, int button, long hwnd, long lParam) {
16651665
@Override
16661666
public Rectangle getClientArea () {
16671667
checkDevice ();
1668-
return DPIUtil.autoScaleDown(getClientAreaInPixels());
1668+
return DPIUtil.scaleDown(getClientAreaInPixels(), DPIUtil.getDeviceZoom());
16691669
}
16701670

16711671
Rectangle getClientAreaInPixels () {

0 commit comments

Comments
 (0)