From 950276679e78d22546399d358ef228dffa179c16 Mon Sep 17 00:00:00 2001 From: "rem..om" Date: Mon, 2 Jan 2012 09:11:13 +0000 Subject: [PATCH] Nifty : applied patch posted by iwgeric in this thread http://jmonkeyengine.org/groups/android/forum/topic/error-with-nifty-and-awt/?topic_page=2&num=15#post-147332 fixes nifty interaction on touch event on android. git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8971 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../com/jme3/niftygui/InputSystemJme.java | 36 ++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/engine/src/niftygui/com/jme3/niftygui/InputSystemJme.java b/engine/src/niftygui/com/jme3/niftygui/InputSystemJme.java index 937ce64e0..8a2d1c702 100644 --- a/engine/src/niftygui/com/jme3/niftygui/InputSystemJme.java +++ b/engine/src/niftygui/com/jme3/niftygui/InputSystemJme.java @@ -89,6 +89,37 @@ public class InputSystemJme implements InputSystem, RawInputListener { boolean result = nifty.update(); } + private void onTouchEventQueued(TouchEvent evt, NiftyInputConsumer nic) { + boolean consumed = false; + + x = (int) evt.getX(); + y = (int) (height - evt.getY()); + + switch (evt.getType()) { + case DOWN: + consumed = nic.processMouseEvent(x, y, 0, 0, false); + isDragging = true; + niftyOwnsDragging = consumed; + if (consumed){ + evt.setConsumed(); + } + + break; + + case UP: + if (niftyOwnsDragging){ + consumed = nic.processMouseEvent(x, y, 0, buttonIndex, pressed); + if (consumed){ + evt.setConsumed(); + } + } + + isDragging = false; + niftyOwnsDragging = false; + break; + } + } + private void onMouseMotionEventQueued(MouseMotionEvent evt, NiftyInputConsumer nic) { x = evt.getX(); y = height - evt.getY(); @@ -175,7 +206,8 @@ public class InputSystemJme implements InputSystem, RawInputListener { inputQueue.add(evt); } - public void onTouchEvent(TouchEvent evt) { + public void onTouchEvent(TouchEvent evt) { + inputQueue.add(evt); } public void forwardEvents(NiftyInputConsumer nic) { @@ -189,6 +221,8 @@ public class InputSystemJme implements InputSystem, RawInputListener { onMouseButtonEventQueued( (MouseButtonEvent)evt, nic); }else if (evt instanceof KeyInputEvent){ onKeyEventQueued( (KeyInputEvent)evt, nic); + }else if (evt instanceof TouchEvent){ + onTouchEventQueued( (TouchEvent)evt, nic); } }