1 /******************************************************************************* 2 * Copyright 2011 See AUTHORS file. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 ******************************************************************************/ 16 17 package com.badlogic.gdx.tests; 18 19 import com.badlogic.gdx.Application; 20 import com.badlogic.gdx.Gdx; 21 import com.badlogic.gdx.InputMultiplexer; 22 import com.badlogic.gdx.InputProcessor; 23 import com.badlogic.gdx.input.GestureDetector; 24 import com.badlogic.gdx.input.GestureDetector.GestureListener; 25 import com.badlogic.gdx.math.Vector2; 26 import com.badlogic.gdx.tests.box2d.ApplyForce; 27 import com.badlogic.gdx.tests.box2d.BodyTypes; 28 import com.badlogic.gdx.tests.box2d.Box2DTest; 29 import com.badlogic.gdx.tests.box2d.Bridge; 30 import com.badlogic.gdx.tests.box2d.Cantilever; 31 import com.badlogic.gdx.tests.box2d.Chain; 32 import com.badlogic.gdx.tests.box2d.CharacterCollision; 33 import com.badlogic.gdx.tests.box2d.CollisionFiltering; 34 import com.badlogic.gdx.tests.box2d.ContactListenerTest; 35 import com.badlogic.gdx.tests.box2d.ContinuousTest; 36 import com.badlogic.gdx.tests.box2d.ConveyorBelt; 37 import com.badlogic.gdx.tests.box2d.DebugRendererTest; 38 import com.badlogic.gdx.tests.box2d.OneSidedPlatform; 39 import com.badlogic.gdx.tests.box2d.Prismatic; 40 import com.badlogic.gdx.tests.box2d.Pyramid; 41 import com.badlogic.gdx.tests.box2d.SimpleTest; 42 import com.badlogic.gdx.tests.box2d.SphereStack; 43 import com.badlogic.gdx.tests.box2d.VaryingRestitution; 44 import com.badlogic.gdx.tests.box2d.VerticalStack; 45 import com.badlogic.gdx.tests.utils.GdxTest; 46 47 public class Box2DTestCollection extends GdxTest implements InputProcessor, GestureListener { 48 private final Box2DTest[] tests = {new DebugRendererTest(), new CollisionFiltering(), new Chain(), new Bridge(), 49 new SphereStack(), new Cantilever(), new ApplyForce(), new ContinuousTest(), new Prismatic(), new CharacterCollision(), 50 new BodyTypes(), new SimpleTest(), new Pyramid(), new OneSidedPlatform(), new VerticalStack(), new VaryingRestitution(), 51 new ConveyorBelt()}; 52 53 private int testIndex = 0; 54 55 private Application app = null; 56 57 @Override 58 public void render () { 59 tests[testIndex].render(); 60 } 61 62 @Override 63 public void create () { 64 if (this.app == null) { 65 this.app = Gdx.app; 66 Box2DTest test = tests[testIndex]; 67 test.create(); 68 } 69 70 InputMultiplexer multiplexer = new InputMultiplexer(); 71 multiplexer.addProcessor(this); 72 multiplexer.addProcessor(new GestureDetector(this)); 73 Gdx.input.setInputProcessor(multiplexer); 74 } 75 76 @Override 77 public void dispose () { 78 tests[testIndex].dispose(); 79 } 80 81 @Override 82 public boolean keyDown (int keycode) { 83 tests[testIndex].keyDown(keycode); 84 85 return false; 86 } 87 88 @Override 89 public boolean keyTyped (char character) { 90 tests[testIndex].keyTyped(character); 91 return false; 92 } 93 94 @Override 95 public boolean keyUp (int keycode) { 96 tests[testIndex].keyUp(keycode); 97 return false; 98 } 99 100 @Override 101 public boolean touchDown (int x, int y, int pointer, int button) { 102 tests[testIndex].touchDown(x, y, pointer, button); 103 return false; 104 } 105 106 @Override 107 public boolean touchDragged (int x, int y, int pointer) { 108 tests[testIndex].touchDragged(x, y, pointer); 109 return false; 110 } 111 112 @Override 113 public boolean touchUp (int x, int y, int pointer, int button) { 114 tests[testIndex].touchUp(x, y, pointer, button); 115 return false; 116 } 117 118 @Override 119 public boolean mouseMoved (int x, int y) { 120 return false; 121 } 122 123 @Override 124 public boolean scrolled (int amount) { 125 return false; 126 } 127 128 @Override 129 public boolean touchDown (float x, float y, int pointer, int button) { 130 return false; 131 } 132 133 @Override 134 public boolean tap (float x, float y, int count, int button) { 135 app.log("TestCollection", "disposing test '" + tests[testIndex].getClass().getName()); 136 tests[testIndex].dispose(); 137 testIndex++; 138 if (testIndex >= tests.length) testIndex = 0; 139 Box2DTest test = tests[testIndex]; 140 test.create(); 141 app.log("TestCollection", "created test '" + tests[testIndex].getClass().getName()); 142 return false; 143 } 144 145 @Override 146 public boolean longPress (float x, float y) { 147 return false; 148 } 149 150 @Override 151 public boolean fling (float velocityX, float velocityY, int button) { 152 return false; 153 } 154 155 @Override 156 public boolean pan (float x, float y, float deltaX, float deltaY) { 157 return false; 158 } 159 160 @Override 161 public boolean panStop (float x, float y, int pointer, int button) { 162 return false; 163 } 164 165 @Override 166 public boolean zoom (float originalDistance, float currentDistance) { 167 return false; 168 } 169 170 @Override 171 public boolean pinch (Vector2 initialFirstPointer, Vector2 initialSecondPointer, Vector2 firstPointer, Vector2 secondPointer) { 172 return false; 173 } 174 175 @Override 176 public void pinchStop () { 177 } 178 } 179