Skip to content

Commit

Permalink
feat: 클릭이 영역을 벗어나면 작동하지 않도록 함
Browse files Browse the repository at this point in the history
  • Loading branch information
briandr97 committed Nov 6, 2023
1 parent 88388bb commit c2d0c79
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.graphics.Point
import android.graphics.RectF
import android.util.AttributeSet
import android.view.MotionEvent
Expand Down Expand Up @@ -55,7 +56,7 @@ class GameButton(context: Context, attrs: AttributeSet? = null) : AppCompatButto
}

private val ripplePaint = Paint().apply {
this.color = Color.parseColor("#4D000000")
this.color = ContextCompat.getColor(this@GameButton.context, R.color.custom_button_ripple)
}

override fun onDraw(canvas: Canvas) {
Expand All @@ -75,7 +76,9 @@ class GameButton(context: Context, attrs: AttributeSet? = null) : AppCompatButto
MotionEvent.ACTION_UP -> {
isClicked = false
invalidate()
clickAction?.onClick(this)
if (isClickInsideButton(Point(event.x.toInt(), event.y.toInt()))) {
clickAction?.onClick(this)
}
}
}
return true
Expand All @@ -85,6 +88,12 @@ class GameButton(context: Context, attrs: AttributeSet? = null) : AppCompatButto
clickAction = l
}

private fun isClickInsideButton(point: Point): Boolean {
val isXInside = point.x in 0..this.width
val isYInside = point.y in 0..this.height
return isXInside && isYInside
}

private fun drawRipple(canvas: Canvas) {
canvas.drawRoundRect(getBottomRect(), radius, radius, ripplePaint)
}
Expand Down

0 comments on commit c2d0c79

Please sign in to comment.