Example usage for com.badlogic.gdx InputMultiplexer addProcessor

List of usage examples for com.badlogic.gdx InputMultiplexer addProcessor

Introduction

In this page you can find the example usage for com.badlogic.gdx InputMultiplexer addProcessor.

Prototype

public void addProcessor(InputProcessor processor) 

Source Link

Usage

From source file:org.oscim.gdx.GdxMap.java

License:Open Source License

@Override
public void create() {
    mMap = new MapAdapter();
    mMapRenderer = new MapRenderer(mMap);

    Gdx.graphics.setContinuousRendering(false);
    Gdx.app.setLogLevel(Application.LOG_DEBUG);

    int w = Gdx.graphics.getWidth();
    int h = Gdx.graphics.getHeight();

    mMap.viewport().setScreenSize(w, h);
    mMapRenderer.onSurfaceCreated();//w ww . j  a v a 2 s.c o  m
    mMapRenderer.onSurfaceChanged(w, h);

    InputMultiplexer mux = new InputMultiplexer();
    mux.addProcessor(new InputHandler(this));
    //mux.addProcessor(new GestureDetector(20, 0.5f, 2, 0.05f,
    //                                     new MapController(mMap)));
    mux.addProcessor(new MotionHandler(mMap));

    Gdx.input.setInputProcessor(mux);

    createLayers();
}

From source file:org.oscim.theme.comparator.vtm.MapApplicationAdapter.java

License:Open Source License

@Override
public void create() {
    map = new MapAdapter() {

        @Override//from w  w  w  .  j a  v a 2  s . co m
        public void beginFrame() {
            super.beginFrame();
        }

        @Override
        public void onMapEvent(Event e, final MapPosition mapPosition) {
            super.onMapEvent(e, mapPosition);
            if (e == Map.MOVE_EVENT || e == Map.SCALE_EVENT) {
                bothMapPositionHandler.mapPositionChangedFromVtmMap(mapPosition);
            }
        }
    };
    mapRenderer = new MapRenderer(map);
    Gdx.graphics.setContinuousRendering(true);
    Gdx.app.setLogLevel(Application.LOG_DEBUG);

    int w = Gdx.graphics.getWidth();
    int h = Gdx.graphics.getHeight();

    map.viewport().setViewSize(w, h);
    mapRenderer.onSurfaceCreated();
    mapRenderer.onSurfaceChanged(w, h);

    InputMultiplexer mux = new InputMultiplexer();
    mux.addProcessor(new MotionHandler(map) {
        @Override
        public boolean scrolled(int amount) {
            super.scrolled(amount);
            MapPosition mapPosition = map.getMapPosition();
            int zoomLevel = mapPosition.getZoomLevel() - amount;
            mapPosition.setZoomLevel(zoomLevel);
            map.setMapPosition(mapPosition);
            bothMapPositionHandler.mapPositionChangedFromVtmMap(mapPosition);
            return true;
        }
    });
    mux.addProcessor(new GestureDetector(new GestureHandlerImpl(map)));

    Gdx.input.setInputProcessor(mux);

    mapScaleBar = new DefaultMapScaleBar(map);
    mapScaleBar.setScaleBarMode(DefaultMapScaleBar.ScaleBarMode.BOTH);
    mapScaleBar.setDistanceUnitAdapter(MetricUnitAdapter.INSTANCE);
    mapScaleBar.setSecondaryDistanceUnitAdapter(ImperialUnitAdapter.INSTANCE);
    mapScaleBarLayer = new MapScaleBarLayer(map, mapScaleBar);
    mapScaleBarLayer.getRenderer().setPosition(GLViewport.Position.BOTTOM_LEFT);

    centerCrossLayer = new CenterCrossLayer(map);
}

From source file:org.saltosion.pixelprophecy.Prophecy.java

License:Open Source License

@Override
public void create() {
    // Initialize InputMultiplexer
    InputMultiplexer multiplexer = new InputMultiplexer();
    Gdx.input.setInputProcessor(multiplexer);

    // Initialize GUIManager
    guiManager = new GUIManager();
    multiplexer.addProcessor(new GUIInputAdapter(guiManager));

    //Initialize StateManager
    MapLoader mapLoader = new MapLoader();
    stateManager = new StateManager();
    stateManager.addState(Names.GAME_STATE, new GameState(multiplexer, guiManager, mapLoader));
    stateManager.addState(Names.LOADING_STATE, new LoadingState(guiManager, mapLoader));
    stateManager.addState(Names.MAINMENU_STATE, new MainMenuState(guiManager));
    stateManager.setState(Names.LOADING_STATE);
}

From source file:pl.kotcrab.gdxcombat.GdxCombat.java

License:Apache License

public void changeScene(AbstractScene scene) {
    if (activeScene != null)
        activeScene.dispose();//from  ww  w.  j  ava2s .  c o m

    activeScene = scene;

    InputMultiplexer multiplexer = new InputMultiplexer();
    multiplexer.addProcessor(new GestureDetector(activeScene));
    multiplexer.addProcessor(activeScene);

    Gdx.input.setInputProcessor(multiplexer);
}

From source file:pl.kotcrab.jdialogue.editor.Renderer.java

License:Open Source License

@Override
public void create() {
    Assets.load();/*from w ww.ja  v  a 2s. c  om*/

    prefs = Gdx.app.getPreferences("pl.kotcrab.dialoguelib.editorprefs");
    App.setPrefs(prefs);
    App.loadPrefs();

    camera = new OrthographicCamera(1280, 720);
    camera.position.x = 1280 / 2;
    camera.position.y = 720 / 2;
    Touch.setCamera(camera);
    cameraRect = CameraUtils.calcCameraBoundingRectangle(camera);

    shapeRenderer = new ShapeRenderer();
    batch = new SpriteBatch();

    rectangularSelection = new RectangularSelection(new RectangularSelectionListener() {
        @Override
        public void finishedDrawing(ArrayList<DComponent> matchingComponents) {
            selectedComponentsList = matchingComponents;
        }
    }, componentList);

    InputMultiplexer mul = new InputMultiplexer();
    mul.addProcessor(this);
    mul.addProcessor(new GestureDetector(this));
    mul.addProcessor(rectangularSelection);
    Gdx.input.setInputProcessor(mul);

    connectionRenderer = new ConnectionRenderer();

    infoText = new KotcrabText(Assets.consolasFont, "Load or create new project to begin!", false, 0, 0);
    infoText.setScale(1.4f);

}

From source file:pl.kotcrab.libgdx.util.RectangleDrawer.java

License:Apache License

public void attachInputProcessor() {
    if (Gdx.input.getInputProcessor() == null) {
        Gdx.input.setInputProcessor(this);
        return;//www  .j ava 2  s  .  c  om
    }

    if (Gdx.input.getInputProcessor() instanceof InputMultiplexer) {
        InputMultiplexer mul = (InputMultiplexer) Gdx.input.getInputProcessor();
        mul.addProcessor(this);
        Gdx.input.setInputProcessor(mul);
    } else {
        InputMultiplexer mul = new InputMultiplexer();
        mul.addProcessor(Gdx.input.getInputProcessor());
        mul.addProcessor(this);
        Gdx.input.setInputProcessor(mul);
    }
}

From source file:presentation.abstraction.AStage.java

License:Open Source License

/**
 * Initialized a stage./*from  w  w w.  ja v a 2 s . c om*/
 */
protected void initStage() {
    stage = new Stage();
    InputMultiplexer input = InputGame.getInputMultiplexer();
    input.clear();
    input.addProcessor(stage);
    this.resize(WIDTH, HEIGHT);
    // Panel.
    Table root = new Table();
    root.setFillParent(true);
    this.stage.addActor(root);
    // Put image of background of this screen.
    Drawable image = new TextureRegionDrawable(ResourcesMenus.mainMenuBackground);
    root.setBackground(image);
}

From source file:rx.libgdx.sources.GdxInputEventSource.java

License:Apache License

/**
 * @see rx.GdxObservable#fromInput//  ww w . ja  v  a  2s  .  c om
 */
public static Observable<InputEvent> fromInput() {
    return create(new Observable.OnSubscribe<InputEvent>() {

        @Override
        public void call(final Subscriber<? super InputEvent> subscriber) {
            final InputProcessor processor = new InputProcessor() {

                @Override
                public boolean touchUp(int screenX, int screenY, int pointer, int button) {
                    if (!subscriber.isUnsubscribed()) {
                        subscriber.onNext(new TouchUpEvent(screenX, screenY, pointer, button));
                        return true;
                    }
                    return false;
                }

                @Override
                public boolean touchDown(int screenX, int screenY, int pointer, int button) {
                    if (!subscriber.isUnsubscribed()) {
                        subscriber.onNext(new TouchDownEvent(screenX, screenY, pointer, button));
                        return true;
                    }
                    return false;
                }

                @Override
                public boolean touchDragged(int screenX, int screenY, int pointer) {
                    if (!subscriber.isUnsubscribed()) {
                        subscriber.onNext(new TouchDraggedEvent(screenX, screenY, pointer));
                        return true;
                    }
                    return false;
                }

                @Override
                public boolean keyDown(int keycode) {
                    if (!subscriber.isUnsubscribed()) {
                        subscriber.onNext(new KeyDownEvent(keycode));
                        return true;
                    }
                    return false;
                }

                @Override
                public boolean keyUp(int keycode) {
                    if (!subscriber.isUnsubscribed()) {
                        subscriber.onNext(new KeyUpEvent(keycode));
                        return true;
                    }
                    return false;
                }

                @Override
                public boolean keyTyped(char character) {
                    if (!subscriber.isUnsubscribed()) {
                        subscriber.onNext(new KeyTypedEvent(character));
                        return true;
                    }
                    return false;
                }

                @Override
                public boolean mouseMoved(int screenX, int screenY) {
                    if (!subscriber.isUnsubscribed()) {
                        subscriber.onNext(new MouseMovedEvent(screenX, screenY));
                        return true;
                    }
                    return false;
                }

                @Override
                public boolean scrolled(int amount) {
                    if (!subscriber.isUnsubscribed()) {
                        subscriber.onNext(new ScrolledEvent(amount));
                        return true;
                    }
                    return false;
                }

            };

            final InputProcessor wrapped = Gdx.input.getInputProcessor();
            final InputMultiplexer im;
            if (wrapped instanceof InputMultiplexer) {
                im = (InputMultiplexer) wrapped;
            } else if (wrapped != null) {
                im = new InputMultiplexer(wrapped);
            } else {
                im = new InputMultiplexer();
            }

            im.addProcessor(processor);

            subscriber.add(Subscriptions.create(new Action0() {

                @Override
                public void call() {
                    im.removeProcessor(processor);
                    if (wrapped != null && wrapped != im && im.size() == 1) {
                        Gdx.input.setInputProcessor(wrapped);
                    }
                }

            }));

            Gdx.input.setInputProcessor(im);
        }

    });
}

From source file:scene3d.demo.Scene3dDemo.java

License:Apache License

@Override
public void create() {
    //2d stuff/*from   w  w  w  . j a  v  a 2  s.  c  om*/
    stage2d = new Stage();
    skin = new Skin(Gdx.files.internal("skin/uiskin.json"));
    fpsLabel = new Label("ff", skin);
    fpsLabel.setPosition(Gdx.graphics.getWidth() - 260, Gdx.graphics.getHeight() - 40);
    visibleLabel = new Label("ff", skin);
    visibleLabel.setPosition(Gdx.graphics.getWidth() - 260, Gdx.graphics.getHeight() - 60);
    positionLabel = new Label("Position", skin);
    positionLabel.setPosition(Gdx.graphics.getWidth() - 260, Gdx.graphics.getHeight() - 80);
    rotationLabel = new Label("Rotation", skin);
    rotationLabel.setPosition(Gdx.graphics.getWidth() - 260, Gdx.graphics.getHeight() - 100);
    positionCameraLabel = new Label("Position", skin);
    positionCameraLabel.setPosition(20, Gdx.graphics.getHeight() - 40);
    rotationCameraLabel = new Label("Rotation", skin);
    rotationCameraLabel.setPosition(20, Gdx.graphics.getHeight() - 60);
    stage2d.addActor(fpsLabel);
    stage2d.addActor(visibleLabel);
    stage2d.addActor(positionLabel);
    stage2d.addActor(rotationLabel);
    stage2d.addActor(positionCameraLabel);
    stage2d.addActor(rotationCameraLabel);
    stage2d.addListener(new InputListener() {
        @Override
        public boolean keyUp(InputEvent event, int keycode) {
            if (keycode == Keys.LEFT)
                leftKey = false;
            if (keycode == Keys.RIGHT)
                rightKey = false;
            if (keycode == Keys.UP)
                upKey = false;
            if (keycode == Keys.DOWN)
                downKey = false;
            if (keycode == Keys.SPACE)
                spaceKey = false;
            return super.keyUp(event, keycode);
        }

        @Override
        public boolean keyDown(InputEvent event, int keycode) {
            if (keycode == Keys.LEFT)
                leftKey = true;
            if (keycode == Keys.RIGHT)
                rightKey = true;
            if (keycode == Keys.UP)
                upKey = true;
            if (keycode == Keys.DOWN)
                downKey = true;
            if (keycode == Keys.SPACE)
                spaceKey = true;
            return super.keyDown(event, keycode);
        }
    });

    //3dstuff
    stage3d = new Stage3d();
    modelBuilder = new ModelBuilder();
    model = modelBuilder.createBox(5f, 5f, 5f, new Material("Color", ColorAttribute.createDiffuse(Color.WHITE)),
            Usage.Position | Usage.Normal);

    model2 = modelBuilder.createBox(2f, 2f, 2f,
            new Material("Color", ColorAttribute.createDiffuse(Color.WHITE)), Usage.Position | Usage.Normal);
    actor2 = new Actor3d(model2, 10f, 0f, 0f);
    model3 = modelBuilder.createBox(2f, 2f, 2f,
            new Material("Color", ColorAttribute.createDiffuse(Color.ORANGE)), Usage.Position | Usage.Normal);
    actor3 = new Actor3d(model3, -10f, 0f, 0f);
    actor2.setColor(Color.RED);
    actor2.setName("actor2");
    actor3.setName("actor3");
    camController = new CameraInputController(stage3d.getCamera());
    InputMultiplexer im = new InputMultiplexer();
    im.addProcessor(stage2d);// 2d should get click events first
    //im.addProcessor(stage3d);
    im.addProcessor(camController);
    Gdx.input.setInputProcessor(im);
    stage3d.touchable = Touchable.enabled; // only then will it detect hit actor3d

    ModelBuilder builder = new ModelBuilder();
    builder.begin();
    MeshPartBuilder part = builder.part("floor", GL20.GL_TRIANGLES,
            Usage.Position | Usage.TextureCoordinates | Usage.Normal, new Material());
    for (float x = -200f; x < 200f; x += 10f) {
        for (float z = -200f; z < 200f; z += 10f) {
            part.rect(x, 0, z + 10f, x + 10f, 0, z + 10f, x + 10f, 0, z, x, 0, z, 0, 1, 0);
        }
    }
    floor = new Actor3d(builder.end());
    AssetManager am = new AssetManager();
    am.load("data/g3d/knight.g3db", Model.class);
    am.load("data/g3d/skydome.g3db", Model.class);
    am.load("data/g3d/concrete.png", Texture.class);
    am.finishLoading();
    knight = new Actor3d(am.get("data/g3d/knight.g3db", Model.class), 0f, 18f, 0f);
    knight.getAnimation().inAction = true;
    knight.getAnimation().animate("Walk", -1, 1f, null, 0.2f);
    skydome = new Actor3d(am.get("data/g3d/skydome.g3db", Model.class));
    floor.materials.get(0).set(TextureAttribute.createDiffuse(am.get("data/g3d/concrete.png", Texture.class)));
    stage3d.addActor3d(skydome);
    stage3d.addActor3d(floor);
    knight.setPitch(-90f);
    knight.setYaw(-130f);
    testActor3d();
    //stage3d.addAction3d(Actions3d.rotateBy(0f, 90f, 0f, 2f));
    //testGroup3d();
    //testStage3d();
}

From source file:se.danielj.geometridestroyer.Credits.java

License:GNU General Public License

public Credits(final Core core, InputMultiplexer inputMultiplexer) {
    this.core = core;
    stage = new Stage();
    stage.setViewport(Constants.STAGE_WIDTH, Constants.STAGE_HEIGHT, false);

    inputMultiplexer.addProcessor(this);

    Image ogam = new Image(new TextureRegionDrawable(SpriteManager.getSprite(SpriteManager.Sprites.OGAM)));
    ogam.setPosition((Constants.STAGE_WIDTH - ogam.getWidth()) / 2, 440);
    stage.addActor(ogam);//from  ww  w  .j av a 2 s .co  m

    LabelStyle style = new LabelStyle();
    style.font = FontManager.getNormalFont();
    style.fontColor = new Color(1, 1, 1, 1);
    Label title = new Label(
            "     Geometri Destroyer was created during\n      February 2013 for One Game A Month.\n\n\n\nProgramming, graphics: Daniel \"MaTachi\" Jonsson,\n                       http://danielj.se\nLibraries: LibGDX and Box2D\nFont: GNUTypewriter, SIL OFL\nMusic: Szymon Matuszewski - Fallen, CC-BY 3.0\nSoftware used: Eclipse, GIMP and\n               Inkscape on Ubuntu",
            style);
    title.setPosition(50, 10);
    stage.addActor(title);
}