import { GDispatcher } from "../../libs/tc/util/GDispatcher";

/**
 * Created by Administrator on 2017/8/11.
 */
export default class ItemCell1 extends eui.ItemRenderer
{
    public pic: any;
    public candrag:boolean;
    public img: egret.Bitmap;
    public shape: egret.Shape;

    constructor()
    {
        super();

        var iw:number = 116;
        var ih:number = 116;
        this.skinName = new ItemCell();
        this.shape = new egret.Shape();
        this.shape.graphics.beginFill(0);
        this.shape.graphics.drawRoundRect(0, 0, iw, ih, 20, 20);
        this.shape.graphics.endFill();
        // this.img = new egret.Bitmap();
        this.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this.onBegin, this);
        // this.addEventListener(egret.TouchEvent.TOUCH_END, ()=>{
        //     console.log(55555555)
        // }, this);
    }

    public dataChanged(): void
    {
        this.pic = this.data;
        this.img.texture = this.pic.texture;
        this.addChild(this.shape);
        this.shape.x = 11;
        this.shape.y = 10;
        this.img.mask = this.shape;
        this.img.visible = true;
    }

    public onBegin(e: egret.TouchEvent): void
    {
        this.img.visible = false;
        GDispatcher.dispatchEvent("dragStart", {pic: this.pic, callback: this.stopDrag.bind(this), ox: e.stageX, oy: e.stageY});
    }

    public stopDrag(): void
    {
        // if(pic)
        // {
        //     this.data = pic;
        //     this.dataChanged();
        // }
        // else
        // {
        //     GDispatcher.dispatchEvent("spliceItem", this.itemIndex);
        // }

        this.img.visible = true;
    }
}