public boolean processGestureEvent(MTGestureEvent ge) { DragEvent de = (DragEvent) ge; try { Body body = (Body) comp.getUserData("box2d"); MouseJoint mouseJoint; Vector3D to = new Vector3D(de.getTo()); // Un-scale position from mt4j to box2d PhysicsHelper.scaleDown(to, scale); switch (de.getId()) { case DragEvent.GESTURE_STARTED: comp.sendToFront(); body.wakeUp(); body.setXForm(new Vec2(to.x, to.y), body.getAngle()); mouseJoint = PhysicsHelper.createDragJoint(world, body, to.x, to.y); comp.setUserData(comp.getID(), mouseJoint); break; case DragEvent.GESTURE_UPDATED: mouseJoint = (MouseJoint) comp.getUserData(comp.getID()); if (mouseJoint != null) { boolean onCorrectGameSide = ((MTComponent) de.getTarget()).containsPointGlobal(de.getTo()); // System.out.println(((MTComponent)de.getTargetComponent()).getName() + " Contains // " + to + " -> " + contains); if (onCorrectGameSide) { mouseJoint.setTarget(new Vec2(to.x, to.y)); } } break; case DragEvent.GESTURE_ENDED: mouseJoint = (MouseJoint) comp.getUserData(comp.getID()); if (mouseJoint != null) { comp.setUserData(comp.getID(), null); // Only destroy the joint if it isnt already (go through joint list and check) for (Joint joint = world.getJointList(); joint != null; joint = joint.getNext()) { JointType type = joint.getType(); switch (type) { case MOUSE_JOINT: MouseJoint mj = (MouseJoint) joint; if (body.equals(mj.getBody1()) || body.equals(mj.getBody2())) { if (mj.equals(mouseJoint)) { world.destroyJoint(mj); } } break; default: break; } } } mouseJoint = null; break; default: break; } } catch (Exception e) { System.err.println(e.getMessage()); } return false; }
public boolean processGestureEvent(MTGestureEvent ge) { DepthGestureEvent depthEv; if (ge instanceof DepthGestureEvent) { lastEvent = ge; depthEv = (DepthGestureEvent) ge; } else { return false; } switch (depthEv.getId()) { case MTGestureEvent.GESTURE_STARTED: { if (dragDepthTarget instanceof MTComponent) { MTComponent baseComp = (MTComponent) dragDepthTarget; baseComp.sendToFront(); } Vector3D zVector = new Vector3D(0.0f, 0.0f, depthEv.getTranslationVect().z); if (!(dragDepthTarget instanceof Cluster3DExt)) { dragDepthTarget.translateGlobal(zVector); } else { // only move children, not cluster itself // cause it should stay on the floor Cluster3DExt cl = (Cluster3DExt) dragDepthTarget; for (MTComponent comp : cl.getChildren()) { if (!(comp instanceof MTPolygon)) { comp.translateGlobal(zVector); } } } break; } case MTGestureEvent.GESTURE_UPDATED: { Vector3D zVector = new Vector3D(0.0f, 0.0f, depthEv.getTranslationVect().z); if (!(dragDepthTarget instanceof Cluster3DExt) && !gestureAborted) { dragDepthTarget.translateGlobal(zVector); } else { // only move children, not cluster itself // cause it should stay on the floor Cluster3DExt cl = (Cluster3DExt) dragDepthTarget; // remove cl.translateGlobal(zVector); // remove end /*for(MTComponent comp : cl.getChildren()) { if(!(comp instanceof MTPolygon)) { comp.translateGlobal(zVector); } }*/ } break; } case MTGestureEvent.GESTURE_ENDED: break; default: break; } return true; }
/* (non-Javadoc) * @see com.jMT.input.gestureAction.IGestureAction#processGesture(com.jMT.input.inputAnalyzers.GestureEvent) */ public boolean processGestureEvent(MTGestureEvent g) { // width = polyButton.getWidthLocal();// if (g instanceof TapEvent) { TapEvent clickEvent = (TapEvent) g; if (g.getTargetComponent() instanceof MTComponent) { MTComponent comp = (MTComponent) g.getTargetComponent(); // Hack for keeping up with the buttons current width if it was changed // due to .scale or something sometime if (comp instanceof IclickableButton) { IclickableButton button = (IclickableButton) comp; if (!button.isSelected()) { // this.width = ((AbstractShape)button).getWidthLocal(); this.width = getCurrentUnscaledWidth(); // this.getReferenceComp().getWidthVectObjSpace(); // //TODO aktuelle width holen zu comptoscale relative // this.width = this.getReferenceComp().getWidthLocal(); } } switch (clickEvent.getId()) { case MTGestureEvent.GESTURE_DETECTED: // if (comp.isGestureAllowed(TapAnalyzer.class) // && comp.isVisible() // ){ comp.sendToFront(); // if ( ((TapEvent)g).getId() == TapEvent.BUTTON_DOWN){ if (((TapEvent) g).getTapID() == TapEvent.BUTTON_DOWN) { // Resize button // getCompToResize().setSizeLocal(width-5, width-5); // Vector3D centerPoint = this.getRefCompCenterLocal(); // this.getCompToResize().scale(1/this.getReferenceComp().getWidthLocal(), // 1/this.getReferenceComp().getHeightLocal(), 1, centerPoint); // this.getCompToResize().scale(width-5, width-5, 1, centerPoint); // this.resize(width-5, width-5); // this.shrink(width-shrinkValue, width-shrinkValue); this.shrink(width - sizeChangeValue, height - sizeChangeValue); if (comp instanceof IclickableButton) { IclickableButton polyButton = (IclickableButton) g.getTargetComponent(); polyButton.fireActionPerformed((TapEvent) g); polyButton.setSelected(true); } } // } break; case MTGestureEvent.GESTURE_UPDATED: // NOTE: usually click gesture analyzers dont send gesture update events // if (comp.isGestureAllowed(TapAnalyzer.class) // && comp.isVisible() // ){ // if ( ((TapEvent)g).getId() == TapEvent.BUTTON_DOWN){ if (((TapEvent) g).getTapID() == TapEvent.BUTTON_DOWN) { if (comp instanceof IclickableButton) { IclickableButton polyButton = (IclickableButton) g.getTargetComponent(); polyButton.fireActionPerformed((TapEvent) g); } } // } break; case MTGestureEvent.GESTURE_ENDED: // if (comp.isGestureAllowed(TapAnalyzer.class) // && comp.isVisible() // ){ // if ( ((TapEvent)g).getId() == TapEvent.BUTTON_CLICKED // || ((TapEvent)g).getId() == TapEvent.BUTTON_UP // ){ if (((TapEvent) g).getTapID() == TapEvent.BUTTON_CLICKED || ((TapEvent) g).getTapID() == TapEvent.BUTTON_UP) { // Resize button // polyButton.setSizeLocal(width, width); // this.resize(width, width); // this.enlarge(width, width); this.enlarge(width, height); // Vector3D centerPoint = this.getRefCompCenterLocal(); // this.getCompToResize().scale(1/this.getReferenceComp().getWidthLocal(), // 1/this.getReferenceComp().getHeightLocal(), 1, centerPoint); // this.getCompToResize().scale(width, width, 1, centerPoint); if (comp instanceof IclickableButton) { IclickableButton polyButton = (IclickableButton) g.getTargetComponent(); polyButton.fireActionPerformed((TapEvent) g); polyButton.setSelected(false); } } // } break; default: break; } } } return false; }