Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
23 changes: 14 additions & 9 deletions src/gov/nasa/worldwind/awt/AWTInputHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 5 additions & 3 deletions src/gov/nasa/worldwind/awt/AbstractViewInputHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -973,8 +973,10 @@ protected static Point constrainToSourceBounds(Point point, Object source)
int y = (int) point.getY();
if (y < 0)
y = 0;
if (y > c.getHeight())
y = c.getHeight();

// c.getHeight() is AWT coords height, point is MouseEvent GL surface coords
if (y >= source.getView().getViewport().height)
y = source.getView().getViewport().height - 1;

return new Point(x, y);
}
Expand Down
6 changes: 3 additions & 3 deletions src/gov/nasa/worldwind/awt/BasicViewInputHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -258,17 +258,17 @@ 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;



ViewInputAttributes.DeviceAttributes deviceAttributes =
getAttributes().getDeviceAttributes(ViewInputAttributes.DEVICE_MOUSE);

Expand Down
30 changes: 15 additions & 15 deletions src/gov/nasa/worldwind/drag/DragContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -81,19 +81,19 @@ 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()
{
return point;
}

/**
* 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.
*/
Expand All @@ -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.
*/
Expand All @@ -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.
*/
Expand All @@ -139,20 +139,20 @@ 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()
{
return initialPoint;
}

/**
* 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.
*/
Expand Down
4 changes: 1 addition & 3 deletions src/gov/nasa/worldwind/drag/DraggableSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 4 additions & 3 deletions src/gov/nasa/worldwind/event/DragSelectEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
10 changes: 9 additions & 1 deletion src/gov/nasa/worldwind/event/SelectEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions src/gov/nasa/worldwind/render/DrawContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
12 changes: 11 additions & 1 deletion src/gov/nasa/worldwind/render/DrawContextImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
}
29 changes: 8 additions & 21 deletions src/gov/nasa/worldwind/render/ScreenImage.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,6 @@ public class ScreenImage extends WWObjectImpl implements Renderable, Exportable
* is computed in <code>computeOffsets</code> and used in <code>draw</code> Initially <code>null</code>.
*/
protected Point screenLocation;
/**
* Indicates the location of this screen image in the viewport (on the screen) in AWT coordinates. This property is
* assigned in <code>setScreenLocation</code> and <code>computeOffsets</code>. In <code>computeOffsets</code>, this
* is computed by converting the <code>screenLocation</code> from OpenGL coordinates to AWT coordinates. Initially
* <code>null</code>.
*/
protected Point awtScreenLocation;
protected double dx;
protected double dy;
protected Layer pickLayer;
Expand Down Expand Up @@ -122,7 +115,7 @@ public void render(DrawContext dc)
*/
public Point getScreenLocation()
{
return this.awtScreenLocation;
return this.screenLocation;
}

/**
Expand All @@ -136,7 +129,7 @@ public Point getScreenLocation()
public Point getScreenLocation(DrawContext dc)
{
this.computeOffsets(dc);
return this.awtScreenLocation;
return this.screenLocation;
}

/**
Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -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);
Expand Down
Loading