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
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
17 changes: 11 additions & 6 deletions src/gov/nasa/worldwind/awt/AbstractViewInputHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -954,27 +954,32 @@ 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;

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);
}
Expand Down
12 changes: 6 additions & 6 deletions src/gov/nasa/worldwind/awt/BasicViewInputHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
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]);
}
}
Loading