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 static com.badlogic.gdx.scenes.scene2d.actions.Actions.*; 20 21 import com.badlogic.gdx.Gdx; 22 import com.badlogic.gdx.graphics.GL20; 23 import com.badlogic.gdx.graphics.Texture; 24 import com.badlogic.gdx.graphics.g2d.Batch; 25 import com.badlogic.gdx.graphics.g2d.TextureRegion; 26 import com.badlogic.gdx.scenes.scene2d.Actor; 27 import com.badlogic.gdx.scenes.scene2d.Group; 28 import com.badlogic.gdx.scenes.scene2d.Stage; 29 import com.badlogic.gdx.scenes.scene2d.ui.Skin; 30 import com.badlogic.gdx.scenes.scene2d.ui.Table; 31 import com.badlogic.gdx.scenes.scene2d.ui.TextButton; 32 import com.badlogic.gdx.tests.utils.GdxTest; 33 34 /** @author Daniel Holderbaum */ 35 public class StageDebugTest extends GdxTest { 36 static TextureRegion textureRegion; 37 38 private Stage stage; 39 private Stage stage1; 40 private Stage stage2; 41 42 class DebugActor extends Actor { 43 @Override draw(Batch batch, float parentAlpha)44 public void draw (Batch batch, float parentAlpha) { 45 batch.draw(textureRegion, getX(), getY(), getOriginX(), getOriginY(), getWidth(), getHeight(), getScaleX(), getScaleY(), 46 getRotation()); 47 } 48 } 49 50 @Override create()51 public void create () { 52 textureRegion = new TextureRegion(new Texture("data/badlogic.jpg")); 53 54 Gdx.input.setInputProcessor(this); 55 56 stage1 = new Stage(); 57 stage1.getCamera().position.set(100, 100, 0); 58 59 Group group = new Group(); 60 // group.setBounds(0, 0, 10, 10); 61 // group.setOrigin(25, 50); 62 group.setRotation(10); 63 group.setScale(1.2f); 64 stage1.addActor(group); 65 66 DebugActor actor = new DebugActor(); 67 actor.setBounds(300, 140, 50, 100); 68 actor.setOrigin(25, 50); 69 actor.setRotation(-45); 70 actor.setScale(2f); 71 actor.addAction(forever(rotateBy(360, 8f))); 72 group.addActor(actor); 73 74 group.debugAll(); 75 76 stage2 = new Stage(); 77 Skin skin = new Skin(Gdx.files.internal("data/uiskin.json")); 78 79 TextButton shortButton = new TextButton("Button short", skin); 80 shortButton.debug(); 81 82 TextButton longButton = new TextButton("Button loooooooooong", skin); 83 longButton.debug(); 84 85 Table root = new Table(skin); 86 root.setFillParent(true); 87 root.setBackground(skin.getDrawable("default-pane")); 88 root.defaults().space(6); 89 root.setTransform(true); 90 root.rotateBy(10); 91 root.setScale(1.3f, 1); 92 root.debug(); 93 stage2.addActor(root); 94 95 root.add(shortButton).pad(5); 96 root.add(longButton).row(); 97 root.add("Colspan").colspan(2).row(); 98 99 switchStage(); 100 } 101 102 @Override render()103 public void render () { 104 Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT); 105 stage.act(); 106 stage.draw(); 107 } 108 109 @Override touchDown(int screenX, int screenY, int pointer, int button)110 public boolean touchDown (int screenX, int screenY, int pointer, int button) { 111 switchStage(); 112 return false; 113 } 114 115 @Override resize(int width, int height)116 public void resize (int width, int height) { 117 stage1.getViewport().update(width, height, true); 118 stage2.getViewport().update(width, height, true); 119 } 120 switchStage()121 private void switchStage () { 122 if (stage != stage2) { 123 stage = stage2; 124 } else { 125 stage = stage1; 126 } 127 } 128 129 } 130