Ejemplo n.º 1
0
  private void alignSelectedCenter(boolean yAlign) {
    if (selectedEntities.size == 0) return;

    UndoableActionGroup undoableGroup = new UndoableActionGroup("Change Alignment");

    float targetPos = 0;

    for (EntityProxy proxy : selectedEntities) {
      if (yAlign) targetPos += proxy.getX();
      else targetPos += proxy.getY();
    }

    targetPos /= selectedEntities.size;

    for (EntityProxy proxy : selectedEntities) {
      MoveEntityAction action = new MoveEntityAction(proxy);

      if (yAlign == true) proxy.setX(targetPos);
      else proxy.setY(targetPos);

      action.saveNewData(proxy);
      undoableGroup.add(action);
    }

    undoableGroup.finalizeGroup();
    undoModule.add(undoableGroup);
  }
Ejemplo n.º 2
0
  private void alignSelected(int align) {
    if (selectedEntities.size == 0) return;

    UndoableActionGroup undoableGroup = new UndoableActionGroup("Change Alignment");

    if (align == Align.left || align == Align.right) {
      float targetX = selectedEntities.get(0).getX();

      for (EntityProxy proxy : selectedEntities) {
        if (align == Align.left) {
          if (proxy.getX() < targetX) targetX = proxy.getX();
        } else {
          if (proxy.getX() > targetX) targetX = proxy.getX();
        }
      }

      for (EntityProxy proxy : selectedEntities) {
        MoveEntityAction action = new MoveEntityAction(proxy);
        proxy.setX(targetX);
        action.saveNewData(proxy);
        undoableGroup.add(action);
      }
    }

    if (align == Align.top || align == Align.bottom) {
      float targetY = selectedEntities.get(0).getY();

      for (EntityProxy proxy : selectedEntities) {
        if (align == Align.top) {
          if (proxy.getY() < targetY) targetY = proxy.getY();
        } else {
          if (proxy.getY() > targetY) targetY = proxy.getY();
        }
      }

      for (EntityProxy proxy : selectedEntities) {
        MoveEntityAction action = new MoveEntityAction(proxy);
        proxy.setY(targetY);
        action.saveNewData(proxy);
        undoableGroup.add(action);
      }
    }

    undoableGroup.finalizeGroup();
    undoModule.add(undoableGroup);
  }