Refine search
Stage stage = event.getStage(); dragActor.remove(); // Remove so it cannot be hit (Touchable.disabled isn't enough). dragActor = null; float stageX = event.getStageX() + touchOffsetX, stageY = event.getStageY() + touchOffsetY; Actor hit = event.getStage().hit(stageX, stageY, true); // Prefer touchable actors. 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; dragActor = actor; if (actor == null) return; 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 boolean act (float delta) { if (capture) target.addCaptureListener(listener); else target.addListener(listener); return true; }
private void setContainerPosition (Actor actor, float x, float y) { this.targetActor = actor; Stage stage = actor.getStage(); if (stage == null) return; container.pack(); float offsetX = manager.offsetX, offsetY = manager.offsetY, dist = manager.edgeDistance; Vector2 point = actor.localToStageCoordinates(tmp.set(x + offsetX, y - offsetY - container.getHeight())); if (point.y < dist) point = actor.localToStageCoordinates(tmp.set(x + offsetX, y + offsetY)); if (point.x < dist) point.x = dist; if (point.x + container.getWidth() > stage.getWidth() - dist) point.x = stage.getWidth() - dist - container.getWidth(); if (point.y + container.getHeight() > stage.getHeight() - dist) point.y = stage.getHeight() - dist - container.getHeight(); container.setPosition(point.x, point.y); point = actor.localToStageCoordinates(tmp.set(actor.getWidth() / 2, actor.getHeight() / 2)); point.sub(container.getX(), container.getY()); container.setOrigin(point.x, point.y); }
/** @return May be null. */ private TextField findNextTextField (Array<Actor> actors, TextField best, Vector2 bestCoords, Vector2 currentCoords, boolean up) { for (int i = 0, n = actors.size; i < n; i++) { Actor actor = actors.get(i); if (actor instanceof TextField) { if (actor == this) continue; TextField textField = (TextField)actor; if (textField.isDisabled() || !textField.focusTraversal || !textField.ancestorsVisible()) continue; Vector2 actorCoords = actor.getParent().localToStageCoordinates(tmp3.set(actor.getX(), actor.getY())); boolean below = actorCoords.y != currentCoords.y && (actorCoords.y < currentCoords.y ^ up); boolean right = actorCoords.y == currentCoords.y && (actorCoords.x > currentCoords.x ^ up); if (!below && !right) continue; boolean better = best == null || (actorCoords.y != bestCoords.y && (actorCoords.y > bestCoords.y ^ up)); if (!better) better = actorCoords.y == bestCoords.y && (actorCoords.x < bestCoords.x ^ up); if (better) { best = (TextField)actor; bestCoords.set(actorCoords); } } else if (actor instanceof Group) best = findNextTextField(((Group)actor).getChildren(), best, bestCoords, currentCoords, up); } return best; }
protected void addActor(CocoCreatorUIEditor editor, Actor actor, ObjectData option) { Array<Actor> arrayActors = editor.getActors().get(actor.getName()); if (arrayActors == null) { arrayActors = new Array<Actor>(); } arrayActors.add(actor); editor.getActors().put(actor.getName(), arrayActors); editor.getActionActors().put(option.getActionTag(), actor); }
private void computeSize (Array<Node> nodes, float indent, float plusMinusWidth) { float ySpacing = this.ySpacing; float spacing = iconSpacingLeft + iconSpacingRight; for (int i = 0, n = nodes.size; i < n; i++) { Node node = nodes.get(i); float rowWidth = indent + plusMinusWidth; Actor actor = node.actor; if (actor instanceof Layout) { Layout layout = (Layout)actor; rowWidth += layout.getPrefWidth(); node.height = layout.getPrefHeight(); } else { rowWidth += actor.getWidth(); node.height = actor.getHeight(); } if (node.icon != null) { rowWidth += spacing + node.icon.getMinWidth(); node.height = Math.max(node.height, node.icon.getMinHeight()); } prefWidth = Math.max(prefWidth, rowWidth); prefHeight -= node.height + ySpacing; if (node.expanded) computeSize(node.children, indent + indentSpacing, plusMinusWidth); } }
/** Draws selection, icons, and expand icons. */ private void draw (Batch batch, Array<Node> nodes, float indent, float plusMinusWidth) { Drawable plus = style.plus, minus = style.minus; float x = getX(), y = getY(), expandX = x + indent, iconX = expandX + plusMinusWidth + iconSpacingLeft; for (int i = 0, n = nodes.size; i < n; i++) { Node node = nodes.get(i); float height = node.height; Actor actor = node.actor; if (selection.contains(node) && style.selection != null) { style.selection.draw(batch, x, y + actor.getY() - ySpacing / 2, getWidth(), height + ySpacing); } else if (node == overNode && style.over != null) { style.over.draw(batch, x, y + actor.getY() - ySpacing / 2, getWidth(), height + ySpacing); } if (node.icon != null) { float iconY = y + actor.getY() + Math.round((height - node.icon.getMinHeight()) / 2); batch.setColor(actor.getColor()); node.icon.draw(batch, iconX, iconY, node.icon.getMinWidth(), node.icon.getMinHeight()); batch.setColor(Color.WHITE); } if (node.children.size == 0) continue; Drawable expandIcon = node.expanded ? minus : plus; float iconY = y + actor.getY() + Math.round((height - expandIcon.getMinHeight()) / 2); expandIcon.draw(batch, expandX, iconY, expandIcon.getMinWidth(), expandIcon.getMinHeight()); if (node.expanded) draw(batch, node.children, indent + indentSpacing, plusMinusWidth); } }
private void getStageCoordinatesWithinParent (final InputEvent event) { final Actor parent = mimic.getActor().getParent(); if (parent != null) { MIMIC_COORDINATES.set(Vector2.Zero); parent.localToStageCoordinates(MIMIC_COORDINATES); final float parentX = MIMIC_COORDINATES.x; final float parentY = MIMIC_COORDINATES.y; final float parentEndX = parentX + parent.getWidth(); final float parentEndY = parentY + parent.getHeight(); MIMIC_COORDINATES.set(event.getStageX() + offsetX, event.getStageY() + offsetY); if (MIMIC_COORDINATES.x < parentX) { MIMIC_COORDINATES.x = parentX; } else if (MIMIC_COORDINATES.x + mimic.getWidth() > parentEndX) { MIMIC_COORDINATES.x = parentEndX - mimic.getWidth(); } if (MIMIC_COORDINATES.y < parentY) { MIMIC_COORDINATES.y = parentY; } else if (MIMIC_COORDINATES.y + mimic.getHeight() > parentEndY) { MIMIC_COORDINATES.y = parentEndY - mimic.getHeight(); } STAGE_COORDINATES.set(MathUtils.clamp(event.getStageX(), parentX, parentEndX - 1f), MathUtils.clamp(event.getStageY(), parentY, parentEndY - 1f)); } else { getStageCoordinatesWithOffset(event); } }
void selectNodes (Array<Node> nodes, float low, float high) { for (int i = 0, n = nodes.size; i < n; i++) { Node node = nodes.get(i); if (node.actor.getY() < low) break; if (!node.isSelectable()) continue; if (node.actor.getY() <= high) selection.add(node); if (node.expanded) selectNodes(node.children, low, high); } }
private float layout (Array<Node> nodes, float indent, float y, float plusMinusWidth) { float ySpacing = this.ySpacing; float spacing = iconSpacingLeft + iconSpacingRight; for (int i = 0, n = nodes.size; i < n; i++) { Node node = nodes.get(i); float x = indent + plusMinusWidth; if (node.icon != null) x += spacing + node.icon.getMinWidth(); if (node.actor instanceof Layout) ((Layout)node.actor).pack(); y -= node.getHeight(); node.actor.setPosition(x, y); y -= ySpacing; if (node.expanded) y = layout(node.children, indent + indentSpacing, y, plusMinusWidth); } return y; }
/** Returns the first actor found with the specified name. Note this recursively compares the name of every actor in the * group. */ public <T extends Actor> T findActor (String name) { Array<Actor> children = this.children; for (int i = 0, n = children.size; i < n; i++) if (name.equals(children.get(i).getName())) return (T)children.get(i); for (int i = 0, n = children.size; i < n; i++) { Actor child = children.get(i); if (child instanceof Group) { Actor actor = ((Group)child).findActor(name); if (actor != null) return (T)actor; } } return null; }
@Override public void tick(float delta) { // Draw background if (drawBackground && background != null) { getBatch().begin(); getBatch().setColor(backgroundColor); getBatch().draw(background, 0, 0, Screen.getWidth(), Screen.getHeight()); getBatch().end(); } // Similar to Google's Android "Project Butter": // Updating mouse dependent stuff in render() if (!Gdx.input.isTouched()) { mousePos = screenToStageCoordinates(mousePos.set(Gdx.input.getX(), Gdx.input.getY())); for (Actor a : getActors()) { currentActorRect.set(a.getX(), a.getY(), a.getWidth(), a.getHeight()); for (EventListener el : a.getListeners()) { if (!(el instanceof InputListener)) continue; InputListener il = (InputListener) el; if (currentActorRect.contains(mousePos.x, mousePos.y)) { il.enter(null, mousePos.x, mousePos.y, -1, null); } else { il.exit(null, mousePos.x, mousePos.y, -1, null); } } } } super.draw(); getBatch().begin(); }
@Override public void enter (InputEvent event, float x, float y, int pointer, Actor fromActor) { if (pointer == -1) { Vector2 targetPos = target.localToStageCoordinates(new Vector2()); setX(targetPos.x + (target.getWidth() - getWidth()) / 2); float tooltipY = targetPos.y - getHeight() - 6; float stageHeight = target.getStage().getHeight(); //is there enough space to display above widget? if (stageHeight - tooltipY > stageHeight) setY(targetPos.y + target.getHeight() + 6); //display above widget else setY(tooltipY); //display below displayTask.cancel(); Timer.schedule(displayTask, appearDelayTime); } }
@Override protected void update(float percent) { if (temp == null) { temp = new Vector2(actor.getX(), actor.getY()); } // TODO Auto-generated method stub valueAt(temp, percent); actor.setPosition(temp.x, temp.y); }
public void create () { stage = new Stage(); Gdx.input.setInputProcessor(stage); actor.setBounds(15, 15, 100, 100); actor.setOrigin(50, 50); stage.addActor(actor); actor.addListener(new InputListener() { public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) { System.out.println("down"); table.pack(); table.setPosition(5, 100); stage.addActor(table); actor.addAction(forever(sequence(moveBy(50, 0, 2), moveBy(-50, 0, 2), run(new Runnable() { public void run () { actor.setZIndex(0);
@Override public void draw (final Batch batch, final float parentAlpha) { if (actor != null) { LAST_POSITION.set(actor.getX(), actor.getY()); actor.setPosition(getX(), getY()); actor.draw(batch, getColor().a * parentAlpha); actor.setPosition(LAST_POSITION.x, LAST_POSITION.y); } } }