PageRenderTime 30ms CodeModel.GetById 18ms app.highlight 9ms RepoModel.GetById 2ms app.codeStats 0ms

/examples/basic/css/menus/MenuExampleScene.java

http://mt4j.googlecode.com/
Java | 95 lines | 67 code | 22 blank | 6 comment | 3 complexity | 1e71812ee3c872e2a323cd85f6441895 MD5 | raw file
 1package basic.css.menus;
 2
 3import java.util.ArrayList;
 4import java.util.List;
 5
 6import org.mt4j.MTApplication;
 7import org.mt4j.components.css.style.CSSSelector;
 8import org.mt4j.components.css.util.CSSKeywords.CSSSelectorType;
 9import org.mt4j.components.css.util.CSSTemplates;
10import org.mt4j.input.inputProcessors.IGestureEventListener;
11import org.mt4j.input.inputProcessors.MTGestureEvent;
12import org.mt4j.input.inputProcessors.componentProcessors.tapProcessor.TapEvent;
13import org.mt4j.sceneManagement.AbstractScene;
14import org.mt4j.util.math.Vector3D;
15import org.mt4jx.components.visibleComponents.widgets.menus.MTHUD;
16import org.mt4jx.components.visibleComponents.widgets.menus.MTHexagonMenu;
17import org.mt4jx.components.visibleComponents.widgets.menus.MTSquareMenu;
18import org.mt4jx.components.visibleComponents.widgets.menus.MenuItem;
19
20import processing.core.PImage;
21
22
23public class MenuExampleScene  extends AbstractScene{
24	private MTApplication app;
25	
26	public MenuExampleScene(MTApplication mtApplication, String name) {
27		super(mtApplication, name);
28
29		this.app = mtApplication;
30			
31			//Set CSS Enabled for all components
32			app.getCssStyleManager().setGloballyEnabled(true);
33
34			//Load a different CSS Style for each component
35			app.getCssStyleManager().loadStylesAndOverrideSelector(CSSTemplates.MATRIXSTYLE, new CSSSelector("MTHUD", CSSSelectorType.CLASS));
36			app.getCssStyleManager().loadStylesAndOverrideSelector(CSSTemplates.BLUESTYLE, new CSSSelector("MTHexagonMenu", CSSSelectorType.CLASS));
37			app.getCssStyleManager().loadStylesAndOverrideSelector(CSSTemplates.REDSTYLE, new CSSSelector("MTSquareMenu", CSSSelectorType.CLASS));
38			
39			PImage p1 = app.loadImage("basic/css/data/p1.jpg");
40			PImage p2 = app.loadImage("basic/css/data/p2.jpg");
41			PImage p3 = app.loadImage("basic/css/data/p3.jpg");
42			
43			//Create Menu Items
44			List<MenuItem> menus = new ArrayList<MenuItem>();
45			menus.add(new MenuItem("Start", new gestureListener("Start")));
46			menus.add(new MenuItem("Open", new gestureListener("Open")));
47			menus.add(new MenuItem("Close", new gestureListener("Close")));
48			menus.add(new MenuItem("Exit", new gestureListener("Exit")));
49			menus.add(new MenuItem("Save", new gestureListener("Save")));
50			menus.add(new MenuItem("Load", new gestureListener("Load")));
51			menus.add(new MenuItem("Cancel", new gestureListener("Cancel")));
52			menus.add(new MenuItem("Undo", new gestureListener("Undo")));
53			menus.add(new MenuItem(p1, new gestureListener("Picture Item 1")));
54			menus.add(new MenuItem(p2, new gestureListener("Picture Item 2")));
55			menus.add(new MenuItem(p3, new gestureListener("Picture Item 3")));
56			
57			//Create Square Menu
58			MTSquareMenu sm = new MTSquareMenu(app, new Vector3D(25,200),  menus, 75);
59			this.getCanvas().addChild(sm);
60			
61			//Create Hexagon Menu
62			MTHexagonMenu hm = new MTHexagonMenu(app, new Vector3D(500,200),  menus, 100);
63			this.getCanvas().addChild(hm);
64			
65			//Create Heads up display (on bottom of the screen)
66			MTHUD hud = new MTHUD(app,menus, 64, MTHUD.BOTTOM );
67			this.getCanvas().addChild(hud);
68			
69	}
70
71	public void onEnter() {}
72	
73	public void onLeave() {}
74
75	public class gestureListener implements IGestureEventListener {
76		String string;
77		public gestureListener(String string) {
78			super();
79			this.string = string;
80		}
81		
82		
83		public boolean processGestureEvent(MTGestureEvent ge) {
84
85			if (ge instanceof TapEvent) {
86				TapEvent te = (TapEvent) ge;
87				if (te.getTapID() == TapEvent.TAPPED) {
88					System.out.println(string);
89				}
90			}
91			return true;
92		}
93		
94	}
95}