/** @language english
* <p>The LDisplayObject class is the base class for all objects that can be placed on the display list. The display list manages all objects displayed in the runtimes. Use the LDisplayObjectContainer class to arrange the display objects in the display list. LDisplayObjectContainer objects can have child display objects, while other display objects, such as LShape and LTextField objects, are "leaf" nodes that have only parents and siblings, no children.</p>
* <p>The LDisplayObject class supports basic functionality like the x and y position of an object, as well as more advanced properties of the object such as its transformation matrix.</p>
* <p>LDisplayObject is an abstract base class; therefore, you cannot call LDisplayObject directly. </p>
* <p>All display objects inherit from the LDisplayObject class.</p>
* @class LDisplayObject
* @extends LEventDispatcher
* @constructor
* @since 1.6.0
* @public
*/
var LDisplayObject = (function () {
function LDisplayObject () {
var s = this;
LExtends(s, LEventDispatcher, []);
s.name = "instance" + s.objectIndex;
/** @language english
* Indicates the x coordinate of the LDisplayObject instance relative to the local coordinates of the parent LDisplayObjectContainer. If the object is inside a LDisplayObjectContainer that has transformations, it is in the local coordinate system of the enclosing LDisplayObjectContainer. Thus, for a LDisplayObjectContainer rotated 90° counterclockwise, the LDisplayObjectContainer's children inherit a coordinate system that is rotated 90° counterclockwise. The object's coordinates refer to the registration point position.
* @property x
* @type float
* @default 0
* @since 1.6.0
* @public
*/
s.x = 0;
/** @language english
* Indicates the y coordinate of the LDisplayObject instance relative to the local coordinates of the parent LDisplayObjectContainer. If the object is inside a LDisplayObjectContainer that has transformations, it is in the local coordinate system of the enclosing LDisplayObjectContainer. Thus, for a LDisplayObjectContainer rotated 90° counterclockwise, the LDisplayObjectContainer's children inherit a coordinate system that is rotated 90° counterclockwise. The object's coordinates refer to the registration point position.
* @property y
* @type float
* @default 0
* @since 1.6.0
* @public
*/
s.y = 0;
s.width = 0;
s.height = 0;
/** @language english
* Indicates the horizontal scale (percentage) of the object as applied from the registration point. The default registration point is (0,0). 1.0 equals 100% scale.
* @property scaleX
* @type float
* @default 1
* @since 1.6.0
* @public
*/
s.scaleX = 1;
/** @language english
* Indicates the vertical scale (percentage) of an object as applied from the registration point of the object. The default registration point is (0,0). 1.0 is 100% scale.
* @property scaleY
* @type float
* @default 1
* @since 1.6.0
* @public
*/
s.scaleY = 1;
/** @language english
* Indicates the alpha transparency value of the object specified. Valid values are 0 (fully transparent) to 1 (fully opaque). The default value is 1. Display objects with alpha set to 0 are active, even though they are invisible.
* @property alpha
* @type float
* @default 0
* @since 1.6.0
* @public
*/
s.alpha = 1;
/** @language english
* Whether or not the display object is visible. Display objects that are not visible are disabled. For example, if visible=false for an LInteractiveObject instance, it cannot be clicked.
* @property visible
* @type Boolean
* @default true
* @since 1.6.0
* @public
*/
s.visible = true;
/** @language english
* Indicates the rotation of the LDisplayObject instance, in degrees, from its original orientation. Values from 0 to 180 represent clockwise rotation; values from 0 to -180 represent counterclockwise rotation. Values outside this range are added to or subtracted from 360 to obtain a value within the range. For example, the statement my_video.rotate = 450 is the same as my_video.rotate = 90.
* @property rotate
* @type float
* @default 0
* @since 1.6.0
* @public
*/
s.rotate = 0;
/** @language english
* The calling display object is masked by the specified mask object. To ensure that masking works when the Stage is scaled, the mask display object must be in an active part of the display list. The mask object itself is not drawn. Set mask to null to remove the mask.
* @property mask
* @type LDisplayObject
* @default null
* @since 1.6.0
* @public
*/
s.mask = null;
/** @language english
* A value from the LBlendMode class that specifies which blend mode to use. A bitmap can be drawn internally in two ways. If you have a blend mode enabled or an external clipping mask, the bitmap is drawn by adding a bitmap-filled square shape to the vector render. If you attempt to set this property to an invalid value, runtimes set the value to LBlendMode.NORMAL.
* @property blendMode
* @type String
* @default null
* @since 1.8.0
* @public
*/
s.blendMode = null;
/** @language english
* An indexed array that contains each filter object currently associated with the display object.
* @property filters
* @type Array
* @default null
* @since 1.6.0
* @public
*/
s.filters = null;
}
var p = {
_createCanvas:function(){
var s = this;
if (!s._canvas) {
s._canvas = document.createElement("canvas");
s._context = s._canvas.getContext("2d");
}
},
ll_show : function () {
var s = this, c = LGlobal.canvas;
if (!s._canShow()) {
return;
}
if (!LGlobal.box2d && typeof s._ll_loopframe == "function") {
s._ll_loopframe();
}
c.save();
s._showReady(c);
if (s.blendMode) {
c.globalCompositeOperation = s.blendMode;
}
if (s.filters) {
s._ll_setShadow();
}
s._rotateReady();
if (s.mask != null && s.mask.ll_show) {
s.mask.ll_show();
c.clip();
}
s._transformRotate();
s._transformScale();
s._coordinate(c);
if (s.alpha < 1) {
c.globalAlpha = s.alpha;
}
s._ll_show(c);
c.restore();
if (LGlobal.box2d != null && typeof s._ll_loopframe == "function") {
s._ll_loopframe();
}
},
_canShow : function () {
return this.visible;
},
_coordinate : function (c) {
var s = this;
if (s.x != 0 || s.y != 0) {
c.transform(1, 0, 0, 1, s.x, s.y);
}
},
_rotateReady : function () {},
_showReady : function (c) {},
_ll_show : function (c) {},
_ll_setShadow : function () {
var s = this, f = s.filters, i, l;
if (!f) {
return;
}
for (i = 0, l = f.length; i < l; i++) {
f[i].ll_show();
}
},
_transformRotate : function () {
var s = this, c;
if (s.rotate == 0) {
return;
}
c = LGlobal.canvas, rotateFlag = Math.PI / 180, rotateObj = new LMatrix();
if ((typeof s.rotatex) == UNDEFINED) {
s.rotatex = 0;
s.rotatey = 0;
}
if (s.box2dBody) {
rotateFlag = 1;
}
rotateObj.a = Math.cos(s.rotate * rotateFlag);
rotateObj.b = Math.sin(s.rotate * rotateFlag);
rotateObj.c = -rotateObj.b;
rotateObj.d = rotateObj.a;
rotateObj.tx = s.x + s.rotatex;
rotateObj.ty = s.y + s.rotatey;
rotateObj.transform(c).setTo(1, 0, 0, 1, -rotateObj.tx, -rotateObj.ty).transform(c);
},
_transformScale : function () {
var s = this,c = LGlobal.canvas, scaleObj;
if (s.scaleX == 1 && s.scaleY == 1) {
return;
}
scaleObj = new LMatrix();
if (s.scaleX != 1) {
scaleObj.tx = s.x;
}
if (s.scaleY != 1) {
scaleObj.ty = s.y;
}
scaleObj.a = s.scaleX;
scaleObj.d = s.scaleY;
scaleObj.transform(c).setTo(1, 0, 0, 1, -scaleObj.tx, -scaleObj.ty).transform(c);
},
copyProperty : function (a) {
var s = this, k;
for (k in a) {
if (typeof a[k] == "number" || typeof a[k] == "string" || typeof a[k] == "boolean") {
if (k == "objectindex" || k == "objectIndex") {
continue;
}
s[k] = a[k];
} else if (Array.isArray(a[k])) {
s[k] = a[k].slice();
}
}
if (a.mask) {
s.mask = a.mask.clone();
}
},
getAbsoluteScale : function () {
var s = this, sX, sY, p;
sX = s.scaleX;
sY = s.scaleY;
p = s.parent;
while (p && p != "root") {
sX *= p.scaleX;
sY *= p.scaleY;
p = p.parent;
}
return {scaleX : sX, scaleY : sY};
},
/** @language english
* Get the coordinates (Relative to the canvas).
* @method getRootCoordinate
* @return {LPoint} a LPoint object。
* @since 1.7.7
* @public
*/
getRootCoordinate : function () {
var s = this, sx, sy, p;
sx=s.x;
sy=s.y;
p = s.parent;
while (p && p != "root") {
sx *= p.scaleX;
sy *= p.scaleY;
sx += p.x;
sy += p.y;
p = p.parent;
}
return new LPoint(sx,sy);
},
/** @language english
* Returns a rectangle that defines the area of the display object relative to the coordinate system of the targetCoordinateSpace object.
* @method getBounds
* @param {LDisplayObject} targetCoordinateSpace The display object that defines the coordinate system to use.
* @return {LRectangle} The rectangle that defines the area of the display object relative to the targetCoordinateSpace object's coordinate system.
* @since 1.7.7
* @public
*/
getBounds : function (d) {
if (typeof d == UNDEFINED) {
return new LRectangle(0, 0, 0, 0);
}
var s = this, x = 0, y = 0, w = 0, h = 0, sp, dp;
if (s.objectIndex != d.objectIndex) {
sp = s.getRootCoordinate();
dp = d.getRootCoordinate();
x = sp.x - dp.x;
y = sp.y - dp.y;
}
if (d.getWidth) {
w = d.getWidth();
}
if (d.getHeight) {
h = d.getHeight();
}
return new LRectangle(x, y, w, h);
},
getDataCanvas : function () {
var s = this, _o, o, _c, c;
s._createCanvas();
o = LGlobal.canvasObj;
c = LGlobal.canvas;
_o = s._canvas;
_c = s._context;
s.width = s.getWidth();
s.height = s.getHeight();
_o.width = s.width;
_o.height = s.height;
_c.clearRect(0, 0, s.width, s.height);
LGlobal.canvasObj = s._canvas;
LGlobal.canvas = s._context;
s.ll_show();
s._canvas = _o;
s._context = _c;
LGlobal.canvasObj = o;
LGlobal.canvas = c;
return s._canvas;
},
/** @language english
* Get a string of base64-encoded image.
* @method getDataURL
* @return {Base64 Image} a string of base64-encoded image.
* @since 1.7.7
* @public
*/
getDataURL : function () {
var s = this, r = s.getDataCanvas();
return r.toDataURL();
},
ismouseonShapes : function (shapes, mx, my) {
var s = this, parent = s, m, child, j, v, arg;
if (typeof shapes == UNDEFINED) {
shapes = s.shapes;
}
m = s.getRootMatrix();
for (j = shapes.length - 1; j >= 0; j--) {
child = shapes[j];
arg = child.arg;
v = s._changeShape(child.type, arg, m);
if (child.type == LShape.VERTICES) {
if (LGlobal.hitPolygon(v, mx, my)) {
return true;
}
} else if (child.type == LShape.RECT) {
if (LGlobal.hitPolygon(v, mx, my)) {
return true;
}
} else if (child.type == LShape.ARC) {
if ((v[0] - mx) * (v[0] - mx) + (v[1] - my) * (v[1] - my) < v[3]) {
return true;
}
}
}
return false;
},
_changeShape : function (type, arg, m) {
var v, arg = arg, r2, i, l, v1, v2;
if (type == LShape.VERTICES) {
v = [];
for (i = 0, l = arg.length; i < l; i++) {
v[i] = m.toArray([arg[i][0], arg[i][1], 1]);
}
} else if (type == LShape.RECT) {
v = [[arg[0], arg[1]], [arg[0] + arg[2], arg[1]], [arg[0] + arg[2], arg[1] + arg[3]], [arg[0], arg[1] + arg[3]]];
for (i = 0, l = v.length; i < l; i++) {
v[i] = m.toArray([v[i][0], v[i][1],1]);
}
} else if (type == LShape.ARC) {
v1 = m.toArray([arg[0], arg[1], 1]);
v2 = m.toArray([arg[0] + arg[2], arg[1], 1]);
r2 = (v1[0] - v2[0]) * (v1[0] - v2[0]) + (v1[1] - v2[1]) * (v1[1] - v2[1]);
v = [v1[0], v1[1], Math.sqrt(r2), r2];
}
return v;
},
getRootMatrix : function () {
var parent = this, m = new LMatrix();
while (parent && parent != "root") {
if (parent.scaleX != 1 || parent.scaleY != 1) {
m.scale(parent.scaleX, parent.scaleY);
}
if (parent.rotate != 0) {
m.rotate(parent.rotate);
}
if (parent.x != 0 || parent.y != 0) {
m.translate(parent.x, parent.y);
}
parent = parent.parent;
}
return m;
},
/** @language english
* Remove self from the parent container.
* @method remove
* @since 1.7.7
* @public
*/
remove : function () {
var s = this, p = s.parent;
if (!p || p == "root") {
return;
}
p.removeChild(s);
}
};
for (var k in p) {
LDisplayObject.prototype[k] = p[k];
}
return LDisplayObject;
})();
/** @language english
* [broadcast event] Dispatched when the playhead is entering a new frame.
* <p><a href="LEvent.html#property_ENTER_FRAME">LEvent.ENTER_FRAME</a></p>
* @event LEvent.ENTER_FRAME
*/