package com.ys.bdtp.cad.test

import android.graphics.Bitmap
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Matrix
import android.graphics.Paint
import android.graphics.RectF
import android.util.Log
import com.ys.bdtp.graph.SGraphyItem
import com.ys.bdtp.graph.SMotionEvent
import com.ys.bdtp.graph.enums.SGraphyItemFlag
import java.util.*


/**
 * 设备
 * @author  Andy
 */
class GraphyTwoItem(parent: SGraphyItem? = null) : SGraphyItem(parent) {

    // 画笔
    private var pen = Paint()
    var flag:Boolean = false
    var isClick:Boolean = false
    /** 当前设备 */
    var isCurrent:Boolean=false
    private lateinit var bitmapdianbiao:Bitmap
    private lateinit var bitmapequipment:Bitmap
    private lateinit var decodeResource:Bitmap
    private var bitheight = 0
    private var bitwidth = 0

    /** png图数据 */
    private var pngWidth = 16
    private var pngHeight = 16
    /** png定位点的坐标 */
    private val pngLocatX = 8
    private val pngLocatY = 14

    /** 原始宽 */
    private var originalWidth = 0
    /** 原始高 */
    private var originalHeight = 0
    private var rate = 1f
    var color = Color.RED
    /**
     * 默认构造函数
     */
    init {

//        hide()
        isClick=true
        isCurrent=false
        pen.color = color
        pen.strokeWidth = 5f
        pen.isAntiAlias=false

        /** item获取焦点ItemIsFocusable,移动ItemIsMovable */
        flags= EnumSet.of(SGraphyItemFlag.ItemIsFocusable)
//        this.parent = parent


    } // init

    /**
     * Item对象边界区域
     */
    override fun boundingRect(): RectF {
        return RectF(0f,0f,600f,300f)
    } // Function boundingRect()

    /**
     * @param   canvas      画布对象
     */
    override fun onDraw(canvas: Canvas) {
        try {
            canvas.drawRect(0f,0f,600f,300f,pen)
            invalidate()
        } catch (e: Exception) {
            e.printStackTrace()
        }
        return
    } // Function paint()

    /**
     *  点击
     */
    override fun onSingleTapUp(e: SMotionEvent): Boolean {
        Log.e("被点击2","**************************************")
        Log.e("X",e.x.toString())
        Log.e("y",e.y.toString())
        return true
    }

    override fun onScroll(e1: SMotionEvent, e2: SMotionEvent, distanceX: Float, distanceY: Float): Boolean {
        flag=false
        Log.e("item","滑动")
        return super.onScroll(e1, e2, distanceX, distanceY)
    }





    /**
     *
     * @param bm        传入的bitmap
     * @param newWidth  指定的图片宽
     * @param newHeight 指定的图片高
     * @return  newbm   返回 bitmap类型
     */
    private fun setImgSize(bm: Bitmap?, newWidth: Int, newHeight: Int): Bitmap {
        // 获得图片的宽高.
        val width = bm!!.width
        val height = bm.height
        // 计算缩放比例.
        val scaleWidth = newWidth.toFloat() / width
        val scaleHeight = newHeight.toFloat() / height
        // 取得想要缩放的matrix参数.
        val matrix = Matrix()
        matrix.postScale(scaleWidth, scaleHeight)
//        bm.config = Bitmap.Config.RGB_565
        // 得到新的图片.
        return Bitmap.createBitmap(bm, 0, 0, width, height, matrix, true)
    }
} // Class GraphyWallItem