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

import android.graphics.RectF
import android.os.Parcelable
import kotlinx.parcelize.Parcelize

@Parcelize
sealed class CropBoxStyle : Parcelable {

    fun getRect(width: Int, height: Int, horizontalPadding: Int): RectF {
        // 计算矩形区域的宽度
        val boxWidth = width - 2 * horizontalPadding
        val boxHeight = getBoxHeight(boxWidth)
        val left = width - boxWidth - horizontalPadding
        val top = (height - boxHeight) / 2
        val right = left + boxWidth
        val bottom = top + boxHeight
        return RectF(left.toFloat(), top.toFloat(), right.toFloat(), bottom.toFloat())
    }

    abstract fun getBoxHeight(boxWidth: Int): Int

    object Circle : CropBoxStyle() {

        override fun getBoxHeight(boxWidth: Int): Int {
            return boxWidth
        }
    }

    class Rectangle(val radio: Float) : CropBoxStyle() {
        override fun getBoxHeight(boxWidth: Int): Int {
            return (boxWidth * radio).toInt()
        }
    }
}