Skip to content

Instantly share code, notes, and snippets.

@fievx
Created September 23, 2018 12:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fievx/9b0c0b3c812522c7ebf420047be3afb6 to your computer and use it in GitHub Desktop.
Save fievx/9b0c0b3c812522c7ebf420047be3afb6 to your computer and use it in GitHub Desktop.
fun getPath(width: Int, height: Int): Path {
return Path().apply {
val cutoutRadius = 50f
val cutoutWidth = if (cutoutRadius != 0f) cutoutRadius else width / 8f
val cutoutHeight = 3 * cutoutWidth / 4
val padding = 0f
val pathLeft = padding
val pathRight = width - padding
val pathTop = padding
val pathBottom = height.toFloat() - padding
val cutoutXStart = width / 2 - cutoutWidth
val cutoutXEnd = cutoutXStart + cutoutWidth * 2
val topCutoutYStart = pathTop - cutoutHeight
val topCutoutYEnd = pathTop + cutoutHeight
val botCutoutYStart = pathBottom - cutoutHeight
val botCutoutYEnd = pathBottom + cutoutHeight
fillType = Path.FillType.WINDING
moveTo(pathLeft + cornerRadius, pathTop)
lineTo(cutoutXStart, pathTop)
// top cutout
arcTo(RectF(cutoutXStart, topCutoutYStart, cutoutXEnd, topCutoutYEnd), 180f, -180f)
lineTo(pathRight - cornerRadius, pathTop)
//top right corner
arcTo(RectF(pathRight - cornerRadius * 2, pathTop, pathRight, pathTop + cornerRadius * 2), 270f, 90f)
lineTo(pathRight, pathBottom - cornerRadius)
//bottom right corner
arcTo(RectF(pathRight - cornerRadius * 2, pathBottom - cornerRadius * 2, pathRight, pathBottom), 0f, 90f)
lineTo(cutoutXEnd, pathBottom)
// bottom cutour
arcTo(RectF(cutoutXStart, botCutoutYStart, cutoutXEnd, botCutoutYEnd), 0f, -180f)
lineTo(pathLeft + cornerRadius, pathBottom)
//bottom left corner
arcTo(RectF(pathLeft, pathBottom - cornerRadius * 2, pathLeft + cornerRadius * 2, pathBottom), 90f, 90f)
lineTo(pathLeft, pathTop - cornerRadius)
//top left corner
arcTo(RectF(pathLeft, pathTop, pathLeft + cornerRadius * 2, pathTop + cornerRadius * 2), 180f, 90f)
close()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment