Skip to content

Commit

Permalink
Fixed borderless grids bug after software update
Browse files Browse the repository at this point in the history
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().
  • Loading branch information
SpiritualForest committed Aug 11, 2022
1 parent c5d3c38 commit 3342648
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 3342648

Please sign in to comment.