changeset 1272:a4bd88439e22

RT-22096: Fixed coordinates of touch points delivered to a transformed node.
author Pavel Safrata
date Wed, 06 Jun 2012 18:00:24 +0200
parents 188ee39990fe
children 6593c5847d5b
files javafx-ui-common/src/javafx/scene/Scene.java javafx-ui-common/src/javafx/scene/input/TouchPoint.java javafx-ui-common/test/unit/javafx/scene/input/TouchEventTest.java
diffstat 3 files changed, 78 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/javafx-ui-common/src/javafx/scene/Scene.java	Wed Jun 06 12:14:18 2012 +0200
+++ b/javafx-ui-common/src/javafx/scene/Scene.java	Wed Jun 06 18:00:24 2012 +0200
@@ -1641,6 +1641,10 @@
                         break;
                 }
 
+                for (TouchPoint t : touchPoints) {
+                    t.impl_reset();
+                }
+
                 TouchEvent te = TouchEvent.impl_touchEvent(type, tp, touchList,
                         touchEventSetId, e.isShiftDown(), e.isControlDown(),
                         e.isAltDown(), e.isMetaDown());
--- a/javafx-ui-common/src/javafx/scene/input/TouchPoint.java	Wed Jun 06 12:14:18 2012 +0200
+++ b/javafx-ui-common/src/javafx/scene/input/TouchPoint.java	Wed Jun 06 18:00:24 2012 +0200
@@ -120,6 +120,16 @@
         this.target = target;
     }
 
+    /**
+     * @treatAsPrivate implementation detail
+     * @deprecated This is an internal API that is not intended for use and will be removed in the next version
+     */
+    @Deprecated
+    public void impl_reset() {
+        x = sceneX;
+        y = sceneY;
+    }
+
     private EventTarget grabbed = null;
 
     /**
--- a/javafx-ui-common/test/unit/javafx/scene/input/TouchEventTest.java	Wed Jun 06 12:14:18 2012 +0200
+++ b/javafx-ui-common/test/unit/javafx/scene/input/TouchEventTest.java	Wed Jun 06 18:00:24 2012 +0200
@@ -1110,6 +1110,70 @@
     }
 
     @Test
+    public void pointsShouldBeTransformedCorrectly() {
+        Scene scene = createScene();
+        Rectangle rect =
+                (Rectangle) scene.getRoot().getChildrenUnmodifiable().get(0);
+        rect.setTranslateX(15);
+        rect.setTranslateY(5);
+
+        touched = 0;
+        rect.addEventHandler(TouchEvent.ANY, new EventHandler<TouchEvent>() {
+            @Override public void handle(TouchEvent event) {
+                touched++;
+                switch(touched) {
+                    case 1:
+                        assertEquals(115.0, event.getTouchPoint().getX(), 0.0001);
+                        assertEquals(125.0, event.getTouchPoint().getY(), 0.0001);
+                        assertEquals(130.0, event.getTouchPoint().getSceneX(), 0.0001);
+                        assertEquals(130.0, event.getTouchPoint().getSceneY(), 0.0001);
+                        break;
+                    case 2:
+                    case 3:
+                    case 4:
+                    case 5:
+                        assertEquals(115.0, event.getTouchPoints().get(0).getX(), 0.0001);
+                        assertEquals(125.0, event.getTouchPoints().get(0).getY(), 0.0001);
+                        assertEquals(130.0, event.getTouchPoints().get(0).getSceneX(), 0.0001);
+                        assertEquals(130.0, event.getTouchPoints().get(0).getSceneY(), 0.0001);
+                        assertEquals(125.0, event.getTouchPoints().get(1).getX(), 0.0001);
+                        assertEquals(135.0, event.getTouchPoints().get(1).getY(), 0.0001);
+                        assertEquals(140.0, event.getTouchPoints().get(1).getSceneX(), 0.0001);
+                        assertEquals(140.0, event.getTouchPoints().get(1).getSceneY(), 0.0001);
+                        break;
+                    default:
+                        fail("Wrong touch point id " + event.getTouchPoint().getId());
+                }
+            }
+        });
+
+        ((StubScene) scene.impl_getPeer()).getListener().touchEventBegin(
+                System.currentTimeMillis(), 1, true, true, false, true, false);
+        ((StubScene) scene.impl_getPeer()).getListener().touchEventNext(
+                TouchPoint.State.PRESSED, 1, 130, 130, 130, 130);
+        ((StubScene) scene.impl_getPeer()).getListener().touchEventEnd();
+
+        ((StubScene) scene.impl_getPeer()).getListener().touchEventBegin(
+                System.currentTimeMillis(), 2, true, true, false, true, false);
+        ((StubScene) scene.impl_getPeer()).getListener().touchEventNext(
+                TouchPoint.State.STATIONARY, 1, 130, 130, 130, 130);
+        ((StubScene) scene.impl_getPeer()).getListener().touchEventNext(
+                TouchPoint.State.PRESSED, 2, 140, 140, 140, 140);
+        ((StubScene) scene.impl_getPeer()).getListener().touchEventEnd();
+
+        ((StubScene) scene.impl_getPeer()).getListener().touchEventBegin(
+                System.currentTimeMillis(), 2, true, true, false, true, false);
+        ((StubScene) scene.impl_getPeer()).getListener().touchEventNext(
+                TouchPoint.State.RELEASED, 1, 130, 130, 130, 130);
+        ((StubScene) scene.impl_getPeer()).getListener().touchEventNext(
+                TouchPoint.State.RELEASED, 2, 140, 140, 140, 140);
+        ((StubScene) scene.impl_getPeer()).getListener().touchEventEnd();
+
+
+        assertEquals(5, touched);
+    }
+
+    @Test
     public void shouldIgnoreIndirectTouchEvents() {
         Scene scene = createScene();
         Rectangle rect =