package com.ys.bdtp.cad.items


import android.content.Context
import android.graphics.*
import com.ys.bdtp.cad.types.Point
import com.ys.bdtp.cad.R
import com.ys.bdtp.graph.SGraphyItem
import java.util.*

/**
 * Created by lihao.
 * Date: 2021/6/4
 */
class QrcodeItem(
    var context: Context,
    val data: Point,
    parent: SGraphyItem? = null,
    defaultScale: Float? = null
) :
    SGraphyItem(parent) {
    /** 新建 画笔 */
    val mPaint_inner = Paint()
    val mPaint_center = Paint()
    val mPaint_outer = Paint()

    /** 按时 画笔 */
    val not_overTime_inner = Paint()
    val not_overTime_outer = Paint()

    /** 逾期 画笔 */
    val overTime_inner = Paint()
    val overTime_outer = Paint()

    /** 承接查验复核中 */
    val checkReviewing_inner = Paint()
    val checkReviewing_outer = Paint()
    var mDefaultScale = 0f

    //var defaultScale = 1.0f
    //var mScale = 1f
    var mBitmap: Bitmap

    init {
        if (defaultScale != null) {
            mDefaultScale = defaultScale
        }
//        flags = EnumSet.of(
//            SGraphyItemFlag.ItemIsMovable,
//            SGraphyItemFlag.ItemIsSelectable,
//            SGraphyItemFlag.ItemIsFocusable
//        )
        /** 按时 */
        not_overTime_inner.color = Color.parseColor("#ffffff")
        not_overTime_inner.isAntiAlias = true
        not_overTime_inner.style = Paint.Style.FILL

        not_overTime_outer.color = Color.parseColor("#04df97")//绿色
        not_overTime_outer.isAntiAlias = true
        not_overTime_outer.style = Paint.Style.FILL

        /** 逾期 */
        overTime_inner.color = Color.parseColor("#ffffff")
        overTime_inner.isAntiAlias = true
        overTime_inner.style = Paint.Style.FILL

        overTime_outer.color = Color.parseColor("#ff3b33")//红色
        overTime_outer.isAntiAlias = true
        overTime_outer.style = Paint.Style.FILL

        /** 承接查验复核中 */
        checkReviewing_inner.color = Color.parseColor("#ffffff")
        checkReviewing_inner.isAntiAlias = true
        checkReviewing_inner.style = Paint.Style.FILL

        checkReviewing_outer.color = Color.parseColor("#F7B500")//黄色
        checkReviewing_outer.isAntiAlias = true
        checkReviewing_outer.style = Paint.Style.FILL

        /** 新建 */
        //内圈
        mPaint_inner.color = Color.parseColor("#5E59E1")
        mPaint_inner.isAntiAlias = true
        mPaint_inner.style = Paint.Style.FILL
        //中圈
        mPaint_center.color = Color.parseColor("#ffffff")
        mPaint_center.isAntiAlias = true
        mPaint_center.style = Paint.Style.FILL
        //外圈
        mPaint_outer.color = Color.parseColor("#260c90eb")
        mPaint_outer.isAntiAlias = true
        mPaint_outer.style = Paint.Style.FILL
        mBitmap = BitmapFactory.decodeResource(context.resources, R.drawable.qrcode)
    }

    override fun boundingRect(): RectF {
        return RectF(data.mX - 250f, data.mY - 250f, data.mX + 250f, data.mY + 250f)
    }

    /**
     * Item绘制操作
     *
     * @param   canvas          画布
     * @param   rect            绘制区域
     */
    override fun onDraw(canvas: Canvas) {
//        data.scalePoint = mDefaultScale / scene!!.view!!.scale
//        mPaint_inner.color = if (this.isSelected) {
//            Color.RED
//        } else {
//            Color.BLUE
//        }
//        canvas.drawCircle(data.mX, data.mY, 500f, mPaint_inner)
        val matrix = Matrix()
        matrix.postScale(4.0000007f, 4.0000007f)
        matrix.postTranslate(data.mX - 400f, data.mY - 400f)
        canvas.drawBitmap(mBitmap, matrix, mPaint_center)
        super.onDraw(canvas)
    } // Function onDraw()

}