Example usage for com.badlogic.gdx.scenes.scene2d.utils SpriteDrawable getSprite

List of usage examples for com.badlogic.gdx.scenes.scene2d.utils SpriteDrawable getSprite

Introduction

In this page you can find the example usage for com.badlogic.gdx.scenes.scene2d.utils SpriteDrawable getSprite.

Prototype

public Sprite getSprite() 

Source Link

Usage

From source file:es.eucm.ead.engine.debugger.SimpleDebugger.java

License:Open Source License

public SimpleDebugger(Game game, GameLoader gameLoader) {
    this.setTouchable(Touchable.disabled);
    this.history = new Array<String>();
    final CommandInterpreter commandInterpreter = new CommandInterpreter(game, gameLoader);
    BitmapFont font = new BitmapFont(
            Gdx.files.internal("es/eucm/ead/engine/resources/binary/fonts/ubuntu-16-bold.fnt"), true);
    this.setX(0);
    this.setY(580);

    Pixmap p = new Pixmap(10, 10, Pixmap.Format.RGBA8888);
    p.setColor(Color.BLACK);/*from w ww  .ja  v  a  2  s .c o m*/
    p.fill();
    TextureRegionDrawable background = new TextureRegionDrawable(new TextureRegion(new Texture(p)));
    p.dispose();
    p = new Pixmap(2, 30, Pixmap.Format.RGBA8888);
    p.setColor(Color.WHITE);
    p.fill();
    TextureRegionDrawable cursor = new TextureRegionDrawable(new TextureRegion(new Texture(p)));
    p.dispose();

    Label.LabelStyle style = new Label.LabelStyle();
    SpriteDrawable backgroundSprite = new SpriteDrawable(new Sprite(background.getRegion()));
    backgroundSprite.getSprite().setColor(new Color(0, 0, 0, 0.5f));
    style.background = backgroundSprite;
    style.font = font;
    style.fontColor = Color.WHITE;
    result = new Label("", style);
    result.setWrap(true);
    int y = -100;

    result.setBounds(0, y, 800, -y);
    this.addActor(result);

    TextField.TextFieldStyle tfStyle = new TextField.TextFieldStyle();
    tfStyle.font = font;
    tfStyle.background = background;
    tfStyle.selection = cursor;
    tfStyle.fontColor = Color.WHITE;
    tfStyle.cursor = cursor;
    interpreter = new TextField("", tfStyle);
    interpreter.setBounds(10, 0, 800, 20);
    interpreter.getStyle().font = font;
    interpreter.addListener(new InputListener() {
        @Override
        public boolean keyDown(InputEvent event, int keycode) {
            switch (keycode) {
            case Input.Keys.ENTER:
                String command = interpreter.getText();
                if (history.size == 0 || !history.peek().equals(command)) {
                    history.add(command);
                }
                historyPointer = history.size;
                result.setText(commandInterpreter.interpret(command));
                interpreter.setText("");
                break;
            case Input.Keys.ESCAPE:
                setVisible(false);
                break;
            case Input.Keys.UP:
                previousCommand();
                break;
            case Input.Keys.DOWN:
                nextCommand();
                break;
            }
            return true;
        }
    });

    Button.ButtonStyle buttonStyle = new Button.ButtonStyle();
    Label label = new Label(">", style);
    buttonStyle.up = background;
    button = new Button(label, buttonStyle);
    button.setHeight(20);
    button.addListener(new InputListener() {
        @Override
        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            setVisible(true);
            return false;
        }
    });

    this.addActor(interpreter);
    setVisible(false);
    this.addActor(button);
    ((EAdEngine) Gdx.app.getApplicationListener()).getStage().addListener(new InputListener() {
        @Override
        public boolean keyDown(InputEvent event, int keycode) {
            switch (keycode) {
            case Input.Keys.F12:
                setVisible(true);
                break;
            }
            return false;
        }
    });
}