Search in sources :

Example 6 with Skin

use of com.badlogic.gdx.scenes.scene2d.ui.Skin in project libgdx by libgdx.

the class TextAreaTest2 method create.

@Override
public void create() {
    stage = new Stage();
    Gdx.input.setInputProcessor(stage);
    skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    //Create a string that perfectly fills the float array used in the textarea float array
    FloatArray dummyArray = new FloatArray();
    String limit = "";
    // Minus one, because TextField adds a magic char
    for (int i = 0; i < dummyArray.items.length - 1; i++) {
        limit += "a";
    }
    TextArea textArea = new TextArea(limit, skin);
    textArea.setX(10);
    textArea.setY(10);
    textArea.setWidth(200);
    textArea.setHeight(200);
    stage.addActor(textArea);
}
Also used : FloatArray(com.badlogic.gdx.utils.FloatArray) TextArea(com.badlogic.gdx.scenes.scene2d.ui.TextArea) Stage(com.badlogic.gdx.scenes.scene2d.Stage) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin)

Example 7 with Skin

use of com.badlogic.gdx.scenes.scene2d.ui.Skin in project libgdx by libgdx.

the class TextButtonTest method create.

@Override
public void create() {
    stage = new Stage();
    Gdx.input.setInputProcessor(stage);
    skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    for (int i = 0; i < 1; i++) {
        TextButton t = new TextButton("Button" + i, skin);
        t.setX(MathUtils.random(0, Gdx.graphics.getWidth()));
        t.setY(MathUtils.random(0, Gdx.graphics.getHeight()));
        t.setWidth(MathUtils.random(50, 200));
        t.setHeight(MathUtils.random(0, 100));
        stage.addActor(t);
    }
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Stage(com.badlogic.gdx.scenes.scene2d.Stage) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin)

Example 8 with Skin

use of com.badlogic.gdx.scenes.scene2d.ui.Skin in project libgdx by libgdx.

the class TouchpadTest method create.

public void create() {
    stage = new Stage();
    Gdx.input.setInputProcessor(stage);
    Skin skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    touchpad = new Touchpad(20, skin);
    touchpad.setBounds(15, 15, 100, 100);
    stage.addActor(touchpad);
}
Also used : Touchpad(com.badlogic.gdx.scenes.scene2d.ui.Touchpad) Stage(com.badlogic.gdx.scenes.scene2d.Stage) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin)

Example 9 with Skin

use of com.badlogic.gdx.scenes.scene2d.ui.Skin in project libgdx by libgdx.

the class ImageTest method create.

@Override
public void create() {
    skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    image2 = new TextureRegion(new Texture(Gdx.files.internal("data/badlogic.jpg")));
    ui = new Stage();
    Gdx.input.setInputProcessor(ui);
    root = new Table();
    root.setSize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    ui.addActor(root);
    root.debug();
    Image image = new Image(image2);
    image.setScaling(Scaling.fill);
    root.add(image).width(image2.getRegionWidth()).height(image2.getRegionHeight());
}
Also used : TextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) Stage(com.badlogic.gdx.scenes.scene2d.Stage) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin) Image(com.badlogic.gdx.scenes.scene2d.ui.Image) Texture(com.badlogic.gdx.graphics.Texture)

Example 10 with Skin

use of com.badlogic.gdx.scenes.scene2d.ui.Skin in project libgdx by libgdx.

the class InterpolationTest method create.

@Override
public void create() {
    Gdx.gl.glClearColor(.3f, .3f, .3f, 1);
    renderer = new ShapeRenderer();
    skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    stage = new Stage(new ScreenViewport());
    resetPositions();
    Field[] interpolationFields = ClassReflection.getFields(Interpolation.class);
    // see how many fields are actually interpolations (for safety; other fields may be added with future)
    int interpolationMembers = 0;
    for (int i = 0; i < interpolationFields.length; i++) if (ClassReflection.isAssignableFrom(Interpolation.class, interpolationFields[i].getDeclaringClass()))
        interpolationMembers++;
    // get interpolation names
    interpolationNames = new String[interpolationMembers];
    for (int i = 0; i < interpolationFields.length; i++) if (ClassReflection.isAssignableFrom(Interpolation.class, interpolationFields[i].getDeclaringClass()))
        interpolationNames[i] = interpolationFields[i].getName();
    selectedInterpolation = interpolationNames[0];
    list = new List(skin);
    list.setItems(interpolationNames);
    list.addListener(new ChangeListener() {

        public void changed(ChangeEvent event, Actor actor) {
            selectedInterpolation = list.getSelected();
            time = 0;
            resetPositions();
        }
    });
    ScrollPane scroll = new ScrollPane(list, skin);
    scroll.setFadeScrollBars(false);
    scroll.setScrollingDisabled(true, false);
    table = new Table();
    table.setFillParent(true);
    table.add(scroll).expandX().left().width(100);
    stage.addActor(table);
    Gdx.input.setInputProcessor(new InputMultiplexer(new InputAdapter() {

        public boolean scrolled(int amount) {
            if (!Gdx.input.isKeyPressed(Keys.CONTROL_LEFT))
                return false;
            duration -= amount / 15f;
            duration = MathUtils.clamp(duration, 0, Float.POSITIVE_INFINITY);
            return true;
        }
    }, stage, new InputAdapter() {

        public boolean touchDown(int screenX, int screenY, int pointer, int button) {
            if (// if "walking" was interrupted by this touch down event
            !Float.isNaN(time))
                // set startPosition to the current position
                startPosition.set(getPosition(time));
            targetPosition.set(stage.screenToStageCoordinates(targetPosition.set(screenX, screenY)));
            time = 0;
            return true;
        }
    }));
}
Also used : Table(com.badlogic.gdx.scenes.scene2d.ui.Table) InputAdapter(com.badlogic.gdx.InputAdapter) ScreenViewport(com.badlogic.gdx.utils.viewport.ScreenViewport) ShapeRenderer(com.badlogic.gdx.graphics.glutils.ShapeRenderer) Field(com.badlogic.gdx.utils.reflect.Field) Interpolation(com.badlogic.gdx.math.Interpolation) InputMultiplexer(com.badlogic.gdx.InputMultiplexer) ScrollPane(com.badlogic.gdx.scenes.scene2d.ui.ScrollPane) Actor(com.badlogic.gdx.scenes.scene2d.Actor) Stage(com.badlogic.gdx.scenes.scene2d.Stage) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin) List(com.badlogic.gdx.scenes.scene2d.ui.List) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)

Aggregations

Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)41 Stage (com.badlogic.gdx.scenes.scene2d.Stage)36 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)27 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)20 TextButton (com.badlogic.gdx.scenes.scene2d.ui.TextButton)17 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)13 Texture (com.badlogic.gdx.graphics.Texture)11 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)10 Actor (com.badlogic.gdx.scenes.scene2d.Actor)10 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)9 ScrollPane (com.badlogic.gdx.scenes.scene2d.ui.ScrollPane)9 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)9 ClickListener (com.badlogic.gdx.scenes.scene2d.utils.ClickListener)9 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)8 ScreenViewport (com.badlogic.gdx.utils.viewport.ScreenViewport)8 CheckBox (com.badlogic.gdx.scenes.scene2d.ui.CheckBox)6 Image (com.badlogic.gdx.scenes.scene2d.ui.Image)6 TextureAtlas (com.badlogic.gdx.graphics.g2d.TextureAtlas)4 InputListener (com.badlogic.gdx.scenes.scene2d.InputListener)4 List (com.badlogic.gdx.scenes.scene2d.ui.List)4