Search in sources :

Example 1 with InputMultiplexer

use of com.badlogic.gdx.InputMultiplexer in project libgdx-inGameConsole by StrongJoshua.

the class GUIConsole method resetInputProcessing.

/* (non-Javadoc)
	 * @see com.strongjoshua.console.Console#resetInputProcessing()
	 */
@Override
public void resetInputProcessing() {
    usesMultiplexer = true;
    appInput = Gdx.input.getInputProcessor();
    if (appInput != null) {
        if (hasStage(appInput)) {
            log("Console already added to input processor!", LogLevel.ERROR);
            Gdx.app.log("Console", "Already added to input processor!");
            return;
        }
        multiplexer = new InputMultiplexer();
        multiplexer.addProcessor(stage);
        multiplexer.addProcessor(appInput);
        Gdx.input.setInputProcessor(multiplexer);
    } else {
        Gdx.input.setInputProcessor(stage);
    }
}
Also used : InputMultiplexer(com.badlogic.gdx.InputMultiplexer)

Example 2 with InputMultiplexer

use of com.badlogic.gdx.InputMultiplexer in project libgdx-inGameConsole by StrongJoshua.

the class GUIConsole method hasStage.

/** Compares the given processor to the console's stage. If given a multiplexer, it is iterated through recursively to check all
	 * of the multiplexer's processors for comparison.
	 * @param processor
	 * @return processor == this.stage */
private boolean hasStage(InputProcessor processor) {
    if (!(processor instanceof InputMultiplexer)) {
        return processor == stage;
    }
    InputMultiplexer im = (InputMultiplexer) processor;
    Array<InputProcessor> ips = im.getProcessors();
    for (InputProcessor ip : ips) {
        if (hasStage(ip)) {
            return true;
        }
    }
    return false;
}
Also used : InputMultiplexer(com.badlogic.gdx.InputMultiplexer) InputProcessor(com.badlogic.gdx.InputProcessor)

Example 3 with InputMultiplexer

use of com.badlogic.gdx.InputMultiplexer in project libgdx by libgdx.

the class BulletTestCollection method create.

@Override
public void create() {
    if (app == null) {
        app = Gdx.app;
        tests[testIndex].create();
    }
    cameraController = new CameraInputController(tests[testIndex].camera);
    cameraController.activateKey = Keys.CONTROL_LEFT;
    cameraController.autoUpdate = false;
    cameraController.forwardTarget = false;
    cameraController.translateTarget = false;
    Gdx.input.setInputProcessor(new InputMultiplexer(cameraController, this, new GestureDetector(this)));
    font = new BitmapFont(Gdx.files.internal("data/arial-15.fnt"), false);
    hud = new Stage();
    hud.addActor(fpsLabel = new Label(" ", new Label.LabelStyle(font, Color.WHITE)));
    fpsLabel.setPosition(0, 0);
    hud.addActor(titleLabel = new Label(tests[testIndex].getClass().getSimpleName(), new Label.LabelStyle(font, Color.WHITE)));
    titleLabel.setY(hud.getHeight() - titleLabel.getHeight());
    hud.addActor(instructLabel = new Label("A\nB\nC\nD\nE\nF", new Label.LabelStyle(font, Color.WHITE)));
    instructLabel.setY(titleLabel.getY() - instructLabel.getHeight());
    instructLabel.setAlignment(Align.top | Align.left);
    instructLabel.setText(tests[testIndex].instructions);
}
Also used : CameraInputController(com.badlogic.gdx.graphics.g3d.utils.CameraInputController) InputMultiplexer(com.badlogic.gdx.InputMultiplexer) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) Stage(com.badlogic.gdx.scenes.scene2d.Stage) GestureDetector(com.badlogic.gdx.input.GestureDetector) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont)

Example 4 with InputMultiplexer

use of com.badlogic.gdx.InputMultiplexer in project libgdx by libgdx.

the class ViewportTest1 method create.

public void create() {
    stage = new Stage();
    Skin skin = new Skin(Gdx.files.internal("data/uiskin.json"));
    label = new Label("", skin);
    Table root = new Table(skin);
    root.setFillParent(true);
    root.setBackground(skin.getDrawable("default-pane"));
    root.debug().defaults().space(6);
    root.add(new TextButton("Button 1", skin));
    root.add(new TextButton("Button 2", skin)).row();
    root.add("Press spacebar to change the viewport:").colspan(2).row();
    root.add(label).colspan(2);
    stage.addActor(root);
    viewports = getViewports(stage.getCamera());
    names = getViewportNames();
    stage.setViewport(viewports.first());
    label.setText(names.first());
    Gdx.input.setInputProcessor(new InputMultiplexer(new InputAdapter() {

        public boolean keyDown(int keycode) {
            if (keycode == Input.Keys.SPACE) {
                int index = (viewports.indexOf(stage.getViewport(), true) + 1) % viewports.size;
                label.setText(names.get(index));
                Viewport viewport = viewports.get(index);
                stage.setViewport(viewport);
                resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
            }
            return false;
        }
    }, stage));
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) InputMultiplexer(com.badlogic.gdx.InputMultiplexer) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) InputAdapter(com.badlogic.gdx.InputAdapter) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) StretchViewport(com.badlogic.gdx.utils.viewport.StretchViewport) ExtendViewport(com.badlogic.gdx.utils.viewport.ExtendViewport) ScalingViewport(com.badlogic.gdx.utils.viewport.ScalingViewport) FitViewport(com.badlogic.gdx.utils.viewport.FitViewport) Viewport(com.badlogic.gdx.utils.viewport.Viewport) FillViewport(com.badlogic.gdx.utils.viewport.FillViewport) ScreenViewport(com.badlogic.gdx.utils.viewport.ScreenViewport) Stage(com.badlogic.gdx.scenes.scene2d.Stage) Skin(com.badlogic.gdx.scenes.scene2d.ui.Skin)

Example 5 with InputMultiplexer

use of com.badlogic.gdx.InputMultiplexer in project libgdx by libgdx.

the class TextureRegion3DTest method create.

@Override
public void create() {
    Gdx.gl.glClearColor(0.2f, 0.3f, 1.0f, 0.f);
    atlas = new TextureAtlas(Gdx.files.internal("data/testpack"));
    regions = atlas.getRegions();
    modelBatch = new ModelBatch(new DefaultShaderProvider());
    environment = new Environment();
    environment.set(new ColorAttribute(ColorAttribute.AmbientLight, .4f, .4f, .4f, 1f));
    environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -1f, -0.8f, -0.2f));
    cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    cam.position.set(10f, 10f, 10f);
    cam.lookAt(0, 0, 0);
    cam.near = 0.1f;
    cam.far = 300f;
    cam.update();
    ModelBuilder modelBuilder = new ModelBuilder();
    final Material material = new Material(ColorAttribute.createDiffuse(1f, 1f, 1f, 1f), new TextureAttribute(TextureAttribute.Diffuse));
    model = modelBuilder.createBox(5f, 5f, 5f, material, Usage.Position | Usage.Normal | Usage.TextureCoordinates);
    instance = new ModelInstance(model);
    attribute = instance.materials.get(0).get(TextureAttribute.class, TextureAttribute.Diffuse);
    Gdx.input.setInputProcessor(new InputMultiplexer(this, inputController = new CameraInputController(cam)));
}
Also used : DefaultShaderProvider(com.badlogic.gdx.graphics.g3d.utils.DefaultShaderProvider) Material(com.badlogic.gdx.graphics.g3d.Material) PerspectiveCamera(com.badlogic.gdx.graphics.PerspectiveCamera) ModelInstance(com.badlogic.gdx.graphics.g3d.ModelInstance) ModelBuilder(com.badlogic.gdx.graphics.g3d.utils.ModelBuilder) CameraInputController(com.badlogic.gdx.graphics.g3d.utils.CameraInputController) InputMultiplexer(com.badlogic.gdx.InputMultiplexer) TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas) DirectionalLight(com.badlogic.gdx.graphics.g3d.environment.DirectionalLight) ModelBatch(com.badlogic.gdx.graphics.g3d.ModelBatch) Environment(com.badlogic.gdx.graphics.g3d.Environment) ColorAttribute(com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute) TextureAttribute(com.badlogic.gdx.graphics.g3d.attributes.TextureAttribute)

Aggregations

InputMultiplexer (com.badlogic.gdx.InputMultiplexer)16 PerspectiveCamera (com.badlogic.gdx.graphics.PerspectiveCamera)6 Material (com.badlogic.gdx.graphics.g3d.Material)5 ModelInstance (com.badlogic.gdx.graphics.g3d.ModelInstance)5 CameraInputController (com.badlogic.gdx.graphics.g3d.utils.CameraInputController)5 ModelBuilder (com.badlogic.gdx.graphics.g3d.utils.ModelBuilder)5 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)4 Environment (com.badlogic.gdx.graphics.g3d.Environment)4 ModelBatch (com.badlogic.gdx.graphics.g3d.ModelBatch)4 ColorAttribute (com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute)4 DirectionalLight (com.badlogic.gdx.graphics.g3d.environment.DirectionalLight)4 InputAdapter (com.badlogic.gdx.InputAdapter)3 Texture (com.badlogic.gdx.graphics.Texture)3 DefaultShaderProvider (com.badlogic.gdx.graphics.g3d.utils.DefaultShaderProvider)3 ShaderProgram (com.badlogic.gdx.graphics.glutils.ShaderProgram)3 Stage (com.badlogic.gdx.scenes.scene2d.Stage)3 InputProcessor (com.badlogic.gdx.InputProcessor)2 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)2 GestureDetector (com.badlogic.gdx.input.GestureDetector)2 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)2