• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.Gdx;
20 import com.badlogic.gdx.Input.Peripheral;
21 import com.badlogic.gdx.graphics.Color;
22 import com.badlogic.gdx.graphics.GL20;
23 import com.badlogic.gdx.graphics.OrthographicCamera;
24 import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
25 import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;
26 import com.badlogic.gdx.tests.utils.GdxTest;
27 import com.badlogic.gdx.utils.TimeUtils;
28 
29 public class MultitouchTest extends GdxTest {
30 	ShapeRenderer renderer;
31 	OrthographicCamera camera;
32 	long startTime = TimeUtils.nanoTime();
33 
34 	Color[] colors = {Color.RED, Color.BLUE, Color.GREEN, Color.WHITE, Color.PINK, Color.ORANGE, Color.YELLOW, Color.MAGENTA,
35 		Color.CYAN, Color.LIGHT_GRAY, Color.GRAY, Color.DARK_GRAY};
36 
37 	@Override
render()38 	public void render () {
39 		Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
40 		camera.update();
41 		renderer.setProjectionMatrix(camera.combined);
42 		renderer.begin(ShapeType.Filled);
43 		int size = Math.max(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()) / 10;
44 		for (int i = 0; i < 10; i++) {
45 			if (Gdx.input.isTouched(i) == false) continue;
46 
47 			float x = Gdx.input.getX(i);
48 			float y = Gdx.graphics.getHeight() - Gdx.input.getY(i) - 1;
49 			Color color = colors[i % colors.length];
50 			renderer.setColor(color);
51 			renderer.triangle(x, y + size, x + size, y - size, x - size, y - size);
52 		}
53 		renderer.end();
54 	}
55 
56 	@Override
create()57 	public void create () {
58 		Gdx.app.log("Multitouch", "multitouch supported: " + Gdx.input.isPeripheralAvailable(Peripheral.MultitouchScreen));
59 		renderer = new ShapeRenderer();
60 		camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
61 		camera.position.set(Gdx.graphics.getWidth() / 2.0f, Gdx.graphics.getHeight() / 2.0f, 0);
62 		Gdx.input.setInputProcessor(this);
63 	}
64 
65 	@Override
dispose()66 	public void dispose () {
67 		renderer.dispose();
68 	}
69 }
70