/*
 * ********************************************************************************************************************
 *                     :*$@@%$*:                         ;:                ;;    ;;
 *                   :@@%!  :!@@%:                       %!             ;%%@@%$ =@@@@@@@%;     @%@@@%%%%@@@@@
 *                  :@%;       :$=                       %%$$$%$$         ;$$  ;$@=   !@$
 *                  =@!                                  %!              @ $=;%   !@@@%:      !$$$$$$$$$$$$$$=
 *                  =@*                                  %!              @ $= % %@=   =%@!      %=
 *             *$%%! @@=        ;=$%%%$*:                %!              @ $= % =%%%%%%@$      *%:         =%
 *           %@@!:    !@@@%=$@@@@%!  :*@@$:              %!              @ $= % $*     ;@      @*          :%*
 *         ;@@!          ;!!!;:         ;@%:      =======@%========*     @ $$ % $%*****$@     :@$=*********=@$
 *         $@*   ;@@@%=!:                *@*
 *         =@$    ;;;!=%@@@@=!           =@!
 *          %@$:      =@%: :*@@@*       %@=                    Copyright (c) 2016-2018.  北京上格云技术有限公司
 *           ;%@@$=$@@%*       *@@@$=%@@%;
 *              ::;::             ::;::                                              All rights reservad.
 * ********************************************************************************************************************
 */

package cn.sagacloud.android.cadengine.test

import android.content.Context
import android.graphics.*
import android.util.Log


import com.sybotan.android.graphy.SGraphyItem
import com.sybotan.android.graphy.SMotionEvent
import com.sybotan.android.graphy.enums.SGraphyItemFlag
import java.util.*
import kotlin.math.log


/**
 * 设备
 * @author  Andy
 */
class GraphyFmItem(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.BLACK

    /**
     * 默认构造函数
     */
    init {

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

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



    } // 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("被点击1","**************************************")
        return true
    }

    /**
     *
     * @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