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

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

Introduction

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

Prototype

public void setScrollY(float pixels) 

Source Link

Usage

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

License:Apache License

@Override
public boolean scrolled(int amount) {
    if (getScrollFocus() instanceof ScrollPane) {
        ScrollPane s = (ScrollPane) getScrollFocus();
        s.setScrollY(s.getScrollY() + SCROLL_PIXEL_AMOUNT * amount);
        return true;
    }// w  w  w.  j a  v  a 2s. com
    return false;
}

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);/*from w  w  w  . jav  a 2s . 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;
}