Skip to content

Commit 1d54936

Browse files
committed
MenuItem Image Half Scaling #62
This commit contributes to enforcing half scaling on the MenuItem Image. On Win32, the OS is responsible for painting the Image of a MenuItem and it expects images to be in standard sizes i.e. 16px, 24 px, 32 px, etc. If the images are not provided within these sizes, Windows tries to rescale them, leading to unexpected sizes and masking. Since, half scaling yields the images in standard sizes, MenuItems are scaled accordingly. contributes to #62 and #127
1 parent 1bc7548 commit 1d54936

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@
3737
*/
3838
public class DPIUtil {
3939

40+
public static final String AUTOSCALE_QUARTER = "quarter";
41+
public static final String AUTOSCALE_HALF = "half";
42+
public static final String AUTOSCALE_EXACT = "exact";
43+
4044
private static final int DPI_ZOOM_100 = 96;
4145

4246
private static int deviceZoom = 100;
@@ -632,6 +636,10 @@ public static boolean useCairoAutoScale() {
632636
}
633637

634638
public static int getZoomForAutoscaleProperty (int nativeDeviceZoom) {
639+
return getZoomForAutoscaleProperty(nativeDeviceZoom, autoScaleValue);
640+
}
641+
642+
public static int getZoomForAutoscaleProperty (int nativeDeviceZoom, String autoScaleValue) {
635643
int zoom = 0;
636644
if (autoScaleValue != null) {
637645
if ("false".equalsIgnoreCase (autoScaleValue)) {

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,10 @@ public void setImage (Image image) {
782782
} else {
783783
if (OS.IsAppThemed ()) {
784784
if (hBitmap != 0) OS.DeleteObject (hBitmap);
785-
info.hbmpItem = hBitmap = image != null ? Display.create32bitDIB (image, getZoom()) : 0;
785+
// MenuItem images are painted badly/squeezed down by windows on quarter
786+
// scaling size, e.g. at zoom 125%, 175%, etc.
787+
int zoom = DPIUtil.getZoomForAutoscaleProperty(nativeZoom, DPIUtil.AUTOSCALE_HALF);
788+
info.hbmpItem = hBitmap = image != null ? Display.create32bitDIB (image, zoom) : 0;
786789
} else {
787790
info.hbmpItem = image != null ? OS.HBMMENU_CALLBACK : 0;
788791
}

0 commit comments

Comments
 (0)