mirror of
https://github.com/konvajs/konva.git
synced 2026-01-09 11:34:38 +08:00
more unit tests working, more refactoring
This commit is contained in:
@@ -218,19 +218,18 @@
|
||||
* @method
|
||||
* @memberof Kinetic.Container.prototype
|
||||
* @param {Object} pos
|
||||
* @param {Number} pos.x
|
||||
* @param {Number} pos.y
|
||||
* @returns {Array} array of shapes
|
||||
*/
|
||||
getAllIntersections: function() {
|
||||
var pos = Kinetic.Util._getXY(Array.prototype.slice.call(arguments));
|
||||
getAllIntersections: function(pos) {
|
||||
var arr = [];
|
||||
var shapes = this.find('Shape');
|
||||
|
||||
var len = shapes.length;
|
||||
for(var n = 0; n < len; n++) {
|
||||
var shape = shapes[n];
|
||||
this.find('Shape').each(function(shape) {
|
||||
if(shape.isVisible() && shape.intersects(pos)) {
|
||||
arr.push(shape);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return arr;
|
||||
},
|
||||
@@ -297,19 +296,16 @@
|
||||
Kinetic.Container.prototype.get = Kinetic.Container.prototype.find;
|
||||
|
||||
// add getters setters
|
||||
Kinetic.Factory.addBoxGetterSetter(Kinetic.Container, 'clip');
|
||||
Kinetic.Factory.addGetterSetter(Kinetic.Container, 'clip');
|
||||
|
||||
/**
|
||||
* set clip
|
||||
* @method
|
||||
* @name setClip
|
||||
* @memberof Kinetic.Container.prototype
|
||||
* @param {Object|Array}
|
||||
* @param {Object} clip {x:x, y:y, width:width, height:height}
|
||||
* @example
|
||||
* // set clip x, y, width and height with an array<br>
|
||||
* image.setClip([20, 20, 100, 100]);<br><br>
|
||||
*
|
||||
* // set clip x, y, width and height with an object<br>
|
||||
* // set clip x, y, width and height<br>
|
||||
* image.setClip({<br>
|
||||
* x: 20,<br>
|
||||
* y: 20,<br>
|
||||
@@ -318,44 +314,21 @@
|
||||
* });
|
||||
*/
|
||||
|
||||
/**
|
||||
* set clipX
|
||||
* @method
|
||||
* @name setClipX
|
||||
* @memberof Kinetic.Container.prototype
|
||||
* @param {Number} x
|
||||
*/
|
||||
|
||||
/**
|
||||
* set clipY
|
||||
* @name setClipY
|
||||
* @method
|
||||
* @memberof Kinetic.Container.prototype
|
||||
* @param {Number} y
|
||||
*/
|
||||
|
||||
/**
|
||||
* set clipWidth
|
||||
* @name setClipWidth
|
||||
* @method
|
||||
* @memberof Kinetic.Container.prototype
|
||||
* @param {Number} width
|
||||
*/
|
||||
|
||||
/**
|
||||
* set clipHeight
|
||||
* @name setClipHeight
|
||||
* @method
|
||||
* @memberof Kinetic.Container.prototype
|
||||
* @param {Number} height
|
||||
*/
|
||||
|
||||
/**
|
||||
* get clip
|
||||
* @name getClip
|
||||
* @method
|
||||
* @memberof Kinetic.Container.prototype
|
||||
* @return {Object}
|
||||
* @returns {Object}
|
||||
*/
|
||||
|
||||
Kinetic.Factory.addComponentGetterSetter(Kinetic.Container, 'clip', 'x', 0);
|
||||
/**
|
||||
* set clip x
|
||||
* @method
|
||||
* @name setClipX
|
||||
* @memberof Kinetic.Container.prototype
|
||||
* @param {Number} x
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -363,6 +336,16 @@
|
||||
* @name getClipX
|
||||
* @method
|
||||
* @memberof Kinetic.Container.prototype
|
||||
* @returns {Number}
|
||||
*/
|
||||
|
||||
Kinetic.Factory.addComponentGetterSetter(Kinetic.Container, 'clip', 'y', 0);
|
||||
/**
|
||||
* set clip y
|
||||
* @name setClipY
|
||||
* @method
|
||||
* @memberof Kinetic.Container.prototype
|
||||
* @param {Number} y
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -370,6 +353,16 @@
|
||||
* @name getClipY
|
||||
* @method
|
||||
* @memberof Kinetic.Container.prototype
|
||||
* @returns {Number}
|
||||
*/
|
||||
|
||||
Kinetic.Factory.addComponentGetterSetter(Kinetic.Container, 'clip', 'width', 0);
|
||||
/**
|
||||
* set clip width
|
||||
* @name setClipWidth
|
||||
* @method
|
||||
* @memberof Kinetic.Container.prototype
|
||||
* @param {Number} width
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -377,6 +370,16 @@
|
||||
* @name getClipWidth
|
||||
* @method
|
||||
* @memberof Kinetic.Container.prototype
|
||||
* @returns {Number}
|
||||
*/
|
||||
|
||||
Kinetic.Factory.addComponentGetterSetter(Kinetic.Container, 'clip', 'height', 0);
|
||||
/**
|
||||
* set clip height
|
||||
* @name setClipHeight
|
||||
* @method
|
||||
* @memberof Kinetic.Container.prototype
|
||||
* @param {Number} height
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -384,6 +387,6 @@
|
||||
* @name getClipHeight
|
||||
* @method
|
||||
* @memberof Kinetic.Container.prototype
|
||||
* @returns {Number}
|
||||
*/
|
||||
|
||||
})();
|
||||
|
||||
@@ -226,8 +226,8 @@
|
||||
this.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
|
||||
},
|
||||
_clip: function(container) {
|
||||
var clipX = container.getClipX() || 0,
|
||||
clipY = container.getClipY() || 0,
|
||||
var clipX = container.getClipX(),
|
||||
clipY = container.getClipY(),
|
||||
clipWidth = container.getClipWidth(),
|
||||
clipHeight = container.getClipHeight();
|
||||
|
||||
|
||||
10
src/Layer.js
10
src/Layer.js
@@ -44,11 +44,13 @@
|
||||
* method for determining if a point intersects a shape or not
|
||||
* @method
|
||||
* @memberof Kinetic.Layer.prototype
|
||||
* @param {Kinetic.Shape|null} shape
|
||||
* @param {Object} pos
|
||||
* @param {Number} pos.x
|
||||
* @param {Number} pos.y
|
||||
* @returns {Kinetic.Shape}
|
||||
*/
|
||||
getIntersection: function() {
|
||||
var pos = Kinetic.Util._getXY(Array.prototype.slice.call(arguments)),
|
||||
obj, i, intersectionOffset, shape;
|
||||
getIntersection: function(pos) {
|
||||
var obj, i, intersectionOffset, shape;
|
||||
|
||||
if(this.isVisible()) {
|
||||
for (i=0; i<INTERSECTION_OFFSETS_LEN; i++) {
|
||||
|
||||
@@ -633,7 +633,7 @@
|
||||
y += changeY;
|
||||
}
|
||||
|
||||
this.setPosition(x, y);
|
||||
this.setPosition({x:x, y:y});
|
||||
return this;
|
||||
},
|
||||
_eachAncestorReverse: function(func, includeSelf) {
|
||||
|
||||
13
src/Shape.js
13
src/Shape.js
@@ -106,14 +106,13 @@
|
||||
* because it performs much better
|
||||
* @method
|
||||
* @memberof Kinetic.Shape.prototype
|
||||
* @param {Object} point point can be an object containing
|
||||
* an x and y property, or it can be an array with two elements
|
||||
* in which the first element is the x component and the second
|
||||
* element is the y component
|
||||
* @param {Object} point
|
||||
* @param {Number} point.x
|
||||
* @param {Number} point.y
|
||||
* @returns {Boolean}
|
||||
*/
|
||||
intersects: function() {
|
||||
var pos = Kinetic.Util._getXY(Array.prototype.slice.call(arguments)),
|
||||
stage = this.getStage(),
|
||||
intersects: function(pos) {
|
||||
var stage = this.getStage(),
|
||||
bufferHitCanvas = stage.bufferHitCanvas,
|
||||
p;
|
||||
|
||||
|
||||
10
src/Stage.js
10
src/Stage.js
@@ -254,11 +254,13 @@
|
||||
* method for determining if a point intersects a shape or not
|
||||
* @method
|
||||
* @memberof Kinetic.Stage.prototype
|
||||
* @param {Kinetic.Shape} shape
|
||||
* @param {Object} pos
|
||||
* @param {Number} pos.x
|
||||
* @param {Number} pos.y
|
||||
* @returns {Kinetic.Shape}
|
||||
*/
|
||||
getIntersection: function() {
|
||||
var pos = Kinetic.Util._getXY(Array.prototype.slice.call(arguments)),
|
||||
layers = this.getChildren(),
|
||||
getIntersection: function(pos) {
|
||||
var layers = this.getChildren(),
|
||||
len = layers.length,
|
||||
end = len - 1,
|
||||
n, shape;
|
||||
|
||||
Reference in New Issue
Block a user