@@ -33,7 +33,7 @@ public Point map(Control from, Control to, int x, int y) {
3333 Point mappedPointInPoints ;
3434 if (from == null ) {
3535 Point mappedPointInpixels = display .mapInPixels (from , to ,
36- getPixelsFromPoint (to .getShell ().getMonitor (), x , y , 0 ));
36+ getPixelsFromPoint (to .getShell ().getMonitor (), x , y ));
3737 mappedPointInPoints = DPIUtil .scaleDown (mappedPointInpixels , to .getZoom ());
3838 } else if (to == null ) {
3939 Point mappedPointInpixels = display .mapInPixels (from , to , DPIUtil .scaleUp (new Point (x , y ), from .getZoom ()));
@@ -83,17 +83,17 @@ public Point translateFromDisplayCoordinates(Point point, int zoom) {
8383
8484 @ Override
8585 public Point translateToDisplayCoordinates (Point point , int zoom ) {
86- return translateLocationInPointsToDisplayCoordinateSystem (point .x , point .y , point .zoom );
86+ return translateLocationInPointsToDisplayCoordinateSystem (point .x , point .y , point .monitor );
8787 }
8888
8989 @ Override
9090 public Rectangle translateFromDisplayCoordinates (Rectangle rect , int zoom ) {
91- return translateRectangleInPixelsFromDisplayCoordinateSystemByContainment (rect .x , rect .y , rect .width , rect .height , rect .zoom );
91+ return translateRectangleInPixelsFromDisplayCoordinateSystemByContainment (rect .x , rect .y , rect .width , rect .height , rect .monitor );
9292 }
9393
9494 @ Override
9595 public Rectangle translateToDisplayCoordinates (Rectangle rect , int zoom ) {
96- return translateRectangleInPointsToDisplayCoordinateSystemByContainment (rect .x , rect .y , rect .width , rect .height , rect .zoom );
96+ return translateRectangleInPointsToDisplayCoordinateSystemByContainment (rect .x , rect .y , rect .width , rect .height , rect .monitor );
9797 }
9898
9999 @ Override
@@ -104,62 +104,53 @@ public Point getCursorLocation() {
104104
105105 @ Override
106106 public void setCursorLocation (int x , int y ) {
107- Point cursorLocationInPixels = translateLocationInPointsToDisplayCoordinateSystem (x , y , 0 );
107+ Point cursorLocationInPixels = translateLocationInPointsToDisplayCoordinateSystem (x , y , null );
108108 display .setCursorLocationInPixels (cursorLocationInPixels .x , cursorLocationInPixels .y );
109109 }
110110
111- private Point translateLocationInPointsToDisplayCoordinateSystem (int x , int y , int zoom ) {
112- Monitor monitor = getContainingMonitor (x , y );
113- return getPixelsFromPoint (monitor , x , y , zoom );
111+ private Point translateLocationInPointsToDisplayCoordinateSystem (int x , int y , Monitor monitor ) {
112+ if (monitor == null )
113+ monitor = getContainingMonitor (x , y );
114+ return getPixelsFromPoint (monitor , x , y );
114115 }
115116
116117 private Point translateLocationInPixelsFromDisplayCoordinateSystem (int x , int y ) {
117118 Monitor monitor = getContainingMonitorInPixelsCoordinate (x , y );
118119 return getPointFromPixels (monitor , x , y );
119120 }
120121
121- private Rectangle translateRectangleInPointsToDisplayCoordinateSystemByContainment (int x , int y , int width , int height , int zoom ) {
122- Monitor monitorByLocation = getContainingMonitor (x , y );
123- Monitor monitorByContainment = getContainingMonitor (x , y , width , height );
124- return translateRectangleInPixelsInDisplayCoordinateSystem (x , y , width , height , zoom , monitorByLocation , monitorByContainment );
122+ private Rectangle translateRectangleInPointsToDisplayCoordinateSystemByContainment (int x , int y , int width , int height , Monitor monitor ) {
123+ // if in the gap i.e. getContainingMonitor(x, y, width, height) == null, use monitor, if monitor not available, use monitor [0]
124+ if (monitor == null )
125+ monitor = getContainingMonitor (x , y , width , height );
126+ return translateRectangleInPixelsInDisplayCoordinateSystem (x , y , width , height , monitor );
125127 }
126128
127129 private Rectangle translateRectangleInPixelsInDisplayCoordinateSystem (int x , int y , int width , int height , Monitor monitor ) {
128- return translateRectangleInPixelsInDisplayCoordinateSystem (x , y , width , height , 0 , monitor , monitor );
129- }
130-
131- private Rectangle translateRectangleInPixelsInDisplayCoordinateSystem (int x , int y , int width , int height , int zoom , Monitor monitorOfLocation , Monitor monitorOfArea ) {
132- Point topLeft = getPixelsFromPoint (monitorOfLocation , x , y , zoom );
133- if (zoom == 0 )
134- zoom = getApplicableMonitorZoom (monitorOfArea );
130+ Point topLeft = getPixelsFromPoint (monitor , x , y );
131+ int zoom = getApplicableMonitorZoom (monitor );
135132 int widthInPixels = DPIUtil .scaleUp (width , zoom );
136133 int heightInPixels = DPIUtil .scaleUp (height , zoom );
137134 return new Rectangle (topLeft .x , topLeft .y , widthInPixels , heightInPixels );
138135 }
139136
140- private Rectangle translateRectangleInPixelsFromDisplayCoordinateSystemByContainment (int x , int y , int widthInPixels , int heightInPixels , int zoom ) {
141- Monitor monitorByLocation = getContainingMonitor (x , y );
137+ private Rectangle translateRectangleInPixelsFromDisplayCoordinateSystemByContainment (int x , int y , int widthInPixels , int heightInPixels , Monitor monitor ) {
138+ // Monitor monitorByLocation = getContainingMonitor(x, y);
139+ if (monitor == null )
142140 // TODO
143- Monitor monitorByContainment = getContainingMonitor (x , y , widthInPixels , heightInPixels );
144- // Monitor monitorByContainment = getContainingMonitorInPixelsCoordinate(x, y, widthInPixels, heightInPixels);
141+ monitor = getContainingMonitor (x , y , widthInPixels , heightInPixels );
142+ // Monitor monitorByContainment = getContainingMonitorInPixelsCoordinate(x, y, widthInPixels, heightInPixels);
145143 return translateRectangleInPointsInDisplayCoordinateSystem (x , y , widthInPixels , heightInPixels ,
146- monitorByLocation , monitorByContainment );
147- }
148-
149- private Rectangle translateRectangleInPointsInDisplayCoordinateSystem (int x , int y , int widthInPixels ,
150- int heightInPixels , Monitor monitor ) {
151- return translateRectangleInPointsInDisplayCoordinateSystem (x , y , widthInPixels , heightInPixels , monitor ,
152144 monitor );
153145 }
154146
155- private Rectangle translateRectangleInPointsInDisplayCoordinateSystem (int x , int y , int widthInPixels , int heightInPixels , Monitor monitorOfLocation , Monitor monitorOfArea ) {
156- // Point topLeft = getPointFromPixels(monitorOfLocation, x, y);
157- int zoom = getApplicableMonitorZoom (monitorOfArea );
158- Point topLeft = getPointFromPixels (monitorOfArea , x , y );
147+ private Rectangle translateRectangleInPointsInDisplayCoordinateSystem (int x , int y , int widthInPixels , int heightInPixels , Monitor monitor ) {
148+ int zoom = getApplicableMonitorZoom (monitor );
149+ Point topLeft = getPointFromPixels (monitor , x , y );
159150 int width = DPIUtil .scaleDown (widthInPixels , zoom );
160151 int height = DPIUtil .scaleDown (heightInPixels , zoom );
161152 Rectangle rect = new Rectangle (topLeft .x , topLeft .y , width , height );
162- rect .zoom = zoom ;
153+ rect .monitor = monitor ;
163154 return rect ;
164155 }
165156
@@ -227,9 +218,8 @@ private Rectangle getMonitorClientAreaInPixels(Monitor monitor) {
227218 return new Rectangle (monitor .clientX , monitor .clientY , widthInPixels , heightInPixels );
228219 }
229220
230- private Point getPixelsFromPoint (Monitor monitor , int x , int y , int zoom ) {
231- if (zoom == 0 )
232- zoom = getApplicableMonitorZoom (monitor );
221+ private Point getPixelsFromPoint (Monitor monitor , int x , int y ) {
222+ int zoom = getApplicableMonitorZoom (monitor );
233223 int mappedX = DPIUtil .scaleUp (x - monitor .clientX , zoom ) + monitor .clientX ;
234224 int mappedY = DPIUtil .scaleUp (y - monitor .clientY , zoom ) + monitor .clientY ;
235225 return new Point (mappedX , mappedY );
@@ -239,7 +229,7 @@ private Point getPointFromPixels(Monitor monitor, int x, int y) {
239229 int mappedX = DPIUtil .scaleDown (x - monitor .clientX , zoom ) + monitor .clientX ;
240230 int mappedY = DPIUtil .scaleDown (y - monitor .clientY , zoom ) + monitor .clientY ;
241231 Point pt = new Point (mappedX , mappedY );
242- pt .zoom = zoom ;
232+ pt .monitor = monitor ;
243233 return pt ;
244234 }
245235
0 commit comments