PageRenderTime 25ms CodeModel.GetById 11ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

/examples/basic/scenes/Scene3.java

http://mt4j.googlecode.com/
Java | 109 lines | 87 code | 16 blank | 6 comment | 8 complexity | ec3dbdcf6f06ffe39da2ff69520849b4 MD5 | raw file
  1package basic.scenes;
  2
  3import java.awt.event.ActionEvent;
  4import java.awt.event.ActionListener;
  5
  6import org.mt4j.MTApplication;
  7import org.mt4j.components.TransformSpace;
  8import org.mt4j.components.visibleComponents.font.FontManager;
  9import org.mt4j.components.visibleComponents.widgets.MTTextArea;
 10import org.mt4j.components.visibleComponents.widgets.buttons.MTImageButton;
 11import org.mt4j.input.inputProcessors.IGestureEventListener;
 12import org.mt4j.input.inputProcessors.MTGestureEvent;
 13import org.mt4j.input.inputProcessors.componentProcessors.flickProcessor.FlickEvent;
 14import org.mt4j.input.inputProcessors.componentProcessors.flickProcessor.FlickProcessor;
 15import org.mt4j.input.inputProcessors.componentProcessors.tapProcessor.TapEvent;
 16import org.mt4j.input.inputProcessors.globalProcessors.CursorTracer;
 17import org.mt4j.sceneManagement.AbstractScene;
 18import org.mt4j.sceneManagement.transition.FadeTransition;
 19import org.mt4j.sceneManagement.transition.FlipTransition;
 20import org.mt4j.util.MT4jSettings;
 21import org.mt4j.util.MTColor;
 22import org.mt4j.util.math.Vector3D;
 23import org.mt4j.util.opengl.GLFBO;
 24
 25import processing.core.PImage;
 26
 27public class Scene3 extends AbstractScene {
 28
 29	private MTApplication mtApp;
 30	
 31//	private String imagePath = System.getProperty("user.dir") + File.separator + "examples"+  File.separator +"basic"+  File.separator + "scenes" + File.separator + "data" + File.separator;
 32	private String imagePath =  "basic" +  MTApplication.separator + "scenes" + MTApplication.separator + "data" + MTApplication.separator;
 33
 34	public Scene3(MTApplication mtApplication, String name) {
 35		super(mtApplication, name);
 36		this.mtApp = mtApplication;
 37		
 38		//Set the background color
 39		this.setClearColor(new MTColor(150, 188, 146, 255));
 40		
 41		this.registerGlobalInputProcessor(new CursorTracer(mtApp, this));
 42		
 43		//Create a textfield
 44		MTTextArea textField = new MTTextArea(mtApplication, FontManager.getInstance().createFont(mtApplication, "arial.ttf", 
 45				50, MTColor.WHITE)); 
 46		textField.setNoFill(true);
 47		textField.setNoStroke(true);
 48		textField.setText("Scene 3");
 49		this.getCanvas().addChild(textField);
 50		textField.setPositionGlobal(new Vector3D(mtApplication.width/2f, mtApplication.height/2f));
 51		
 52		//Button to return to the previous scene
 53		PImage arrow = mtApplication.loadImage(imagePath + "arrowRight.png");
 54		MTImageButton previousSceneButton = new MTImageButton(mtApplication, arrow);
 55		previousSceneButton.setNoStroke(true);
 56		if (MT4jSettings.getInstance().isOpenGlMode())
 57			previousSceneButton.setUseDirectGL(true);
 58		previousSceneButton.addActionListener(new ActionListener() {
 59			public void actionPerformed(ActionEvent ae) {
 60				switch (ae.getID()) {
 61				case TapEvent.TAPPED:
 62					mtApp.popScene();
 63					break;
 64				default:
 65					break;
 66				}
 67			}
 68		});
 69		getCanvas().addChild(previousSceneButton);
 70		previousSceneButton.scale(-1, 1, 1, previousSceneButton.getCenterPointLocal(), TransformSpace.LOCAL);
 71		previousSceneButton.setPositionGlobal(new Vector3D(previousSceneButton.getWidthXY(TransformSpace.GLOBAL) + 5, mtApp.height - previousSceneButton.getHeightXY(TransformSpace.GLOBAL) - 5, 0));
 72		
 73		//Set a scene transition - Flip transition only available using opengl supporting the FBO extenstion
 74		if (MT4jSettings.getInstance().isOpenGlMode() && GLFBO.isSupported(mtApp))
 75			this.setTransition(new FlipTransition(mtApp, 700));
 76		else{
 77			this.setTransition(new FadeTransition(mtApp));
 78		}
 79		
 80		//Register flick gesture with the canvas to change the scene
 81		getCanvas().registerInputProcessor(new FlickProcessor());
 82		getCanvas().addGestureListener(FlickProcessor.class, new IGestureEventListener() {
 83			public boolean processGestureEvent(MTGestureEvent ge) {
 84				FlickEvent e = (FlickEvent)ge;
 85				if (e.getId() == MTGestureEvent.GESTURE_ENDED && e.isFlick()){
 86					switch (e.getDirection()) {
 87					case EAST:
 88					case NORTH_EAST:
 89					case SOUTH_EAST:
 90						mtApp.popScene();
 91						break;
 92					default:
 93						break;
 94					}
 95				}
 96				return false;
 97			}
 98		});
 99	}
100
101	public void onEnter() {
102		System.out.println("Entered scene: " +  this.getName());
103	}
104	
105	public void onLeave() {	
106		System.out.println("Left scene: " +  this.getName());
107	}
108
109}