/
HighlightShape.kt
52 lines (42 loc) · 1020 Bytes
/
HighlightShape.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package com.hyy.highlightpro.shape
import android.graphics.*
/**
*Create by hyy on 2021/2/7
*/
open class HighlightShape(val blurRadius: Float = 0.0f) {
private lateinit var paint: Paint
//clip path
internal val path by lazy {
Path()
}
init {
paint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
isDither = true
color = Color.WHITE
}
//paint blur style
if (blurRadius > 0) {
paint.maskFilter = BlurMaskFilter(blurRadius, BlurMaskFilter.Blur.SOLID)
}
}
protected var rect: RectF? = null
/**
* init rect child should override initRect and init path
* */
open fun initRect(rectF: RectF) {
this.rect = rectF
}
/**
* draw our path
*/
fun drawPath(canvas: Canvas) {
rect?.run {
if (isEmpty.not()) {
canvas.drawPath(path, paint)
}
}
}
fun setPaint(paint: Paint) {
this.paint = paint
}
}