mirror of
https://github.com/konvajs/konva.git
synced 2025-06-28 15:23:44 +08:00
refactored _getXY utility and usage
This commit is contained in:
parent
e4f5e11792
commit
7be0e5f577
49
dist/kinetic-core.js
vendored
49
dist/kinetic-core.js
vendored
@ -162,7 +162,12 @@ Kinetic.GlobalObject = {
|
||||
_isObject: function(obj) {
|
||||
return obj === Object(obj);
|
||||
},
|
||||
_getPoint: function(arg) {
|
||||
/*
|
||||
* takes the arguments passed into a function and
|
||||
* creates a point object from it. The arguments
|
||||
* can be an obect or an array
|
||||
*/
|
||||
_getXY: function(arg) {
|
||||
if(arg.length === 1) {
|
||||
return arg[0];
|
||||
}
|
||||
@ -544,7 +549,7 @@ Kinetic.Node.prototype = {
|
||||
* @param {Object} point
|
||||
*/
|
||||
setPosition: function() {
|
||||
var pos = Kinetic.GlobalObject._getPoint(arguments);
|
||||
var pos = Kinetic.GlobalObject._getXY(arguments);
|
||||
this.attrs.x = pos.x;
|
||||
this.attrs.y = pos.y;
|
||||
},
|
||||
@ -608,7 +613,7 @@ Kinetic.Node.prototype = {
|
||||
* y property
|
||||
*/
|
||||
setAbsolutePosition: function() {
|
||||
var pos = Kinetic.GlobalObject._getPoint(arguments);
|
||||
var pos = Kinetic.GlobalObject._getXY(arguments);
|
||||
/*
|
||||
* save rotation and scale and
|
||||
* then remove them from the transform
|
||||
@ -876,7 +881,7 @@ Kinetic.Node.prototype = {
|
||||
* @param {Number} y
|
||||
*/
|
||||
setCenterOffset: function() {
|
||||
var pos = Kinetic.GlobalObject._getPoint(arguments);
|
||||
var pos = Kinetic.GlobalObject._getXY(arguments);
|
||||
this.attrs.centerOffset.x = pos.x;
|
||||
this.attrs.centerOffset.y = pos.y;
|
||||
},
|
||||
@ -1676,7 +1681,7 @@ Kinetic.Stage.prototype = {
|
||||
* @param {Object} point
|
||||
*/
|
||||
getIntersections: function() {
|
||||
var pos = Kinetic.GlobalObject._getPoint(arguments);
|
||||
var pos = Kinetic.GlobalObject._getXY(arguments);
|
||||
var arr = [];
|
||||
var shapes = this.get('Shape');
|
||||
|
||||
@ -2452,11 +2457,16 @@ Kinetic.GlobalObject.extend(Kinetic.Group, Kinetic.Node);
|
||||
* @constructor
|
||||
* @augments Kinetic.Node
|
||||
* @param {Object} config
|
||||
* @config {String|CanvasGradient|CanvasPattern} [fill] fill
|
||||
* @config {String|Object} [fill] fill can be a string color, a linear gradient object, a radial
|
||||
* gradient object, or a pattern object.
|
||||
* @config {String} [stroke] stroke color
|
||||
* @config {Number} [strokeWidth] stroke width
|
||||
* @config {String} [lineJoin] line join. Can be "miter", "round", or "bevel". The default
|
||||
* @config {String} [lineJoin] line join can be "miter", "round", or "bevel". The default
|
||||
* is "miter"
|
||||
* @config {String} [shadowColor] shadow color
|
||||
* @config {Number} [shadowBlur] shadow blur
|
||||
* @config {Object|Array} [shadowOffset] shadow offset. The shadow offset obect should contain an object
|
||||
* with an x and y property, or an array with two elements that represent x, y
|
||||
* @config {String} [detectionType] shape detection type. Can be "path" or "pixel".
|
||||
* The default is "path" because it performs better
|
||||
*/
|
||||
@ -2547,8 +2557,8 @@ Kinetic.Shape.prototype = {
|
||||
}
|
||||
},
|
||||
/**
|
||||
* helper method to fill and stroke a shape
|
||||
* based on its fill, stroke, and strokeWidth, properties
|
||||
* helper method to fill the shape with a color, linear gradient,
|
||||
* radial gradient, or pattern
|
||||
*/
|
||||
fill: function() {
|
||||
var context = this.getContext();
|
||||
@ -2636,9 +2646,9 @@ Kinetic.Shape.prototype = {
|
||||
}
|
||||
},
|
||||
/**
|
||||
* set fill which can be a color, gradient object,
|
||||
* or pattern object
|
||||
* @param {String|CanvasGradient|CanvasPattern} fill
|
||||
* set fill which can be a color, linear gradient object,
|
||||
* radial gradient object, or pattern object
|
||||
* @param {String|Object} fill
|
||||
*/
|
||||
setFill: function(fill) {
|
||||
this.attrs.fill = fill;
|
||||
@ -2664,8 +2674,8 @@ Kinetic.Shape.prototype = {
|
||||
},
|
||||
/**
|
||||
* set line join
|
||||
* @param {String} lineJoin. Can be "miter", "round", or "bevel". The
|
||||
* default is "miter"
|
||||
* @param {String} lineJoin. Can be miter, round, or bevel. The
|
||||
* default is miter
|
||||
*/
|
||||
setLineJoin: function(lineJoin) {
|
||||
this.attrs.lineJoin = lineJoin;
|
||||
@ -2704,7 +2714,7 @@ Kinetic.Shape.prototype = {
|
||||
},
|
||||
/**
|
||||
* set shadow blur
|
||||
* @param {Integer}
|
||||
* @param {Number}
|
||||
*/
|
||||
setShadowBlur: function(blur) {
|
||||
this.attrs.shadowBlur = blur;
|
||||
@ -2717,10 +2727,11 @@ Kinetic.Shape.prototype = {
|
||||
},
|
||||
/**
|
||||
* set shadow offset
|
||||
* @param {Object} offset
|
||||
* @param {Object|Array} offset
|
||||
*/
|
||||
setShadowOffset: function(offset) {
|
||||
this.attrs.shadowOffset = offset;
|
||||
setShadowOffset: function() {
|
||||
var pos = Kinetic.GlobalObject._getXY(arguments);
|
||||
this.attrs.shadowOffset = pos;
|
||||
},
|
||||
/**
|
||||
* get shadow offset
|
||||
@ -2762,7 +2773,7 @@ Kinetic.Shape.prototype = {
|
||||
* determines if point is in the shape
|
||||
*/
|
||||
intersects: function() {
|
||||
var pos = Kinetic.GlobalObject._getPoint(arguments);
|
||||
var pos = Kinetic.GlobalObject._getXY(arguments);
|
||||
var stage = this.getStage();
|
||||
|
||||
if(this.attrs.detectionType === 'path') {
|
||||
|
4
dist/kinetic-core.min.js
vendored
4
dist/kinetic-core.min.js
vendored
File diff suppressed because one or more lines are too long
@ -134,7 +134,12 @@ Kinetic.GlobalObject = {
|
||||
_isObject: function(obj) {
|
||||
return obj === Object(obj);
|
||||
},
|
||||
_getPoint: function(arg) {
|
||||
/*
|
||||
* takes the arguments passed into a function and
|
||||
* creates a point object from it. The arguments
|
||||
* can be an obect or an array
|
||||
*/
|
||||
_getXY: function(arg) {
|
||||
if(arg.length === 1) {
|
||||
return arg[0];
|
||||
}
|
||||
|
@ -318,7 +318,7 @@ Kinetic.Node.prototype = {
|
||||
* @param {Object} point
|
||||
*/
|
||||
setPosition: function() {
|
||||
var pos = Kinetic.GlobalObject._getPoint(arguments);
|
||||
var pos = Kinetic.GlobalObject._getXY(arguments);
|
||||
this.attrs.x = pos.x;
|
||||
this.attrs.y = pos.y;
|
||||
},
|
||||
@ -382,7 +382,7 @@ Kinetic.Node.prototype = {
|
||||
* y property
|
||||
*/
|
||||
setAbsolutePosition: function() {
|
||||
var pos = Kinetic.GlobalObject._getPoint(arguments);
|
||||
var pos = Kinetic.GlobalObject._getXY(arguments);
|
||||
/*
|
||||
* save rotation and scale and
|
||||
* then remove them from the transform
|
||||
@ -650,7 +650,7 @@ Kinetic.Node.prototype = {
|
||||
* @param {Number} y
|
||||
*/
|
||||
setCenterOffset: function() {
|
||||
var pos = Kinetic.GlobalObject._getPoint(arguments);
|
||||
var pos = Kinetic.GlobalObject._getXY(arguments);
|
||||
this.attrs.centerOffset.x = pos.x;
|
||||
this.attrs.centerOffset.y = pos.y;
|
||||
},
|
||||
|
34
src/Shape.js
34
src/Shape.js
@ -7,11 +7,16 @@
|
||||
* @constructor
|
||||
* @augments Kinetic.Node
|
||||
* @param {Object} config
|
||||
* @config {String|CanvasGradient|CanvasPattern} [fill] fill
|
||||
* @config {String|Object} [fill] fill can be a string color, a linear gradient object, a radial
|
||||
* gradient object, or a pattern object.
|
||||
* @config {String} [stroke] stroke color
|
||||
* @config {Number} [strokeWidth] stroke width
|
||||
* @config {String} [lineJoin] line join. Can be "miter", "round", or "bevel". The default
|
||||
* @config {String} [lineJoin] line join can be "miter", "round", or "bevel". The default
|
||||
* is "miter"
|
||||
* @config {String} [shadowColor] shadow color
|
||||
* @config {Number} [shadowBlur] shadow blur
|
||||
* @config {Object|Array} [shadowOffset] shadow offset. The shadow offset obect should contain an object
|
||||
* with an x and y property, or an array with two elements that represent x, y
|
||||
* @config {String} [detectionType] shape detection type. Can be "path" or "pixel".
|
||||
* The default is "path" because it performs better
|
||||
*/
|
||||
@ -102,8 +107,8 @@ Kinetic.Shape.prototype = {
|
||||
}
|
||||
},
|
||||
/**
|
||||
* helper method to fill and stroke a shape
|
||||
* based on its fill, stroke, and strokeWidth, properties
|
||||
* helper method to fill the shape with a color, linear gradient,
|
||||
* radial gradient, or pattern
|
||||
*/
|
||||
fill: function() {
|
||||
var context = this.getContext();
|
||||
@ -191,9 +196,9 @@ Kinetic.Shape.prototype = {
|
||||
}
|
||||
},
|
||||
/**
|
||||
* set fill which can be a color, gradient object,
|
||||
* or pattern object
|
||||
* @param {String|CanvasGradient|CanvasPattern} fill
|
||||
* set fill which can be a color, linear gradient object,
|
||||
* radial gradient object, or pattern object
|
||||
* @param {String|Object} fill
|
||||
*/
|
||||
setFill: function(fill) {
|
||||
this.attrs.fill = fill;
|
||||
@ -219,8 +224,8 @@ Kinetic.Shape.prototype = {
|
||||
},
|
||||
/**
|
||||
* set line join
|
||||
* @param {String} lineJoin. Can be "miter", "round", or "bevel". The
|
||||
* default is "miter"
|
||||
* @param {String} lineJoin. Can be miter, round, or bevel. The
|
||||
* default is miter
|
||||
*/
|
||||
setLineJoin: function(lineJoin) {
|
||||
this.attrs.lineJoin = lineJoin;
|
||||
@ -259,7 +264,7 @@ Kinetic.Shape.prototype = {
|
||||
},
|
||||
/**
|
||||
* set shadow blur
|
||||
* @param {Integer}
|
||||
* @param {Number}
|
||||
*/
|
||||
setShadowBlur: function(blur) {
|
||||
this.attrs.shadowBlur = blur;
|
||||
@ -272,10 +277,11 @@ Kinetic.Shape.prototype = {
|
||||
},
|
||||
/**
|
||||
* set shadow offset
|
||||
* @param {Object} offset
|
||||
* @param {Object|Array} offset
|
||||
*/
|
||||
setShadowOffset: function(offset) {
|
||||
this.attrs.shadowOffset = offset;
|
||||
setShadowOffset: function() {
|
||||
var pos = Kinetic.GlobalObject._getXY(arguments);
|
||||
this.attrs.shadowOffset = pos;
|
||||
},
|
||||
/**
|
||||
* get shadow offset
|
||||
@ -317,7 +323,7 @@ Kinetic.Shape.prototype = {
|
||||
* determines if point is in the shape
|
||||
*/
|
||||
intersects: function() {
|
||||
var pos = Kinetic.GlobalObject._getPoint(arguments);
|
||||
var pos = Kinetic.GlobalObject._getXY(arguments);
|
||||
var stage = this.getStage();
|
||||
|
||||
if(this.attrs.detectionType === 'path') {
|
||||
|
@ -367,7 +367,7 @@ Kinetic.Stage.prototype = {
|
||||
* @param {Object} point
|
||||
*/
|
||||
getIntersections: function() {
|
||||
var pos = Kinetic.GlobalObject._getPoint(arguments);
|
||||
var pos = Kinetic.GlobalObject._getXY(arguments);
|
||||
var arr = [];
|
||||
var shapes = this.get('Shape');
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user