Skip to content

Commit

Permalink
Adapt calls for image bounds to consider the actual zoom level of the…
Browse files Browse the repository at this point in the history
… containing control

Contributes to eclipse-platform#62
and eclipse-platform#127
  • Loading branch information
akoch-yatta committed Mar 28, 2024
1 parent ce83bf5 commit f2a01d8
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public int add (Image image) {
index++;
}
if (count == 0) {
Rectangle rect = image.getBoundsInPixels ();
Rectangle rect = image.getBoundsInPixels();
OS.ImageList_SetIconSize (handle, rect.width, rect.height);
}
set (index, image, count);
Expand Down Expand Up @@ -369,7 +369,7 @@ void set (int index, Image image, int count) {
* Note that the image size has to match the image list icon size.
*/
long hBitmap = 0, hMask = 0;
ImageData data = image.getImageData (DPIUtil.getDeviceZoom ());
ImageData data = image.getImageDataAtCurrentZoom();
switch (data.getTransparencyType ()) {
case SWT.TRANSPARENCY_ALPHA:
/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ int computeLeftMargin () {
if ((style & (SWT.PUSH | SWT.TOGGLE)) == 0) return MARGIN;
int margin = 0;
if (image != null && text.length () != 0) {
Rectangle bounds = image.getBoundsInPixels ();
Rectangle bounds = DPIUtil.autoScaleBounds(image.getBounds(), this.getZoom(), 100);
margin += bounds.width + MARGIN * 2;
long oldFont = 0;
long hDC = OS.GetDC (handle);
Expand Down Expand Up @@ -345,7 +345,7 @@ else if ((style & SWT.RIGHT) != 0) {
boolean hasImage = image != null, hasText = true;
if (hasImage) {
if (image != null) {
Rectangle rect = image.getBoundsInPixels ();
Rectangle rect = DPIUtil.autoScaleBounds(image.getBounds(), this.getZoom(), 100);
width = rect.width;
if (hasText && text.length () != 0) {
width += MARGIN * 2;
Expand Down Expand Up @@ -1378,11 +1378,12 @@ LRESULT wmNotifyChild (NMHDR hdr, long wParam, long lParam) {
GC gc = GC.win32_new (nmcd.hdc, data);

int margin = computeLeftMargin();
int imageWidth = image.getBoundsInPixels().width;
Rectangle imageBounds = DPIUtil.autoScaleBounds(image.getBounds(), this.getZoom(), 100);
int imageWidth = imageBounds.width;
left += (imageWidth + (isRadioOrCheck() ? 2 * MARGIN : MARGIN)); // for SWT.RIGHT_TO_LEFT right and left are inverted

int x = margin + (isRadioOrCheck() ? radioOrCheckTextPadding : 3);
int y = Math.max (0, (nmcd.bottom - image.getBoundsInPixels().height) / 2);
int y = Math.max (0, (nmcd.bottom - imageBounds.height) / 2);
gc.drawImage (image, DPIUtil.autoScaleDown(x), DPIUtil.autoScaleDown(y));
gc.dispose ();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1161,7 +1161,7 @@ static long create32bitDIB (long hBitmap, int alpha, byte [] alphaData, int tran

static Image createIcon (Image image) {
Device device = image.getDevice ();
ImageData data = image.getImageData (DPIUtil.getDeviceZoom ());
ImageData data = image.getImageDataAtCurrentZoom();
if (data.alpha == -1 && data.alphaData == null) {
ImageData mask = data.getTransparencyMask ();
return new Image (device, data, mask);
Expand Down Expand Up @@ -2464,7 +2464,7 @@ Font getSystemFont (int zoom) {
this.systemFont = systemFont;
if (systemFont != null) {
this.lfSystemFont = systemFont.getFontData()[0].data;
}
}
}

return systemFont;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ static int checkStyle (int style) {
return new Point (width, height);
}
if (isImageMode) {
Rectangle rect = image.getBoundsInPixels();
Rectangle rect = DPIUtil.autoScaleBounds(image.getBounds(), this.getZoom(), 100);
width += rect.width;
height += rect.height;
} else {
Expand Down Expand Up @@ -553,7 +553,7 @@ void wmDrawChildImage(DRAWITEMSTRUCT struct) {
int height = struct.bottom - struct.top;
if (width == 0 || height == 0) return;

Rectangle imageRect = image.getBoundsInPixels ();
Rectangle imageRect = DPIUtil.autoScaleBounds(image.getBounds(), getZoom(), 100);

int x = 0;
if ((style & SWT.CENTER) != 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ int imageIndex (Image image) {
*/
if (image == null) return -1;
if (imageList == null) {
Rectangle bounds = image.getBoundsInPixels ();
Rectangle bounds = DPIUtil.autoScaleBounds(image.getBounds(), this.getZoom(), 100);
imageList = display.getImageList (style & SWT.RIGHT_TO_LEFT, bounds.width, bounds.height);
int index = imageList.add (image);
long hImageList = imageList.getHandle ();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1107,7 +1107,7 @@ void updateImages (boolean enabled) {
ImageList hotImageList = parent.getHotImageList ();
ImageList disabledImageList = parent.getDisabledImageList();
if (info.iImage == OS.I_IMAGENONE) {
Rectangle bounds = DPIUtil.autoScaleBounds(image.getBounds(), 100, getParent().getZoom());
Rectangle bounds = DPIUtil.autoScaleBounds(image.getBounds(), getParent().getZoom(), 100);
int listStyle = parent.style & SWT.RIGHT_TO_LEFT;
if (imageList == null) {
imageList = display.getImageListToolBar (listStyle, bounds.width, bounds.height);
Expand Down Expand Up @@ -1229,7 +1229,7 @@ private static void handleDPIChange(Widget widget, int newZoom, float scalingFac
Display display = item.getDisplay();
int listStyle = parent.style & SWT.RIGHT_TO_LEFT;

Rectangle bounds = DPIUtil.autoScaleBounds(image.getBounds(), 100, newZoom);
Rectangle bounds = DPIUtil.autoScaleBounds(image.getBounds(), newZoom, 100);
if (parent.getImageList() == null) {
parent.setImageList (display.getImageListToolBar (listStyle, bounds.width, bounds.height));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3739,7 +3739,7 @@ boolean hitTestSelection (long hItem, int x, int y) {
int imageIndex (Image image, int index) {
if (image == null) return OS.I_IMAGENONE;
if (imageList == null) {
Rectangle bounds = image.getBoundsInPixels ();
Rectangle bounds = DPIUtil.autoScaleBounds(image.getBounds(), this.getZoom(), 100);
imageList = display.getImageList (style & SWT.RIGHT_TO_LEFT, bounds.width, bounds.height);
}
int imageIndex = imageList.indexOf (image);
Expand All @@ -3763,7 +3763,7 @@ int imageIndex (Image image, int index) {
int imageIndexHeader (Image image) {
if (image == null) return OS.I_IMAGENONE;
if (headerImageList == null) {
Rectangle bounds = image.getBoundsInPixels ();
Rectangle bounds = DPIUtil.autoScaleBounds(image.getBounds(), this.getZoom(), 100);
headerImageList = display.getImageList (style & SWT.RIGHT_TO_LEFT, bounds.width, bounds.height);
int index = headerImageList.indexOf (image);
if (index == -1) index = headerImageList.add (image);
Expand Down Expand Up @@ -7540,7 +7540,7 @@ LRESULT wmNotifyChild (NMHDR hdr, long wParam, long lParam) {
}
case OS.NM_CUSTOMDRAW: {
if (hdr.hwndFrom == hwndHeader) break;
if (hooks (SWT.MeasureItem)) {
if (hooks (SWT.MeasureItem)) {
if (hwndHeader == 0) createParent ();
}
if (!customDraw && findImageControl () == null) {
Expand Down Expand Up @@ -7926,9 +7926,10 @@ LRESULT wmNotifyHeader (NMHDR hdr, long wParam, long lParam) {
GCData data = new GCData();
data.device = display;
GC gc = GC.win32_new (nmcd.hdc, data);
int y = Math.max (0, (nmcd.bottom - columns[i].image.getBoundsInPixels().height) / 2);
Rectangle imageBounds = DPIUtil.autoScaleBounds(columns[i].image.getBounds(), this.getZoom(), 100);
int y = Math.max (0, (nmcd.bottom - imageBounds.height) / 2);
gc.drawImage (columns[i].image, DPIUtil.autoScaleDown(x), DPIUtil.autoScaleDown(y));
x += columns[i].image.getBoundsInPixels().width + 12;
x += imageBounds.width + 12;
gc.dispose ();
}

Expand Down

0 comments on commit f2a01d8

Please sign in to comment.