Skip to content

Commit

Permalink
WIP : consume the zoom context in pt and rect
Browse files Browse the repository at this point in the history
  • Loading branch information
amartya4256 committed Jan 8, 2025
1 parent 6104592 commit 6ccccbb
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public final class Point implements Serializable {
*/
public int y;

public int zoom;

static final long serialVersionUID = 3257002163938146354L;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ public final class Rectangle implements Serializable {
*/
public int height;

public int zoom;

static final long serialVersionUID = 3256439218279428914L;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5512,7 +5512,7 @@ public Rectangle map (Control from, Control to, Rectangle rectangle) {
public Point map (Control from, Control to, int x, int y) {
Point mappedPointInPoints;
if (from == null) {
Point mappedPointInpixels = mapInPixels(from, to, getPixelsFromPoint(to.getShell().getMonitor(), x, y));
Point mappedPointInpixels = mapInPixels(from, to, getPixelsFromPoint(to.getShell().getMonitor(), x, y, 0));
mappedPointInPoints = DPIUtil.scaleDown(mappedPointInpixels, to.getZoom());
} else if (to == null) {
Point mappedPointInpixels = mapInPixels(from, to, DPIUtil.scaleUp(new Point(x, y), from.getZoom()));
Expand Down Expand Up @@ -5555,17 +5555,17 @@ public Point translateFromDisplayCoordinates(Point point, int zoom) {

@Override
public Point translateToDisplayCoordinates(Point point, int zoom) {
return translateLocationInPointsToDisplayCoordinateSystem(point.x, point.y);
return translateLocationInPointsToDisplayCoordinateSystem(point.x, point.y, point.zoom);
}

@Override
public Rectangle translateFromDisplayCoordinates(Rectangle rect, int zoom) {
return translateRectangleInPixelsFromDisplayCoordinateSystemByContainment(rect.x, rect.y, rect.width, rect.height);
return translateRectangleInPixelsFromDisplayCoordinateSystemByContainment(rect.x, rect.y, rect.width, rect.height, rect.zoom);
}

@Override
public Rectangle translateToDisplayCoordinates(Rectangle rect, int zoom) {
return translateRectangleInPointsToDisplayCoordinateSystemByContainment(rect.x, rect.y, rect.width, rect.height);
return translateRectangleInPointsToDisplayCoordinateSystemByContainment(rect.x, rect.y, rect.width, rect.height, rect.zoom);
}

@Override
Expand All @@ -5576,39 +5576,40 @@ public Point getCursorLocation () {

@Override
public void setCursorLocation (int x, int y) {
Point cursorLocationInPixels = translateLocationInPointsToDisplayCoordinateSystem(x, y);
Point cursorLocationInPixels = translateLocationInPointsToDisplayCoordinateSystem(x, y, 0);
setCursorLocationInPixels (cursorLocationInPixels.x, cursorLocationInPixels.y);
}

private Point translateLocationInPointsToDisplayCoordinateSystem(int x, int y) {
private Point translateLocationInPointsToDisplayCoordinateSystem(int x, int y, int zoom) {
Monitor monitor = getContainingMonitor(x, y);
return getPixelsFromPoint(monitor, x, y);
return getPixelsFromPoint(monitor, x, y, zoom);
}

private Point translateLocationInPixelsFromDisplayCoordinateSystem(int x, int y) {
Monitor monitor = getContainingMonitorInPixelsCoordinate(x, y);
return getPointFromPixels(monitor, x, y);
}

private Rectangle translateRectangleInPointsToDisplayCoordinateSystemByContainment(int x, int y, int width, int height) {
private Rectangle translateRectangleInPointsToDisplayCoordinateSystemByContainment(int x, int y, int width, int height, int zoom) {
Monitor monitorByLocation = getContainingMonitor(x, y);
Monitor monitorByContainment = getContainingMonitor(x, y, width, height);
return translateRectangleInPixelsInDisplayCoordinateSystem(x, y, width, height, monitorByLocation, monitorByContainment);
return translateRectangleInPixelsInDisplayCoordinateSystem(x, y, width, height, zoom, monitorByLocation, monitorByContainment);
}

private Rectangle translateRectangleInPixelsInDisplayCoordinateSystem(int x, int y, int width, int height, Monitor monitor) {
return translateRectangleInPixelsInDisplayCoordinateSystem(x, y, width, height, monitor, monitor);
return translateRectangleInPixelsInDisplayCoordinateSystem(x, y, width, height, 0, monitor, monitor);
}

private Rectangle translateRectangleInPixelsInDisplayCoordinateSystem(int x, int y, int width, int height, Monitor monitorOfLocation, Monitor monitorOfArea) {
Point topLeft = getPixelsFromPoint(monitorOfLocation, x, y);
int zoom = getApplicableMonitorZoom(monitorOfArea);
private Rectangle translateRectangleInPixelsInDisplayCoordinateSystem(int x, int y, int width, int height, int zoom, Monitor monitorOfLocation, Monitor monitorOfArea) {
Point topLeft = getPixelsFromPoint(monitorOfLocation, x, y, zoom);
if (zoom == 0)
zoom = getApplicableMonitorZoom(monitorOfArea);
int widthInPixels = DPIUtil.scaleUp(width, zoom);
int heightInPixels = DPIUtil.scaleUp(height, zoom);
return new Rectangle(topLeft.x, topLeft.y, widthInPixels, heightInPixels);
}

private Rectangle translateRectangleInPixelsFromDisplayCoordinateSystemByContainment(int x, int y, int widthInPixels, int heightInPixels) {
private Rectangle translateRectangleInPixelsFromDisplayCoordinateSystemByContainment(int x, int y, int widthInPixels, int heightInPixels, int zoom) {
Monitor monitorByLocation = getContainingMonitor(x, y);
Monitor monitorByContainment = getContainingMonitor(x, y, widthInPixels, heightInPixels);
return translateRectangleInPointsInDisplayCoordinateSystem(x, y, widthInPixels, heightInPixels, monitorByLocation, monitorByContainment);
Expand All @@ -5620,11 +5621,14 @@ 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);
// Point topLeft = getPointFromPixels(monitorOfLocation, x, y);
int zoom = getApplicableMonitorZoom(monitorOfArea);
Point topLeft = getPointFromPixels(monitorOfArea, x, y);
int width = DPIUtil.scaleDown(widthInPixels, zoom);
int height = DPIUtil.scaleDown(heightInPixels, zoom);
return new Rectangle(topLeft.x, topLeft.y, width, height);
Rectangle rect = new Rectangle(topLeft.x, topLeft.y, width, height);
rect.zoom = zoom;
return rect;
}

private Monitor getContainingMonitor(int x, int y) {
Expand Down Expand Up @@ -5673,8 +5677,9 @@ private Rectangle getMonitorClientAreaInPixels(Monitor monitor) {
return new Rectangle(monitor.clientX, monitor.clientY, widthInPixels, heightInPixels);
}

private Point getPixelsFromPoint(Monitor monitor, int x, int y) {
int zoom = getApplicableMonitorZoom(monitor);
private Point getPixelsFromPoint(Monitor monitor, int x, int y, int zoom) {
if(zoom == 0)
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);
Expand All @@ -5684,7 +5689,9 @@ private Point getPointFromPixels(Monitor monitor, int x, int y) {
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);
Point pt = new Point(mappedX, mappedY);
pt.zoom = zoom;
return pt;
}

private int getApplicableMonitorZoom(Monitor monitor) {
Expand Down

0 comments on commit 6ccccbb

Please sign in to comment.