Esempio n. 1
0
  public void updateProperties() {
    if (editActors == null) return;

    updateProperties = true;

    Actor model = editActors.get(0);
    getStage().setKeyboardFocus(null);
    name.setText(model.getName());
    visible.setChecked(model.isVisible());
    positionX.setText(String.format(Locale.ENGLISH, "%.2f", model.getX()));
    positionY.setText(String.format(Locale.ENGLISH, "%.2f", model.getY()));
    rotation.setText(String.format(Locale.ENGLISH, "%.2f", model.getRotation()));
    lockRatio.setChecked(Math.abs(model.getScaleX() - model.getScaleY()) < 0.01f);
    scaleX.setText(String.format(Locale.ENGLISH, "%.2f", model.getScaleX()));
    scaleY.setText(String.format(Locale.ENGLISH, "%.2f", model.getScaleY()));
    Color color = model.getColor();
    r.setText(String.format(Locale.ENGLISH, "%.0f", color.r * 255));
    g.setText(String.format(Locale.ENGLISH, "%.0f", color.g * 255));
    b.setText(String.format(Locale.ENGLISH, "%.0f", color.b * 255));
    a.setText(String.format(Locale.ENGLISH, "%.0f", color.a * 255));

    scaleY.setDisabled(lockRatio.isChecked());
    scaleY.setColor(lockRatio.isChecked() ? disableColor : enableColor);

    updateProperties = false;
  }
Esempio n. 2
0
 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 == this) continue;
     if (actor instanceof TextField) {
       TextField textField = (TextField) actor;
       if (textField.isDisabled() || !textField.focusTraversal) continue;
       Vector2 actorCoords =
           actor.getParent().localToStageCoordinates(tmp3.set(actor.getX(), actor.getY()));
       if ((actorCoords.y < currentCoords.y
               || (actorCoords.y == currentCoords.y && actorCoords.x > currentCoords.x))
           ^ up) {
         if (best == null
             || (actorCoords.y > bestCoords.y
                     || (actorCoords.y == bestCoords.y && actorCoords.x < bestCoords.x))
                 ^ up) {
           best = (TextField) actor;
           bestCoords.set(actorCoords);
         }
       }
     } else if (actor instanceof Group)
       best =
           findNextTextField(((Group) actor).getChildren(), best, bestCoords, currentCoords, up);
   }
   return best;
 }
  public void drawDebug(SpriteBatch batch) {
    if (debugRenderer == null) {
      if (Gdx.graphics.isGL20Available())
        debugRenderer = new ImmediateModeRenderer20(64, false, true, 0);
      else debugRenderer = new ImmediateModeRenderer10(64);
    }

    float x = getX(), y = getY();

    debugRenderer.begin(batch.getProjectionMatrix(), GL10.GL_LINES);

    float x1 = x;
    float y1 = y;
    float x2 = x1 + getPrefWidth();
    float y2 = y1 + getPrefHeight();
    drawDebugItem(x1, y1, x2, y2, 1, 0, 0);

    for (Actor a : getChildren()) {
      if (debugRenderer.getNumVertices() == 64) {
        debugRenderer.end();
        debugRenderer.begin(batch.getProjectionMatrix(), GL10.GL_LINES);
      }

      x1 = x + a.getX();
      y1 = y + a.getY();
      x2 = x1 + a.getWidth();
      y2 = y1 + a.getHeight();
      drawDebugItem(x1, y1, x2, y2, 0, 1, 0);
    }

    debugRenderer.end();
  }
Esempio n. 4
0
 /**
  * @return the positions of the actors in the list
  * @param actors
  */
 private List<Vector2> getPositions(SnapshotArray<Actor> actors) {
   List<Vector2> oldPositions = new ArrayList<Vector2>();
   for (Actor actor : actors) {
     oldPositions.add(new Vector2(actor.getX(), actor.getY()));
   }
   return oldPositions;
 }
Esempio n. 5
0
  public void drawDebug(SpriteBatch batch) {
    if (getDebug() == Debug.none || debugRects == null) return;
    if (debugRenderer == null) {
      if (Gdx.graphics.isGL20Available())
        debugRenderer = new ImmediateModeRenderer20(64, false, true, 0);
      else debugRenderer = new ImmediateModeRenderer10(64);
    }

    float x = 0, y = 0;
    Actor parent = getTable();
    while (parent != null) {
      if (parent instanceof Group) {
        x += parent.getX();
        y += parent.getY();
      }
      parent = parent.getParent();
    }

    debugRenderer.begin(batch.getProjectionMatrix(), GL10.GL_LINES);
    for (int i = 0, n = debugRects.size; i < n; i++) {
      DebugRect rect = debugRects.get(i);
      float x1 = x + rect.x;
      float y1 = y + rect.y - rect.height;
      float x2 = x1 + rect.width;
      float y2 = y1 + rect.height;
      float r = rect.type == Debug.cell ? 1 : 0;
      float g = rect.type == Debug.widget ? 1 : 0;
      float b = rect.type == Debug.table ? 1 : 0;

      debugRenderer.color(r, g, b, 1);
      debugRenderer.vertex(x1, y1, 0);
      debugRenderer.color(r, g, b, 1);
      debugRenderer.vertex(x1, y2, 0);

      debugRenderer.color(r, g, b, 1);
      debugRenderer.vertex(x1, y2, 0);
      debugRenderer.color(r, g, b, 1);
      debugRenderer.vertex(x2, y2, 0);

      debugRenderer.color(r, g, b, 1);
      debugRenderer.vertex(x2, y2, 0);
      debugRenderer.color(r, g, b, 1);
      debugRenderer.vertex(x2, y1, 0);

      debugRenderer.color(r, g, b, 1);
      debugRenderer.vertex(x2, y1, 0);
      debugRenderer.color(r, g, b, 1);
      debugRenderer.vertex(x1, y1, 0);

      if (debugRenderer.getNumVertices() == 64) {
        debugRenderer.end();
        debugRenderer.begin(batch.getProjectionMatrix(), GL10.GL_LINES);
      }
    }
    debugRenderer.end();
  }
Esempio n. 6
0
 /**
  * Transforms the specified point in the actor's coordinates to be in the stage's coordinates.
  * Note this method will ONLY work for screen aligned, unrotated, unscaled actors!
  */
 public Vector2 localToStageCoordinates(Vector2 localCoords) {
   Actor actor = this;
   while (actor != null) {
     if (actor.getRotation() != 0 || actor.getScaleX() != 1 || actor.getScaleY() != 1)
       throw new GdxRuntimeException("Only unrotated and unscaled actors may use this method.");
     localCoords.x += actor.getX();
     localCoords.y += actor.getY();
     actor = actor.getParent();
   }
   return localCoords;
 }
Esempio n. 7
0
  /** Draws selection, icons, and expand icons. */
  private void draw(SpriteBatch batch, Array<Node> nodes, float indent) {
    Drawable plus = style.plus, minus = style.minus;
    float x = getX(), y = getY();
    for (int i = 0, n = nodes.size; i < n; i++) {
      Node node = nodes.get(i);
      Actor actor = node.actor;

      if (selectedNodes.contains(node, true) && style.selection != null) {
        style.selection.draw(
            batch, x, y + actor.getY() - ySpacing / 2, getWidth(), node.height + ySpacing);
      } else if (node == overNode && style.over != null) {
        style.over.draw(
            batch, x, y + actor.getY() - ySpacing / 2, getWidth(), node.height + ySpacing);
      }

      if (node.icon != null) {
        float iconY = actor.getY() + Math.round((node.height - node.icon.getMinHeight()) / 2);
        batch.setColor(actor.getColor());
        node.icon.draw(
            batch,
            x + node.actor.getX() - iconSpacing - node.icon.getMinWidth(),
            y + 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 = actor.getY() + Math.round((node.height - expandIcon.getMinHeight()) / 2);
      expandIcon.draw(
          batch,
          x + indent - iconSpacing,
          y + iconY,
          expandIcon.getMinWidth(),
          expandIcon.getMinHeight());
      if (node.expanded) draw(batch, node.children, indent + indentSpacing);
    }
  }
Esempio n. 8
0
 public SelectionGhost(ShapeRenderer shapeRenderer, Actor representedActor) {
   this.shapeRenderer = shapeRenderer;
   this.representedActor = representedActor;
   setOrigin(representedActor.getOriginX(), representedActor.getOriginY());
   setBounds(
       representedActor.getX(),
       representedActor.getY(),
       representedActor.getWidth(),
       representedActor.getHeight());
   setRotation(representedActor.getRotation());
   setScale(representedActor.getScaleX(), representedActor.getScaleY());
   startingRotation = representedActor.getRotation();
 }
Esempio n. 9
0
  protected void checkBounds() {

    if (follow) {
      setX(followed.getX() - getWidth() / 2);
      setY(followed.getY() + followed.getHeight());
    }

    if (getX() + getWidth() > Gdx.app.getGraphics().getWidth())
      setX(getX() - (getWidth() - (Gdx.app.getGraphics().getWidth() - getX())));

    if (getY() + getHeight() > Gdx.app.getGraphics().getHeight())
      setY(getY() - (getHeight() - (Gdx.app.getGraphics().getHeight() - getY())));

    if (getX() < 0) setX(0);
    if (getY() < 0) setY(0);
  }
Esempio n. 10
0
  private LinkedList<Unit> selectCharacters() {
    LinkedList<Unit> units = new LinkedList<>();

    for (Actor actor : getStage().getActors()) {
      if (!(actor instanceof Unit)) continue;

      Rectangle boundingBox =
          new Rectangle(actor.getX(), actor.getY(), actor.getWidth(), actor.getHeight());

      if (selectionBox.overlaps(boundingBox)) {
        units.add((Unit) actor);
      }
    }

    return units;
  }
Esempio n. 11
0
  /**
   * Creates a {@link ModelEntity}. This method should only be invoked if the return value of the
   * {@link #save()} method was true.
   */
  public void createSceneElement() {
    ModelEntity savedElement =
        this.controller.getTemplates().createSceneElement(this.savePath.path());

    Actor rootGroup = scaledView.getGroupEditorDragListener().getRootGroup();

    Actor scaledAct = rootGroup == null ? scaledView : rootGroup;

    savedElement.setScaleX(1 / scaledAct.getScaleX());
    savedElement.setScaleY(1 / scaledAct.getScaleY());
    Vector2 pos = mesh.getPosition();

    savedElement.setX(pos.x - scaledAct.getX());
    savedElement.setY(pos.y - scaledAct.getY());

    Q.getComponent(savedElement, RepoElement.class).setThumbnail(thumbSavePath.name());

    this.controller.action(AddSceneElement.class, savedElement);
  }
Esempio n. 12
0
  /** Adjusts the position and size of the given group to its children */
  public static void adjustGroup(Actor root) {
    if (!(root instanceof Group)) {
      return;
    }

    Group group = (Group) root;
    if (group.getChildren().size == 0) {
      return;
    }

    Vector2 origin = Pools.obtain(Vector2.class);
    Vector2 size = Pools.obtain(Vector2.class);
    Vector2 tmp3 = Pools.obtain(Vector2.class);
    Vector2 tmp4 = Pools.obtain(Vector2.class);

    calculateBounds(group.getChildren(), origin, size);

    /*
     * minX and minY are the new origin (new 0, 0), so everything inside the
     * group must be translated that much.
     */
    for (Actor actor : group.getChildren()) {
      actor.setPosition(actor.getX() - origin.x, actor.getY() - origin.y);
    }

    /*
     * Now, we calculate the current origin (0, 0) and the new origin (minX,
     * minY), and group is translated by that difference.
     */
    group.localToParentCoordinates(tmp3.set(0, 0));
    group.localToParentCoordinates(tmp4.set(origin.x, origin.y));
    tmp4.sub(tmp3);
    group.setBounds(group.getX() + tmp4.x, group.getY() + tmp4.y, size.x, size.y);
    group.setOrigin(size.x / 2.0f, size.y / 2.0f);

    Pools.free(origin);
    Pools.free(size);
    Pools.free(tmp3);
    Pools.free(tmp4);
  }
Esempio n. 13
0
  @Override
  public void draw(SpriteBatch batch, float parentAlpha) {
    if (widget == null) return;

    validate();

    // Setup transform for this group.
    applyTransform(batch, computeTransform());

    if (scrollX)
      hKnobBounds.x =
          hScrollBounds.x + (int) ((hScrollBounds.width - hKnobBounds.width) * getScrollPercentX());
    if (scrollY)
      vKnobBounds.y =
          vScrollBounds.y
              + (int) ((vScrollBounds.height - vKnobBounds.height) * (1 - getScrollPercentY()));

    // Calculate the widget's position depending on the scroll state and available widget area.
    float y = widgetAreaBounds.y;
    if (!scrollY) y -= (int) maxY;
    else y -= (int) (maxY - visualAmountY);

    if (!fadeScrollBars && scrollbarsOnTop && scrollX) {
      float scrollbarHeight = 0;
      if (style.hScrollKnob != null) scrollbarHeight = style.hScrollKnob.getMinHeight();
      if (style.hScroll != null)
        scrollbarHeight = Math.max(scrollbarHeight, style.hScroll.getMinHeight());
      y += scrollbarHeight;
    }

    float x = widgetAreaBounds.x;
    if (scrollX) x -= (int) visualAmountX;
    widget.setPosition(x, y);

    if (widget instanceof Cullable) {
      widgetCullingArea.x = -widget.getX() + widgetAreaBounds.x;
      widgetCullingArea.y = -widget.getY() + widgetAreaBounds.y;
      widgetCullingArea.width = widgetAreaBounds.width;
      widgetCullingArea.height = widgetAreaBounds.height;
      ((Cullable) widget).setCullingArea(widgetCullingArea);
    }

    // Caculate the scissor bounds based on the batch transform, the available widget area and the
    // camera transform. We need to
    // project those to screen coordinates for OpenGL ES to consume.
    getStage().calculateScissors(widgetAreaBounds, scissorBounds);

    // Draw the background ninepatch.
    Color color = getColor();
    batch.setColor(color.r, color.g, color.b, color.a * parentAlpha);
    if (style.background != null) style.background.draw(batch, 0, 0, getWidth(), getHeight());
    batch.flush();

    // Enable scissors for widget area and draw the widget.
    if (ScissorStack.pushScissors(scissorBounds)) {
      drawChildren(batch, parentAlpha);
      ScissorStack.popScissors();
    }

    // Render scrollbars and knobs on top.
    batch.setColor(
        color.r,
        color.g,
        color.b,
        color.a * parentAlpha * Interpolation.fade.apply(fadeAlpha / fadeAlphaSeconds));
    if (scrollX && scrollY) {
      if (style.corner != null) {
        style.corner.draw(
            batch,
            hScrollBounds.x + hScrollBounds.width,
            hScrollBounds.y,
            vScrollBounds.width,
            vScrollBounds.y);
      }
    }
    if (scrollX) {
      if (style.hScroll != null)
        style.hScroll.draw(
            batch, hScrollBounds.x, hScrollBounds.y, hScrollBounds.width, hScrollBounds.height);
      if (style.hScrollKnob != null)
        style.hScrollKnob.draw(
            batch, hKnobBounds.x, hKnobBounds.y, hKnobBounds.width, hKnobBounds.height);
    }
    if (scrollY) {
      if (style.vScroll != null)
        style.vScroll.draw(
            batch, vScrollBounds.x, vScrollBounds.y, vScrollBounds.width, vScrollBounds.height);
      if (style.vScrollKnob != null)
        style.vScrollKnob.draw(
            batch, vKnobBounds.x, vKnobBounds.y, vKnobBounds.width, vKnobBounds.height);
    }

    resetTransform(batch);
  }
Esempio n. 14
0
 private void toStageCoordinates(Actor actor, Vector2 point) {
   point.x += actor.getX();
   point.y += actor.getY();
   toStageCoordinates(actor.getParent(), point);
 }
Esempio n. 15
0
 /**
  * Draws all children. {@link #applyTransform(SpriteBatch)} should be called before and {@link
  * #resetTransform(SpriteBatch)} after this method if {@link #setTransform(boolean) transform} is
  * true. If {@link #setTransform(boolean) transform} is false these methods don't need to be
  * called, children positions are temporarily offset by the group position when drawn. This method
  * avoids drawing children completely outside the {@link #setCullingArea(Rectangle) culling area},
  * if set.
  */
 protected void drawChildren(SpriteBatch batch, float parentAlpha) {
   parentAlpha *= getColor().a;
   DelayedRemovalArray<Actor> children = this.children;
   children.begin();
   if (cullingArea != null) {
     // Draw children only if inside culling area.
     if (transform) {
       for (int i = 0, n = children.size; i < n; i++) {
         Actor child = children.get(i);
         if (!child.isVisible()) continue;
         float x = child.getX();
         float y = child.getY();
         if (x <= cullingArea.x + cullingArea.width
             && y <= cullingArea.y + cullingArea.height
             && x + child.getWidth() >= cullingArea.x
             && y + child.getHeight() >= cullingArea.y) {
           child.draw(batch, parentAlpha);
         }
       }
       batch.flush();
     } else {
       // No transform for this group, offset each child.
       float offsetX = getX();
       float offsetY = getY();
       setPosition(0, 0);
       for (int i = 0, n = children.size; i < n; i++) {
         Actor child = children.get(i);
         if (!child.isVisible()) continue;
         float x = child.getX();
         float y = child.getY();
         if (x <= cullingArea.x + cullingArea.width
             && y <= cullingArea.y + cullingArea.height
             && x + child.getWidth() >= cullingArea.x
             && y + child.getHeight() >= cullingArea.y) {
           child.translate(offsetX, offsetY);
           child.draw(batch, parentAlpha);
           child.setPosition(x, y);
         }
       }
       setPosition(offsetX, offsetY);
     }
   } else {
     if (transform) {
       for (int i = 0, n = children.size; i < n; i++) {
         Actor child = children.get(i);
         if (!child.isVisible()) continue;
         child.draw(batch, parentAlpha);
       }
       batch.flush();
     } else {
       // No transform for this group, offset each child.
       float offsetX = getX();
       float offsetY = getY();
       setPosition(0, 0);
       for (int i = 0, n = children.size; i < n; i++) {
         Actor child = children.get(i);
         if (!child.isVisible()) continue;
         float x = child.getX();
         float y = child.getY();
         child.translate(offsetX, offsetY);
         child.draw(batch, parentAlpha);
         child.setPosition(x, y);
       }
       setPosition(offsetX, offsetY);
     }
   }
   children.end();
 }