diff --git a/app/src/main/java/com/kaajjo/libresudoku/ui/components/board/Board.kt b/app/src/main/java/com/kaajjo/libresudoku/ui/components/board/Board.kt index 1af5cc6..6d83bcf 100644 --- a/app/src/main/java/com/kaajjo/libresudoku/ui/components/board/Board.kt +++ b/app/src/main/java/com/kaajjo/libresudoku/ui/components/board/Board.kt @@ -79,6 +79,7 @@ fun Board( questions: Boolean = false, renderNotes: Boolean = true, cellsToHighlight: List? = null, + notesToHighlight: List = emptyList(), zoomable: Boolean = false, boardColors: SudokuBoardColors = LocalBoardColors.current, crossHighlight: Boolean = false, @@ -112,8 +113,8 @@ fun Board( val horThick by remember(size) { mutableIntStateOf(ceil(sqrt(size.toFloat())).toInt()) } var fontSizePx = with(LocalDensity.current) { mainTextSize.toPx() } - var noteSizePx = with(LocalDensity.current) { noteTextSize.toPx() } - var killerSumSizePx = with(LocalDensity.current) { noteTextSize.toPx() * 0.9f } + val noteSizePx = with(LocalDensity.current) { (cellSizeDivWidth * 0.8f).toSp().toPx() } + val killerSumSizePx = with(LocalDensity.current) { noteSizePx * 1.1f } val thinLineWidth = with(LocalDensity.current) { 1.3.dp.toPx() } val thickLineWidth = with(LocalDensity.current) { 1.3.dp.toPx() } @@ -163,6 +164,15 @@ fun Board( ) } + val noteHighlightPaint by remember { + mutableStateOf( + Paint().apply { + color = highlightColor.copy(alpha = 0.3f).toArgb() + isAntiAlias = true + } + ) + } + var killerSumPaint by remember { mutableStateOf( Paint().apply { @@ -180,16 +190,6 @@ fun Board( mainTextSize.value, context.resources.displayMetrics ) - noteSizePx = TypedValue.applyDimension( - TypedValue.COMPLEX_UNIT_SP, - noteTextSize.value, - context.resources.displayMetrics - ) - killerSumSizePx = TypedValue.applyDimension( - TypedValue.COMPLEX_UNIT_SP, - noteTextSize.value * 0.9f, - context.resources.displayMetrics - ) textPaint = Paint().apply { color = foregroundColor.toArgb() isAntiAlias = true @@ -397,7 +397,9 @@ fun Board( drawNotes( size = size, paint = notePaint, + highlightPaint = noteHighlightPaint, notes = notes, + notesToHighlight = notesToHighlight, cellSize = cellSize, cellSizeDivWidth = cellSizeDivWidth, killerSumBounds = killerSumBounds diff --git a/app/src/main/java/com/kaajjo/libresudoku/ui/components/board/BoardDrawUtil.kt b/app/src/main/java/com/kaajjo/libresudoku/ui/components/board/BoardDrawUtil.kt index 3f720a1..a02c3d2 100644 --- a/app/src/main/java/com/kaajjo/libresudoku/ui/components/board/BoardDrawUtil.kt +++ b/app/src/main/java/com/kaajjo/libresudoku/ui/components/board/BoardDrawUtil.kt @@ -45,7 +45,9 @@ fun DrawScope.drawRoundCell( fun DrawScope.drawNotes( size: Int, paint: Paint, + highlightPaint: Paint, notes: List, + notesToHighlight: List, cellSize: Float, cellSizeDivWidth: Float, killerSumBounds: android.graphics.Rect, @@ -61,13 +63,29 @@ fun DrawScope.drawNotes( val noteTextMeasure = paint.measureText(textToDraw) val noteCol = getNoteColumnNumber(note.value, size) + val noteRow = getNoteRowNumber(note.value, size) + + + + val horizontalPadding = + if (noteRow == 0) noteTextMeasure / 3f + else if (noteRow == 1) 0f + else if (noteRow == 2 && note.value > 9) 0f + else -(noteTextMeasure / 3f) + + + if (notesToHighlight.contains(note)) { + canvas.nativeCanvas.drawCircle( + note.col * cellSize + cellSizeDivWidth / 2f + (cellSizeDivWidth * noteRow) + horizontalPadding, + note.row * cellSize + noteBounds.height() * 1.5f + killerSumBounds.height() + (cellDivHeight * noteCol) - (noteBounds.height() * 0.5f), + noteTextMeasure * 1.1f, + highlightPaint + ) + } canvas.nativeCanvas.drawText( textToDraw, - note.col * cellSize + cellSizeDivWidth / 2f + (cellSizeDivWidth * getNoteRowNumber( - note.value, - size - )) - noteTextMeasure / 2f, + note.col * cellSize + cellSizeDivWidth / 2f + (cellSizeDivWidth * noteRow) - noteTextMeasure / 2f + horizontalPadding, note.row * cellSize + noteBounds.height() * 1.5f + killerSumBounds.height() + (cellDivHeight * noteCol), paint ) @@ -135,10 +153,11 @@ fun roundRectForCell( rect: Rect, cornerRadius: CornerRadius ): RoundRect { - val topLeft = if (row == 0 && col == 0) cornerRadius else CornerRadius.Zero - val topRight = if (row == 0 && col == gameSize - 1)cornerRadius else CornerRadius.Zero + val topLeft = if (row == 0 && col == 0) cornerRadius else CornerRadius.Zero + val topRight = if (row == 0 && col == gameSize - 1) cornerRadius else CornerRadius.Zero val bottomLeft = if (row == gameSize - 1 && col == 0) cornerRadius else CornerRadius.Zero - val bottomRight = if (row == gameSize - 1 && col == gameSize - 1) cornerRadius else CornerRadius.Zero + val bottomRight = + if (row == gameSize - 1 && col == gameSize - 1) cornerRadius else CornerRadius.Zero return RoundRect( rect = rect, diff --git a/app/src/main/java/com/kaajjo/libresudoku/ui/game/GameScreen.kt b/app/src/main/java/com/kaajjo/libresudoku/ui/game/GameScreen.kt index 31eb3a4..cb433c1 100644 --- a/app/src/main/java/com/kaajjo/libresudoku/ui/game/GameScreen.kt +++ b/app/src/main/java/com/kaajjo/libresudoku/ui/game/GameScreen.kt @@ -359,6 +359,11 @@ fun GameScreen( identicalNumbersHighlight = highlightIdentical, errorsHighlight = errorHighlight != 0, positionLines = positionLines, + notesToHighlight = if (viewModel.digitFirstNumber > 0) { + viewModel.notes.filter { it.value == viewModel.digitFirstNumber } + } else { + emptyList() + }, enabled = viewModel.gamePlaying && !viewModel.endGame, questions = !(viewModel.gamePlaying || viewModel.endGame) && SDK_INT < Build.VERSION_CODES.R, renderNotes = renderNotes && !viewModel.showSolution,