Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 25 additions & 23 deletions chartLib/src/main/kotlin/info/appdev/charting/utils/Fill.kt
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ open class Fill {
}

fun fillRect(
c: Canvas, paint: Paint,
canvas: Canvas, paint: Paint,
left: Float, top: Float, right: Float, bottom: Float,
gradientDirection: Direction?, mRoundedBarRadius: Float
) {
Expand All @@ -90,12 +90,12 @@ open class Fill {
}

if (this.isClipPathSupported) {
val save = c.save()
val save = canvas.save()

c.clipRect(left, top, right, bottom)
c.drawColor(mFinalColor!!)
canvas.clipRect(left, top, right, bottom)
canvas.drawColor(mFinalColor!!)

c.restoreToCount(save)
canvas.restoreToCount(save)
} else {
// save
val previous = paint.style
Expand All @@ -105,7 +105,7 @@ open class Fill {
paint.style = Paint.Style.FILL
paint.color = mFinalColor!!

c.drawRoundRect(RectF(left, top, right, bottom), mRoundedBarRadius, mRoundedBarRadius, paint)
canvas.drawRoundRect(RectF(left, top, right, bottom), mRoundedBarRadius, mRoundedBarRadius, paint)

// restore
paint.color = previousColor
Expand Down Expand Up @@ -142,7 +142,7 @@ open class Fill {

paint.shader = gradient

c.drawRoundRect(RectF(left, top, right, bottom), mRoundedBarRadius, mRoundedBarRadius, paint)
canvas.drawRoundRect(RectF(left, top, right, bottom), mRoundedBarRadius, mRoundedBarRadius, paint)
}

Type.DRAWABLE -> {
Expand All @@ -151,13 +151,15 @@ open class Fill {
}

drawable!!.setBounds(left.toInt(), top.toInt(), right.toInt(), bottom.toInt())
drawable!!.draw(c)
drawable!!.draw(canvas)
}
}
}

fun fillPath(
c: Canvas, path: Path, paint: Paint,
canvas: Canvas,
path: Path,
paint: Paint,
clipRect: RectF?
) {
when (this.type) {
Expand All @@ -169,12 +171,12 @@ open class Fill {
}

if (clipRect != null && this.isClipPathSupported) {
val save = c.save()
val save = canvas.save()

c.clipPath(path)
c.drawColor(mFinalColor!!)
canvas.clipPath(path)
canvas.drawColor(mFinalColor!!)

c.restoreToCount(save)
canvas.restoreToCount(save)
} else {
// save
val previous = paint.style
Expand All @@ -184,7 +186,7 @@ open class Fill {
paint.style = Paint.Style.FILL
paint.color = mFinalColor!!

c.drawPath(path, paint)
canvas.drawPath(path, paint)

// restore
paint.color = previousColor
Expand All @@ -196,16 +198,16 @@ open class Fill {
val gradient = LinearGradient(
0f,
0f,
c.width.toFloat(),
c.height.toFloat(),
canvas.width.toFloat(),
canvas.height.toFloat(),
this.gradientColors!!,
this.gradientPositions,
Shader.TileMode.MIRROR
)

paint.shader = gradient

c.drawPath(path, paint)
canvas.drawPath(path, paint)
}

Type.DRAWABLE -> {
Expand All @@ -215,18 +217,18 @@ open class Fill {

ensureClipPathSupported()

val save = c.save()
c.clipPath(path)
val save = canvas.save()
canvas.clipPath(path)

drawable!!.setBounds(
if (clipRect == null) 0 else clipRect.left.toInt(),
if (clipRect == null) 0 else clipRect.top.toInt(),
if (clipRect == null) c.width else clipRect.right.toInt(),
if (clipRect == null) c.height else clipRect.bottom.toInt()
if (clipRect == null) canvas.width else clipRect.right.toInt(),
if (clipRect == null) canvas.height else clipRect.bottom.toInt()
)
drawable!!.draw(c)
drawable!!.draw(canvas)

c.restoreToCount(save)
canvas.restoreToCount(save)
}
}
}
Expand Down
Loading