drawTextOptimized method

void drawTextOptimized()

Implementation

void drawTextOptimized() {
  drawIn(0, textCenter[0][0], textCenter[0][1]);
  isdrawed[0] = true;
  bool checkattempt = false;
  for (var i = 1; i < textlist.length; i++) {
    double w = textlist[i].width;
    double h = textlist[i].height;
    int attempts = 0;

    bool isadded = false;

    while (!isadded) {
      int getX = Random().nextInt(mapX.toInt() - w.toInt());
      int direction = Random().nextInt(2);
      if (direction == 0) {
        for (int y = textCenter[i][1].toInt(); y > 0; y--) {
          if (checkMapOptimized(getX, y, w, h)) {
            drawIn(i, getX.toDouble(), y.toDouble());
            isadded = true;
            isdrawed[i] = true;
            break;
          }
        }
      } else if (direction == 1) {
        for (int y = textCenter[i][1].toInt(); y < mapY; y++) {
          if (checkMapOptimized(getX, y, w, h)) {
            drawIn(i, getX.toDouble(), y.toDouble());
            isadded = true;
            isdrawed[i] = true;
            break;
          }
        }
      }
      attempts += 1;
      if (attempts > attempt) {
        isadded = true;
        checkattempt = true;
      }
    }
    if (checkattempt) {
      return;
    }
  }
}