diff --git a/src/gov/nasa/worldwind/awt/AWTInputHandler.java b/src/gov/nasa/worldwind/awt/AWTInputHandler.java
index 564ed3fcb3..4915cd6d77 100644
--- a/src/gov/nasa/worldwind/awt/AWTInputHandler.java
+++ b/src/gov/nasa/worldwind/awt/AWTInputHandler.java
@@ -404,24 +404,26 @@ public void mouseClicked(final MouseEvent awtMouseEvent)
if (pickedObjects != null && pickedObjects.getTopPickedObject() != null
&& !pickedObjects.getTopPickedObject().isTerrain())
{
- // Something is under the cursor, so it's deemed "selected".
+ Point awtPt = awtMouseEvent.getPoint(); // AWT screen coordinates
+
+ // Something is under the cursor, so it's deemed "selected".
if (MouseEvent.BUTTON1 == mouseEvent.getButton())
{
if (mouseEvent.getClickCount() <= 1)
{
this.callSelectListeners(new SelectEvent(this.wwd, SelectEvent.LEFT_CLICK,
- mouseEvent, pickedObjects));
+ awtPt, mouseEvent, pickedObjects));
}
else
{
this.callSelectListeners(new SelectEvent(this.wwd, SelectEvent.LEFT_DOUBLE_CLICK,
- mouseEvent, pickedObjects));
+ awtPt, mouseEvent, pickedObjects));
}
}
else if (MouseEvent.BUTTON3 == mouseEvent.getButton())
{
this.callSelectListeners(new SelectEvent(this.wwd, SelectEvent.RIGHT_CLICK,
- mouseEvent, pickedObjects));
+ awtPt, mouseEvent, pickedObjects));
}
this.wwd.getView().firePropertyChange(AVKey.VIEW, null, this.wwd.getView());
@@ -472,16 +474,18 @@ public void mousePressed(MouseEvent awtMouseEvent)
if (this.objectsAtButtonPress != null && objectsAtButtonPress.getTopPickedObject() != null
&& !this.objectsAtButtonPress.getTopPickedObject().isTerrain())
{
+ Point awtPt = awtMouseEvent.getPoint(); // AWT screen coordinates
+
// Something is under the cursor, so it's deemed "selected".
if (MouseEvent.BUTTON1 == mouseEvent.getButton())
{
this.callSelectListeners(new SelectEvent(this.wwd, SelectEvent.LEFT_PRESS,
- mouseEvent, this.objectsAtButtonPress));
+ awtPt, mouseEvent, this.objectsAtButtonPress));
}
else if (MouseEvent.BUTTON3 == mouseEvent.getButton())
{
this.callSelectListeners(new SelectEvent(this.wwd, SelectEvent.RIGHT_PRESS,
- mouseEvent, this.objectsAtButtonPress));
+ awtPt, mouseEvent, this.objectsAtButtonPress));
}
// Initiate a repaint.
@@ -600,8 +604,9 @@ public void mouseDragged(MouseEvent awtMouseEvent)
&& !pickedObjects.getTopPickedObject().isTerrain()))
{
this.isDragging = true;
- DragSelectEvent selectEvent = new DragSelectEvent(this.wwd, SelectEvent.DRAG, mouseEvent, pickedObjects,
- prevMousePoint);
+ DragSelectEvent selectEvent = new DragSelectEvent(this.wwd, SelectEvent.DRAG,
+ awtMouseEvent.getPoint(), mouseEvent,
+ pickedObjects, prevMousePoint);
this.callSelectListeners(selectEvent);
// If no listener consumed the event, then cancel the drag.
@@ -790,7 +795,7 @@ protected void cancelDrag()
if (this.isDragging)
{
this.callSelectListeners(new DragSelectEvent(this.wwd, SelectEvent.DRAG_END, null,
- this.objectsAtButtonPress, this.mousePoint));
+ null, this.objectsAtButtonPress, this.mousePoint));
}
this.isDragging = false;
diff --git a/src/gov/nasa/worldwind/awt/AbstractViewInputHandler.java b/src/gov/nasa/worldwind/awt/AbstractViewInputHandler.java
index b0783cd1f4..012457796b 100644
--- a/src/gov/nasa/worldwind/awt/AbstractViewInputHandler.java
+++ b/src/gov/nasa/worldwind/awt/AbstractViewInputHandler.java
@@ -954,7 +954,7 @@ public double computeDragSlope(Point point1, Point point2, Vec4 vec1, Vec4 vec2)
return slope - 1.0;
}
- protected static Point constrainToSourceBounds(Point point, Object source)
+ protected static Point constrainToSourceBounds(Point point, WorldWindow source)
{
if (point == null)
return null;
@@ -962,19 +962,24 @@ protected static Point constrainToSourceBounds(Point point, Object source)
if (!(source instanceof Component))
return point;
- Component c = (Component) source;
+ // source.getHeight(), source.getWidth() are AWT coords height,
+ // but the 'point' is MouseEvent GL surface coords.
+ // Clamp to GL viewport size.
+ int glWidth = source.getView().getViewport().width;
+ int glHeight = source.getView().getViewport().height;
int x = (int) point.getX();
if (x < 0)
x = 0;
- if (x > c.getWidth())
- x = c.getWidth();
+ if (x >= glWidth)
+ x = glWidth - 1;
int y = (int) point.getY();
if (y < 0)
y = 0;
- if (y > c.getHeight())
- y = c.getHeight();
+
+ if (y >= glHeight)
+ y = glHeight - 1;
return new Point(x, y);
}
diff --git a/src/gov/nasa/worldwind/awt/BasicViewInputHandler.java b/src/gov/nasa/worldwind/awt/BasicViewInputHandler.java
index e7af6f0ca6..2008517ca6 100644
--- a/src/gov/nasa/worldwind/awt/BasicViewInputHandler.java
+++ b/src/gov/nasa/worldwind/awt/BasicViewInputHandler.java
@@ -219,10 +219,10 @@ public boolean inputActionPerformed(KeyEventState keys, String target,
Point movement = ViewUtil.subtract(point, lastPoint);
int headingInput = movement.x;
- int pitchInput = movement.y;
+ int pitchInput = -movement.y;
Point totalMovement = ViewUtil.subtract(point, mouseDownPoint);
int totalHeadingInput = totalMovement.x;
- int totalPitchInput = totalMovement.y;
+ int totalPitchInput = -totalMovement.y;
ViewInputAttributes.DeviceAttributes deviceAttributes =
getAttributes().getDeviceAttributes(ViewInputAttributes.DEVICE_MOUSE);
@@ -258,16 +258,16 @@ public boolean inputActionPerformed(AbstractViewInputHandler inputHandler,
return false;
}
+ // 'mouseEvent' is in GL surface coords, (0,0) in lower left of canvas
+ // Make down mouse movement increase the pitch.
Point movement = ViewUtil.subtract(point, lastPoint);
int headingInput = movement.x;
- int pitchInput = movement.y;
+ int pitchInput = -movement.y;
if (mouseDownPoint == null)
mouseDownPoint = lastPoint;
Point totalMovement = ViewUtil.subtract(point, mouseDownPoint);
int totalHeadingInput = totalMovement.x;
- int totalPitchInput = totalMovement.y;
-
-
+ int totalPitchInput = -totalMovement.y;
ViewInputAttributes.DeviceAttributes deviceAttributes =
getAttributes().getDeviceAttributes(ViewInputAttributes.DEVICE_MOUSE);
diff --git a/src/gov/nasa/worldwind/drag/DragContext.java b/src/gov/nasa/worldwind/drag/DragContext.java
index 6623902e88..935f2c31b4 100644
--- a/src/gov/nasa/worldwind/drag/DragContext.java
+++ b/src/gov/nasa/worldwind/drag/DragContext.java
@@ -41,16 +41,16 @@
public class DragContext
{
/**
- * In accordance with the AWT screen coordinates the top left point of the window is the origin.
+ * In accordance with the GL surface coordinates the top left point of the window is the origin.
*/
protected Point point;
/**
- * In accordance with the AWT screen coordinates the top left point of the window is the origin. This point is the
+ * In accordance with the GL surface coordinates the top left point of the window is the origin. This point is the
* previous screen point.
*/
protected Point previousPoint;
/**
- * In accordance with the AWT screen coordinates the top left point of the window is the origin. This point refers
+ * In accordance with the GL surface coordinates the top left point of the window is the origin. This point refers
* to the initial point of the drag event.
*/
protected Point initialPoint;
@@ -81,9 +81,9 @@ public DragContext()
}
/**
- * Returns the current screen point with the origin at the top left corner of the window.
+ * Returns the current GL surface point with the origin at the top left corner of the window.
*
- * @return the current screen point.
+ * @return the current GL surface point.
*/
public Point getPoint()
{
@@ -91,9 +91,9 @@ public Point getPoint()
}
/**
- * Set the {@link DragContext} current screen point.
+ * Set the {@link DragContext} current GL surface point.
*
- * @param point the point to assign to the current screen point.
+ * @param point the point to assign to the current GL surface point.
*
* @throws IllegalArgumentException if the point is null.
*/
@@ -110,7 +110,7 @@ public void setPoint(Point point)
}
/**
- * Returns the previous screen point with the origin at the top left corner of the window.
+ * Returns the previous GL surface point with the origin at the top left corner of the window.
*
* @return the previous point.
*/
@@ -120,9 +120,9 @@ public Point getPreviousPoint()
}
/**
- * Set the {@link DragContext} previous screen point.
+ * Set the {@link DragContext} previous GL surface point.
*
- * @param previousPoint the screen point to assign to the previous screen point.
+ * @param previousPoint the GL surface point to assign to the previous screen point.
*
* @throws IllegalArgumentException if the previousPoint is null.
*/
@@ -139,10 +139,10 @@ public void setPreviousPoint(Point previousPoint)
}
/**
- * Returns the initial screen point with the origin at the top left corner of the window. The initial point is the
- * screen point at the initiation of the drag event.
+ * Returns the initial GL surface point with the origin at the top left corner of the window. The initial point is the
+ * GL surface point at the initiation of the drag event.
*
- * @return the initial screen point.
+ * @return the initial GL surface point.
*/
public Point getInitialPoint()
{
@@ -150,9 +150,9 @@ public Point getInitialPoint()
}
/**
- * Set the {@link DragContext} initial screen point.
+ * Set the {@link DragContext} initial GL surface point.
*
- * @param initialPoint the screen point to assign to the initial screen point.
+ * @param initialPoint the GL surface point to assign to the initial screen point.
*
* @throws IllegalArgumentException if the initialPoint is null.
*/
diff --git a/src/gov/nasa/worldwind/drag/DraggableSupport.java b/src/gov/nasa/worldwind/drag/DraggableSupport.java
index 3a5e7b52a5..7af85f8eb6 100644
--- a/src/gov/nasa/worldwind/drag/DraggableSupport.java
+++ b/src/gov/nasa/worldwind/drag/DraggableSupport.java
@@ -428,9 +428,7 @@ protected Vec4 computeScreenOffsetFromReferencePosition(Position dragObjectRefer
Vec4 screenPointOffset = new Vec4(
dragContext.getInitialPoint().getX() - dragObjectScreenPoint.getX(),
- dragContext.getInitialPoint().getY() - (
- dragContext.getView().getViewport().getHeight()
- - dragObjectScreenPoint.getY() - 1.0)
+ dragContext.getInitialPoint().getY() - dragObjectScreenPoint.getY()
);
return screenPointOffset;
diff --git a/src/gov/nasa/worldwind/event/DragSelectEvent.java b/src/gov/nasa/worldwind/event/DragSelectEvent.java
index fcd36fe33a..c694b58f1b 100644
--- a/src/gov/nasa/worldwind/event/DragSelectEvent.java
+++ b/src/gov/nasa/worldwind/event/DragSelectEvent.java
@@ -42,10 +42,11 @@ public class DragSelectEvent extends SelectEvent
{
private final java.awt.Point previousPickPoint;
- public DragSelectEvent(Object source, String eventAction, MouseEvent mouseEvent, PickedObjectList pickedObjects,
- java.awt.Point previousPickPoint)
+ public DragSelectEvent(Object source, String eventAction, java.awt.Point awtPt, MouseEvent mouseEvent,
+ PickedObjectList pickedObjects,
+ java.awt.Point previousPickPoint)
{
- super(source, eventAction, mouseEvent, pickedObjects);
+ super(source, eventAction, awtPt, mouseEvent, pickedObjects);
this.previousPickPoint = previousPickPoint;
}
diff --git a/src/gov/nasa/worldwind/event/SelectEvent.java b/src/gov/nasa/worldwind/event/SelectEvent.java
index 0100deae12..1804356111 100644
--- a/src/gov/nasa/worldwind/event/SelectEvent.java
+++ b/src/gov/nasa/worldwind/event/SelectEvent.java
@@ -104,15 +104,17 @@ public class SelectEvent extends WWEvent
private final Point pickPoint; // GL surface coordinates
private final Rectangle pickRect; // GL surface coordinates
private final MouseEvent mouseEvent; // GL surface coordinates
+ private final Point awtMousePt; // AWT screen coordinates
private final PickedObjectList pickedObjects;
- public SelectEvent(Object source, String eventAction, MouseEvent mouseEvent, PickedObjectList pickedObjects)
+ public SelectEvent(Object source, String eventAction, Point awtPt, MouseEvent mouseEvent, PickedObjectList pickedObjects)
{
super(source);
this.eventAction = eventAction;
this.pickPoint = mouseEvent != null ? mouseEvent.getPoint() : null;
this.pickRect = null;
this.mouseEvent = mouseEvent;
+ this.awtMousePt = awtPt;
this.pickedObjects = pickedObjects;
}
@@ -123,6 +125,7 @@ public SelectEvent(Object source, String eventAction, Point pickPoint, PickedObj
this.pickPoint = pickPoint;
this.pickRect = null;
this.mouseEvent = null;
+ this.awtMousePt = null;
this.pickedObjects = pickedObjects;
}
@@ -133,6 +136,7 @@ public SelectEvent(Object source, String eventAction, Rectangle pickRectangle, P
this.pickPoint = null;
this.pickRect = pickRectangle;
this.mouseEvent = null;
+ this.awtMousePt = null;
this.pickedObjects = pickedObjects;
}
@@ -150,6 +154,10 @@ public String getEventAction()
return this.eventAction != null ? this.eventAction : "gov.nasa.worldwind.SelectEvent.UnknownEventAction";
}
+ public Point getAwtMousePt() {
+ return awtMousePt;
+ }
+
public Point getPickPoint()
{
return this.pickPoint;
diff --git a/src/gov/nasa/worldwind/render/DrawContext.java b/src/gov/nasa/worldwind/render/DrawContext.java
index ffc935a719..c6e8567a5e 100644
--- a/src/gov/nasa/worldwind/render/DrawContext.java
+++ b/src/gov/nasa/worldwind/render/DrawContext.java
@@ -1051,4 +1051,11 @@ public interface DrawContext extends WWObject, Disposable
* Convert AWT effective screen location to GL surface location using DPI scaling.
*/
int [] awtPointToGLpoint(Point pt);
+
+ /**
+ * Convert GL surface coordinate point to AWT device point using DPI scaling.
+ * @param glPoint
+ * @return
+ */
+ public Point glPointToAwtPoint(Point glPoint);
}
diff --git a/src/gov/nasa/worldwind/render/DrawContextImpl.java b/src/gov/nasa/worldwind/render/DrawContextImpl.java
index eaed5cc1c7..c24100b162 100644
--- a/src/gov/nasa/worldwind/render/DrawContextImpl.java
+++ b/src/gov/nasa/worldwind/render/DrawContextImpl.java
@@ -1752,7 +1752,17 @@ else if (altitudeMode == WorldWind.RELATIVE_TO_GROUND)
// Convert to GL surface coordinates
int [] glSurfacePt = drawable.getNativeSurface().convertToPixelUnits(awtPt);
int glSurfaceHeight = drawable.getSurfaceHeight();
- glSurfacePt[1] = glSurfaceHeight - glSurfacePt[1] - 1;
+ glSurfacePt[1] = glSurfaceHeight-1 - glSurfacePt[1];
return glSurfacePt;
}
+
+ public Point glPointToAwtPoint(Point glPoint) {
+ GLDrawable drawable = glContext.getGLDrawable();
+ if (drawable == null) return glPoint;
+
+ final int viewportHeight = getView().getViewport().height;
+ int [] glPt = { glPoint.x, viewportHeight-1 - glPoint.y };
+ getGLDrawable().getNativeSurface().convertToWindowUnits(glPt);
+ return new Point(glPt[0], glPt[1]);
+ }
}
diff --git a/src/gov/nasa/worldwind/render/ScreenImage.java b/src/gov/nasa/worldwind/render/ScreenImage.java
index 69c33b5cb7..488d283002 100644
--- a/src/gov/nasa/worldwind/render/ScreenImage.java
+++ b/src/gov/nasa/worldwind/render/ScreenImage.java
@@ -78,13 +78,6 @@ public class ScreenImage extends WWObjectImpl implements Renderable, Exportable
* is computed in computeOffsets and used in draw Initially null.
*/
protected Point screenLocation;
- /**
- * Indicates the location of this screen image in the viewport (on the screen) in AWT coordinates. This property is
- * assigned in setScreenLocation and computeOffsets. In computeOffsets, this
- * is computed by converting the screenLocation from OpenGL coordinates to AWT coordinates. Initially
- * null.
- */
- protected Point awtScreenLocation;
protected double dx;
protected double dy;
protected Layer pickLayer;
@@ -122,7 +115,7 @@ public void render(DrawContext dc)
*/
public Point getScreenLocation()
{
- return this.awtScreenLocation;
+ return this.screenLocation;
}
/**
@@ -136,7 +129,7 @@ public Point getScreenLocation()
public Point getScreenLocation(DrawContext dc)
{
this.computeOffsets(dc);
- return this.awtScreenLocation;
+ return this.screenLocation;
}
/**
@@ -151,17 +144,16 @@ public Point getScreenLocation(DrawContext dc)
*/
public void setScreenLocation(Point screenLocation)
{
- // Use units PIXELS for the X screen offset, and and INSET_PIXELS for the Y screen offset. The Offset is in
- // OpenGL coordinates with the origin in the lower-left corner, but the Point is in AWT coordinates with the
- // origin in the upper-left corner. This offset translates the origin from the lower-left to the upper-left
- // corner.
- this.screenOffset = new Offset(screenLocation.getX(), screenLocation.getY(), AVKey.PIXELS, AVKey.INSET_PIXELS);
+ // Use units PIXELS for the X screen offset, and and PIXELS for the Y screen offset. The Offset is in
+ // OpenGL coordinates with the origin in the lower-left corner, as is the Point. This offset
+ // translates the origin from the lower-left to the upper-left corner.
+ this.screenOffset = new Offset(screenLocation.getX(), screenLocation.getY(), AVKey.PIXELS, AVKey.PIXELS);
this.imageOffset = new Offset(0.5, 0.5, AVKey.FRACTION, AVKey.FRACTION);
// Set cached screen location to the initial screen location so that it can be retrieved if getScreenLocation()
// is called before the image is rendered. This maintains backward compatibility with the previous behavior of
// ScreenImage.
- this.awtScreenLocation = new Point(screenLocation);
+ this.screenLocation = new Point(screenLocation);
}
/**
@@ -544,12 +536,7 @@ else if (this.getImageSource() == null) // If no image source is set, draw a rec
{
this.screenLocation = new Point(viewportWidth / 2, viewportHeight / 2);
}
-
- // Convert the screen location from OpenGL to AWT coordinates and store the result in awtScreenLocation. The
- // awtScreenLocation property is used in getScreenLocation to indicate the screen location in AWT
- // coordinates.
- this.awtScreenLocation = new Point(this.screenLocation.x, viewportHeight - this.screenLocation.y);
-
+
Point.Double overlayPoint;
if (this.imageOffset != null)
overlayPoint = this.imageOffset.computeOffset(this.width, this.height, null, null);
diff --git a/src/gov/nasa/worldwindx/examples/ContextMenusOnShapes.java b/src/gov/nasa/worldwindx/examples/ContextMenusOnShapes.java
index c432b47db4..9ace62fed7 100644
--- a/src/gov/nasa/worldwindx/examples/ContextMenusOnShapes.java
+++ b/src/gov/nasa/worldwindx/examples/ContextMenusOnShapes.java
@@ -72,7 +72,6 @@ public void selected(SelectEvent event) {
}
}
- @SuppressWarnings({"UnusedDeclaration"})
protected void highlight(SelectEvent event, Object o) {
if (this.lastPickedPlacemark == o) {
return; // same thing selected
@@ -110,7 +109,7 @@ protected void showContextMenu(SelectEvent event) {
}
ContextMenu menu = new ContextMenu((Component) event.getSource(), menuInfo);
- menu.show(event.getMouseEvent());
+ menu.show(event.getAwtMousePt());
}
}
}
@@ -145,7 +144,7 @@ protected void makeMenuItems() {
}
}
- public void show(final MouseEvent event) {
+ public void show(final Point screenPt) {
JPopupMenu popup = new JPopupMenu();
popup.add(this.menuTitleItem);
@@ -156,7 +155,7 @@ public void show(final MouseEvent event) {
popup.add(subMenu);
}
- popup.show(sourceComponent, event.getX(), event.getY());
+ popup.show(sourceComponent, (int)screenPt.getX(), (int)screenPt.getY());
}
}