Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSravan Kumar Lakkimsetti2016-02-03 05:49:05 +0000
committerSravan Kumar Lakkimsetti2016-02-03 05:49:05 +0000
commit1888432b8a02ce4c7c1fd54af1e9a0ae5c149d39 (patch)
treec8d426352778a8c305c9f94431106df5b87a8b9d
parentab0c6137e3ec800bdda4ed5635963c2a7a9e16fe (diff)
parentcec2a0ce0998e5a3b943b9309818dc308b824d38 (diff)
downloadeclipse.platform.swt-1888432b8a02ce4c7c1fd54af1e9a0ae5c149d39.tar.gz
eclipse.platform.swt-1888432b8a02ce4c7c1fd54af1e9a0ae5c149d39.tar.xz
eclipse.platform.swt-1888432b8a02ce4c7c1fd54af1e9a0ae5c149d39.zip
Merge branch 'slakkimsetti/NeonhiDpiWork' of
ssh://slakkimsetti@git.eclipse.org/gitroot/platform/eclipse.platform.swt.git into slakkimsetti/NeonhiDpiWork Conflicts: bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/DPIUtil.java
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Image.java25
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/DPIUtil.java219
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Resource.java25
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java4
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Device.java4
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/GC.java160
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java65
-rw-r--r--tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_Image.java2
8 files changed, 251 insertions, 253 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Image.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Image.java
index fb95673dfb..eb3d395eff 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Image.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Image.java
@@ -10,10 +10,10 @@
*******************************************************************************/
package org.eclipse.swt.graphics;
+import java.io.*;
-import org.eclipse.swt.internal.cocoa.*;
import org.eclipse.swt.*;
-import java.io.*;
+import org.eclipse.swt.internal.cocoa.*;
/**
* Instances of this class are graphics which have been prepared
@@ -875,14 +875,14 @@ public Rectangle getBounds(int zoom) {
*/
public ImageData getImageData() {
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- ImageData imageData = _getImageData();
- if (imageData != null && getEnableAutoScaling()) {
- data = DPIUtil.autoScaleImageData(data, 100, currentDeviceZoom);
- }
- return imageData;
+ return _getImageData();
}
-ImageData _getImageData() {
+ImageData _getImageData () {
+ return _getImageData(100);
+}
+
+ImageData _getImageData(int zoom) {
NSAutoreleasePool pool = null;
if (!NSThread.isMainThread()) pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
try {
@@ -953,7 +953,6 @@ ImageData _getImageData() {
}
/**
-<<<<<<< HEAD
* Returns an <code>ImageData</code> for specified zoom, based on the receiver
* Modifications made to this <code>ImageData</code> will not affect the
* Image.
@@ -971,17 +970,15 @@ ImageData _getImageData() {
* </ul>
*
* @see ImageData
- *
+ *
* @since 3.105
*/
public ImageData getImageData (int zoom) {
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return DPIUtil.getImageData (this, zoom);
+ return _getImageData (zoom);
}
-/**
-=======
->>>>>>> refs/remotes/origin/master
+/**
* Invokes platform specific functionality to allocate a new image.
* <p>
* <b>IMPORTANT:</b> This method is <em>not</em> part of the public
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/DPIUtil.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/DPIUtil.java
index 5b25ebf515..d8ae97cc8b 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/DPIUtil.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/DPIUtil.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2015 IBM Corporation and others.
+ * Copyright (c) 2016 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -27,119 +27,147 @@ public class DPIUtil {
private static boolean autoScale = true;
/**
- * Compute the zoom value based on the DPI value.
- *
- * @return zoom
+ * Auto-scale down ImageData
*/
-static int mapDPIToZoom (int dpi) {
- int zoom;
- if (dpi >= DPI_ZOOM_200) {
- zoom = 200;
- } else if (dpi >= DPI_ZOOM_150) {
- zoom = 150;
- } else {
- zoom = 100;
- }
- return zoom;
+public static ImageData autoScaleDown (ImageData imageData, Device device) {
+ if (!getAutoScale () || imageData == null || device == null) return imageData;
+ float scaleFactor = getScalingFactor (device);
+ return scaleFactor == 1 ? imageData
+ : imageData.scaledTo (Math.round ((float)imageData.width / scaleFactor), Math.round ((float)imageData.height / scaleFactor));
}
/**
- * Gets Image file path at specified zoom level, if image is missing then
- * fall-back to 100% image. If provider or fall-back image is not available,
- * throw error.
+ * Auto-scale down int dimensions.
*/
-static String validateAndGetImagePathAtZoom (ImageFileNameProvider provider, int zoom, boolean[] found) {
- if (provider == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- String filename = provider.getImagePath (zoom);
- found [0] = (filename != null);
- /* If image is null when (zoom != 100%), fall-back to image at 100% zoom */
- if (zoom != 100 && !found [0]) filename = provider.getImagePath (100);
- if (filename == null) SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- return filename;
+public static int autoScaleDown (int size, Device device) {
+ if (!getAutoScale () || device == null) return size;
+ float scaleFactor = getScalingFactor (device);
+ return Math.round (size / scaleFactor);
}
/**
- * Gets Image data at specified zoom level, if image is missing then
- * fall-back to 100% image. If provider or fall-back image is not available,
- * throw error.
+ * Returns a new scaled down Point.
*/
-static ImageData validateAndGetImageDataAtZoom (ImageDataProvider provider, int zoom, boolean[] found) {
- if (provider == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- ImageData data = provider.getImageData (zoom);
- found [0] = (data != null);
- /* If image is null when (zoom != 100%), fall-back to image at 100% zoom */
- if (zoom != 100 && !found [0]) data = provider.getImageData (100);
- if (data == null) SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- return data;
+public static Point autoScaleDown (Point point, Device device) {
+ if (!getAutoScale () || point == null || device == null) return point;
+ float scaleFactor = getScalingFactor (device);
+ if (scaleFactor == 1) return point;
+ Point scaledPoint = new Point (0,0);
+ scaledPoint.x = Math.round (point.x / scaleFactor);
+ scaledPoint.y = Math.round (point.y / scaleFactor);
+ return scaledPoint;
}
+
/**
- * Gets scaling factor for the current Image
+ * Returns a new scaled down Rectangle.
*/
-static float getscalingFactor (Image image) {
- float scalingFactor = ((float)image.getDeviceZoom ())/((float) 100);
- return scalingFactor;
+public static Rectangle autoScaleDown (Rectangle rect, Device device) {
+ if (!getAutoScale () || rect == null || device == null) return rect;
+ float scaleFactor = getScalingFactor (device);
+ if (scaleFactor == 1) return rect;
+ Rectangle scaledRect = new Rectangle (0,0,0,0);
+ scaledRect.x = Math.round (rect.x / scaleFactor);
+ scaledRect.y = Math.round (rect.y / scaleFactor);
+ scaledRect.width = Math.round (rect.width / scaleFactor);
+ scaledRect.height = Math.round (rect.height / scaleFactor);
+ return scaledRect;
}
+
/**
* Auto-scale image with ImageData
*/
-static ImageData autoScaleImageData (ImageData imageData, int targetZoom, int currentZoom) {
- if (imageData == null || targetZoom == currentZoom) return imageData;
+private static ImageData autoScaleImageData (ImageData imageData, int targetZoom, int currentZoom) {
+ if (!getAutoScale () || imageData == null || targetZoom == currentZoom) return imageData;
float scaleFactor = ((float) targetZoom)/((float) currentZoom);
- return imageData.scaledTo ((int)((float)imageData.width * scaleFactor), (int)((float)imageData.height * scaleFactor));
+ return imageData.scaledTo (Math.round ((float)imageData.width * scaleFactor), Math.round ((float)imageData.height * scaleFactor));
+}
+/**
+ * Auto-scale up ImageData
+ */
+public static ImageData autoScaleUp (ImageData imageData, Device device) {
+ if (!getAutoScale () || imageData == null || device == null) return imageData;
+ float scaleFactor = getScalingFactor (device);
+ return scaleFactor == 1 ? imageData
+ : imageData.scaledTo (Math.round ((float)imageData.width * scaleFactor), Math.round ((float)imageData.height * scaleFactor));
}
+
/**
- * Auto-scale image with ImageFileName
+ * Auto-scale up int dimensions.
*/
-static ImageData autoScaleImageFileName (String filename, int targetZoom, int currentZoom) {
- if (filename == null) return null;
- ImageData imageData = new ImageData (filename);
- return autoScaleImageData (imageData, targetZoom, currentZoom);
+public static int autoScaleUp (int size, Device device) {
+ if (!getAutoScale () || device == null) return size;
+ float scaleFactor = getScalingFactor (device);
+ return Math.round (size * scaleFactor);
}
/**
- * Returns a new rectangle as per the scaleFactor.
+ * Returns a new scaled up Point.
*/
-static Rectangle scale (Rectangle rect, int targetZoom, int currentZoom) {
- if (rect == null || targetZoom == currentZoom) return rect;
- float scaleFactor = ((float)targetZoom) / (float)currentZoom;
- Rectangle returnRect = new Rectangle (0,0,0,0);
- returnRect.x = (int) (rect.x * scaleFactor);
- returnRect.y = (int) (rect.y * scaleFactor);
- returnRect.width = Math.max(1, (int) (rect.width * scaleFactor));
- returnRect.height = Math.max(1, (int) (rect.height * scaleFactor));
- return returnRect;
+public static Point autoScaleUp (Point point, Device device) {
+ if (!getAutoScale () || point == null || device == null) return point;
+ float scaleFactor = getScalingFactor (device);
+ if (scaleFactor == 1) return point;
+ Point scaledPoint = new Point (0,0);
+ scaledPoint.x = Math.round (point.x * scaleFactor);
+ scaledPoint.y = Math.round (point.y * scaleFactor);
+ return scaledPoint;
+}
+
+/**
+ * Returns a new scaled up Rectangle.
+ */
+public static Rectangle autoScaleUp (Rectangle rect, Device device) {
+ if (!getAutoScale () || rect == null || device == null) return rect;
+ float scaleFactor = getScalingFactor (device);
+ if (scaleFactor == 1) return rect;
+ Rectangle scaledRect = new Rectangle (0,0,0,0);
+ scaledRect.x = Math.round (rect.x * scaleFactor);
+ scaledRect.y = Math.round (rect.y * scaleFactor);
+ scaledRect.width = Math.round (rect.width * scaleFactor);
+ scaledRect.height = Math.round (rect.height * scaleFactor);
+ return scaledRect;
+}
+public static boolean getAutoScale () {
+ return autoScale;
}
/**
* Returns an <code>ImageData</code> for specified zoom.
*/
-static ImageData getImageData (Image image, int zoom) {
- if (image.currentDeviceZoom == zoom) return image._getImageData ();
+static ImageData getImageData (Image image, int source_zoom, int target_zoom) {
+ if (source_zoom == target_zoom) return image._getImageData ();
ImageData imageData = null;
if (image.imageDataProvider != null) {
boolean[] found = new boolean[1];
- imageData = DPIUtil.validateAndGetImageDataAtZoom (image.imageDataProvider, zoom, found);
+ imageData = DPIUtil.validateAndGetImageDataAtZoom (image.imageDataProvider, target_zoom, found);
if (!found[0]) {
- imageData = DPIUtil.autoScaleImageData (imageData, zoom, 100);
+ imageData = DPIUtil.autoScaleImageData (imageData, target_zoom, 100);
}
} else if (image.imageFileNameProvider != null) {
boolean[] found = new boolean[1];
- String filename = DPIUtil.validateAndGetImagePathAtZoom (image.imageFileNameProvider, zoom, found);
+ String filename = DPIUtil.validateAndGetImagePathAtZoom (image.imageFileNameProvider, target_zoom, found);
if (!found[0]) {
- imageData = DPIUtil.autoScaleImageFileName (filename, zoom, 100);
+ imageData = DPIUtil.autoScaleImageData (new ImageData(filename), target_zoom, 100);
} else {
imageData = new ImageData (filename);
}
} else {
/* Get ImageData at currentZoom and scale it to specified zoom. */
imageData = image._getImageData ();
- imageData = DPIUtil.autoScaleImageData (imageData, zoom, image.currentDeviceZoom);
+ imageData = DPIUtil.autoScaleImageData (imageData, target_zoom, source_zoom);
}
return imageData;
}
/**
+ * Gets scaling factor for the current Image
+ */
+public static float getscalingFactor (Image image) {
+ return ((float)image.getDevice ().getDeviceZoom ()) / 100f;
+}
+
+/**
* Returns Scaling factor from the display
* @return float scaling factor
*/
@@ -151,11 +179,64 @@ public static float getScalingFactor (Device device) {
return scalingFactor;
}
-public static boolean getAutoScale () {
- return autoScale;
+/**
+ * Compute the zoom value based on the DPI value.
+ *
+ * @return zoom
+ */
+static int mapDPIToZoom (int dpi) {
+ int zoom;
+ if (dpi >= DPI_ZOOM_200) {
+ zoom = 200;
+ } else if (dpi >= DPI_ZOOM_150) {
+ zoom = 150;
+ } else {
+ zoom = 100;
+ }
+ return zoom;
+}
+/**
+ * Returns a new rectangle as per the scaleFactor.
+ */
+static Rectangle scale (Rectangle rect, int targetZoom, int currentZoom) {
+ if (rect == null || targetZoom == currentZoom) return rect;
+ float scaleFactor = ((float)targetZoom) / (float)currentZoom;
+ Rectangle returnRect = new Rectangle (0,0,0,0);
+ returnRect.x = Math.round (rect.x * scaleFactor);
+ returnRect.y = Math.round (rect.y * scaleFactor);
+ returnRect.width = Math.round (rect.width * scaleFactor);
+ returnRect.height = Math.round (rect.height * scaleFactor);
+ return returnRect;
}
-public static void setAutoScale (boolean autoScale) {
- DPIUtil.autoScale = autoScale;
+/**
+ * Gets Image data at specified zoom level, if image is missing then
+ * fall-back to 100% image. If provider or fall-back image is not available,
+ * throw error.
+ */
+static ImageData validateAndGetImageDataAtZoom (ImageDataProvider provider, int zoom, boolean[] found) {
+ if (provider == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
+ ImageData data = provider.getImageData (zoom);
+ found [0] = (data != null);
+ /* If image is null when (zoom != 100%), fall-back to image at 100% zoom */
+ if (zoom != 100 && !found [0]) data = provider.getImageData (100);
+ if (data == null) SWT.error (SWT.ERROR_INVALID_ARGUMENT);
+ return data;
}
+
+/**
+ * Gets Image file path at specified zoom level, if image is missing then
+ * fall-back to 100% image. If provider or fall-back image is not available,
+ * throw error.
+ */
+static String validateAndGetImagePathAtZoom (ImageFileNameProvider provider, int zoom, boolean[] found) {
+ if (provider == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
+ String filename = provider.getImagePath (zoom);
+ found [0] = (filename != null);
+ /* If image is null when (zoom != 100%), fall-back to image at 100% zoom */
+ if (zoom != 100 && !found [0]) filename = provider.getImagePath (100);
+ if (filename == null) SWT.error (SWT.ERROR_INVALID_ARGUMENT);
+ return filename;
+}
+
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Resource.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Resource.java
index a775f639bf..5b54cc27a6 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Resource.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Resource.java
@@ -82,24 +82,6 @@ public Device getDevice() {
return device;
}
-/**
- * Returns autoScaling settings for hiDpi screens
- *
- * @return boolean value for autoScaling
- * @since 3.105
- *
- */
-public boolean getEnableAutoScaling() {
- return DPIUtil.getAutoScale();
-}
-/**
- * Sets autoScaling settings for hiDpi screens
- * @since 3.105
- *
- */
-void setEnableAutoScaling(boolean value) {
- DPIUtil.setAutoScale(value);
-}
void init() {
if (device.tracking) device.new_Object(this);
}
@@ -116,11 +98,4 @@ void init() {
*/
public abstract boolean isDisposed();
-/**
- * @since 3.105
- */
-public int getDeviceZoom () {
- return device.getDeviceZoom ();
-}
-
} \ No newline at end of file
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java
index 067898720a..82125fcd7d 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java
@@ -174,7 +174,7 @@ public final class Image extends Resource implements Drawable {
/**
* Attribute to cache current device zoom level
*/
- int currentDeviceZoom = 100;
+ private int currentDeviceZoom = 100;
boolean autoScaled = false;
@@ -1548,7 +1548,7 @@ ImageData _getImageData() {
*/
public ImageData getImageData (int zoom) {
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return DPIUtil.getImageData (this, zoom);
+ return DPIUtil.getImageData (this, currentDeviceZoom, zoom);
}
/**
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Device.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Device.java
index 9888f708bb..5c287a1796 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Device.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Device.java
@@ -1000,4 +1000,8 @@ void setEnableAutoScaling(boolean value) {
enableAutoScaling = value;
}
+public int getDeviceZoom () {
+ return DPIUtil.mapDPIToZoom ( _getDPIx ());
+}
+
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/GC.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/GC.java
index 215f167035..9dbed7e0ec 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/GC.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/GC.java
@@ -170,7 +170,7 @@ public GC(Drawable drawable, int style) {
if (device == null) device = Device.getDevice();
if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
this.device = data.device = device;
- this.autoScaleEnabled = getEnableAutoScaling ();
+ this.autoScaleEnabled = DPIUtil.getAutoScale ();
init (drawable, data, hDC);
init();
}
@@ -450,11 +450,8 @@ public void copyArea(Image image, int x, int y) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
if (image.type != SWT.BITMAP || image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (autoScaleEnabled) {
- float scaleFactor = ((float)this.getDeviceZoom()) / 100f;
- x = (int)(x * scaleFactor);
- y = (int)(y * scaleFactor);
- }
+ x = DPIUtil.autoScaleUp(x, device);
+ y = DPIUtil.autoScaleUp(y, device);
/* Copy the bitmap area */
Rectangle rect = image.getBounds();
long /*int*/ memHdc = OS.CreateCompatibleDC(handle);
@@ -736,13 +733,8 @@ void disposeGdip() {
public void drawArc (int x, int y, int width, int height, int startAngle, int arcAngle) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
checkGC(DRAW);
- if (autoScaleEnabled) {
- float scaleFactor = ((float)getDeviceZoom()) / 100f;
- x = (int) (x * scaleFactor);
- y = (int) (y * scaleFactor);
- width = (int) (width * scaleFactor);
- height = (int) (height * scaleFactor);
- }
+ width = DPIUtil.autoScaleUp(width, device);
+ height = DPIUtil.autoScaleUp(height, device);
if (width < 0) {
x = x + width;
width = -width;
@@ -840,13 +832,11 @@ public void drawArc (int x, int y, int width, int height, int startAngle, int ar
*/
public void drawFocus (int x, int y, int width, int height) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (autoScaleEnabled) {
- float scaleFactor = (float) getDeviceZoom()/100f;
- x = (int) (x * scaleFactor);
- y = (int) (y * scaleFactor);
- width = (int) (width * scaleFactor);
- height = (int) (height *scaleFactor);
- }
+ x = DPIUtil.autoScaleUp (x, device);
+ y = DPIUtil.autoScaleUp (y, device);
+ width = DPIUtil.autoScaleUp (width, device);
+ height = DPIUtil.autoScaleUp (height, device);
+
if ((data.uiState & OS.UISF_HIDEFOCUS) != 0) return;
data.focusDrawn = true;
long /*int*/ hdc = handle;
@@ -1698,13 +1688,10 @@ void drawBitmap(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight,
*/
public void drawLine (int x1, int y1, int x2, int y2) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (autoScaleEnabled) {
- float scaleFactor = (float) getDeviceZoom()/100f;
- x1 = (int) (x1 * scaleFactor);
- x2 = (int) (x2 * scaleFactor);
- y1 = (int) (y1 * scaleFactor);
- y2 = (int) (y2 *scaleFactor);
- }
+ x1 = DPIUtil.autoScaleUp (x1, device);
+ x2 = DPIUtil.autoScaleUp (x2, device);
+ y1 = DPIUtil.autoScaleUp (y1, device);
+ y2 = DPIUtil.autoScaleUp (y2, device);
checkGC(DRAW);
long /*int*/ gdipGraphics = data.gdipGraphics;
@@ -1755,13 +1742,11 @@ public void drawLine (int x1, int y1, int x2, int y2) {
*/
public void drawOval (int x, int y, int width, int height) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (autoScaleEnabled) {
- float scaleFactor = (float) getDeviceZoom()/100f;
- x = (int) (x * scaleFactor);
- y = (int) (y * scaleFactor);
- width = (int) (width * scaleFactor);
- height = (int) (height *scaleFactor);
- }
+ x = DPIUtil.autoScaleUp (x, device);
+ y = DPIUtil.autoScaleUp (y, device);
+ width = DPIUtil.autoScaleUp (width, device);
+ height = DPIUtil.autoScaleUp (height, device);
+
checkGC(DRAW);
long /*int*/ gdipGraphics = data.gdipGraphics;
if (gdipGraphics != 0) {
@@ -1830,11 +1815,9 @@ public void drawPath (Path path) {
*/
public void drawPoint (int x, int y) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (autoScaleEnabled) {
- float scaleFactor = (float) getDeviceZoom()/100f;
- x = (int) (x * scaleFactor);
- y = (int) (y * scaleFactor);
- }
+ x = DPIUtil.autoScaleUp (x, device);
+ y = DPIUtil.autoScaleUp (y, device);
+
if (data.gdipGraphics != 0) {
checkGC(DRAW);
Gdip.Graphics_FillRectangle(data.gdipGraphics, getFgBrush(), x, y, 1, 1);
@@ -1957,11 +1940,10 @@ public void drawPolyline(int[] pointArray) {
public void drawRectangle (int x, int y, int width, int height) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
if (autoScaleEnabled) {
- float scaleFactor = (float) getDeviceZoom()/100f;
- x = (int) (x * scaleFactor);
- y = (int) (y * scaleFactor);
- width = (int) (width * scaleFactor);
- height = (int) (height *scaleFactor);
+ x = DPIUtil.autoScaleUp (x, device);
+ y = DPIUtil.autoScaleUp (y, device);
+ width = DPIUtil.autoScaleUp (width, device);
+ height = DPIUtil.autoScaleUp (height, device);
}
checkGC(DRAW);
long /*int*/ gdipGraphics = data.gdipGraphics;
@@ -2039,15 +2021,13 @@ public void drawRectangle (Rectangle rect) {
*/
public void drawRoundRectangle (int x, int y, int width, int height, int arcWidth, int arcHeight) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (autoScaleEnabled) {
- float scaleFactor = (float) getDeviceZoom()/100f;
- x = (int) (x * scaleFactor);
- y = (int) (y * scaleFactor);
- width = (int) (width * scaleFactor);
- height = (int) (height *scaleFactor);
- arcWidth = (int)(arcWidth *scaleFactor);
- arcHeight = (int)(arcHeight * scaleFactor);
- }
+ x = DPIUtil.autoScaleUp (x, device);
+ y = DPIUtil.autoScaleUp (y, device);
+ width = DPIUtil.autoScaleUp (width, device);
+ height = DPIUtil.autoScaleUp (height, device);
+ arcWidth = DPIUtil.autoScaleUp (arcWidth, device);
+ arcHeight = DPIUtil.autoScaleUp (arcHeight, device);
+
checkGC(DRAW);
if (data.gdipGraphics != 0) {
drawRoundRectangleGdip(data.gdipGraphics, data.gdipPen, x, y, width, height, arcWidth, arcHeight);
@@ -2744,13 +2724,11 @@ public boolean equals (Object object) {
*/
public void fillArc (int x, int y, int width, int height, int startAngle, int arcAngle) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (autoScaleEnabled) {
- float scaleFactor = (float) getDeviceZoom()/100f;
- x = (int) (x * scaleFactor);
- y = (int) (y * scaleFactor);
- width = (int) (width * scaleFactor);
- height = (int) (height *scaleFactor);
- }
+ x = DPIUtil.autoScaleUp (x, device);
+ y = DPIUtil.autoScaleUp (y, device);
+ width = DPIUtil.autoScaleUp (width, device);
+ height = DPIUtil.autoScaleUp (height, device);
+
checkGC(FILL);
if (width < 0) {
x = x + width;
@@ -2852,13 +2830,11 @@ public void fillArc (int x, int y, int width, int height, int startAngle, int ar
*/
public void fillGradientRectangle(int x, int y, int width, int height, boolean vertical) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (autoScaleEnabled) {
- float scaleFactor = (float) getDeviceZoom()/100f;
- x = (int) (x * scaleFactor);
- y = (int) (y * scaleFactor);
- width = (int) (width * scaleFactor);
- height = (int) (height *scaleFactor);
- }
+ x = DPIUtil.autoScaleUp (x, device);
+ y = DPIUtil.autoScaleUp (y, device);
+ width = DPIUtil.autoScaleUp (width, device);
+ height = DPIUtil.autoScaleUp (height, device);
+
if (width == 0 || height == 0) return;
RGB backgroundRGB, foregroundRGB;
@@ -2985,13 +2961,11 @@ public void fillGradientRectangle(int x, int y, int width, int height, boolean v
*/
public void fillOval (int x, int y, int width, int height) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (autoScaleEnabled) {
- float scaleFactor = (float) getDeviceZoom()/100f;
- x = (int) (x * scaleFactor);
- y = (int) (y * scaleFactor);
- width = (int) (width * scaleFactor);
- height = (int) (height *scaleFactor);
- }
+ x = DPIUtil.autoScaleUp (x, device);
+ y = DPIUtil.autoScaleUp (y, device);
+ width = DPIUtil.autoScaleUp (width, device);
+ height = DPIUtil.autoScaleUp (height, device);
+
checkGC(FILL);
if (data.gdipGraphics != 0) {
Gdip.Graphics_FillEllipse(data.gdipGraphics, data.gdipBrush, x, y, width, height);
@@ -3094,11 +3068,10 @@ public void fillPolygon(int[] pointArray) {
public void fillRectangle (int x, int y, int width, int height) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
if (autoScaleEnabled) {
- float scaleFactor = (float) getDeviceZoom()/100f;
- x = (int) (x * scaleFactor);
- y = (int) (y * scaleFactor);
- width = (int) (width * scaleFactor);
- height = (int) (height *scaleFactor);
+ x = DPIUtil.autoScaleUp (x, device);
+ y = DPIUtil.autoScaleUp (y, device);
+ width = DPIUtil.autoScaleUp (width, device);
+ height = DPIUtil.autoScaleUp (height, device);
}
checkGC(FILL);
if (data.gdipGraphics != 0) {
@@ -3163,15 +3136,13 @@ public void fillRectangle (Rectangle rect) {
*/
public void fillRoundRectangle (int x, int y, int width, int height, int arcWidth, int arcHeight) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (autoScaleEnabled) {
- float scaleFactor = this.getDeviceZoom() / 100f;
- x = (int)(x * scaleFactor);
- y = (int)(y * scaleFactor);
- width = (int)(width * scaleFactor);
- height = (int)(height * scaleFactor);
- arcWidth = (int)(arcWidth *scaleFactor);
- arcHeight = (int)(arcHeight * scaleFactor);
- }
+ x = DPIUtil.autoScaleUp (x, device);
+ y = DPIUtil.autoScaleUp (y, device);
+ width = DPIUtil.autoScaleUp (width, device);
+ height = DPIUtil.autoScaleUp (height, device);
+ arcWidth = DPIUtil.autoScaleUp (arcWidth, device);
+ arcHeight = DPIUtil.autoScaleUp (arcHeight, device);
+
checkGC(FILL);
if (data.gdipGraphics != 0) {
fillRoundRectangleGdip(data.gdipGraphics, data.gdipBrush, x, y, width, height, arcWidth, arcHeight);
@@ -3810,12 +3781,7 @@ public int getLineStyle() {
*/
public int getLineWidth() {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- int returnVal = (int)data.lineWidth;
- if (autoScaleEnabled) {
- float scaleFactor = ((float)this.getDeviceZoom()) / 100f;
- returnVal = (int)(returnVal / scaleFactor);
- }
- return returnVal;
+ return DPIUtil.autoScaleDown((int)data.lineWidth, device);
}
/**
@@ -4887,10 +4853,8 @@ public void setLineStyle(int lineStyle) {
*/
public void setLineWidth(int lineWidth) {
if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (autoScaleEnabled) {
- float scaleFactor = ((float)this.getDeviceZoom()) / 100f;
- lineWidth = (int)(lineWidth * scaleFactor);
- }
+ lineWidth = DPIUtil.autoScaleUp (lineWidth, device);
+
if (data.lineWidth == lineWidth) return;
data.lineWidth = lineWidth;
data.state &= ~(LINE_WIDTH | DRAW_OFFSET);
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java
index 6a9afc79bb..37d51545ce 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java
@@ -136,7 +136,7 @@ public final class Image extends Resource implements Drawable {
/**
* Attribute to cache current device zoom level
*/
- int currentDeviceZoom = 100;
+ private int currentDeviceZoom = 100;
/**
* width of the image
@@ -197,12 +197,8 @@ Image (Device device) {
*/
public Image(Device device, int width, int height) {
super(device);
- if (this.getEnableAutoScaling ()) {
- currentDeviceZoom = getDeviceZoom();
- float scaleFactor = ((float)currentDeviceZoom / 100f);
- width = (int)(width * scaleFactor);
- height = (int)(height * scaleFactor);
- }
+ width = DPIUtil.autoScaleUp (width, device);
+ height = DPIUtil.autoScaleUp (height, device);
init(width, height);
init();
}
@@ -462,19 +458,9 @@ public Image(Device device, Image srcImage, int flag) {
public Image(Device device, Rectangle bounds) {
super(device);
if (bounds == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
-<<<<<<< HEAD
- if (getEnableAutoScaling ()) {
- currentDeviceZoom = getDeviceZoom();
- Rectangle bounds1 = DPIUtil.scale(bounds, currentDeviceZoom, 100);
- init(bounds1.width, bounds1.height);
- } else {
- init(bounds.width, bounds.height);
- }
- init();
-=======
+ bounds = DPIUtil.autoScaleUp (bounds, device);
init(bounds.width, bounds.height);
init();
->>>>>>> refs/remotes/origin/master
}
/**
@@ -503,10 +489,7 @@ public Image(Device device, Rectangle bounds) {
public Image(Device device, ImageData data) {
super(device);
if (data == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (getEnableAutoScaling()) {
- currentDeviceZoom = getDeviceZoom();
- data = DPIUtil.autoScaleImageData(data, currentDeviceZoom, 100);
- }
+ data = DPIUtil.autoScaleUp (data, device);
init(data);
init();
}
@@ -548,11 +531,8 @@ public Image(Device device, ImageData source, ImageData mask) {
if (source.width != mask.width || source.height != mask.height) {
SWT.error(SWT.ERROR_INVALID_ARGUMENT);
}
- if (getEnableAutoScaling()){
- currentDeviceZoom = getDeviceZoom();
- source = DPIUtil.autoScaleImageData(source, currentDeviceZoom, 100);
- mask = DPIUtil.autoScaleImageData(mask, currentDeviceZoom, 100);
- }
+ source = DPIUtil.autoScaleUp(source, device);
+ mask = DPIUtil.autoScaleUp(mask, device);
mask = ImageData.convertMask(mask);
init(this.device, this, source, mask);
init();
@@ -689,14 +669,14 @@ public Image (Device device, String filename) {
public Image(Device device, ImageFileNameProvider imageFileNameProvider) {
super(device);
this.imageFileNameProvider = imageFileNameProvider;
- currentDeviceZoom = getDeviceZoom ();
+ currentDeviceZoom = device.getDeviceZoom ();
boolean[] found = new boolean[1];
String fileName = DPIUtil.validateAndGetImagePathAtZoom (imageFileNameProvider, currentDeviceZoom, found);
if (found[0]) {
initNative (fileName);
if (this.handle == 0) init(new ImageData (fileName));
} else {
- ImageData resizedData = DPIUtil.autoScaleImageFileName(fileName, currentDeviceZoom, 100);
+ ImageData resizedData = DPIUtil.autoScaleUp (new ImageData (fileName), device);
init(resizedData);
}
init();
@@ -734,13 +714,13 @@ public Image(Device device, ImageFileNameProvider imageFileNameProvider) {
public Image(Device device, ImageDataProvider imageDataProvider) {
super(device);
this.imageDataProvider = imageDataProvider;
- currentDeviceZoom = getDeviceZoom ();
+ currentDeviceZoom = device.getDeviceZoom ();
boolean[] found = new boolean[1];
ImageData data = DPIUtil.validateAndGetImageDataAtZoom(imageDataProvider, currentDeviceZoom, found);
if (found[0]) {
init(data);
} else {
- ImageData resizedData = DPIUtil.autoScaleImageData(data, currentDeviceZoom, 100);
+ ImageData resizedData = DPIUtil.autoScaleUp(data, device);
init (resizedData);
}
init();
@@ -754,7 +734,7 @@ public Image(Device device, ImageDataProvider imageDataProvider) {
boolean refreshImageForZoom () {
boolean refreshed = false;
if (imageFileNameProvider != null) {
- int deviceZoomLevel = getDeviceZoom();
+ int deviceZoomLevel = device.getDeviceZoom();
if (deviceZoomLevel != currentDeviceZoom) {
boolean[] found = new boolean[1];
String filename = DPIUtil.validateAndGetImagePathAtZoom (imageFileNameProvider, deviceZoomLevel, found);
@@ -770,7 +750,7 @@ boolean refreshImageForZoom () {
if (!found[0]) {
/* Release current native resources */
destroy ();
- ImageData resizedData = DPIUtil.autoScaleImageFileName(filename, deviceZoomLevel, 100);
+ ImageData resizedData = DPIUtil.autoScaleUp (new ImageData (filename), device);
init(resizedData);
init ();
refreshed = true;
@@ -778,7 +758,7 @@ boolean refreshImageForZoom () {
currentDeviceZoom = deviceZoomLevel;
}
} else if (imageDataProvider != null) {
- int deviceZoomLevel = getDeviceZoom();
+ int deviceZoomLevel = device.getDeviceZoom();
if (deviceZoomLevel != currentDeviceZoom) {
boolean[] found = new boolean[1];
ImageData data = DPIUtil.validateAndGetImageDataAtZoom (imageDataProvider, deviceZoomLevel, found);
@@ -793,7 +773,7 @@ boolean refreshImageForZoom () {
if (!found[0]) {
/* Release current native resources */
destroy ();
- ImageData resizedData = DPIUtil.autoScaleImageData(data, deviceZoomLevel, 100);
+ ImageData resizedData = DPIUtil.autoScaleUp (data, device);
init(resizedData);
init();
refreshed = true;
@@ -1396,15 +1376,12 @@ public Color getBackground() {
public Rectangle getBounds() {
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
Rectangle bounds = _getBounds();
- if (getEnableAutoScaling()) {
- bounds = DPIUtil.scale(bounds, 100, currentDeviceZoom);
- }
- return bounds;
+ return DPIUtil.autoScaleDown (bounds, device);
}
/**
* @return a rectangle specifying the image's bounds at current zoom.
- */
+ */
Rectangle _getBounds() {
if (width != -1 && height != -1) {
return new Rectangle(0, 0, width, height);
@@ -1835,17 +1812,17 @@ ImageData _getImageData() {
* </ul>
*
* @see ImageData
- *
+ *
* @since 3.105
*/
public ImageData getImageData (int zoom) {
if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return DPIUtil.getImageData (this, zoom);
+ return DPIUtil.getImageData (this, currentDeviceZoom, zoom);
}
/**
- * Returns an integer hash code for the receiver. Any two
- * objects that return <code>true</code> when passed to
+ * Returns an integer hash code for the receiver. Any two
+ * objects that return <code>true</code> when passed to
=======
* Returns an integer hash code for the receiver. Any two
* objects that return <code>true</code> when passed to
diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_Image.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_Image.java
index ab09ad1f83..3670b3fec4 100644
--- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_Image.java
+++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_Image.java
@@ -738,7 +738,7 @@ public void test_getBounds_Zoom() {
Rectangle bounds = new Rectangle(0, 0, 10, 20);
Rectangle bounds2 = new Rectangle(0, 0, 20, 40);
Image image = new Image(display, bounds.width, bounds.height);
- int zoom = image.getDeviceZoom();
+ int zoom = image.getDevice ().getDeviceZoom();
image.dispose();
try {
image.getBounds(zoom);

Back to the top