package com.gh.gamecenter.common.view.cropbox

import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.RectF

interface CropBoxDrawer {

    fun onDraw(rectF: RectF, canvas: Canvas, paint: Paint)

    fun onDrawDecoration(rectF: RectF, canvas: Canvas, paint: Paint)

    class CircleDrawer : CropBoxDrawer {

        override fun onDraw(rectF: RectF, canvas: Canvas, paint: Paint) {
            canvas.drawCircle(rectF.centerX(), rectF.centerY(), rectF.width() / 2, paint)
        }

        override fun onDrawDecoration(rectF: RectF, canvas: Canvas, paint: Paint) {
            canvas.drawCircle(rectF.centerX(), rectF.centerY(), (rectF.width() - paint.strokeWidth) / 2, paint)
        }
    }

    class RectangleDrawer : CropBoxDrawer {
        override fun onDraw(rectF: RectF, canvas: Canvas, paint: Paint) {
            canvas.drawRect(rectF, paint)
        }

        override fun onDrawDecoration(rectF: RectF, canvas: Canvas, paint: Paint) {
            val realRectF = RectF(
                rectF.left + paint.strokeWidth / 2,
                rectF.top,
                rectF.right - paint.strokeWidth / 2,
                rectF.bottom
            )
            canvas.drawRect(realRectF, paint)
        }

    }
}