Skip to content

Commit

Permalink
Guard monitor.zoom with isRescalingAtRuntime flag
Browse files Browse the repository at this point in the history
This contribution protects the unintended usage of different zoom levels
of different monitors in trasnlating the points and rectangles from
control to display coordinate system when the isRescalingAtRuntime flag
is disabled.

contributes to #62 and #127
  • Loading branch information
amartya4256 authored and HeikoKlare committed Oct 14, 2024
1 parent 8fe0fb0 commit 7a04f7a
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3157,7 +3157,7 @@ private Rectangle translateRectangleInPixelsInDisplayCoordinateSystem(int x, int

private Rectangle translateRectangleInPixelsInDisplayCoordinateSystem(int x, int y, int width, int height, Monitor monitorOfLocation, Monitor monitorOfArea) {
Point topLeft = getPixelsFromPoint(monitorOfLocation, x, y);
int zoom = DPIUtil.getZoomForAutoscaleProperty(monitorOfArea.zoom);
int zoom = getApplicableMonitorZoom(monitorOfArea);
int widthInPixels = DPIUtil.scaleUp(width, zoom);
int heightInPixels = DPIUtil.scaleUp(height, zoom);
return new Rectangle(topLeft.x, topLeft.y, widthInPixels, heightInPixels);
Expand All @@ -3176,12 +3176,16 @@ private Rectangle translateRectangleInPointsInDisplayCoordinateSystem(int x, int

private Rectangle translateRectangleInPointsInDisplayCoordinateSystem(int x, int y, int widthInPixels, int heightInPixels, Monitor monitorOfLocation, Monitor monitorOfArea) {
Point topLeft = getPointFromPixels(monitorOfLocation, x, y);
int zoom = DPIUtil.getZoomForAutoscaleProperty(monitorOfArea.zoom);
int zoom = getApplicableMonitorZoom(monitorOfArea);
int width = DPIUtil.scaleDown(widthInPixels, zoom);
int height = DPIUtil.scaleDown(heightInPixels, zoom);
return new Rectangle(topLeft.x, topLeft.y, width, height);
}

private int getApplicableMonitorZoom(Monitor monitor) {
return DPIUtil.getZoomForAutoscaleProperty(isRescalingAtRuntime() ? monitor.zoom : getDeviceZoom());
}

long messageProc (long hwnd, long msg, long wParam, long lParam) {
switch ((int)msg) {
case SWT_RUNASYNC: {
Expand Down Expand Up @@ -5480,21 +5484,21 @@ private Monitor getContainingMonitorInPixelsCoordinate(int xInPixels, int yInPix
}

private Rectangle getMonitorClientAreaInPixels(Monitor monitor) {
int zoom = DPIUtil.getZoomForAutoscaleProperty(monitor.zoom);
int zoom = getApplicableMonitorZoom(monitor);
int widthInPixels = DPIUtil.scaleUp(monitor.clientWidth, zoom);
int heightInPixels = DPIUtil.scaleUp(monitor.clientHeight, zoom);
return new Rectangle(monitor.clientX, monitor.clientY, widthInPixels, heightInPixels);
}

private Point getPixelsFromPoint(Monitor monitor, int x, int y) {
int zoom = DPIUtil.getZoomForAutoscaleProperty(monitor.zoom);
int zoom = getApplicableMonitorZoom(monitor);
int mappedX = DPIUtil.scaleUp(x - monitor.clientX, zoom) + monitor.clientX;
int mappedY = DPIUtil.scaleUp(y - monitor.clientY, zoom) + monitor.clientY;
return new Point(mappedX, mappedY);
}

private Point getPointFromPixels(Monitor monitor, int x, int y) {
int zoom = DPIUtil.getZoomForAutoscaleProperty(monitor.zoom);
int zoom = getApplicableMonitorZoom(monitor);
int mappedX = DPIUtil.scaleDown(x - monitor.clientX, zoom) + monitor.clientX;
int mappedY = DPIUtil.scaleDown(y - monitor.clientY, zoom) + monitor.clientY;
return new Point(mappedX, mappedY);
Expand Down

0 comments on commit 7a04f7a

Please sign in to comment.