Exemplo n.º 1
0
  private void draw(Canvas canvas, int row, int column, RenderOptions renderOptions) {

    int blockWidth = renderOptions.getWidth() / getColumnCount();
    int blockHeight = renderOptions.getHeight() / getRowCount();
    int blockSize = Math.min(blockWidth, blockHeight);

    RenderOptions blockRenderOptions = new RenderOptions(renderOptions);
    blockRenderOptions.setWidth(blockSize);
    blockRenderOptions.setHeight(blockSize);

    QuiltBlock quiltBlock = getQuiltBlock(row, column);
    if (quiltBlock != null) {
      PaperPiecedBlock block = quiltBlock.getBlock();
      if (block != null) {
        int blockLeft = renderOptions.getLeft() + (column * blockSize);
        int blockTop = renderOptions.getTop() + (row * blockSize);
        // canvas.drawRect(blockLeft, blockTop, blockLeft
        // + m_cachedBlockSize, blockTop + m_cachedBlockSize,
        // m_debugPaint);

        blockRenderOptions.setLeft(blockLeft);
        blockRenderOptions.setTop(blockTop);

        block.draw(canvas, blockRenderOptions);
      }
    }
  }
Exemplo n.º 2
0
  static final Quilt createFromJSONObject(JSONObject jsonObject) throws JSONException {

    int rowCount = jsonObject.optInt("rowCount", 0);
    int columnCount = jsonObject.optInt("columnCount", 0);
    float width = (float) jsonObject.optDouble("width", 0);
    float height = (float) jsonObject.optDouble("height", 0);

    Quilt quilt = new Quilt(rowCount, columnCount, width, height);

    if (jsonObject.has("quiltBlocks")) {
      JSONArray jsonQuiltBlocks = jsonObject.getJSONArray("quiltBlocks");

      int index = -1;
      for (int row = 0; row < quilt.m_rowCount; ++row) {
        for (int column = 0; column < quilt.m_columnCount; ++column) {
          index += 1;
          if (index < jsonQuiltBlocks.length()) {
            JSONObject jsonQuiltBlock = jsonQuiltBlocks.optJSONObject(index);
            if (jsonQuiltBlock != null) {
              QuiltBlock quiltBlock = QuiltBlock.createFromJSONObject(jsonQuiltBlock);
              quilt.setQuiltBlock(row, column, quiltBlock);
            }
          }
        }
      }
    }

    quilt.m_new = false;
    return quilt;
  }
Exemplo n.º 3
0
  JSONObject createJSONObject() throws JSONException {

    JSONArray jsonQuiltBlocks = new JSONArray();
    for (int row = 0; row < m_rowCount; ++row) {
      for (int column = 0; column < m_columnCount; ++column) {
        QuiltBlock quiltBlock = getQuiltBlock(row, column);
        if (quiltBlock != null) {
          jsonQuiltBlocks.put(quiltBlock.createJSONObject());
        } else {
          jsonQuiltBlocks.put(JSONObject.NULL);
        }
      }
    }

    JSONObject jsonQuilt = new JSONObject();
    jsonQuilt.put("objectType", "quilt");
    jsonQuilt.put("rowCount", m_rowCount);
    jsonQuilt.put("columnCount", m_columnCount);
    jsonQuilt.put("width", m_width);
    jsonQuilt.put("height", m_height);
    jsonQuilt.put("quiltBlocks", jsonQuiltBlocks);

    return jsonQuilt;
  }