Example usage for com.badlogic.gdx.scenes.scene2d.ui ScrollPane setScrollX

List of usage examples for com.badlogic.gdx.scenes.scene2d.ui ScrollPane setScrollX

Introduction

In this page you can find the example usage for com.badlogic.gdx.scenes.scene2d.ui ScrollPane setScrollX.

Prototype

public void setScrollX(float pixels) 

Source Link

Usage

From source file:com.ridiculousRPG.ui.ActorsOnStageService.java

License:Apache License

@Override
public boolean keyDown(int keycode) {
    // unfocus if actor is removed
    if (focusedActor != null && !ActorFocusUtil.isActorOnStage(focusedActor, getRoot())) {
        setKeyboardFocus(null);//  ww w .  j av  a 2  s.c  o m
        focusedActor = null;
        awaitingKeyUp = false;
    }
    // consume tab key down
    if (keycode == Keys.TAB) {
        if (Gdx.input.isKeyPressed(Keys.SHIFT_LEFT) || Gdx.input.isKeyPressed(Keys.SHIFT_RIGHT)) {
            return checkScroll(ActorFocusUtil.focusPrev(focusedActor, getRoot(), false, false, this)
                    || ActorFocusUtil.focusLastChild(getRoot(), this));
        }
        return checkScroll(ActorFocusUtil.focusNext(focusedActor, getRoot(), false, false, this)
                || ActorFocusUtil.focusFirstChild(getRoot(), this));
    }
    // alowed childs to consume key down
    boolean consumed = super.keyDown(keycode);
    if (!consumed && !awaitingKeyUp) {
        switch (keycode) {
        case Keys.SPACE:
            if (focusedActor != null)
                break;
            // else fall through
        case Keys.ENTER:
            return (awaitingKeyUp = actionKeyPressed(true));
        case Keys.ESCAPE:
            if (focusedActor != null) {
                setKeyboardFocus(null);
            }
            return false;
        case Keys.UP:
            if (!checkScroll(ActorFocusUtil.focusPrev(focusedActor, getRoot(), true, false, this))
                    && getScrollFocus() instanceof ScrollPane) {
                ScrollPane s = (ScrollPane) getScrollFocus();
                s.setScrollY(s.getScrollY() - SCROLL_PIXEL_AMOUNT);
            }
            return true;
        case Keys.DOWN:
            if (!checkScroll(ActorFocusUtil.focusNext(focusedActor, getRoot(), true, false, this))
                    && getScrollFocus() instanceof ScrollPane) {
                ScrollPane s = (ScrollPane) getScrollFocus();
                s.setScrollY(s.getScrollY() + SCROLL_PIXEL_AMOUNT);
            }
            return true;
        case Keys.LEFT:
            if (!checkScroll(ActorFocusUtil.focusPrev(focusedActor, getRoot(), false, true, this))
                    && getScrollFocus() instanceof ScrollPane) {
                ScrollPane s = (ScrollPane) getScrollFocus();
                s.setScrollX(s.getScrollX() - SCROLL_PIXEL_AMOUNT);
            }
            return true;
        case Keys.RIGHT:
            if (!checkScroll(ActorFocusUtil.focusNext(focusedActor, getRoot(), false, true, this))
                    && getScrollFocus() instanceof ScrollPane) {
                ScrollPane s = (ScrollPane) getScrollFocus();
                s.setScrollX(s.getScrollX() + SCROLL_PIXEL_AMOUNT);
            }
            return true;
        case Keys.PAGE_UP:
            if (getScrollFocus() instanceof ScrollPane) {
                ScrollPane s = (ScrollPane) getScrollFocus();
                s.setScrollY(s.getScrollY() - s.getHeight() * .7f);
            }
            return true;
        case Keys.PAGE_DOWN:
            if (getScrollFocus() instanceof ScrollPane) {
                ScrollPane s = (ScrollPane) getScrollFocus();
                s.setScrollY(s.getScrollY() + s.getHeight() * .7f);
            }
            return true;
        }
    }
    return consumed;
}