Focusable.js 3.26 KB
var Common = require('Common');

cc.Class({
    extends: cc.Component,

    properties: {
        
        // TODO: to be a real Component?
        //_fLeft:0,
        //_fTop:0,
        //_fWidth:0,
        //_fHeight:0,
        //_oFocusNode:null,//deprecated
        _strTVLink:'',
        _bEnable:false
    },


    //ctor: function (fLeft,fTop,fWidth,fHeight,oFocusNode) {
    ctor: function () {
    
        //this._fLeft=arguments[0];
        //this._fTop=arguments[1];
        //this._fWidth=arguments[2];
        //this._fHeight=arguments[3];
        //this._oFocusNode=arguments[4];
        this._strTVLink=arguments[0];
        this._bEnable=arguments[1];
        //this._fLeft=fLeft;
        //this._fTop=fTop;
        //this._fWidth=fWidth;
        //this._fHeight=fHeight;
        //this._oFocusNode=oFocusNode;

    },

    init: function (/*fLeft,fTop,fWidth,fHeight,oFocusNode,*/strTVLink,bEnable) {
    
        //this._fLeft=arguments[0];
        //this._fTop=arguments[1];
        //this._fWidth=arguments[2];
        //this._fHeight=arguments[3];
        //this._oFocusNode=arguments[4];
        this._strTVLink=strTVLink;
        this._bEnable=bEnable;
        //this._fLeft=fLeft;
        //this._fTop=fTop;
        //this._fWidth=fWidth;
        //this._fHeight=fHeight;
        //this._oFocusNode=oFocusNode;

    },

    // use this for initialization
    onLoad: function () {

    },

    // called every frame, uncomment this function to activate update callback
    // update: function (dt) {

    // },



    getLeft:function(){
        //return this._fLeft;
        
        return Common.SCREEN_WIDTH/2+(this.getX()-this.node.width/2);
    },


    //setLeft:function(fLeft){
    //    this._fLeft=fLeft;
    //},

    getTop:function(){
        //return this._fTop;
        return Common.SCREEN_HEIGHT/2-(this.getY()+this.node.height/2);
    },

    getX:function(){
        let tempNode=this.node;
        let fCenterX=0;
        while (tempNode.parent.parent){//不算TopCanvas
            //cc.log(tempNode.name+"  X: "+tempNode.x)
            fCenterX+=tempNode.x;
            tempNode=tempNode.parent;
        }
        return fCenterX;
    },
    getY:function(){
        let tempNode=this.node;
        let fCenterY=0;
        while (tempNode.parent.parent){//不算TopCanvas
            //cc.log(tempNode.name+"  Y: "+tempNode.y)
            fCenterY+=tempNode.y;
            tempNode=tempNode.parent;
        }
        return fCenterY;
    },
    //setTop:function(fTop){
    //   this._fTop=fTop;
    //},
    getWidth:function(){
        //return this._fWidth;
        return this.node.width; 
    },
    //setWidth:function(fWidth){
    //    this._fWidth=fWidth;
    //},
    getHeight:function(){
        //return this._fHeight;
        return this.node.height;
    },
    //setHeight:function(fHeight){
    //    this._fHeight=fHeight;
    //},
    //getFocusNode:function(){
    //    return this._oFocusNode;
    //},
    //setFocusNode:function(oFocusNode){
    //    this._oFocusNode=oFocusNode;
    //},
    getTVLink:function(){
        return this._strTVLink;
    },
    setTVLink:function(strTVLink){
        this._strTVLink=strTVLink;
    },
    getEnable:function(){
        return this._bEnable;
    },
    setEnable:function(bEnable){
        this._bEnable=bEnable;
    }

});