From 3342648032aefeb7ca18c6f995eccf1461898401 Mon Sep 17 00:00:00 2001 From: SpiritualForest Date: Thu, 11 Aug 2022 14:38:28 +0300 Subject: [PATCH] Fixed borderless grids bug after software update After a software update on the phone, the borders of the Grid canvas and next tetromino canvas were not drawn. I switched the drawing mechanism from drawPoint() in a loop to drawLine(). --- .../androidtetris/activity/tetris/GridCanvas.kt | 12 ++++-------- .../activity/tetris/NextTetrominoCanvas.kt | 14 +++++--------- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/com/androidtetris/activity/tetris/GridCanvas.kt b/app/src/main/java/com/androidtetris/activity/tetris/GridCanvas.kt index 3de4f35..6861322 100644 --- a/app/src/main/java/com/androidtetris/activity/tetris/GridCanvas.kt +++ b/app/src/main/java/com/androidtetris/activity/tetris/GridCanvas.kt @@ -77,15 +77,11 @@ class GridCanvas(context: Context, attrs: AttributeSet?) : View(context, attrs) // Draw border and background paint.color = MaterialColors.getColor(this, R.attr.colorOnPrimary) // First left and right borders - for(y in 0 until height) { - canvas.drawPoint(0f, y.toFloat(), paint) - canvas.drawPoint(width.toFloat()-1, y.toFloat(), paint) - } + canvas.drawLine(0f, 0f, 0f, height.toFloat(), paint) // Left + canvas.drawLine(width.toFloat(), 0f, width.toFloat(), height.toFloat(), paint) // Right // Now top and bottom - for(x in 0 until width) { - canvas.drawPoint(x.toFloat(), 0f, paint) - canvas.drawPoint(x.toFloat(), height.toFloat()-1, paint) - } + canvas.drawLine(0f, 0f, width.toFloat(), 0f, paint) // Top + canvas.drawLine(0f, height.toFloat(), width.toFloat(), height.toFloat(), paint) // Bottom if (gamePaused) { // onDraw() called when the game is paused. // Draw "PAUSE" at the center of the canvas. diff --git a/app/src/main/java/com/androidtetris/activity/tetris/NextTetrominoCanvas.kt b/app/src/main/java/com/androidtetris/activity/tetris/NextTetrominoCanvas.kt index fa3bd92..0761ac8 100644 --- a/app/src/main/java/com/androidtetris/activity/tetris/NextTetrominoCanvas.kt +++ b/app/src/main/java/com/androidtetris/activity/tetris/NextTetrominoCanvas.kt @@ -36,16 +36,12 @@ class NextTetrominoCanvas(context: Context, attrs: AttributeSet?) : View(context // First, draw the border paint.color = MaterialColors.getColor(this, R.attr.colorOnPrimary) // First left and right borders - for(y in 0 until height) { - canvas.drawPoint(0f, y.toFloat(), paint) - canvas.drawPoint(width.toFloat()-1, y.toFloat(), paint) - } + canvas.drawLine(0f, 0f, 0f, height.toFloat(), paint) // Left + canvas.drawLine(width.toFloat(), 0f, width.toFloat(), height.toFloat(), paint) // Right // Now top and bottom - for(x in 0 until width) { - canvas.drawPoint(x.toFloat(), 0f, paint) - canvas.drawPoint(x.toFloat(), height.toFloat()-1, paint) - } - + canvas.drawLine(0f, 0f, width.toFloat(), 0f, paint) // Top + canvas.drawLine(0f, height.toFloat(), width.toFloat(), height.toFloat(), paint) // Bottom + // Draw all the tetrominoes var spacing = 0 // For vertical spacing between the tetrominoes for(tetromino in upcoming) {