forked from eclipse-platform/eclipse.platform.swt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use monitor-aware coordinates in multi-zoom coordinate system
This commit contributes to the use of monitor-aware Points and Rectangles for the translation between points and pixels coordinates in the Display Coordinate System. Since the Display Coordinate System can have different scales (zoom) in different monitors, it is designed to be not continuous in the points coordinates. Hence when we manipulate the coordinates of a Point or a Rectangle object, it might end up in a region which is between two monitors in the point coordinate system, which we consider a gap. So, we need the context of the monitor on which those points and rectangles were created in the first place to evaluate the scaling factor. If the context is not available or the coordinates were updated to an irrelevant value, a fallback method tries to evaluate the right monitor for the coordinates and evaluates the scaled value with that. Contributes to eclipse-platform#62 and eclipse-platform#127
- Loading branch information
1 parent
d441a95
commit a0a0485
Showing
6 changed files
with
335 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/MonitorAwarePoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2025 Yatta Solutions and others. | ||
* | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Yatta Solutions - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.swt.graphics; | ||
|
||
import java.util.*; | ||
|
||
import org.eclipse.swt.widgets.*; | ||
|
||
/** | ||
* Instances of this class represent {@link org.eclipse.swt.graphics.Point} | ||
* objects along with the context of the monitor in relation to which they are | ||
* placed on the display. The monitor awareness makes it easy to scale and | ||
* translate the points between pixels and points. | ||
* | ||
* @since 3.129 | ||
* @noreference This class is not intended to be referenced by clients | ||
*/ | ||
public final class MonitorAwarePoint extends Point { | ||
|
||
private static final long serialVersionUID = 6077427420686999194L; | ||
|
||
private final Monitor monitor; | ||
|
||
/** | ||
* Constructs a new MonitorAwarePoint | ||
* | ||
* @param x the x coordinate of the point | ||
* @param y the y coordinate of the point | ||
* @param monitor the monitor with whose context the point is created | ||
*/ | ||
public MonitorAwarePoint(int x, int y, Monitor monitor) { | ||
super(x, y); | ||
this.monitor = monitor; | ||
} | ||
|
||
/** | ||
* {@return the monitor with whose context the instance is created} | ||
*/ | ||
public Monitor getMonitor() { | ||
return monitor; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object object) { | ||
if (this == object) { | ||
return true; | ||
} | ||
if (!super.equals(object)) { | ||
return false; | ||
} | ||
MonitorAwarePoint other = (MonitorAwarePoint) object; | ||
return Objects.equals(this.monitor, other.monitor); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(super.hashCode(), monitor); | ||
} | ||
|
||
} |
73 changes: 73 additions & 0 deletions
73
...es/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/MonitorAwareRectangle.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2025 Yatta Solutions and others. | ||
* | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Yatta Solutions - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.swt.graphics; | ||
|
||
import java.util.*; | ||
|
||
import org.eclipse.swt.widgets.*; | ||
|
||
/** | ||
* Instances of this class represent {@link org.eclipse.swt.graphics.Rectangle} | ||
* objects along with the context of the monitor in relation to which they are | ||
* placed on the display. The monitor awareness makes it easy to scale and | ||
* translate the rectangles between pixels and points. | ||
* | ||
* @since 3.129 | ||
* @noreference This class is not intended to be referenced by clients | ||
*/ | ||
public final class MonitorAwareRectangle extends Rectangle { | ||
|
||
private static final long serialVersionUID = 5041911840525116925L; | ||
|
||
private final Monitor monitor; | ||
|
||
/** | ||
* Constructs a new MonitorAwareRectangle | ||
* | ||
* @param x the x coordinate of the top left corner of the rectangle | ||
* @param y the y coordinate of the top left corner of the rectangle | ||
* @param width the width of the rectangle | ||
* @param height the height of the rectangle | ||
* @param monitor the monitor with whose context the rectangle is created | ||
*/ | ||
public MonitorAwareRectangle(int x, int y, int width, int height, Monitor monitor) { | ||
super(x, y, width, height); | ||
this.monitor = monitor; | ||
} | ||
|
||
/** | ||
* {@return the monitor with whose context the instance is created} | ||
*/ | ||
public Monitor getMonitor() { | ||
return monitor; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object object) { | ||
if (this == object) { | ||
return true; | ||
} | ||
if (!super.equals(object)) { | ||
return false; | ||
} | ||
MonitorAwareRectangle other = (MonitorAwareRectangle) object; | ||
return Objects.equals(this.monitor, other.monitor); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(super.hashCode(), monitor); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.