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.SpriteBatch; 22 import com.badlogic.gdx.scenes.scene2d.Stage; 23 import com.badlogic.gdx.scenes.scene2d.ui.Skin; 24 import com.badlogic.gdx.scenes.scene2d.ui.TextArea; 25 import com.badlogic.gdx.scenes.scene2d.ui.TextField; 26 import com.badlogic.gdx.tests.utils.GdxTest; 27 28 public class TextAreaTest extends GdxTest { 29 private Stage stage; 30 private Skin skin; 31 32 @Override create()33 public void create () { 34 stage = new Stage(); 35 Gdx.input.setInputProcessor(stage); 36 skin = new Skin(Gdx.files.internal("data/uiskin.json")); 37 TextArea textArea = new TextArea( 38 "Text Area\nEssentially, a text field\nwith\nmultiple\nlines.\n" 39 + "It can even handle very loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong lines.", 40 skin); 41 textArea.setX(10); 42 textArea.setY(10); 43 textArea.setWidth(200); 44 textArea.setHeight(200); 45 46 TextField textField = new TextField("Text field", skin); 47 textField.setX(10); 48 textField.setY(220); 49 textField.setWidth(200); 50 textField.setHeight(30); 51 stage.addActor(textArea); 52 stage.addActor(textField); 53 } 54 55 @Override render()56 public void render () { 57 Gdx.gl.glClearColor(0.2f, 0.2f, 0.2f, 1); 58 Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); 59 stage.draw(); 60 Gdx.app.log("X", "FPS: " + Gdx.graphics.getFramesPerSecond()); 61 SpriteBatch spriteBatch = (SpriteBatch)stage.getBatch(); 62 Gdx.app.log("X", "render calls: " + spriteBatch.totalRenderCalls); 63 spriteBatch.totalRenderCalls = 0; 64 } 65 66 @Override resize(int width, int height)67 public void resize (int width, int height) { 68 stage.getViewport().update(width, height, true); 69 } 70 71 @Override dispose()72 public void dispose () { 73 stage.dispose(); 74 skin.dispose(); 75 } 76 } 77