use of com.badlogic.gdx.scenes.scene2d.Stage in project libgdx by libgdx.
the class ParticleControllerTest method create.
@Override
public void create() {
super.create();
emitters = new Array<ParticleController>();
assets.load(DEFAULT_PARTICLE, Texture.class);
assets.load(DEFAULT_SKIN, Skin.class);
loading = true;
environment = new Environment();
environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0f, 0f, 0.1f, 1f));
environment.add(new DirectionalLight().set(1f, 1f, 1f, 0, -0.5f, -1));
billboardParticleBatch = new BillboardParticleBatch();
billboardParticleBatch.setCamera(cam);
ui = new Stage();
builder = new StringBuilder();
}
use of com.badlogic.gdx.scenes.scene2d.Stage in project libgdx by libgdx.
the class DragAndDrop method addSource.
public void addSource(final Source source) {
DragListener listener = new DragListener() {
public void dragStart(InputEvent event, float x, float y, int pointer) {
if (activePointer != -1) {
event.stop();
return;
}
activePointer = pointer;
dragStartTime = System.currentTimeMillis();
payload = source.dragStart(event, getTouchDownX(), getTouchDownY(), pointer);
event.stop();
if (cancelTouchFocus && payload != null)
source.getActor().getStage().cancelTouchFocusExcept(this, source.getActor());
}
public void drag(InputEvent event, float x, float y, int pointer) {
if (payload == null)
return;
if (pointer != activePointer)
return;
Stage stage = event.getStage();
Touchable dragActorTouchable = null;
if (dragActor != null) {
dragActorTouchable = dragActor.getTouchable();
dragActor.setTouchable(Touchable.disabled);
}
// Find target.
Target newTarget = null;
isValidTarget = false;
float stageX = event.getStageX() + touchOffsetX, stageY = event.getStageY() + touchOffsetY;
// Prefer touchable actors.
Actor hit = event.getStage().hit(stageX, stageY, true);
if (hit == null)
hit = event.getStage().hit(stageX, stageY, false);
if (hit != null) {
for (int i = 0, n = targets.size; i < n; i++) {
Target target = targets.get(i);
if (!target.actor.isAscendantOf(hit))
continue;
newTarget = target;
target.actor.stageToLocalCoordinates(tmpVector.set(stageX, stageY));
break;
}
}
// If over a new target, notify the former target that it's being left behind.
if (newTarget != target) {
if (target != null)
target.reset(source, payload);
target = newTarget;
}
// Notify new target of drag.
if (newTarget != null)
isValidTarget = newTarget.drag(source, payload, tmpVector.x, tmpVector.y, pointer);
if (dragActor != null)
dragActor.setTouchable(dragActorTouchable);
// Add/remove and position the drag actor.
Actor actor = null;
if (target != null)
actor = isValidTarget ? payload.validDragActor : payload.invalidDragActor;
if (actor == null)
actor = payload.dragActor;
if (actor == null)
return;
if (dragActor != actor) {
if (dragActor != null)
dragActor.remove();
dragActor = actor;
stage.addActor(actor);
}
float actorX = event.getStageX() - actor.getWidth() + dragActorX;
float actorY = event.getStageY() + dragActorY;
if (keepWithinStage) {
if (actorX < 0)
actorX = 0;
if (actorY < 0)
actorY = 0;
if (actorX + actor.getWidth() > stage.getWidth())
actorX = stage.getWidth() - actor.getWidth();
if (actorY + actor.getHeight() > stage.getHeight())
actorY = stage.getHeight() - actor.getHeight();
}
actor.setPosition(actorX, actorY);
}
public void dragStop(InputEvent event, float x, float y, int pointer) {
if (pointer != activePointer)
return;
activePointer = -1;
if (payload == null)
return;
if (System.currentTimeMillis() - dragStartTime < dragTime)
isValidTarget = false;
if (dragActor != null)
dragActor.remove();
if (isValidTarget) {
float stageX = event.getStageX() + touchOffsetX, stageY = event.getStageY() + touchOffsetY;
target.actor.stageToLocalCoordinates(tmpVector.set(stageX, stageY));
target.drop(source, payload, tmpVector.x, tmpVector.y, pointer);
}
source.dragStop(event, x, y, pointer, payload, isValidTarget ? target : null);
if (target != null)
target.reset(source, payload);
payload = null;
target = null;
isValidTarget = false;
dragActor = null;
}
};
listener.setTapSquareSize(tapSquareSize);
listener.setButton(button);
source.actor.addCaptureListener(listener);
sourceListeners.put(source, listener);
}
use of com.badlogic.gdx.scenes.scene2d.Stage in project libgdx by libgdx.
the class Window method draw.
public void draw(Batch batch, float parentAlpha) {
Stage stage = getStage();
if (stage.getKeyboardFocus() == null)
stage.setKeyboardFocus(this);
keepWithinStage();
if (style.stageBackground != null) {
stageToLocalCoordinates(tmpPosition.set(0, 0));
stageToLocalCoordinates(tmpSize.set(stage.getWidth(), stage.getHeight()));
drawStageBackground(batch, parentAlpha, getX() + tmpPosition.x, getY() + tmpPosition.y, getX() + tmpSize.x, getY() + tmpSize.y);
}
super.draw(batch, parentAlpha);
}
use of com.badlogic.gdx.scenes.scene2d.Stage in project libgdx by libgdx.
the class ScrollPane method act.
public void act(float delta) {
super.act(delta);
boolean panning = flickScrollListener.getGestureDetector().isPanning();
boolean animating = false;
if (fadeAlpha > 0 && fadeScrollBars && !panning && !touchScrollH && !touchScrollV) {
fadeDelay -= delta;
if (fadeDelay <= 0)
fadeAlpha = Math.max(0, fadeAlpha - delta);
animating = true;
}
if (flingTimer > 0) {
resetFade();
float alpha = flingTimer / flingTime;
amountX -= velocityX * alpha * delta;
amountY -= velocityY * alpha * delta;
clamp();
// Stop fling if hit overscroll distance.
if (amountX == -overscrollDistance)
velocityX = 0;
if (amountX >= maxX + overscrollDistance)
velocityX = 0;
if (amountY == -overscrollDistance)
velocityY = 0;
if (amountY >= maxY + overscrollDistance)
velocityY = 0;
flingTimer -= delta;
if (flingTimer <= 0) {
velocityX = 0;
velocityY = 0;
}
animating = true;
}
if (//
smoothScrolling && flingTimer <= 0 && !panning && // Scroll smoothly when grabbing the scrollbar if one pixel of scrollbar movement is > 10% of the scroll area.
(//
(!touchScrollH || (scrollX && maxX / (hScrollBounds.width - hKnobBounds.width) > areaWidth * 0.1f)) && //
(!touchScrollV || (scrollY && maxY / (vScrollBounds.height - vKnobBounds.height) > areaHeight * 0.1f)))) {
if (visualAmountX != amountX) {
if (visualAmountX < amountX)
visualScrollX(Math.min(amountX, visualAmountX + Math.max(200 * delta, (amountX - visualAmountX) * 7 * delta)));
else
visualScrollX(Math.max(amountX, visualAmountX - Math.max(200 * delta, (visualAmountX - amountX) * 7 * delta)));
animating = true;
}
if (visualAmountY != amountY) {
if (visualAmountY < amountY)
visualScrollY(Math.min(amountY, visualAmountY + Math.max(200 * delta, (amountY - visualAmountY) * 7 * delta)));
else
visualScrollY(Math.max(amountY, visualAmountY - Math.max(200 * delta, (visualAmountY - amountY) * 7 * delta)));
animating = true;
}
} else {
if (visualAmountX != amountX)
visualScrollX(amountX);
if (visualAmountY != amountY)
visualScrollY(amountY);
}
if (!panning) {
if (overscrollX && scrollX) {
if (amountX < 0) {
resetFade();
amountX += (overscrollSpeedMin + (overscrollSpeedMax - overscrollSpeedMin) * -amountX / overscrollDistance) * delta;
if (amountX > 0)
scrollX(0);
animating = true;
} else if (amountX > maxX) {
resetFade();
amountX -= (overscrollSpeedMin + (overscrollSpeedMax - overscrollSpeedMin) * -(maxX - amountX) / overscrollDistance) * delta;
if (amountX < maxX)
scrollX(maxX);
animating = true;
}
}
if (overscrollY && scrollY) {
if (amountY < 0) {
resetFade();
amountY += (overscrollSpeedMin + (overscrollSpeedMax - overscrollSpeedMin) * -amountY / overscrollDistance) * delta;
if (amountY > 0)
scrollY(0);
animating = true;
} else if (amountY > maxY) {
resetFade();
amountY -= (overscrollSpeedMin + (overscrollSpeedMax - overscrollSpeedMin) * -(maxY - amountY) / overscrollDistance) * delta;
if (amountY < maxY)
scrollY(maxY);
animating = true;
}
}
}
if (animating) {
Stage stage = getStage();
if (stage != null && stage.getActionsRequestRendering())
Gdx.graphics.requestRendering();
}
}
use of com.badlogic.gdx.scenes.scene2d.Stage in project libgdx by libgdx.
the class Button method draw.
public void draw(Batch batch, float parentAlpha) {
validate();
boolean isDisabled = isDisabled();
boolean isPressed = isPressed();
boolean isChecked = isChecked();
boolean isOver = isOver();
Drawable background = null;
if (isDisabled && style.disabled != null)
background = style.disabled;
else if (isPressed && style.down != null)
background = style.down;
else if (isChecked && style.checked != null)
background = (style.checkedOver != null && isOver) ? style.checkedOver : style.checked;
else if (isOver && style.over != null)
background = style.over;
else if (//
style.up != null)
background = style.up;
setBackground(background);
float offsetX = 0, offsetY = 0;
if (isPressed && !isDisabled) {
offsetX = style.pressedOffsetX;
offsetY = style.pressedOffsetY;
} else if (isChecked && !isDisabled) {
offsetX = style.checkedOffsetX;
offsetY = style.checkedOffsetY;
} else {
offsetX = style.unpressedOffsetX;
offsetY = style.unpressedOffsetY;
}
Array<Actor> children = getChildren();
for (int i = 0; i < children.size; i++) children.get(i).moveBy(offsetX, offsetY);
super.draw(batch, parentAlpha);
for (int i = 0; i < children.size; i++) children.get(i).moveBy(-offsetX, -offsetY);
Stage stage = getStage();
if (stage != null && stage.getActionsRequestRendering() && isPressed != clickListener.isPressed())
Gdx.graphics.requestRendering();
}
Aggregations