From 8b0aa0e7653f74e713880e77f9afbe59caff38f0 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Fri, 27 Apr 2012 03:53:41 +0200 Subject: Bug 556: Newt Mouse Synthetic Drag Event: Clear state if mouse enters/leaves window. Since we cannot guarantee to have the pressed button information when receiving the mouse move event, we synthesize the dragged event (move while mouse button pressed). To simplify the situation and have a compromise, we clear the mouse pressed states when mouse enters or leaves the window to remove the dragged events at re-entering. This seems more sensible, since dragging after re-entering the mouse shall not be expected. --- src/newt/classes/jogamp/newt/WindowImpl.java | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/newt/classes/jogamp/newt/WindowImpl.java b/src/newt/classes/jogamp/newt/WindowImpl.java index 3ceb5c772..004e73983 100644 --- a/src/newt/classes/jogamp/newt/WindowImpl.java +++ b/src/newt/classes/jogamp/newt/WindowImpl.java @@ -2025,6 +2025,8 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer x = Math.min(Math.max(x, 0), getWidth()-1); y = Math.min(Math.max(y, 0), getHeight()-1); mouseInWindow = eventType == MouseEvent.EVENT_MOUSE_ENTERED; + lastMousePressed=0; // clear state + mouseButtonPressed=0; // clear state } if(x<0||y<0||x>=getWidth()||y>=getHeight()) { return; // .. invalid .. @@ -2034,15 +2036,14 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer ", mod "+modifiers+", pos "+x+"/"+y+", button "+button+", lastMousePosition: "+lastMousePosition); } long when = System.currentTimeMillis(); + MouseEvent eEntered = null; 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); + eEntered = new MouseEvent(MouseEvent.EVENT_MOUSE_ENTERED, this, when, + modifiers, x, y, lastMouseClickCount, button, 0); + lastMousePressed=0; // clear state + mouseButtonPressed=0; // clear state } else if(lastMousePosition.getX() == x && lastMousePosition.getY()==y) { if(DEBUG_MOUSE_EVENT) { System.err.println("doMouseEvent: skip EVENT_MOUSE_MOVED w/ same position: "+lastMousePosition); @@ -2102,7 +2103,13 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer } else { e = new MouseEvent(eventType, this, when, modifiers, x, y, 0, button, 0); } - doEvent(enqueue, wait, e); + if(null!=eEntered) { + if(DEBUG_MOUSE_EVENT) { + System.err.println("doMouseEvent: synthesized MOUSE_ENTERED event: "+eEntered); + } + doEvent(enqueue, wait, eEntered); + } + doEvent(enqueue, wait, e); // actual mouse event if(null!=eClicked) { if(DEBUG_MOUSE_EVENT) { System.err.println("doMouseEvent: synthesized MOUSE_CLICKED event: "+eClicked); -- cgit v1.2.3