Skip to content

Commit fd6873d

Browse files
committed
Use monitor instead
1 parent 1351909 commit fd6873d

File tree

3 files changed

+37
-43
lines changed

3 files changed

+37
-43
lines changed

bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Point.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
import java.io.*;
1818

19+
import org.eclipse.swt.widgets.*;
20+
1921
/**
2022
* Instances of this class represent places on the (x, y)
2123
* coordinate plane.
@@ -53,7 +55,7 @@ public final class Point implements Serializable {
5355
*/
5456
public int y;
5557

56-
public int zoom;
58+
public Monitor monitor;
5759

5860
static final long serialVersionUID = 3257002163938146354L;
5961

bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/graphics/Rectangle.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import java.io.*;
1818

1919
import org.eclipse.swt.*;
20+
import org.eclipse.swt.widgets.*;
2021

2122
/**
2223
* Instances of this class represent rectangular areas in an
@@ -67,7 +68,7 @@ public final class Rectangle implements Serializable {
6768
*/
6869
public int height;
6970

70-
public int zoom;
71+
public Monitor monitor;
7172

7273
static final long serialVersionUID = 3256439218279428914L;
7374

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/MultiZoomCoordinateSystemMapper.java

Lines changed: 32 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -98,19 +98,17 @@ public Point translateFromDisplayCoordinates(Point point, int zoom) {
9898

9999
@Override
100100
public Point translateToDisplayCoordinates(Point point, int zoom) {
101-
return translateLocationInPointsToDisplayCoordinateSystem(point.x, point.y);
101+
return translateLocationInPointsToDisplayCoordinateSystem(point.x, point.y, point.monitor);
102102
}
103103

104104
@Override
105105
public Rectangle translateFromDisplayCoordinates(Rectangle rect, int zoom) {
106-
return translateRectangleInPixelsFromDisplayCoordinateSystemByContainment(rect.x, rect.y, rect.width,
107-
rect.height);
106+
return translateRectangleInPixelsFromDisplayCoordinateSystemByContainment(rect.x, rect.y, rect.width, rect.height, rect.monitor);
108107
}
109108

110109
@Override
111110
public Rectangle translateToDisplayCoordinates(Rectangle rect, int zoom) {
112-
return translateRectangleInPointsToDisplayCoordinateSystemByContainment(rect.x, rect.y, rect.width,
113-
rect.height);
111+
return translateRectangleInPointsToDisplayCoordinateSystemByContainment(rect.x, rect.y, rect.width, rect.height, rect.monitor);
114112
}
115113

116114
@Override
@@ -120,13 +118,14 @@ public Point getCursorLocation() {
120118
}
121119

122120
@Override
123-
public void setCursorLocation(int x, int y) {
124-
Point cursorLocationInPixels = translateLocationInPointsToDisplayCoordinateSystem(x, y);
125-
display.setCursorLocationInPixels(cursorLocationInPixels.x, cursorLocationInPixels.y);
121+
public void setCursorLocation (int x, int y) {
122+
Point cursorLocationInPixels = translateLocationInPointsToDisplayCoordinateSystem(x, y, null);
123+
display.setCursorLocationInPixels (cursorLocationInPixels.x, cursorLocationInPixels.y);
126124
}
127125

128-
private Point translateLocationInPointsToDisplayCoordinateSystem(int x, int y) {
129-
Monitor monitor = getContainingMonitor(x, y);
126+
private Point translateLocationInPointsToDisplayCoordinateSystem(int x, int y, Monitor monitor) {
127+
if (monitor == null)
128+
monitor = getContainingMonitor(x, y);
130129
return getPixelsFromPoint(monitor, x, y);
131130
}
132131

@@ -135,49 +134,39 @@ private Point translateLocationInPixelsFromDisplayCoordinateSystem(int x, int y)
135134
return getPointFromPixels(monitor, x, y);
136135
}
137136

138-
private Rectangle translateRectangleInPointsToDisplayCoordinateSystemByContainment(int x, int y, int width,
139-
int height) {
140-
Monitor monitorByLocation = getContainingMonitor(x, y);
141-
Monitor monitorByContainment = getContainingMonitor(x, y, width, height);
142-
return translateRectangleInPixelsInDisplayCoordinateSystem(x, y, width, height, monitorByLocation,
143-
monitorByContainment);
137+
private Rectangle translateRectangleInPointsToDisplayCoordinateSystemByContainment(int x, int y, int width, int height, Monitor monitor) {
138+
// if in the gap i.e. getContainingMonitor(x, y, width, height) == null, use monitor, if monitor not available, use monitor [0]
139+
if (monitor == null)
140+
monitor = getContainingMonitor(x, y, width, height);
141+
return translateRectangleInPixelsInDisplayCoordinateSystem(x, y, width, height, monitor);
144142
}
145143

146-
private Rectangle translateRectangleInPixelsInDisplayCoordinateSystem(int x, int y, int width, int height,
147-
Monitor monitor) {
148-
return translateRectangleInPixelsInDisplayCoordinateSystem(x, y, width, height, monitor, monitor);
149-
}
150-
151-
private Rectangle translateRectangleInPixelsInDisplayCoordinateSystem(int x, int y, int width, int height,
152-
Monitor monitorOfLocation, Monitor monitorOfArea) {
153-
Point topLeft = getPixelsFromPoint(monitorOfLocation, x, y);
154-
int zoom = getApplicableMonitorZoom(monitorOfArea);
144+
private Rectangle translateRectangleInPixelsInDisplayCoordinateSystem(int x, int y, int width, int height, Monitor monitor) {
145+
Point topLeft = getPixelsFromPoint(monitor, x, y);
146+
int zoom = getApplicableMonitorZoom(monitor);
155147
int widthInPixels = DPIUtil.scaleUp(width, zoom);
156148
int heightInPixels = DPIUtil.scaleUp(height, zoom);
157149
return new Rectangle(topLeft.x, topLeft.y, widthInPixels, heightInPixels);
158150
}
159151

160-
private Rectangle translateRectangleInPixelsFromDisplayCoordinateSystemByContainment(int x, int y,
161-
int widthInPixels, int heightInPixels) {
162-
Monitor monitorByLocation = getContainingMonitor(x, y);
163-
Monitor monitorByContainment = getContainingMonitorInPixelsCoordinate(x, y, widthInPixels, heightInPixels);
152+
private Rectangle translateRectangleInPixelsFromDisplayCoordinateSystemByContainment(int x, int y, int widthInPixels, int heightInPixels, Monitor monitor) {
153+
// Monitor monitorByLocation = getContainingMonitor(x, y);
154+
if (monitor == null)
155+
// TODO
156+
monitor = getContainingMonitor(x, y, widthInPixels, heightInPixels);
157+
// Monitor monitorByContainment = getContainingMonitorInPixelsCoordinate(x, y, widthInPixels, heightInPixels);
164158
return translateRectangleInPointsInDisplayCoordinateSystem(x, y, widthInPixels, heightInPixels,
165-
monitorByLocation, monitorByContainment);
166-
}
167-
168-
private Rectangle translateRectangleInPointsInDisplayCoordinateSystem(int x, int y, int widthInPixels,
169-
int heightInPixels, Monitor monitor) {
170-
return translateRectangleInPointsInDisplayCoordinateSystem(x, y, widthInPixels, heightInPixels, monitor,
171159
monitor);
172160
}
173161

174-
private Rectangle translateRectangleInPointsInDisplayCoordinateSystem(int x, int y, int widthInPixels,
175-
int heightInPixels, Monitor monitorOfLocation, Monitor monitorOfArea) {
176-
Point topLeft = getPointFromPixels(monitorOfLocation, x, y);
177-
int zoom = getApplicableMonitorZoom(monitorOfArea);
162+
private Rectangle translateRectangleInPointsInDisplayCoordinateSystem(int x, int y, int widthInPixels, int heightInPixels, Monitor monitor) {
163+
int zoom = getApplicableMonitorZoom(monitor);
164+
Point topLeft = getPointFromPixels(monitor, x, y);
178165
int width = DPIUtil.scaleDown(widthInPixels, zoom);
179166
int height = DPIUtil.scaleDown(heightInPixels, zoom);
180-
return new Rectangle(topLeft.x, topLeft.y, width, height);
167+
Rectangle rect = new Rectangle(topLeft.x, topLeft.y, width, height);
168+
rect.monitor = monitor;
169+
return rect;
181170
}
182171

183172
private Monitor getContainingMonitor(int x, int y) {
@@ -255,7 +244,9 @@ private Point getPointFromPixels(Monitor monitor, int x, int y) {
255244
int zoom = getApplicableMonitorZoom(monitor);
256245
int mappedX = DPIUtil.scaleDown(x - monitor.clientX, zoom) + monitor.clientX;
257246
int mappedY = DPIUtil.scaleDown(y - monitor.clientY, zoom) + monitor.clientY;
258-
return new Point(mappedX, mappedY);
247+
Point pt = new Point(mappedX, mappedY);
248+
pt.monitor = monitor;
249+
return pt;
259250
}
260251

261252
private int getApplicableMonitorZoom(Monitor monitor) {

0 commit comments

Comments
 (0)