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.graphics.GL20; 21 import com.badlogic.gdx.graphics.g2d.Batch; 22 import com.badlogic.gdx.scenes.scene2d.Stage; 23 import com.badlogic.gdx.scenes.scene2d.ui.Label; 24 import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane; 25 import com.badlogic.gdx.scenes.scene2d.ui.Skin; 26 import com.badlogic.gdx.scenes.scene2d.ui.Table; 27 import com.badlogic.gdx.tests.utils.GdxTest; 28 29 public class GroupCullingTest extends GdxTest { 30 static private final int count = 100; 31 32 private Stage stage; 33 private Skin skin; 34 private Table root; 35 private Label drawnLabel; 36 int drawn; 37 create()38 public void create () { 39 stage = new Stage(); 40 Gdx.input.setInputProcessor(stage); 41 42 root = new Table(); 43 root.setFillParent(true); 44 stage.addActor(root); 45 46 skin = new Skin(Gdx.files.internal("data/uiskin.json")); 47 48 Table labels = new Table(); 49 root.add(new ScrollPane(labels, skin)).expand().fill(); 50 root.row(); 51 root.add(drawnLabel = new Label("", skin)); 52 53 for (int i = 0; i < count; i++) { 54 labels.add(new Label("Label: " + i, skin) { 55 public void draw (Batch batch, float parentAlpha) { 56 super.draw(batch, parentAlpha); 57 drawn++; 58 } 59 }); 60 labels.row(); 61 } 62 } 63 64 @Override dispose()65 public void dispose () { 66 stage.dispose(); 67 skin.dispose(); 68 } 69 resize(int width, int height)70 public void resize (int width, int height) { 71 stage.getViewport().update(width, height, true); 72 root.invalidate(); 73 } 74 render()75 public void render () { 76 Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); 77 drawn = 0; 78 stage.act(Gdx.graphics.getDeltaTime()); 79 stage.draw(); 80 drawnLabel.setText("Drawn: " + drawn + "/" + count); 81 drawnLabel.invalidateHierarchy(); 82 } 83 needsGL20()84 public boolean needsGL20 () { 85 return false; 86 } 87 } 88