if (style == null) throw new IllegalArgumentException("style cannot be null.");
this.style = style;
setWidget(widget);
setSize(150, 150);
addCaptureListener(new InputListener() {
private float handlePosition;
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
if (draggingPointer != -1) return false;
if (pointer == 0 && button != 0) return false;
getStage().setScrollFocus(ScrollPane.this);
if (!flickScroll) resetFade();
if (fadeAlpha == 0) return false;
if (scrollX && hScrollBounds.contains(x, y)) {
event.stop();
resetFade();
if (hKnobBounds.contains(x, y)) {
lastPoint.set(x, y);
handlePosition = hKnobBounds.x;
touchScrollH = true;
draggingPointer = pointer;
return true;
}
setScrollX(amountX + areaWidth * (x < hKnobBounds.x ? -1 : 1));
return true;
}
if (scrollY && vScrollBounds.contains(x, y)) {
event.stop();
resetFade();
if (vKnobBounds.contains(x, y)) {
lastPoint.set(x, y);
handlePosition = vKnobBounds.y;
touchScrollV = true;
draggingPointer = pointer;
return true;
}
setScrollY(amountY + areaHeight * (y < vKnobBounds.y ? 1 : -1));
return true;
}
return false;
}
public void touchUp (InputEvent event, float x, float y, int pointer, int button) {
if (pointer != draggingPointer) return;
cancel();
}
public void touchDragged (InputEvent event, float x, float y, int pointer) {
if (pointer != draggingPointer) return;
if (touchScrollH) {
float delta = x - lastPoint.x;
float scrollH = handlePosition + delta;
handlePosition = scrollH;
scrollH = Math.max(hScrollBounds.x, scrollH);
scrollH = Math.min(hScrollBounds.x + hScrollBounds.width - hKnobBounds.width, scrollH);
float total = hScrollBounds.width - hKnobBounds.width;
if (total != 0) setScrollPercentX((scrollH - hScrollBounds.x) / total);
lastPoint.set(x, y);
} else if (touchScrollV) {
float delta = y - lastPoint.y;
float scrollV = handlePosition + delta;
handlePosition = scrollV;
scrollV = Math.max(vScrollBounds.y, scrollV);
scrollV = Math.min(vScrollBounds.y + vScrollBounds.height - vKnobBounds.height, scrollV);
float total = vScrollBounds.height - vKnobBounds.height;
if (total != 0) setScrollPercentY(1 - ((scrollV - vScrollBounds.y) / total));
lastPoint.set(x, y);
}
}
public boolean mouseMoved (InputEvent event, float x, float y) {
if (!flickScroll) resetFade();
return false;
}
});
flickScrollListener = new ActorGestureListener() {
public void pan (InputEvent event, float x, float y, float deltaX, float deltaY) {
resetFade();
amountX -= deltaX;
amountY += deltaY;
clamp();
cancelTouchFocusedChild(event);
}
public void fling (InputEvent event, float x, float y, int button) {
if (Math.abs(x) > 150) {
flingTimer = flingTime;
velocityX = x;
cancelTouchFocusedChild(event);
}
if (Math.abs(y) > 150) {
flingTimer = flingTime;
velocityY = -y;
cancelTouchFocusedChild(event);
}
}
public boolean handle (Event event) {
if (super.handle(event)) {
if (((InputEvent)event).getType() == InputEvent.Type.touchDown) flingTimer = 0;
return true;
}
return false;
}
};
addListener(flickScrollListener);
addListener(new InputListener() {
public boolean scrolled (InputEvent event, float x, float y, int amount) {
resetFade();
if (scrollY)
setScrollY(amountY + getMouseWheelY() * amount);
else if (scrollX) //