List of usage examples for com.google.gwt.dom.client Touch getIdentifier
public final int getIdentifier()
From source file:com.appkit.ui.client.events.recognizer.longtap.LongTapRecognizer.java
License:Apache License
@Override public void onTouchMove(TouchMoveEvent event) { switch (state) { case WAITING: case FINGERS_DOWN: case FINGERS_UP: // compare positions JsArray<Touch> currentTouches = event.getTouches(); for (int i = 0; i < currentTouches.length(); i++) { Touch currentTouch = currentTouches.get(i); for (int j = 0; j < startPositions.length(); j++) { TouchCopy startTouch = startPositions.get(j); if (currentTouch.getIdentifier() == startTouch.getIdentifier()) { if (Math.abs(currentTouch.getPageX() - startTouch.getPageX()) > distance || Math.abs(currentTouch.getPageY() - startTouch.getPageY()) > distance) { state = State.INVALID; break; }//from w w w . j av a2 s . c o m } if (state == State.INVALID) { break; } } } break; default: state = State.INVALID; break; } }
From source file:com.appkit.ui.client.events.touch.TouchCopy.java
License:Apache License
public static TouchCopy copy(Touch touch) { return new TouchCopy(touch.getPageX(), touch.getPageY(), touch.getIdentifier()); }
From source file:com.badlogic.gdx.backends.gwt.GwtInput.java
License:Apache License
private void handleEvent(NativeEvent e) { if (e.getType().equals("mousedown")) { if (!e.getEventTarget().equals(canvas) || touched[0]) { float mouseX = getRelativeX(e, canvas); float mouseY = getRelativeY(e, canvas); if (mouseX < 0 || mouseX > Gdx.graphics.getWidth() || mouseY < 0 || mouseY > Gdx.graphics.getHeight()) { hasFocus = false;/*w w w. j a v a2s. co m*/ } return; } hasFocus = true; this.justTouched = true; this.touched[0] = true; this.pressedButtons.add(getButton(e.getButton())); this.deltaX[0] = 0; this.deltaY[0] = 0; if (isCursorCatched()) { this.touchX[0] += getMovementXJSNI(e); this.touchY[0] += getMovementYJSNI(e); } else { this.touchX[0] = getRelativeX(e, canvas); this.touchY[0] = getRelativeY(e, canvas); } this.currentEventTimeStamp = TimeUtils.nanoTime(); if (processor != null) processor.touchDown(touchX[0], touchY[0], 0, getButton(e.getButton())); } if (e.getType().equals("mousemove")) { if (isCursorCatched()) { this.deltaX[0] = (int) getMovementXJSNI(e); this.deltaY[0] = (int) getMovementYJSNI(e); this.touchX[0] += getMovementXJSNI(e); this.touchY[0] += getMovementYJSNI(e); } else { this.deltaX[0] = getRelativeX(e, canvas) - touchX[0]; this.deltaY[0] = getRelativeY(e, canvas) - touchY[0]; this.touchX[0] = getRelativeX(e, canvas); this.touchY[0] = getRelativeY(e, canvas); } this.currentEventTimeStamp = TimeUtils.nanoTime(); if (processor != null) { if (touched[0]) processor.touchDragged(touchX[0], touchY[0], 0); else processor.mouseMoved(touchX[0], touchY[0]); } } if (e.getType().equals("mouseup")) { if (!touched[0]) return; this.pressedButtons.remove(getButton(e.getButton())); this.touched[0] = pressedButtons.size > 0; if (isCursorCatched()) { this.deltaX[0] = (int) getMovementXJSNI(e); this.deltaY[0] = (int) getMovementYJSNI(e); this.touchX[0] += getMovementXJSNI(e); this.touchY[0] += getMovementYJSNI(e); } else { this.deltaX[0] = getRelativeX(e, canvas) - touchX[0]; this.deltaY[0] = getRelativeY(e, canvas) - touchY[0]; this.touchX[0] = getRelativeX(e, canvas); this.touchY[0] = getRelativeY(e, canvas); } this.currentEventTimeStamp = TimeUtils.nanoTime(); this.touched[0] = false; if (processor != null) processor.touchUp(touchX[0], touchY[0], 0, getButton(e.getButton())); } if (e.getType().equals(getMouseWheelEvent())) { if (processor != null) { processor.scrolled((int) getMouseWheelVelocity(e)); } this.currentEventTimeStamp = TimeUtils.nanoTime(); e.preventDefault(); } if (e.getType().equals("keydown") && hasFocus) { // System.out.println("keydown"); int code = keyForCode(e.getKeyCode()); if (code == 67) { e.preventDefault(); if (processor != null) { processor.keyDown(code); processor.keyTyped('\b'); } } else { if (!pressedKeys[code]) { pressedKeyCount++; pressedKeys[code] = true; keyJustPressed = true; justPressedKeys[code] = true; if (processor != null) { processor.keyDown(code); } } } } if (e.getType().equals("keypress") && hasFocus) { // System.out.println("keypress"); char c = (char) e.getCharCode(); if (processor != null) processor.keyTyped(c); } if (e.getType().equals("keyup") && hasFocus) { // System.out.println("keyup"); int code = keyForCode(e.getKeyCode()); if (pressedKeys[code]) { pressedKeyCount--; pressedKeys[code] = false; } if (processor != null) { processor.keyUp(code); } } if (e.getType().equals("touchstart")) { this.justTouched = true; JsArray<Touch> touches = e.getChangedTouches(); for (int i = 0, j = touches.length(); i < j; i++) { Touch touch = touches.get(i); int real = touch.getIdentifier(); int touchId; touchMap.put(real, touchId = getAvailablePointer()); touched[touchId] = true; touchX[touchId] = getRelativeX(touch, canvas); touchY[touchId] = getRelativeY(touch, canvas); deltaX[touchId] = 0; deltaY[touchId] = 0; if (processor != null) { processor.touchDown(touchX[touchId], touchY[touchId], touchId, Buttons.LEFT); } } this.currentEventTimeStamp = TimeUtils.nanoTime(); e.preventDefault(); } if (e.getType().equals("touchmove")) { JsArray<Touch> touches = e.getChangedTouches(); for (int i = 0, j = touches.length(); i < j; i++) { Touch touch = touches.get(i); int real = touch.getIdentifier(); int touchId = touchMap.get(real); deltaX[touchId] = getRelativeX(touch, canvas) - touchX[touchId]; deltaY[touchId] = getRelativeY(touch, canvas) - touchY[touchId]; touchX[touchId] = getRelativeX(touch, canvas); touchY[touchId] = getRelativeY(touch, canvas); if (processor != null) { processor.touchDragged(touchX[touchId], touchY[touchId], touchId); } } this.currentEventTimeStamp = TimeUtils.nanoTime(); e.preventDefault(); } if (e.getType().equals("touchcancel")) { JsArray<Touch> touches = e.getChangedTouches(); for (int i = 0, j = touches.length(); i < j; i++) { Touch touch = touches.get(i); int real = touch.getIdentifier(); int touchId = touchMap.get(real); touchMap.remove(real); touched[touchId] = false; deltaX[touchId] = getRelativeX(touch, canvas) - touchX[touchId]; deltaY[touchId] = getRelativeY(touch, canvas) - touchY[touchId]; touchX[touchId] = getRelativeX(touch, canvas); touchY[touchId] = getRelativeY(touch, canvas); if (processor != null) { processor.touchUp(touchX[touchId], touchY[touchId], touchId, Buttons.LEFT); } } this.currentEventTimeStamp = TimeUtils.nanoTime(); e.preventDefault(); } if (e.getType().equals("touchend")) { JsArray<Touch> touches = e.getChangedTouches(); for (int i = 0, j = touches.length(); i < j; i++) { Touch touch = touches.get(i); int real = touch.getIdentifier(); int touchId = touchMap.get(real); touchMap.remove(real); touched[touchId] = false; deltaX[touchId] = getRelativeX(touch, canvas) - touchX[touchId]; deltaY[touchId] = getRelativeY(touch, canvas) - touchY[touchId]; touchX[touchId] = getRelativeX(touch, canvas); touchY[touchId] = getRelativeY(touch, canvas); if (processor != null) { processor.touchUp(touchX[touchId], touchY[touchId], touchId, Buttons.LEFT); } } this.currentEventTimeStamp = TimeUtils.nanoTime(); e.preventDefault(); } // if(hasFocus) e.preventDefault(); }
From source file:com.fullmetalgalaxy.client.widget.WgtScroll.java
License:Open Source License
private Touch getTouch(JsArray<Touch> touches, int identifier) { if (touches != null && !isZoomed()) { if (identifier == -1) { if (touches.length() > 0) { return touches.get(0); }//from w w w . j a v a2 s. co m } else if (touches.length() == 1) { Touch touch = touches.get(0); if (touch.getIdentifier() == identifier) { return touch; } } } return null; }
From source file:com.fullmetalgalaxy.client.widget.WgtScroll.java
License:Open Source License
@Override public void onTouchStart(TouchStartEvent p_event) { Touch touch = getTouch(p_event.getChangedTouches(), -1); if (touch != null) { m_currentTouchEventId = touch.getIdentifier(); onDown(Element.as(touch.getTarget()), touch.getClientX(), touch.getClientY()); }/*from w ww . ja v a2s . c om*/ }
From source file:com.googlecode.mgwt.dom.client.event.touch.TouchCopy.java
License:Apache License
public TouchCopy(Touch touch) { this.pageX = touch.getPageX(); this.pageY = touch.getPageY(); this.clientX = touch.getClientX(); this.clientY = touch.getClientY(); this.screenX = touch.getScreenX(); this.screenY = touch.getScreenY(); this.id = touch.getIdentifier(); }
From source file:com.googlecode.mgwt.dom.client.recognizer.tap.MultiTapRecognizer.java
License:Apache License
@Override public void onTouchMove(TouchMoveEvent event) { switch (state) { case FINGERS_GOING_DOWN: case FINGERS_GOING_UP: // compare positions JsArray<Touch> currentTouches = event.getTouches(); for (int i = 0; i < currentTouches.length(); i++) { Touch currentTouch = currentTouches.get(i); for (int j = 0; j < touches.length(); j++) { TouchCopy startTouch = touches.get(j); if (currentTouch.getIdentifier() == startTouch.getIdentifier()) { if (Math.abs(currentTouch.getPageX() - startTouch.getPageX()) > distance || Math.abs(currentTouch.getPageY() - startTouch.getPageY()) > distance) { state = State.INVALID; break; }//from www. j a v a 2 s .c o m } if (state == State.INVALID) { break; } } } break; default: break; } }
From source file:com.sencha.gxt.core.client.gestures.AbstractGestureRecognizer.java
License:sencha.com license
/** * Handles the start of gesture. Typically associated by a touchstart or pointerdown event * * @param startEvent/*from w w w.ja va2 s. co m*/ * @return true if the gesture is not handling the event and can allow it to be propagated, false to indicate that * it has been handled and should not be given to other handlers. Should always return true for any start * event. */ public boolean handleStart(NativeEvent startEvent) { JsArray<Touch> touches = pointerEventsSupport.isSupported() ? pointerEventsSupport.getChangedTouches(startEvent) : startEvent.getChangedTouches(); List<TouchData> startedTouches = new ArrayList<TouchData>(); for (int i = 0; i < touches.length(); i++) { Touch t = touches.get(i); TouchData data = new TouchData(new Point(t.getPageX(), t.getPageY()), t.getIdentifier(), startEvent); startedTouches.add(data); } start(startedTouches); return true; }
From source file:com.sencha.gxt.core.client.gestures.AbstractGestureRecognizer.java
License:sencha.com license
/** * Handles gesture move events// ww w . j a v a2 s . co m * * @param moveEvent * @return true if the gesture is not handling the event and can allow it to be propagated, false to indicate that * it has been handled and should not be given to other handlers. Should always return true for any start * event. */ public boolean handleMove(NativeEvent moveEvent) { JsArray<Touch> touches = pointerEventsSupport.isSupported() ? pointerEventsSupport.getChangedTouches(moveEvent) : moveEvent.getChangedTouches(); List<TouchData> allData = new ArrayList<TouchData>(); int unhandledTouches = 0; for (int i = 0; i < touches.length(); i++) { Touch t = touches.get(i); if (captured.containsKey(t.getIdentifier())) { TouchData data = captured.get(t.getIdentifier()); data.setLastChange(Type.Move); data.setLastPosition(new Point(t.getPageX(), t.getPageY())); data.setLastNativeEvent(moveEvent); allData.add(data); } else { unhandledTouches++; } } if (!allData.isEmpty()) { handlePreventDefault(moveEvent); onMove(allData); } if (unhandledTouches == 0) { moveEvent.stopPropagation(); return false; } return true; }
From source file:com.sencha.gxt.core.client.gestures.AbstractGestureRecognizer.java
License:sencha.com license
/** * Handles gesture cancel events/*from w w w. j a va2s .c o m*/ * * @param cancelEvent * @return true if the gesture is not handling the event and can allow it to be propagated, false to indicate that * it has been handled and should not be given to other handlers. Should always return true for any start * event. */ public boolean handleCancel(NativeEvent cancelEvent) { JsArray<Touch> empty = JsArray.createArray().cast(); JsArray<Touch> touches = pointerEventsSupport.isSupported() ? empty : cancelEvent.getTouches(); //list of items that we are interested in that were canceled by this dom event List<TouchData> canceledData = new ArrayList<TouchData>(interested.values()); for (int i = 0; i < touches.length(); i++) { Touch t = touches.get(i); if (interested.containsKey(t.getIdentifier())) { canceledData.remove(interested.get(t.getIdentifier())); } } for (TouchData data : canceledData) { data.setLastChange(Type.Cancel); data.setLastNativeEvent(cancelEvent); setInterest(data, false); } if (!canceledData.isEmpty()) { handlePreventDefault(cancelEvent); onCancel(canceledData); } //never stopPropagation the cancel event, same as stop return true; }