package com.led.scroller.barrage.banner.app

import android.content.Context
import android.graphics.drawable.GradientDrawable
import androidx.core.content.ContextCompat
import com.led.scroller.barrage.banner.R

fun getShapeDrawable(
    content: Context,
    startColor: Int,
    endColor: Int
): GradientDrawable {
    // 创建圆角矩形形状
    val shape = GradientDrawable()
    shape.shape = GradientDrawable.RECTANGLE

    // 设置形状的渐变颜色
    shape.colors = intArrayOf(
        ContextCompat.getColor(content, startColor),
        ContextCompat.getColor(content, endColor)
    )

    // 设置渐变方向，这里设置为从上到下的方向
    shape.orientation = GradientDrawable.Orientation.TOP_BOTTOM

    // 设置圆角半径
    val cornerRadius = content.resources.getDimension(R.dimen.corner_radius)
    shape.cornerRadius = cornerRadius

    return shape
}

fun dpToPx(dp: Float, context: Context): Float {
    val scale = context.resources.displayMetrics.density
    return dp * scale
}