private MTApplication app;
public MTGesturesExampleScene(MTApplication mtApplication, String name) {
super(mtApplication, name);
this.app = mtApplication;
this.setClearColor(new MTColor(126, 130, 168, 255));
this.registerGlobalInputProcessor(new CursorTracer(app, this));
float verticalPad = 53;
float horizontalPad = 500;
MTColor white = new MTColor(255,255,255);
final MTColor textAreaColor = new MTColor(50,50,50,255);
IFont font = FontManager.getInstance().createFont(app, "arial.ttf", 35, white, white);
//Add canvas background gestures
//Zoom gesture
MTTextArea backgroundZoom = new MTTextArea(mtApplication, font);
backgroundZoom.setFillColor(new MTColor(150,150,150));
backgroundZoom.setNoFill(true);
backgroundZoom.setNoStroke(true);
backgroundZoom.setText("Zoom anywhere on the background!");
backgroundZoom.setPickable(false);
this.getCanvas().addChild(backgroundZoom);
backgroundZoom.setPositionGlobal(new Vector3D(app.width/2f, app.height/2f,0));
getCanvas().registerInputProcessor(new ZoomProcessor(app));
getCanvas().addGestureListener(ZoomProcessor.class, new DefaultZoomAction());
//2 finger pan gesture
MTTextArea backgroundPan = new MTTextArea(mtApplication, font);
backgroundPan.setFillColor(new MTColor(150,150,150));
backgroundPan.setNoFill(true);
backgroundPan.setNoStroke(true);
backgroundPan.setText("Pan anywhere on the background!");
backgroundPan.setPickable(false);
this.getCanvas().addChild(backgroundPan);
backgroundPan.setPositionGlobal(new Vector3D(app.width/2f, app.height/2f + 1*verticalPad,0));
getCanvas().registerInputProcessor(new PanProcessorTwoFingers(app));
getCanvas().addGestureListener(PanProcessorTwoFingers.class, new DefaultPanAction());
//Add component multi-touch gestures
MTTextArea dragOnly = new MTTextArea(mtApplication, font);
dragOnly.setFillColor(textAreaColor);
dragOnly.setStrokeColor(textAreaColor);
dragOnly.setText("Drag me!");
this.clearAllGestures(dragOnly);
dragOnly.registerInputProcessor(new DragProcessor(app));
dragOnly.addGestureListener(DragProcessor.class, new DefaultDragAction());
dragOnly.addGestureListener(DragProcessor.class, new InertiaDragAction()); //Add inertia to dragging
this.getCanvas().addChild(dragOnly);
MTTextArea rotateOnly = new MTTextArea(mtApplication, font);
rotateOnly.setFillColor(textAreaColor);
rotateOnly.setStrokeColor(textAreaColor);
rotateOnly.setText("Rotate me!");
this.clearAllGestures(rotateOnly);
rotateOnly.registerInputProcessor(new RotateProcessor(app));
rotateOnly.addGestureListener(RotateProcessor.class, new DefaultRotateAction());
this.getCanvas().addChild(rotateOnly);
rotateOnly.setAnchor(PositionAnchor.UPPER_LEFT);
rotateOnly.setPositionGlobal(new Vector3D(0, verticalPad,0));
MTTextArea scaleOnly = new MTTextArea(mtApplication, font);
scaleOnly.setFillColor(textAreaColor);
scaleOnly.setStrokeColor(textAreaColor);
scaleOnly.setText("Scale me!");
this.clearAllGestures(scaleOnly);
scaleOnly.registerInputProcessor(new ScaleProcessor(app));
scaleOnly.addGestureListener(ScaleProcessor.class, new DefaultScaleAction());
this.getCanvas().addChild(scaleOnly);
scaleOnly.setAnchor(PositionAnchor.UPPER_LEFT);
scaleOnly.setPositionGlobal(new Vector3D(0, 2*verticalPad,0));
MTTextArea dragAndRotate = new MTTextArea(mtApplication, font);
dragAndRotate.setFillColor(textAreaColor);
dragAndRotate.setStrokeColor(textAreaColor);
dragAndRotate.setText("Drag and Rotate me!");
this.clearAllGestures(dragAndRotate);
dragAndRotate.registerInputProcessor(new RotateProcessor(app));
dragAndRotate.addGestureListener(RotateProcessor.class, new DefaultRotateAction());
dragAndRotate.registerInputProcessor(new DragProcessor(app));
dragAndRotate.addGestureListener(DragProcessor.class, new DefaultDragAction());
this.getCanvas().addChild(dragAndRotate);
dragAndRotate.setAnchor(PositionAnchor.UPPER_LEFT);
dragAndRotate.setPositionGlobal(new Vector3D(0, 3*verticalPad,0));
MTTextArea dragAndScale = new MTTextArea(mtApplication, font);
dragAndScale.setFillColor(textAreaColor);
dragAndScale.setStrokeColor(textAreaColor);
dragAndScale.setText("Drag and Scale me!");
this.clearAllGestures(dragAndScale);
dragAndScale.registerInputProcessor(new ScaleProcessor(app));
dragAndScale.addGestureListener(ScaleProcessor.class, new DefaultScaleAction());
dragAndScale.registerInputProcessor(new DragProcessor(app));
dragAndScale.addGestureListener(DragProcessor.class, new DefaultDragAction());
this.getCanvas().addChild(dragAndScale);
dragAndScale.setAnchor(PositionAnchor.UPPER_LEFT);
dragAndScale.setPositionGlobal(new Vector3D(0, 8*verticalPad,0));
MTTextArea rotateAndScale = new MTTextArea(mtApplication, font);
rotateAndScale.setFillColor(textAreaColor);
rotateAndScale.setStrokeColor(textAreaColor);
rotateAndScale.setText("Rotate and Scale me!");
this.clearAllGestures(rotateAndScale);
rotateAndScale.registerInputProcessor(new ScaleProcessor(app));
rotateAndScale.addGestureListener(ScaleProcessor.class, new DefaultScaleAction());
rotateAndScale.registerInputProcessor(new RotateProcessor(app));
rotateAndScale.addGestureListener(RotateProcessor.class, new DefaultRotateAction());
this.getCanvas().addChild(rotateAndScale);
rotateAndScale.setAnchor(PositionAnchor.UPPER_LEFT);
rotateAndScale.setPositionGlobal(new Vector3D(0,9*verticalPad,0));
MTTextArea dragRotScale = new MTTextArea(mtApplication, font);
dragRotScale.setFillColor(textAreaColor);
dragRotScale.setStrokeColor(textAreaColor);
dragRotScale.setText("Drag, Rotate and Scale me!");
this.clearAllGestures(dragRotScale);
dragRotScale.registerInputProcessor(new ScaleProcessor(app));
dragRotScale.addGestureListener(ScaleProcessor.class, new DefaultScaleAction());
dragRotScale.registerInputProcessor(new RotateProcessor(app));
dragRotScale.addGestureListener(RotateProcessor.class, new DefaultRotateAction());
dragRotScale.registerInputProcessor(new DragProcessor(app));
dragRotScale.addGestureListener(DragProcessor.class, new DefaultDragAction());
this.getCanvas().addChild(dragRotScale);
dragRotScale.setAnchor(PositionAnchor.UPPER_LEFT);
dragRotScale.setPositionGlobal(new Vector3D(0,10*verticalPad,0));
//Tap gesture
final MTTextArea tapOnly = new MTTextArea(mtApplication, font);
tapOnly.setFillColor(textAreaColor);
tapOnly.setStrokeColor(textAreaColor);
tapOnly.setText("Tap me! ---");
this.clearAllGestures(tapOnly);
tapOnly.registerInputProcessor(new TapProcessor(app));
tapOnly.addGestureListener(TapProcessor.class, new IGestureEventListener() {
public boolean processGestureEvent(MTGestureEvent ge) {
TapEvent te = (TapEvent)ge;
switch (te.getId()) {
case MTGestureEvent.GESTURE_DETECTED:
tapOnly.setFillColor(new MTColor(220,220,220,255));
break;
case MTGestureEvent.GESTURE_UPDATED:
break;
case MTGestureEvent.GESTURE_ENDED:
if (te.isTapped()){