Skip to content
Merged
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 @@ -78,11 +78,11 @@ public void testCorrectScaleUpUsingDifferentSetBoundsMethod() {

button.setBounds(new Rectangle(0, 47, 200, 47));
assertEquals("Control::setBounds(Rectangle) doesn't scale up correctly",
new Rectangle(0, 82, 350, 83), button.getBoundsInPixels());
new Rectangle(0, 82, 350, 82), button.getBoundsInPixels());

button.setBounds(0, 47, 200, 47);
assertEquals("Control::setBounds(int, int, int, int) doesn't scale up correctly",
new Rectangle(0, 82, 350, 83), button.getBoundsInPixels());
new Rectangle(0, 82, 350, 82), button.getBoundsInPixels());
}

record FontComparison(int originalFontHeight, int currentFontHeight) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ void translateRectangleInGapPartiallyInRightBackAndForthInSingleZoomShouldBeTheS
void translateRectangleInGapPartiallyInRightBackAndForthInMultiZoomShouldBeInside() {
MultiZoomCoordinateSystemMapper mapper = getMultiZoomCoordinateSystemMapper();
setupMonitors(mapper);
Rectangle rectInPts = new MonitorAwareRectangle(1950, 400, 150, 100, monitors[1]);
Rectangle rectInPts = new Rectangle.WithMonitor(1950, 400, 150, 100, monitors[1]);
Rectangle rectInPxs = mapper.translateToDisplayCoordinates(rectInPts, monitors[0].getZoom());
assertEquals(rectInPts, mapper.translateFromDisplayCoordinates(rectInPxs, monitors[0].getZoom()));
}
Expand Down Expand Up @@ -223,15 +223,15 @@ private Point createExpectedPoint(CoordinateSystemMapper mapper, int x, int y, M
if (mapper instanceof SingleZoomCoordinateSystemMapper) {
return new Point(x, y);
} else {
return new MonitorAwarePoint(x, y, monitor);
return new Point.WithMonitor(x, y, monitor);
}
}

private Rectangle createExpectedRectangle(CoordinateSystemMapper mapper, int x, int y, int width, int height, Monitor monitor) {
if (mapper instanceof SingleZoomCoordinateSystemMapper) {
return new Rectangle(x, y, width, height);
} else {
return new MonitorAwareRectangle(x, y, width, height, monitor);
return new Rectangle.WithMonitor(x, y, width, height, monitor);
}
}

Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

import java.io.*;

import org.eclipse.swt.widgets.*;

/**
* Instances of this class represent places on the (x, y)
* coordinate plane.
Expand All @@ -41,7 +43,7 @@
* @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
*/

public sealed class Point implements Serializable permits MonitorAwarePoint {
public sealed class Point implements Serializable permits Point.OfFloat {

/**
* the x coordinate of the point
Expand Down Expand Up @@ -116,5 +118,82 @@ public String toString () {
return "Point {" + x + ", " + y + "}"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}

/**
* Instances of this class represent {@link org.eclipse.swt.graphics.Point}
* objects with the fields capable of storing more precise value in float.
*
* @since 3.131
* @noreference This class is not intended to be referenced by clients
*/
public static sealed class OfFloat extends Point permits Point.WithMonitor {

private static final long serialVersionUID = -1862062276431597053L;

public float residualX, residualY;

public OfFloat(int x, int y) {
super(x, y);
}

public OfFloat(float x, float y) {
super(Math.round(x), Math.round(y));
this.residualX = x - this.x;
this.residualY = y - this.y;
}

public float getX() {
return x + residualX;
}

public float getY() {
return y + residualY;
}

public void setX(float x) {
this.x = Math.round(x);
this.residualX = x - this.x;
}

public void setY(float y) {
this.y = Math.round(y);
this.residualY = y - this.y;
}
}

/**
* Instances of this class represent {@link org.eclipse.swt.graphics.Point.OfFloat}
* 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.131
* @noreference This class is not intended to be referenced by clients
*/
public static final class WithMonitor extends Point.OfFloat {

private static final long serialVersionUID = 6077427420686999194L;

private final Monitor monitor;

/**
* Constructs a new Point.WithMonitor
*
* @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 WithMonitor(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;
}

}

}
Loading
Loading