/*
 * ********************************************************************************************************************
 *
 *               iFHS7.
 *              ;BBMBMBMc                  rZMBMBR              BMB
 *              MBEr:;PBM,               7MBMMEOBB:             BBB                       RBW
 *     XK:      BO     SB.     :SZ       MBM.       c;;     ir  BBM :FFr       :SSF:    ;xBMB:r   iuGXv.    i:. iF2;
 *     DBBM0r.  :D     S7   ;XMBMB       GMBMu.     MBM:   BMB  MBMBBBMBMS   WMBMBMBBK  MBMBMBM  BMBRBMBW  .MBMBMBMBB
 *      :JMRMMD  ..    ,  1MMRM1;         ;MBMBBR:   MBM  ;MB:  BMB:   MBM. RMBr   sBMH   BM0         UMB,  BMB.  KMBv
 *     ;.   XOW  B1; :uM: 1RE,   i           .2BMBs  rMB. MBO   MBO    JMB; MBB     MBM   BBS    7MBMBOBM:  MBW   :BMc
 *     OBRJ.SEE  MRDOWOR, 3DE:7OBM       .     ;BMB   RMR7BM    BMB    MBB. BMB    ,BMR  .BBZ   MMB   rMB,  BMM   rMB7
 *     :FBRO0D0  RKXSXPR. JOKOOMPi       BMBSSWBMB;    BMBB:    MBMB0ZMBMS  .BMBOXRBMB    MBMDE RBM2;SMBM;  MBB   xBM2
 *         iZGE  O0SHSPO. uGZ7.          sBMBMBDL      :BMO     OZu:BMBK,     rRBMB0;     ,EBMB  xBMBr:ER.  RDU   :OO;
 *     ,BZ, 1D0  RPSFHXR. xWZ .SMr                  . .BBB
 *      :0BMRDG  RESSSKR. 2WOMBW;                   BMBMR
 *         i0BM: SWKHKGO  MBDv
 *           .UB  OOGDM. MK,                                          Copyright (c) 2015-2019.  斯伯坦机器人
 *              ,  XMW  ..
 *                  r                                                                     All rights reserved.
 *
 * ********************************************************************************************************************
 */

package com.sybotan.android.graphy.items

import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.graphics.RectF
import android.util.Log
import com.sybotan.android.graphy.SGraphyItem
import com.sybotan.android.graphy.enums.SGraphyItemFlag
import java.util.*

/**
 * SGraphy图形引擎矩形框Item
 *
 * @author  庞利祥(sybotan@126.com)
 */
open class SGraphyRectItem(rect: RectF, parent: SGraphyItem? = null) : SGraphyItem(parent){
    /**
     * 类对象
     */
    companion object {
        private val TAG = SGraphyRectItem::class.java.name
    } // companion object

    /** 矩形区域 */
    var rect: RectF = rect
        set(value) {
            field = value
            invalidate()
        }
    /** 画笔 */
    private var pen = Paint()

    init {
        pen.color = Color.RED
        flags = EnumSet.of(SGraphyItemFlag.ItemIsMovable)
        isVisible = true
    } // init()

    /**
     * 构造函数
     *
     * @param   left        矩形左上角的x坐标
     * @param   top         矩形左上角的y坐标
     * @param   right       矩形右下角的x坐标
     * @param   bottom      矩形右下角的y坐标
     * @param   parent      指向父节点
     */
    constructor(left: Float, top: Float, right: Float, bottom: Float, parent: SGraphyItem? = null) : this(RectF(left, top, right, bottom), parent)

    /**
     * Item对象边界区域
     *
     * @return  边界区域
     */
    override fun boundingRect(): RectF {
        return rect
    } // Function boundingRect()

    /**
     * Item绘制操作
     *
     * @param   canvas      画布对象
     * @param   rect        更新区域
     */
    override fun onDraw(canvas: Canvas) {
        pen.color = if (this.isSelected) {
            Color.RED
        } else {
            Color.BLUE
        }
        canvas.drawRect(rect, pen)
        return
    } // Function paint()
} // Class SGraphyRectItem()