コード例 #1
0
  private void drawAreaColors(Canvas canvas, int row, int col) {
    int colorNumber = puzzle.getAreaColor(row, col);
    int color = theme.getAreaColor(colorNumber, puzzle.getNumberOfAreaColors());

    canvas.clipRect(0, 0, cellWidth, cellHeight);
    canvas.drawColor(color);
  }
コード例 #2
0
  private void onDraw0(Canvas canvas) {
    if (Constants.LOG_V) Log.v(TAG, "onDraw(" + canvas.getClipBounds() + ")");

    canvas.save();
    canvas.translate(offsetX, offsetY);
    canvas.clipRect(0, 0, size * cellWidth, size * cellHeight);

    Rect clipBounds = canvas.getClipBounds();

    if (theme.isDrawAreaColors(puzzle.getPuzzleType())) drawAreaColors(canvas, clipBounds);
    else drawBackground(canvas);

    drawExtraRegions(canvas, clipBounds);

    if (puzzle.isSolved()) drawCongrats(canvas);
    else if (paused) drawPaused(canvas);
    else {
      drawHighlightedCells(canvas, clipBounds);

      drawMarkedPosition(canvas);
    }

    if (!preview && puzzle.hasErrors()) drawErrors(canvas, clipBounds);

    drawValues(canvas, clipBounds);

    drawGrid(canvas);

    drawRegionBorders(canvas, clipBounds);

    canvas.restore();

    drawOuterBorder(canvas);
  }
コード例 #3
0
 private void drawExtraRegions(Canvas canvas, int row, int col) {
   if (puzzle.isExtraRegion(row, col)) {
     canvas.drawRect(
         0,
         0,
         cellWidth,
         cellHeight,
         theme.getExtraRegionPaint(puzzle.getPuzzleType(), puzzle.getExtraRegionCode(row, col)));
   }
 }
コード例 #4
0
  public void setPuzzle(AndokuPuzzle puzzle) {
    this.puzzle = puzzle;
    size = puzzle == null ? 0 : puzzle.getSize();
    multiValuesPainter.setPuzzleSize(size);

    requestLayout();
    invalidate();
  }
コード例 #5
0
  private void drawValues(Canvas canvas, int row, int col) {
    ValueSet values = puzzle.getValues(row, col);
    if (values.isEmpty()) return;

    if (preview && !puzzle.isSolved()) {
      if (puzzle.isClue(row, col)) {
        boolean show = previewClueCounter++ % 3 != 0;
        String dv = show ? String.valueOf(theme.getSymbol(values.nextValue(0))) : "?";
        canvas.drawText(dv, cellWidth / 2f, textOffset, theme.getCluePaint(preview));
      }
    } else if (values.size() == 1) {
      String dv = String.valueOf(theme.getSymbol(values.nextValue(0)));
      Paint paint = puzzle.isClue(row, col) ? theme.getCluePaint(preview) : theme.getValuePaint();
      canvas.drawText(dv, cellWidth / 2f, textOffset, paint);
    } else {
      multiValuesPainter.paintValues(canvas, values);
    }
  }
コード例 #6
0
  private void drawRegionBorders(Canvas canvas, Rect clipBounds) {
    Paint regionBorderPaint = theme.getRegionBorderPaint();

    for (int row = 0; row < size; row++) {
      float y = row * cellHeight;
      if (y > clipBounds.bottom || y + cellHeight < clipBounds.top) continue;

      for (int col = 0; col < size; col++) {
        float x = col * cellWidth;
        if (x > clipBounds.right || x + cellWidth < clipBounds.left) continue;

        if (row > 0 && puzzle.getAreaCode(row, col) != puzzle.getAreaCode(row - 1, col)) {
          canvas.drawLine(x, y, x + cellWidth, y, regionBorderPaint);
        }
        if (col > 0 && puzzle.getAreaCode(row, col) != puzzle.getAreaCode(row, col - 1)) {
          canvas.drawLine(x, y, x, y + cellHeight, regionBorderPaint);
        }
      }
    }
  }
コード例 #7
0
  private void drawMarkedPosition(Canvas canvas) {
    if (markedPosition == null) return;

    canvas.save();

    float x = markedPosition.col * cellWidth;
    float y = markedPosition.row * cellHeight;
    canvas.translate(x, y);

    Paint paint =
        puzzle.isClue(markedPosition.row, markedPosition.col)
            ? theme.getMarkedPositionCluePaint()
            : theme.getMarkedPositionPaint();
    canvas.clipRect(0, 0, cellWidth, cellHeight);
    canvas.drawPaint(paint);

    canvas.restore();
  }
コード例 #8
0
  private void drawHighlightedCells(Canvas canvas, Rect clipBounds) {
    if (highlightedDigit == null || theme.getHighlightDigitsPolicy() == HighlightDigitsPolicy.NEVER)
      return;

    for (int row = 0; row < size; row++) {
      float y = row * cellHeight;
      if (y > clipBounds.bottom || y + cellHeight < clipBounds.top) continue;

      for (int col = 0; col < size; col++) {
        float x = col * cellWidth;
        if (x > clipBounds.right || x + cellWidth < clipBounds.left) continue;

        final ValueSet values = puzzle.getValues(row, col);
        if (values.contains(highlightedDigit)) {
          drawHighlightedcell(canvas, values.size(), x, y);
        }
      }
    }
  }
コード例 #9
0
  private void drawErrors(Canvas canvas, Rect clipBounds) {
    Paint errorPaint = theme.getErrorPaint();

    float radius = Math.min(cellWidth, cellHeight) * 0.4f;

    final HashSet<RegionError> regionErrors = puzzle.getRegionErrors();

    final HashSet<Position> regionErrorPositions = getUniquePositions(regionErrors);
    for (Position p : regionErrorPositions) {
      float x = p.col * cellWidth;
      if (x > clipBounds.right || x + cellWidth < clipBounds.left) continue;
      float y = p.row * cellHeight;
      if (y > clipBounds.bottom || y + cellHeight < clipBounds.top) continue;

      float cx = x + cellWidth / 2;
      float cy = y + cellHeight / 2;
      canvas.drawCircle(cx, cy, radius, errorPaint);
    }

    for (RegionError error : regionErrors) {
      float cx1 = error.p1.col * cellWidth + cellWidth / 2;
      float cy1 = error.p1.row * cellHeight + cellHeight / 2;

      float cx2 = error.p2.col * cellWidth + cellWidth / 2;
      float cy2 = error.p2.row * cellHeight + cellHeight / 2;

      if (cx1 == cx2) // vertical line
      {
        float vy = cy2 - cy1;
        vy *= (radius / Math.abs(vy));

        canvas.drawLine(cx1, cy1 + vy, cx2, cy2 - vy, errorPaint);
      } else if (cy1 == cy2) // horizontal line
      {
        float vx = cx2 - cx1;
        vx *= (radius / Math.abs(vx));

        canvas.drawLine(cx1 + vx, cy1, cx2 - vx, cy2, errorPaint);
      } else {
        float vx = cx2 - cx1;
        float vy = cy2 - cy1;
        float scale = (float) (radius / Math.sqrt(vx * vx + vy * vy));
        vx *= scale;
        vy *= scale;

        canvas.drawLine(cx1 + vx, cy1 + vy, cx2 - vx, cy2 - vy, errorPaint);
      }
    }

    for (Position p : puzzle.getCellErrors()) {
      float x = p.col * cellWidth;
      if (x > clipBounds.right || x + cellWidth < clipBounds.left) continue;
      float y = p.row * cellHeight;
      if (y > clipBounds.bottom || y + cellHeight < clipBounds.top) continue;

      float cx = x + cellWidth / 2;
      float cy = y + cellHeight / 2;
      float delta = radius / 1.41421356f;
      canvas.drawLine(cx - delta, cy - delta, cx + delta, cy + delta, errorPaint);
      canvas.drawLine(cx + delta, cy - delta, cx - delta, cy + delta, errorPaint);
    }
  }