package com.ys.bdtp.cad.items

import android.graphics.*
import com.ys.bdtp.graph.SGraphyItem
import com.ys.bdtp.graph.SMotionEvent
import java.util.*

/**
 * Created by lihao.
 * Date: 2021/6/7
 * 区域节点
 */
class AreaNodeItem(val data: PointF, parent: SGraphyItem? = null) : SGraphyItem(parent) {
    /** 画笔 */
    val paint = Paint()
    val mPaint_inner = Paint()

    val outPaint = Paint()

    var x: Float = 0f
    var y: Float = 0f
    lateinit var onScroll: OnScroll

    init {
        try {
//            flags = EnumSet.of(SGraphyItemFlag.ItemIsMovable, SGraphyItemFlag.ItemIsSelectable, SGraphyItemFlag.ItemIsFocusable)

        } catch (e: Exception) {
            e.printStackTrace()
        }
        outPaint.style = Paint.Style.STROKE
        outPaint.strokeJoin = Paint.Join.ROUND
        outPaint.isAntiAlias = true
        outPaint.color = Color.rgb(0x66, 0x66, 0xff)
        outPaint.strokeWidth = 150f
        x = data.x
        y = data.y

        //内圈
        mPaint_inner.color = Color.RED
        mPaint_inner.isAntiAlias = true
        mPaint_inner.style = Paint.Style.FILL
    } // Constructor

    override fun boundingRect(): RectF {
        return RectF(data.x - 800f, -data.y - 800f, data.x + 800f, -data.y + 800f)
    }

    override fun onScroll(e1: SMotionEvent, e2: SMotionEvent, distanceX: Float, distanceY: Float): Boolean {
        val fx = pos.x - distanceX * scale.x
        val fy = pos.y - distanceY * scale.y
        x = data.x + fx
        y = data.y - fy
        moveTo(pos.x - distanceX * scale.x, pos.y - distanceY * scale.y)
        onScroll.onScroll(data.x + fx, data.y + fy)
        return true


//        moveTo(pos.x - distanceX * scale.x, pos.y - distanceY * scale.y)

//        onScroll.onScroll(data.x + pos.x - distanceX * scale.x, data.y - pos.y - distanceY * scale.y)
//        onScroll.onScroll(data.x, data.y)


//        return super.onScroll(e1, e2, distanceX, distanceY)
    }

    interface OnScroll {
        fun onScroll(x: Float, y: Float)
    }

    fun setOnScrollListener(onScroll: OnScroll) {
        this.onScroll = onScroll
    }


    /**
     * Item绘制操作
     *
     * @param   canvas          画布
     * @param   rect            绘制区域
     */
    override fun onDraw(canvas: Canvas) {
        canvas.drawCircle(data.x, -data.y, 120f, mPaint_inner)
    } // Function onDraw()

}