diff options
Diffstat (limited to 'src/newt/classes/jogamp')
-rw-r--r-- | src/newt/classes/jogamp/newt/WindowImpl.java | 39 | ||||
-rw-r--r-- | src/newt/classes/jogamp/newt/driver/windows/WindowsWindow.java | 12 |
2 files changed, 47 insertions, 4 deletions
diff --git a/src/newt/classes/jogamp/newt/WindowImpl.java b/src/newt/classes/jogamp/newt/WindowImpl.java index f0c351048..b8f0929a8 100644 --- a/src/newt/classes/jogamp/newt/WindowImpl.java +++ b/src/newt/classes/jogamp/newt/WindowImpl.java @@ -119,6 +119,8 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer private int mouseButtonPressed = 0; // current pressed mouse button number private long lastMousePressed = 0; // last time when a mouse button was pressed private int lastMouseClickCount = 0; // last mouse button click count + private boolean mouseInWindow = false;// mouse entered window - is inside the window (may be synthetic) + private Point lastMousePosition = new Point(); private ArrayList<KeyListener> keyListeners = new ArrayList<KeyListener>(); @@ -1893,17 +1895,46 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer } private void doMouseEvent(boolean enqueue, boolean wait, int eventType, int modifiers, int x, int y, int button, int rotation) { + if(eventType == MouseEvent.EVENT_MOUSE_ENTERED || + eventType == MouseEvent.EVENT_MOUSE_EXITED) { + if(eventType == MouseEvent.EVENT_MOUSE_EXITED && x==-1 && y==-1) { + x = lastMousePosition.getX(); + y = lastMousePosition.getY(); + } + // clip coordinates to window dimension + x = Math.min(Math.max(x, 0), width-1); + y = Math.min(Math.max(y, 0), height-1); + mouseInWindow = eventType == MouseEvent.EVENT_MOUSE_ENTERED; + } if(x<0||y<0||x>=width||y>=height) { return; // .. invalid .. } if(DEBUG_MOUSE_EVENT) { - System.err.println("doMouseEvent: enqueue"+enqueue+", wait "+wait+", "+MouseEvent.getEventTypeString(eventType)+ - ", mod "+modifiers+", pos "+x+"/"+y+", button "+button); + System.err.println("doMouseEvent: enqueue "+enqueue+", wait "+wait+", "+MouseEvent.getEventTypeString(eventType)+ + ", mod "+modifiers+", pos "+x+"/"+y+", button "+button+", lastMousePosition: "+lastMousePosition); + } + long when = System.currentTimeMillis(); + if(eventType == MouseEvent.EVENT_MOUSE_MOVED) { + if(!mouseInWindow) { + mouseInWindow = true; + MouseEvent e = new MouseEvent(MouseEvent.EVENT_MOUSE_ENTERED, this, when, + modifiers, x, y, lastMouseClickCount, button, 0); + if(DEBUG_MOUSE_EVENT) { + System.err.println("doMouseEvent: synthesized MOUSE_ENTERED event: "+e); + } + doEvent(enqueue, wait, e); + } else if(lastMousePosition.getX() == x && lastMousePosition.getY()==y) { + if(DEBUG_MOUSE_EVENT) { + System.err.println("doMouseEvent: skip EVENT_MOUSE_MOVED w/ same position: "+lastMousePosition); + } + return; // skip same position + } + lastMousePosition.setX(x); + lastMousePosition.setY(y); } if(button<0||button>MouseEvent.BUTTON_NUMBER) { throw new NativeWindowException("Invalid mouse button number" + button); } - long when = System.currentTimeMillis(); MouseEvent eClicked = null; MouseEvent e = null; @@ -1951,7 +1982,7 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer doEvent(enqueue, wait, e); if(null!=eClicked) { if(DEBUG_MOUSE_EVENT) { - System.err.println("doMouseEvent: synthesized MOUSE_CLICKED event"); + System.err.println("doMouseEvent: synthesized MOUSE_CLICKED event: "+eClicked); } doEvent(enqueue, wait, eClicked); } diff --git a/src/newt/classes/jogamp/newt/driver/windows/WindowsWindow.java b/src/newt/classes/jogamp/newt/driver/windows/WindowsWindow.java index 6e1444da3..cd5909d42 100644 --- a/src/newt/classes/jogamp/newt/driver/windows/WindowsWindow.java +++ b/src/newt/classes/jogamp/newt/driver/windows/WindowsWindow.java @@ -42,6 +42,9 @@ import javax.media.nativewindow.util.Insets; import javax.media.nativewindow.util.InsetsImmutable; import javax.media.nativewindow.util.Point; +import com.jogamp.newt.event.MouseAdapter; +import com.jogamp.newt.event.MouseEvent; + public class WindowsWindow extends WindowImpl { private long hmon; @@ -112,6 +115,8 @@ public class WindowsWindow extends WindowImpl { throw new NativeWindowException("Error creating window"); } windowHandleClose = getWindowHandle(); + addMouseListener(new MouseTracker()); + if(DEBUG_IMPLEMENTATION) { Exception e = new Exception("Info: Window new window handle "+Thread.currentThread().getName()+ " (Parent HWND "+toHexString(getParentWindowHandle())+ @@ -119,6 +124,12 @@ public class WindowsWindow extends WindowImpl { e.printStackTrace(); } } + + class MouseTracker extends MouseAdapter { + public void mouseEntered(MouseEvent e) { + WindowsWindow.trackPointerLeave0(WindowsWindow.this.getWindowHandle()); + } + } protected void closeNativeImpl() { if (hdc != 0) { @@ -251,4 +262,5 @@ public class WindowsWindow extends WindowImpl { private static native boolean setPointerVisible0(long windowHandle, boolean visible); private static native boolean confinePointer0(long windowHandle, boolean grab, int l, int t, int r, int b); private static native void warpPointer0(long windowHandle, int x, int y); + private static native void trackPointerLeave0(long windowHandle); } |