Skip to content

Commit 644469f

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 644469f

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
@@ -631,7 +631,15 @@ public static boolean useCairoAutoScale() {
631631
return useCairoAutoScale;
632632
}
633633

634+
public static int getZoomForMenuItemImage(int nativeDeviceZoom) {
635+
return getZoomForAutoscaleProperty(nativeDeviceZoom, "half");
636+
}
637+
634638
public static int getZoomForAutoscaleProperty (int nativeDeviceZoom) {
639+
return getZoomForAutoscaleProperty(nativeDeviceZoom, autoScaleValue);
640+
}
641+
642+
private 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.getZoomForMenuItemImage(nativeZoom);
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)