Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replacing the usage of getBoundsInPixels with getBounds #1385

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ void copyAreaInPixels(Image image, int x, int y) {
if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
if (image.type != SWT.BITMAP || image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
/* Copy the bitmap area */
Rectangle rect = image.getBoundsInPixels();
Rectangle rect = image.getBounds(data.nativeZoom);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This modifies the behavior, doesn't it?
Let's assume getBoundsInPixels() returned (100, 100, 100, 100) and let's assume that data.nativeZoom=125. Then getBounds(data.nativeZoom) will scale up from 100 to 125, i.e., it will return (125, 125, 125, 125). Do I miss something?

Copy link
Contributor

@akoch-yatta akoch-yatta Aug 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depends what the native zoom of the image is. If the native zoom of the image is 125, then it will return (100, 100, 100, 100). If the native zoom of the image is 100, then yes. Probably would be good to look out for a snippet, where this is used and play around with that.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not understand that. Why should it return (100, 100, 100, 100) when the native zoom of the image is 125? Within getBounds(int), the "corrected" zoom is used according to DPIUtil.getZoomForAutoscaleProperty(initialNativeZoom), so even if the native zoom of the image is 125, a value of 100 is used for scaling, isn't it?

Copy link
Contributor

@akoch-yatta akoch-yatta Aug 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So you mean the call should be getBounds(getZoom()) to be in the same zoom restrictions as Image uses internally?
That is definetly correct

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I meant for example is the scenario was with mode exact or quarter, where the Image was e.g. created on the primary monitor with 125%. Then getBounds(125) would be equal to getZoom() from the image, so it would return (100, 100, 100, 100)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's true. I had the "default" case in mind (i.e., scaling mode integer200) in which I still think that the behavior might change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's true. I had the "default" case in mind (i.e., scaling mode integer200) in which I still think that the behavior might change.

You are right, the behavior changes. I tested it with the snippet 215, where image.getBoundsInPixels() returns Rectangle {0, 0, 5120, 1440} but later scaled due to native zoom (which is 200) to final value image.getBounds(data.nativeZoom) : Rectangle {0, 0, 10240, 2880}

long memHdc = OS.CreateCompatibleDC(handle);
long hOldBitmap = OS.SelectObject(memHdc, Image.win32_getHandle(image, getZoom()));
OS.BitBlt(memHdc, 0, 0, rect.width, rect.height, handle, x, y, OS.SRCCOPY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,13 +252,13 @@ public Image(Device device, Image srcImage, int flag) {
device = this.device;
if (srcImage == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
if (srcImage.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
Rectangle rect = srcImage.getBoundsInPixels();
this.type = srcImage.type;
this.imageDataProvider = srcImage.imageDataProvider;
this.imageFileNameProvider = srcImage.imageFileNameProvider;
this.styleFlag = srcImage.styleFlag | flag;
initialNativeZoom = srcImage.initialNativeZoom;
this.dataAtBaseZoom = srcImage.dataAtBaseZoom;
Rectangle rect = srcImage.getBounds(initialNativeZoom);
switch (flag) {
case SWT.IMAGE_COPY: {
switch (type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7293,7 +7293,7 @@ LRESULT wmNotifyToolTip (NMTTCUSTOMDRAW nmcd, long lParam) {
if (pinfo.iSubItem != 0) x -= gridWidth;
Image image = item.getImage (pinfo.iSubItem);
if (image != null) {
Rectangle rect = image.getBoundsInPixels ();
Rectangle rect = image.getBoundsInPixels();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it intended that this is only a formatting change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatting leftover

RECT imageRect = item.getBounds (pinfo.iItem, pinfo.iSubItem, false, true, false, false, hDC);
Point size = imageList == null ? new Point (rect.width, rect.height) : imageList.getImageSize ();
int y = imageRect.top + Math.max (0, (imageRect.bottom - imageRect.top - size.y) / 2);
Expand Down
Loading