Skip to content

Commit

Permalink
[win32] different coordinate system strategies
Browse files Browse the repository at this point in the history
This contribution extracts two different strategies to provide a consistent coordinate system in the win32 implemenentation for a single-zoom and a multi-zoom environment. The existing logic remains unchanged in this commit. It is only moved and consolidated in the new inner classes in Display.

Contributes to #62 and #131
Fixes eclipse-platform/eclipse.platform.ui#2595
  • Loading branch information
akoch-yatta authored and HeikoKlare committed Dec 10, 2024
1 parent 811a4a6 commit 6d83968
Show file tree
Hide file tree
Showing 5 changed files with 371 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4007,7 +4007,9 @@ void subclass () {
public Point toControl (int x, int y) {
checkWidget ();
int zoom = getZoom();
return DPIUtil.scaleDown(toControlInPixels(DPIUtil.scaleUp(x, zoom), DPIUtil.scaleUp(y, zoom)), zoom);
Point displayPointInPixels = getDisplay().translateToDisplayCoordinates(new Point(x, y), zoom);
final Point controlPointInPixels = toControlInPixels(displayPointInPixels.x, displayPointInPixels.y);
return DPIUtil.scaleDown(controlPointInPixels, zoom);
}

Point toControlInPixels (int x, int y) {
Expand Down Expand Up @@ -4040,9 +4042,7 @@ Point toControlInPixels (int x, int y) {
public Point toControl (Point point) {
checkWidget ();
if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
int zoom = getZoom();
point = DPIUtil.scaleUp(point, zoom);
return DPIUtil.scaleDown(toControlInPixels(point.x, point.y), zoom);
return toControl(point.x, point.y);
}

/**
Expand All @@ -4068,7 +4068,8 @@ public Point toControl (Point point) {
public Point toDisplay (int x, int y) {
checkWidget ();
int zoom = getZoom();
return DPIUtil.scaleDown(toDisplayInPixels(DPIUtil.scaleUp(x, zoom), DPIUtil.scaleUp(y, zoom)), zoom);
Point displayPointInPixels = toDisplayInPixels(DPIUtil.scaleUp(x, zoom), DPIUtil.scaleUp(y, zoom));
return getDisplay().translateFromDisplayCoordinates(displayPointInPixels, zoom);
}

Point toDisplayInPixels (int x, int y) {
Expand Down Expand Up @@ -4101,9 +4102,7 @@ Point toDisplayInPixels (int x, int y) {
public Point toDisplay (Point point) {
checkWidget ();
if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
int zoom = getZoom();
point = DPIUtil.scaleUp(point, zoom);
return DPIUtil.scaleDown(toDisplayInPixels(point.x, point.y), zoom);
return toDisplay(point.x, point.y);
}

long topHandle () {
Expand Down
Loading

0 comments on commit 6d83968

Please sign in to comment.