- 注册时间
- 2013-10-14
- 最后登录
- 2013-12-16
- 阅读权限
- 20
- 积分
- 132
- 精华
- 0
- 帖子
- 44
|
/**
* 此类用于使用 lufylegend 绘图应用程序编程接口 (API) 创建简单形状
* @class LShape
* @constructor
* @extends LSprite
*/
function LShape(){
base(this, LSprite, []);
this.type = "LShape";
this.toString = function (){
return "[object LShape]";
}
}
/**
*
* @class LSprite
*/
/**
* 检测是否是在遮罩范围内。
* @param {LMouseEvent} e 鼠标事件引用
* @param {Object} cd 包含当前抛出鼠标事件的对象基本信息的对象。{x: 0, y: 0, scaleX: 1, scaleY: 1, alpha: 1, rotate: 0};
* @return Boolean 当精灵没有遮罩或鼠标在遮罩范围内时返回true,否则返回false;
*/
LSprite.prototype.inMaskDomain = function(e, cd){
var s = this;
// console.log("LSprite.inMaskDomain(...) (s.mask instanceof LGraphics)" + (s.mask instanceof LGraphics));
// if(!(s.mask instanceof LGraphics)){
// return true;
// }
return s.mask.ismouseon(e, cd);
};
/**
* [重写函数] 原 LSprite.mouseEvent 检测鼠标事件是否发生在当前对象或其子对象上,若是则执行事件目标对象的鼠标事件处理器,
* 并终止鼠标事件继续传播,同时返回"true"。
* @method mouseEvent
* @param {LMouseEvent} e 鼠标事件对象
* @param {String} type 鼠标事件类型
* @param {Object} cd 包含当前抛出鼠标事件的对象基本信息的对象。{x: 0, y: 0, scaleX: 1, scaleY: 1, alpha: 1, rotate: 0};
* @returns {boolean}
*/
LSprite.prototype.mouseEvent = function (e,type,cd){
// console.log(this.name);
//console.log("core.js LSprite.mouseEvent(e, type, cd) -> e.type = " + e.type + ", type = " + type);
var returnBool = false; //返回是否有处理事件。
if(e==null || e == UNDEFINED)return false;
var s = this;
if(!s.mouseChildren || !s.visible)return false;
if(cd==null)cd={x:0,y:0,scaleX:1,scaleY:1};
var i,k,ox,oy;
if(e.offsetX == UNDEFINED){
ox = e.touches[0].pageX;
oy = e.touches[0].pageY;
}else{
ox = e.offsetX;
oy = e.offsetY;
}
// var mc = {x:s.x+cd.x,y:s.y+cd.y,scaleX:cd.scaleX*s.scaleX,scaleY:cd.scaleY*s.scaleY};
var mc = {x:s.x * cd.scaleX+cd.x,y:s.y * cd.scaleY+cd.y,scaleX:cd.scaleX*s.scaleX,scaleY:cd.scaleY*s.scaleY};
//检查是否在遮罩区域内。
if(s.mask && !s.inMaskDomain(e, cd)){
// if(type != LMouseEvent.MOUSE_MOVE){
// console.log("LSprite.mouseEvent(e,type, cd) s.mask.name = " + s.mask.name);
// console.log("LSprite.mouseEvent(e,type, cd) false = " + false);
// }
return false;
}
for(k=s.childList.length-1;k>=0;k--){
if(s.childList[k].mouseEvent){
i = s.childList[k].mouseEvent(e,type,mc);
/*
* 注意:
* lufylegend-1.7.7.js 中此处语句为 "if (i) return true;",即鼠标事件在遇到处理函数时,执行函数,而后就
* 不再向同级精灵与父级精灵传递事件。
* 在此让事件不再向同级别的底层精灵传递。但是继续向其上级传递。
*/
if (i){
returnBool = true;
//console.log("core.js LSprite.mouseEvent(e, type, cd) -> e.type = " + e.type);
//console.log("core.js LSprite.mouseEvent(e, type, cd) -> " + returnBool);
break;
}
}
}
/*
* 此处修改为图层无论是否添加鼠标侦听,都将使上层的鼠标事件不再传导到下层显示对象上。
* 即当作为最顶层中的最底层时,无论其有无侦听鼠标事件,只要鼠标在其上面点击,即事件直接上父级传播不再,向同级传播。
*/
// if(s.mouseList.length == 0) {
// return returnBool;
// }
if (returnBool && s.mouseList.length == 0) {
return returnBool;
}
// 检测鼠标事件是否发生在当前对象上,若是则执行其鼠标事件处理器。(未知是否会导致性能出现问题。)
var i = s.ismouseon(e, cd);
if(i){
// if(type != LMouseEvent.MOUSE_MOVE){
// console.log(this + ".mouseEvent(...) e.type = " + e.type + ", name = " + this.name + ", parent = " + this.parent);
// }
for(k=0;k<s.mouseList.length;k++){
var o = s.mouseList[k];
if(o.type == type){
/*e.type = type;*/ //此属性决定在 LGlobal.mouseEvent(...)里添加。
e.selfX = ox - (s.x+cd.x);
e.selfY = oy - (s.y+cd.y);
e.clickTarget = s;
if(o.listener instanceof Function){
/* try{*/
o.listener.apply(s, [e, s]);
/* }catch(err){
LGlobal.output(this+ ".mouseEvent(... ) [e, s] = " + [e, s] + " --> 错误名称:" + err.name + ", \n错误信息:" + err.message );
}*/
}else if(o.listener instanceof Delegate){
o.listener.run([e]);
}
//此处改为在代理的情况下使用代理。
// o.listener(e,s);
// 修改注释原语句是为了执行完所有的鼠标侦听。
// return true;
}
}
/*
* 注意:
* 此处原先语句为"return false",结果导致,下层显示对象在上层有遮挡时,依旧能够感应到鼠标事件。
*/
return true;
}else{
return returnBool;
}
};
LSprite.prototype.ismouseon = function(e,cd){
var s = this;
if(!s.visible || e==null)return false;
var k = null,i=false,l=s.childList;
// var sc={x:s.x+cd.x,y:s.y+cd.y,scaleX:cd.scaleX*s.scaleX,scaleY:cd.scaleY*s.scaleY,alpha:cd.alpha*s.alpha};
var sc={x:s.x * cd.scaleX+cd.x,y:s.y * cd.scaleY+cd.y,scaleX:cd.scaleX*s.scaleX,scaleY:cd.scaleY*s.scaleY,alpha:cd.alpha*s.alpha};
//当存在遮罩层的状态下,我们将将遮罩层做为鼠标事件的唯一感应区域,并判断遮罩层是否被鼠标单击到,并直接返回结果。
if(s.mask)
{ return s.mask.ismouseon(e, cd); }
//在没有遮罩层的状态下,将所有存在的子对象作为鼠标事件的感应区域。
for(k=l.length-1;k>=0;k--){
if(l[k].ismouseon)i = l[k].ismouseon(e,sc);
if(i)break;
}
if(!i && s.graphics)i = s.graphics.ismouseon(e,sc);
return i;
};
LSprite.prototype.setChildIndex = function(child/*isplayObject*/, index/*:int*/){
if(index < 0 || index >= s.childList.length){
return;
}
var s = this;
var i = s.childList.indexOf(child);
if(i == -1){
throw new Error(this + ".setChildIndex(child,index) 参数 child: " + child + " 不存在显示列表中!");
}
var arr = s.childList.splice(i,1);
s.childList.splice(index, 0, arr[0]);
};
LSprite.prototype.swapChildren = function(child1/*isplayObject*/, child2/*isplayObject*/)/*:void*/{
var s = this;
var index1 = s.childList.indexOf(child1);
var index2 = s.childList.indexOf(child2);
if(index1 == -1){
throw new Error(this + ".swapChildren(child1, child2) 参数 child1:" + child1 + " 不存在显示列表中!");
}else if(index2 == -1){
throw new Error(this + ".swapChildren(child1, child2) 参数 child2:" + child2 + " 不存在显示列表中!");
}
s.childList[index2] = child1;
s.childList[index1] = child2;
};
LSprite.prototype.swapChildrenAt = function(index1/*:int*/, index2/*:int*/)/*:void*/ {
var s = this;
if(index1 < 0 || index1 >= s.childList.length){
throw new Error(this + ".swapChildrenAt(index1, index2) 参数 index1:" + index1 + " 索引值超出合法范围!");
}else if(index2 < 0 || index2 >= s.childList.length){
throw new Error(this + ".swapChildrenAt(index1, index2) 参数 index2:" + index2 + " 索引值超出合法范围!");
}
var child1 = s.childList[index1];
var child2 = s.childList[index2];
s.childList[index1] = child2;
s.childList[index2] = child1;
};
/**
* 文本字段类。
* @class LTextField
*/
/**
* 【重写函数】 LTextField.mouseEvent(event,type,cood)
* @method mouseEvent
* @param {LMouseEvent} event
* @param {String} type
* @param {Object} cood
* @returns {*}
*/
LTextField.prototype.mouseEvent = function (event,type,cood){
if(cood==null)cood={x:0, y:0, scaleX:1, scaleY:1};
var s = this;
if(s.inputBackLayer == null)return;
return s.inputBackLayer.mouseEvent(event,type,{x:s.x * cood.scaleX+cood.x, y:s.y*cood.scaleY+cood.y, scaleX:s.scaleX*cood.scaleX,scaleY: s.scaleY * cood.scaleY, alpha:1,rotate:0});
};
LSprite.prototype.toString = function (){
return "[object LSprite]";
}; |
|