created new addSettersGetters method, further enhanced dynamic getters and setters

This commit is contained in:
Eric Rowell
2012-06-23 18:09:10 -07:00
parent 80eb50a708
commit c1a08d8073
17 changed files with 160 additions and 184 deletions

170
dist/kinetic-core.js vendored
View File

@@ -79,6 +79,10 @@ Kinetic.GlobalObject = {
this._addGetter(constructor, attr); this._addGetter(constructor, attr);
} }
}, },
addSettersGetters: function(constructor, arr) {
this.addSetters(constructor, arr);
this.addGetters(constructor, arr);
},
_pullNodes: function(stage) { _pullNodes: function(stage) {
var tempNodes = this.tempNodes; var tempNodes = this.tempNodes;
for(var n = 0; n < tempNodes.length; n++) { for(var n = 0; n < tempNodes.length; n++) {
@@ -362,7 +366,14 @@ Kinetic.GlobalObject = {
_addSetter: function(constructor, attr) { _addSetter: function(constructor, attr) {
var that = this; var that = this;
var method = 'set' + attr.charAt(0).toUpperCase() + attr.slice(1); var method = 'set' + attr.charAt(0).toUpperCase() + attr.slice(1);
constructor.prototype[method] = function(arg) { constructor.prototype[method] = function() {
var arg;
if(arguments.length == 1) {
arg = arguments[0];
}
else {
arg = Array.prototype.slice.call(arguments);
}
var obj = {}; var obj = {};
obj[attr] = arg; obj[attr] = arg;
this.setAttrs(obj); this.setAttrs(obj);
@@ -727,15 +738,6 @@ Kinetic.Node.prototype = {
} }
return level; return level;
}, },
/**
* set node scale.
* @param arg
*/
setScale: function() {
this.setAttrs({
scale: Array.prototype.slice.call(arguments)
});
},
/** /**
* set node position * set node position
* @param {Object} point * @param {Object} point
@@ -826,13 +828,6 @@ Kinetic.Node.prototype = {
y: y y: y
}); });
}, },
/**
* set node rotation in degrees
* @param {Number} deg
*/
setRotationDeg: function(deg) {
this.setRotation(deg * Math.PI / 180);
},
/** /**
* get rotation in degrees * get rotation in degrees
*/ */
@@ -979,16 +974,6 @@ Kinetic.Node.prototype = {
simulate: function(eventType) { simulate: function(eventType) {
this._handleEvent(eventType, {}); this._handleEvent(eventType, {});
}, },
/**
* set offset
* @param {Number} x
* @param {Number} y
*/
setOffset: function() {
this.setAttrs({
offset: Array.prototype.slice.call(arguments)
});
},
/** /**
* transition node to another state. Any property that can accept a real * transition node to another state. Any property that can accept a real
* number can be transitioned, including x, y, rotation, alpha, strokeWidth, * number can be transitioned, including x, y, rotation, alpha, strokeWidth,
@@ -1181,8 +1166,8 @@ Kinetic.Node.prototype = {
}; };
// add setters and getters // add setters and getters
Kinetic.GlobalObject.addSetters(Kinetic.Node, ['x', 'y', 'detectionType', 'rotation', 'alpha', 'name', 'id', 'draggable', 'dragConstraint', 'dragBounds', 'listening']); Kinetic.GlobalObject.addSettersGetters(Kinetic.Node, ['x', 'y', 'scale', 'detectionType', 'rotation', 'alpha', 'name', 'id', 'offset', 'draggable', 'dragConstraint', 'dragBounds', 'listening']);
Kinetic.GlobalObject.addGetters(Kinetic.Node, ['scale', 'x', 'y', 'detectionType', 'rotation', 'alpha', 'name', 'id', 'draggable', 'offset', 'dragConstraint', 'dragBounds', 'listening']); Kinetic.GlobalObject.addSetters(Kinetic.Node, ['rotationDeg']);
/** /**
* set node x position * set node x position
@@ -1253,6 +1238,28 @@ Kinetic.GlobalObject.addGetters(Kinetic.Node, ['scale', 'x', 'y', 'detectionType
* @param {Boolean} listening * @param {Boolean} listening
*/ */
/**
* set node rotation in degrees
* @name setRotationDeg
* @methodOf Kinetic.Node.prototype
* @param {Number} deg
*/
/**
* set offset
* @name setOffset
* @methodOf Kinetic.Node.prototype
* @param {Number} x
* @param {Number} y
*/
/**
* set node scale.
* @name setScale
* @param {Number|Array|Object|List} scale
* @methodOf Kinetic.Node.prototype
*/
/** /**
* get scale * get scale
* @name getScale * @name getScale
@@ -2546,8 +2553,7 @@ Kinetic.GlobalObject.extend(Kinetic.Stage, Kinetic.Container);
Kinetic.GlobalObject.extend(Kinetic.Stage, Kinetic.Node); Kinetic.GlobalObject.extend(Kinetic.Stage, Kinetic.Node);
// add setters and getters // add setters and getters
Kinetic.GlobalObject.addSetters(Kinetic.Stage, ['width', 'height', 'throttle']); Kinetic.GlobalObject.addSettersGetters(Kinetic.Stage, ['width', 'height', 'throttle']);
Kinetic.GlobalObject.addGetters(Kinetic.Stage, ['width', 'height', 'throttle']);
/** /**
* get width * get width
@@ -2743,8 +2749,7 @@ Kinetic.GlobalObject.extend(Kinetic.Layer, Kinetic.Container);
Kinetic.GlobalObject.extend(Kinetic.Layer, Kinetic.Node); Kinetic.GlobalObject.extend(Kinetic.Layer, Kinetic.Node);
// add setters and getters // add setters and getters
Kinetic.GlobalObject.addSetters(Kinetic.Layer, ['clearBeforeDraw']); Kinetic.GlobalObject.addSettersGetters(Kinetic.Layer, ['clearBeforeDraw']);
Kinetic.GlobalObject.addGetters(Kinetic.Layer, ['clearBeforeDraw']);
/** /**
* set flag which determines if the layer is cleared or not * set flag which determines if the layer is cleared or not
@@ -2997,10 +3002,10 @@ Kinetic.Shape.prototype = {
} }
// defaults // defaults
if(this.attrs.textStroke) { if(!this.attrs.textStroke) {
this.attrs.textStroke = 'black'; this.attrs.textStroke = 'black';
} }
else if(this.attrs.textStrokeWidth && this.attrs.textStrokeWidth !== 0) { else if(!this.attrs.textStrokeWidth && this.attrs.textStrokeWidth !== 0) {
this.attrs.textStrokeWidth = 2; this.attrs.textStrokeWidth = 2;
} }
context.lineWidth = this.attrs.textStrokeWidth; context.lineWidth = this.attrs.textStrokeWidth;
@@ -3180,8 +3185,7 @@ Kinetic.Shape.prototype = {
Kinetic.GlobalObject.extend(Kinetic.Shape, Kinetic.Node); Kinetic.GlobalObject.extend(Kinetic.Shape, Kinetic.Node);
// add setters and getters // add setters and getters
Kinetic.GlobalObject.addSetters(Kinetic.Shape, ['fill', 'stroke', 'lineJoin', 'strokeWidth', 'shadow', 'drawFunc']); Kinetic.GlobalObject.addSettersGetters(Kinetic.Shape, ['fill', 'stroke', 'lineJoin', 'strokeWidth', 'shadow', 'drawFunc']);
Kinetic.GlobalObject.addGetters(Kinetic.Shape, ['fill', 'stroke', 'lineJoin', 'strokeWidth', 'shadow', 'drawFunc']);
/** /**
* set fill which can be a color, linear gradient object, * set fill which can be a color, linear gradient object,
@@ -3333,8 +3337,7 @@ Kinetic.Rect.prototype = {
Kinetic.GlobalObject.extend(Kinetic.Rect, Kinetic.Shape); Kinetic.GlobalObject.extend(Kinetic.Rect, Kinetic.Shape);
// add setters and getters // add setters and getters
Kinetic.GlobalObject.addSetters(Kinetic.Rect, ['width', 'height', 'cornerRadius']); Kinetic.GlobalObject.addSettersGetters(Kinetic.Rect, ['width', 'height', 'cornerRadius']);
Kinetic.GlobalObject.addGetters(Kinetic.Rect, ['width', 'height', 'cornerRadius']);
/** /**
* set width * set width
@@ -3422,21 +3425,6 @@ Kinetic.Ellipse = function(config) {
Kinetic.Circle = Kinetic.Ellipse; Kinetic.Circle = Kinetic.Ellipse;
Kinetic.Ellipse.prototype = { Kinetic.Ellipse.prototype = {
/**
* set radius
* @param {Number|Object|Array} radius
* radius can be a number, in which the ellipse becomes a circle,
* it can be an object with an x and y component, or it
* can be an array in which the first element is the x component
* and the second element is the y component. The x component
* defines the horizontal radius and the y component
* defines the vertical radius
*/
setRadius: function() {
this.setAttrs({
radius: Array.prototype.slice.call(arguments)
});
},
/** /**
* converts numeric radius into an object * converts numeric radius into an object
*/ */
@@ -3449,15 +3437,26 @@ Kinetic.Ellipse.prototype = {
} }
var pos = go._getXY(radius); var pos = go._getXY(radius);
this.setAttrs({ this.setAttrs({
radius: pos radius: pos
}); });
} }
}; };
// extend Shape // extend Shape
Kinetic.GlobalObject.extend(Kinetic.Ellipse, Kinetic.Shape); Kinetic.GlobalObject.extend(Kinetic.Ellipse, Kinetic.Shape);
// add setters and getters // add setters and getters
Kinetic.GlobalObject.addGetters(Kinetic.Ellipse, ['radius']); Kinetic.GlobalObject.addSettersGetters(Kinetic.Ellipse, ['radius']);
/**
* set radius
* @param {Number|Object|Array} radius
* radius can be a number, in which the ellipse becomes a circle,
* it can be an object with an x and y component, or it
* can be an array in which the first element is the x component
* and the second element is the y component. The x component
* defines the horizontal radius and the y component
* defines the vertical radius
*/
/** /**
* get radius * get radius
@@ -3531,21 +3530,12 @@ Kinetic.Image.prototype = {
width: this.attrs.width, width: this.attrs.width,
height: this.attrs.height height: this.attrs.height
}; };
},
/**
* set crop
*/
setCrop: function() {
this.setAttrs({
crop: Array.prototype.slice.call(arguments)
});
} }
}; };
// extend Shape // extend Shape
Kinetic.GlobalObject.extend(Kinetic.Image, Kinetic.Shape); Kinetic.GlobalObject.extend(Kinetic.Image, Kinetic.Shape);
// add setters and getters // add setters and getters
Kinetic.GlobalObject.addSetters(Kinetic.Image, ['height', 'width', 'image']); Kinetic.GlobalObject.addSettersGetters(Kinetic.Image, ['height', 'width', 'image', 'crop']);
Kinetic.GlobalObject.addGetters(Kinetic.Image, ['crop', 'height', 'width', 'image']);
/** /**
* set width * set width
@@ -3568,6 +3558,13 @@ Kinetic.GlobalObject.addGetters(Kinetic.Image, ['crop', 'height', 'width', 'imag
* @param {ImageObject} image * @param {ImageObject} image
*/ */
/**
* set crop
* @name setCrop
* @methodOf Kinetic.Image.prototype
* @param {Object} config
*/
/** /**
* get crop * get crop
* @name getCrop * @name getCrop
@@ -3677,8 +3674,7 @@ Kinetic.Sprite.prototype = {
Kinetic.GlobalObject.extend(Kinetic.Sprite, Kinetic.Shape); Kinetic.GlobalObject.extend(Kinetic.Sprite, Kinetic.Shape);
// add setters and getters // add setters and getters
Kinetic.GlobalObject.addSetters(Kinetic.Sprite, ['animation', 'animations', 'index']); Kinetic.GlobalObject.addSettersGetters(Kinetic.Sprite, ['animation', 'animations', 'index']);
Kinetic.GlobalObject.addGetters(Kinetic.Sprite, ['animation', 'animations', 'index']);
/** /**
* set animation key * set animation key
@@ -3751,8 +3747,7 @@ Kinetic.Polygon = function(config) {
Kinetic.GlobalObject.extend(Kinetic.Polygon, Kinetic.Shape); Kinetic.GlobalObject.extend(Kinetic.Polygon, Kinetic.Shape);
// add setters and getters // add setters and getters
Kinetic.GlobalObject.addSetters(Kinetic.Polygon, ['points']); Kinetic.GlobalObject.addSettersGetters(Kinetic.Polygon, ['points']);
Kinetic.GlobalObject.addGetters(Kinetic.Polygon, ['points']);
/** /**
* set points array * set points array
@@ -3804,8 +3799,7 @@ Kinetic.RegularPolygon = function(config) {
Kinetic.GlobalObject.extend(Kinetic.RegularPolygon, Kinetic.Shape); Kinetic.GlobalObject.extend(Kinetic.RegularPolygon, Kinetic.Shape);
// add setters and getters // add setters and getters
Kinetic.GlobalObject.addSetters(Kinetic.Rect, ['radius', 'sides']); Kinetic.GlobalObject.addSettersGetters(Kinetic.Rect, ['radius', 'sides']);
Kinetic.GlobalObject.addGetters(Kinetic.Rect, ['radius', 'sides']);
/** /**
* set radius * set radius
@@ -3871,8 +3865,7 @@ Kinetic.Star = function(config) {
Kinetic.GlobalObject.extend(Kinetic.Star, Kinetic.Shape); Kinetic.GlobalObject.extend(Kinetic.Star, Kinetic.Shape);
// add setters and getters // add setters and getters
Kinetic.GlobalObject.addSetters(Kinetic.Star, ['numPoints', 'innerRadius', 'outerRadius']); Kinetic.GlobalObject.addSettersGetters(Kinetic.Star, ['numPoints', 'innerRadius', 'outerRadius']);
Kinetic.GlobalObject.addGetters(Kinetic.Star, ['numPoints', 'innerRadius', 'outerRadius']);
/** /**
* set number of points * set number of points
@@ -4034,8 +4027,7 @@ Kinetic.Text.prototype = {
Kinetic.GlobalObject.extend(Kinetic.Text, Kinetic.Shape); Kinetic.GlobalObject.extend(Kinetic.Text, Kinetic.Shape);
// add setters and getters // add setters and getters
Kinetic.GlobalObject.addSetters(Kinetic.Text, ['fontFamily', 'fontSize', 'fontStyle', 'textFill', 'textStroke', 'textStrokeWidth', 'padding', 'align', 'verticalAlign', 'text', 'width']); Kinetic.GlobalObject.addSettersGetters(Kinetic.Text, ['fontFamily', 'fontSize', 'fontStyle', 'textFill', 'textStroke', 'textStrokeWidth', 'padding', 'align', 'verticalAlign', 'text', 'width']);
Kinetic.GlobalObject.addGetters(Kinetic.Text, ['fontFamily', 'fontSize', 'fontStyle', 'textFill', 'textStroke', 'textStrokeWidth', 'padding', 'align', 'verticalAlign', 'text', 'width']);
/** /**
* set font family * set font family
@@ -4232,16 +4224,6 @@ Kinetic.Line = function(config) {
* Line methods * Line methods
*/ */
Kinetic.Line.prototype = { Kinetic.Line.prototype = {
/**
* set points array
* @param {Array} can be an array of point objects or an array
* of Numbers. e.g. [{x:1,y:2},{x:3,y:4}] or [1,2,3,4]
*/
setPoints: function(points) {
this.setAttrs({
points: points
});
},
/** /**
* draw dashed line. Written by Phrogz * draw dashed line. Written by Phrogz
*/ */
@@ -4294,8 +4276,7 @@ Kinetic.Line.prototype = {
// extend Shape // extend Shape
Kinetic.GlobalObject.extend(Kinetic.Line, Kinetic.Shape); Kinetic.GlobalObject.extend(Kinetic.Line, Kinetic.Shape);
// add setters and getters // add setters and getters
Kinetic.GlobalObject.addSetters(Kinetic.Line, ['dashArray', 'lineCap']); Kinetic.GlobalObject.addSettersGetters(Kinetic.Line, ['dashArray', 'lineCap', 'points']);
Kinetic.GlobalObject.addGetters(Kinetic.Line, ['dashArray', 'lineCap', 'points']);
/** /**
* set dash array. * set dash array.
@@ -4317,6 +4298,14 @@ Kinetic.GlobalObject.addGetters(Kinetic.Line, ['dashArray', 'lineCap', 'points']
* @param {String} lineCap * @param {String} lineCap
*/ */
/**
* set points array
* @name setPoints
* @methodOf Kinetic.Line.prototype
* @param {Array} can be an array of point objects or an array
* of Numbers. e.g. [{x:1,y:2},{x:3,y:4}] or [1,2,3,4]
*/
/** /**
* get dash array * get dash array
* @name getDashArray * @name getDashArray
@@ -4708,8 +4697,7 @@ Kinetic.Path.prototype = {
Kinetic.GlobalObject.extend(Kinetic.Path, Kinetic.Shape); Kinetic.GlobalObject.extend(Kinetic.Path, Kinetic.Shape);
// add setters and getters // add setters and getters
Kinetic.GlobalObject.addSetters(Kinetic.Path, ['data']); Kinetic.GlobalObject.addSettersGetters(Kinetic.Path, ['data']);
Kinetic.GlobalObject.addGetters(Kinetic.Path, ['data']);
/** /**
* set SVG path data string. This method * set SVG path data string. This method

File diff suppressed because one or more lines are too long

View File

@@ -51,6 +51,10 @@ Kinetic.GlobalObject = {
this._addGetter(constructor, attr); this._addGetter(constructor, attr);
} }
}, },
addSettersGetters: function(constructor, arr) {
this.addSetters(constructor, arr);
this.addGetters(constructor, arr);
},
_pullNodes: function(stage) { _pullNodes: function(stage) {
var tempNodes = this.tempNodes; var tempNodes = this.tempNodes;
for(var n = 0; n < tempNodes.length; n++) { for(var n = 0; n < tempNodes.length; n++) {
@@ -334,7 +338,14 @@ Kinetic.GlobalObject = {
_addSetter: function(constructor, attr) { _addSetter: function(constructor, attr) {
var that = this; var that = this;
var method = 'set' + attr.charAt(0).toUpperCase() + attr.slice(1); var method = 'set' + attr.charAt(0).toUpperCase() + attr.slice(1);
constructor.prototype[method] = function(arg) { constructor.prototype[method] = function() {
var arg;
if(arguments.length == 1) {
arg = arguments[0];
}
else {
arg = Array.prototype.slice.call(arguments);
}
var obj = {}; var obj = {};
obj[attr] = arg; obj[attr] = arg;
this.setAttrs(obj); this.setAttrs(obj);

View File

@@ -151,8 +151,7 @@ Kinetic.GlobalObject.extend(Kinetic.Layer, Kinetic.Container);
Kinetic.GlobalObject.extend(Kinetic.Layer, Kinetic.Node); Kinetic.GlobalObject.extend(Kinetic.Layer, Kinetic.Node);
// add setters and getters // add setters and getters
Kinetic.GlobalObject.addSetters(Kinetic.Layer, ['clearBeforeDraw']); Kinetic.GlobalObject.addSettersGetters(Kinetic.Layer, ['clearBeforeDraw']);
Kinetic.GlobalObject.addGetters(Kinetic.Layer, ['clearBeforeDraw']);
/** /**
* set flag which determines if the layer is cleared or not * set flag which determines if the layer is cleared or not

View File

@@ -341,15 +341,6 @@ Kinetic.Node.prototype = {
} }
return level; return level;
}, },
/**
* set node scale.
* @param arg
*/
setScale: function() {
this.setAttrs({
scale: Array.prototype.slice.call(arguments)
});
},
/** /**
* set node position * set node position
* @param {Object} point * @param {Object} point
@@ -440,13 +431,6 @@ Kinetic.Node.prototype = {
y: y y: y
}); });
}, },
/**
* set node rotation in degrees
* @param {Number} deg
*/
setRotationDeg: function(deg) {
this.setRotation(deg * Math.PI / 180);
},
/** /**
* get rotation in degrees * get rotation in degrees
*/ */
@@ -593,16 +577,6 @@ Kinetic.Node.prototype = {
simulate: function(eventType) { simulate: function(eventType) {
this._handleEvent(eventType, {}); this._handleEvent(eventType, {});
}, },
/**
* set offset
* @param {Number} x
* @param {Number} y
*/
setOffset: function() {
this.setAttrs({
offset: Array.prototype.slice.call(arguments)
});
},
/** /**
* transition node to another state. Any property that can accept a real * transition node to another state. Any property that can accept a real
* number can be transitioned, including x, y, rotation, alpha, strokeWidth, * number can be transitioned, including x, y, rotation, alpha, strokeWidth,
@@ -795,8 +769,8 @@ Kinetic.Node.prototype = {
}; };
// add setters and getters // add setters and getters
Kinetic.GlobalObject.addSetters(Kinetic.Node, ['x', 'y', 'detectionType', 'rotation', 'alpha', 'name', 'id', 'draggable', 'dragConstraint', 'dragBounds', 'listening']); Kinetic.GlobalObject.addSettersGetters(Kinetic.Node, ['x', 'y', 'scale', 'detectionType', 'rotation', 'alpha', 'name', 'id', 'offset', 'draggable', 'dragConstraint', 'dragBounds', 'listening']);
Kinetic.GlobalObject.addGetters(Kinetic.Node, ['scale', 'x', 'y', 'detectionType', 'rotation', 'alpha', 'name', 'id', 'draggable', 'offset', 'dragConstraint', 'dragBounds', 'listening']); Kinetic.GlobalObject.addSetters(Kinetic.Node, ['rotationDeg']);
/** /**
* set node x position * set node x position
@@ -867,6 +841,28 @@ Kinetic.GlobalObject.addGetters(Kinetic.Node, ['scale', 'x', 'y', 'detectionType
* @param {Boolean} listening * @param {Boolean} listening
*/ */
/**
* set node rotation in degrees
* @name setRotationDeg
* @methodOf Kinetic.Node.prototype
* @param {Number} deg
*/
/**
* set offset
* @name setOffset
* @methodOf Kinetic.Node.prototype
* @param {Number} x
* @param {Number} y
*/
/**
* set node scale.
* @name setScale
* @param {Number|Array|Object|List} scale
* @methodOf Kinetic.Node.prototype
*/
/** /**
* get scale * get scale
* @name getScale * @name getScale

View File

@@ -201,10 +201,10 @@ Kinetic.Shape.prototype = {
} }
// defaults // defaults
if(this.attrs.textStroke) { if(!this.attrs.textStroke) {
this.attrs.textStroke = 'black'; this.attrs.textStroke = 'black';
} }
else if(this.attrs.textStrokeWidth && this.attrs.textStrokeWidth !== 0) { else if(!this.attrs.textStrokeWidth && this.attrs.textStrokeWidth !== 0) {
this.attrs.textStrokeWidth = 2; this.attrs.textStrokeWidth = 2;
} }
context.lineWidth = this.attrs.textStrokeWidth; context.lineWidth = this.attrs.textStrokeWidth;
@@ -384,8 +384,7 @@ Kinetic.Shape.prototype = {
Kinetic.GlobalObject.extend(Kinetic.Shape, Kinetic.Node); Kinetic.GlobalObject.extend(Kinetic.Shape, Kinetic.Node);
// add setters and getters // add setters and getters
Kinetic.GlobalObject.addSetters(Kinetic.Shape, ['fill', 'stroke', 'lineJoin', 'strokeWidth', 'shadow', 'drawFunc']); Kinetic.GlobalObject.addSettersGetters(Kinetic.Shape, ['fill', 'stroke', 'lineJoin', 'strokeWidth', 'shadow', 'drawFunc']);
Kinetic.GlobalObject.addGetters(Kinetic.Shape, ['fill', 'stroke', 'lineJoin', 'strokeWidth', 'shadow', 'drawFunc']);
/** /**
* set fill which can be a color, linear gradient object, * set fill which can be a color, linear gradient object,

View File

@@ -984,8 +984,7 @@ Kinetic.GlobalObject.extend(Kinetic.Stage, Kinetic.Container);
Kinetic.GlobalObject.extend(Kinetic.Stage, Kinetic.Node); Kinetic.GlobalObject.extend(Kinetic.Stage, Kinetic.Node);
// add setters and getters // add setters and getters
Kinetic.GlobalObject.addSetters(Kinetic.Stage, ['width', 'height', 'throttle']); Kinetic.GlobalObject.addSettersGetters(Kinetic.Stage, ['width', 'height', 'throttle']);
Kinetic.GlobalObject.addGetters(Kinetic.Stage, ['width', 'height', 'throttle']);
/** /**
* get width * get width

View File

@@ -46,21 +46,6 @@ Kinetic.Ellipse = function(config) {
Kinetic.Circle = Kinetic.Ellipse; Kinetic.Circle = Kinetic.Ellipse;
Kinetic.Ellipse.prototype = { Kinetic.Ellipse.prototype = {
/**
* set radius
* @param {Number|Object|Array} radius
* radius can be a number, in which the ellipse becomes a circle,
* it can be an object with an x and y component, or it
* can be an array in which the first element is the x component
* and the second element is the y component. The x component
* defines the horizontal radius and the y component
* defines the vertical radius
*/
setRadius: function() {
this.setAttrs({
radius: Array.prototype.slice.call(arguments)
});
},
/** /**
* converts numeric radius into an object * converts numeric radius into an object
*/ */
@@ -73,15 +58,26 @@ Kinetic.Ellipse.prototype = {
} }
var pos = go._getXY(radius); var pos = go._getXY(radius);
this.setAttrs({ this.setAttrs({
radius: pos radius: pos
}); });
} }
}; };
// extend Shape // extend Shape
Kinetic.GlobalObject.extend(Kinetic.Ellipse, Kinetic.Shape); Kinetic.GlobalObject.extend(Kinetic.Ellipse, Kinetic.Shape);
// add setters and getters // add setters and getters
Kinetic.GlobalObject.addGetters(Kinetic.Ellipse, ['radius']); Kinetic.GlobalObject.addSettersGetters(Kinetic.Ellipse, ['radius']);
/**
* set radius
* @param {Number|Object|Array} radius
* radius can be a number, in which the ellipse becomes a circle,
* it can be an object with an x and y component, or it
* can be an array in which the first element is the x component
* and the second element is the y component. The x component
* defines the horizontal radius and the y component
* defines the vertical radius
*/
/** /**
* get radius * get radius

View File

@@ -65,21 +65,12 @@ Kinetic.Image.prototype = {
width: this.attrs.width, width: this.attrs.width,
height: this.attrs.height height: this.attrs.height
}; };
},
/**
* set crop
*/
setCrop: function() {
this.setAttrs({
crop: Array.prototype.slice.call(arguments)
});
} }
}; };
// extend Shape // extend Shape
Kinetic.GlobalObject.extend(Kinetic.Image, Kinetic.Shape); Kinetic.GlobalObject.extend(Kinetic.Image, Kinetic.Shape);
// add setters and getters // add setters and getters
Kinetic.GlobalObject.addSetters(Kinetic.Image, ['height', 'width', 'image']); Kinetic.GlobalObject.addSettersGetters(Kinetic.Image, ['height', 'width', 'image', 'crop']);
Kinetic.GlobalObject.addGetters(Kinetic.Image, ['crop', 'height', 'width', 'image']);
/** /**
* set width * set width
@@ -102,6 +93,13 @@ Kinetic.GlobalObject.addGetters(Kinetic.Image, ['crop', 'height', 'width', 'imag
* @param {ImageObject} image * @param {ImageObject} image
*/ */
/**
* set crop
* @name setCrop
* @methodOf Kinetic.Image.prototype
* @param {Object} config
*/
/** /**
* get crop * get crop
* @name getCrop * @name getCrop

View File

@@ -51,16 +51,6 @@ Kinetic.Line = function(config) {
* Line methods * Line methods
*/ */
Kinetic.Line.prototype = { Kinetic.Line.prototype = {
/**
* set points array
* @param {Array} can be an array of point objects or an array
* of Numbers. e.g. [{x:1,y:2},{x:3,y:4}] or [1,2,3,4]
*/
setPoints: function(points) {
this.setAttrs({
points: points
});
},
/** /**
* draw dashed line. Written by Phrogz * draw dashed line. Written by Phrogz
*/ */
@@ -113,8 +103,7 @@ Kinetic.Line.prototype = {
// extend Shape // extend Shape
Kinetic.GlobalObject.extend(Kinetic.Line, Kinetic.Shape); Kinetic.GlobalObject.extend(Kinetic.Line, Kinetic.Shape);
// add setters and getters // add setters and getters
Kinetic.GlobalObject.addSetters(Kinetic.Line, ['dashArray', 'lineCap']); Kinetic.GlobalObject.addSettersGetters(Kinetic.Line, ['dashArray', 'lineCap', 'points']);
Kinetic.GlobalObject.addGetters(Kinetic.Line, ['dashArray', 'lineCap', 'points']);
/** /**
* set dash array. * set dash array.
@@ -136,6 +125,14 @@ Kinetic.GlobalObject.addGetters(Kinetic.Line, ['dashArray', 'lineCap', 'points']
* @param {String} lineCap * @param {String} lineCap
*/ */
/**
* set points array
* @name setPoints
* @methodOf Kinetic.Line.prototype
* @param {Array} can be an array of point objects or an array
* of Numbers. e.g. [{x:1,y:2},{x:3,y:4}] or [1,2,3,4]
*/
/** /**
* get dash array * get dash array
* @name getDashArray * @name getDashArray

View File

@@ -372,8 +372,7 @@ Kinetic.Path.prototype = {
Kinetic.GlobalObject.extend(Kinetic.Path, Kinetic.Shape); Kinetic.GlobalObject.extend(Kinetic.Path, Kinetic.Shape);
// add setters and getters // add setters and getters
Kinetic.GlobalObject.addSetters(Kinetic.Path, ['data']); Kinetic.GlobalObject.addSettersGetters(Kinetic.Path, ['data']);
Kinetic.GlobalObject.addGetters(Kinetic.Path, ['data']);
/** /**
* set SVG path data string. This method * set SVG path data string. This method

View File

@@ -31,8 +31,7 @@ Kinetic.Polygon = function(config) {
Kinetic.GlobalObject.extend(Kinetic.Polygon, Kinetic.Shape); Kinetic.GlobalObject.extend(Kinetic.Polygon, Kinetic.Shape);
// add setters and getters // add setters and getters
Kinetic.GlobalObject.addSetters(Kinetic.Polygon, ['points']); Kinetic.GlobalObject.addSettersGetters(Kinetic.Polygon, ['points']);
Kinetic.GlobalObject.addGetters(Kinetic.Polygon, ['points']);
/** /**
* set points array * set points array

View File

@@ -69,8 +69,7 @@ Kinetic.Rect.prototype = {
Kinetic.GlobalObject.extend(Kinetic.Rect, Kinetic.Shape); Kinetic.GlobalObject.extend(Kinetic.Rect, Kinetic.Shape);
// add setters and getters // add setters and getters
Kinetic.GlobalObject.addSetters(Kinetic.Rect, ['width', 'height', 'cornerRadius']); Kinetic.GlobalObject.addSettersGetters(Kinetic.Rect, ['width', 'height', 'cornerRadius']);
Kinetic.GlobalObject.addGetters(Kinetic.Rect, ['width', 'height', 'cornerRadius']);
/** /**
* set width * set width

View File

@@ -35,8 +35,7 @@ Kinetic.RegularPolygon = function(config) {
Kinetic.GlobalObject.extend(Kinetic.RegularPolygon, Kinetic.Shape); Kinetic.GlobalObject.extend(Kinetic.RegularPolygon, Kinetic.Shape);
// add setters and getters // add setters and getters
Kinetic.GlobalObject.addSetters(Kinetic.Rect, ['radius', 'sides']); Kinetic.GlobalObject.addSettersGetters(Kinetic.Rect, ['radius', 'sides']);
Kinetic.GlobalObject.addGetters(Kinetic.Rect, ['radius', 'sides']);
/** /**
* set radius * set radius

View File

@@ -84,8 +84,7 @@ Kinetic.Sprite.prototype = {
Kinetic.GlobalObject.extend(Kinetic.Sprite, Kinetic.Shape); Kinetic.GlobalObject.extend(Kinetic.Sprite, Kinetic.Shape);
// add setters and getters // add setters and getters
Kinetic.GlobalObject.addSetters(Kinetic.Sprite, ['animation', 'animations', 'index']); Kinetic.GlobalObject.addSettersGetters(Kinetic.Sprite, ['animation', 'animations', 'index']);
Kinetic.GlobalObject.addGetters(Kinetic.Sprite, ['animation', 'animations', 'index']);
/** /**
* set animation key * set animation key

View File

@@ -38,8 +38,7 @@ Kinetic.Star = function(config) {
Kinetic.GlobalObject.extend(Kinetic.Star, Kinetic.Shape); Kinetic.GlobalObject.extend(Kinetic.Star, Kinetic.Shape);
// add setters and getters // add setters and getters
Kinetic.GlobalObject.addSetters(Kinetic.Star, ['numPoints', 'innerRadius', 'outerRadius']); Kinetic.GlobalObject.addSettersGetters(Kinetic.Star, ['numPoints', 'innerRadius', 'outerRadius']);
Kinetic.GlobalObject.addGetters(Kinetic.Star, ['numPoints', 'innerRadius', 'outerRadius']);
/** /**
* set number of points * set number of points

View File

@@ -120,8 +120,7 @@ Kinetic.Text.prototype = {
Kinetic.GlobalObject.extend(Kinetic.Text, Kinetic.Shape); Kinetic.GlobalObject.extend(Kinetic.Text, Kinetic.Shape);
// add setters and getters // add setters and getters
Kinetic.GlobalObject.addSetters(Kinetic.Text, ['fontFamily', 'fontSize', 'fontStyle', 'textFill', 'textStroke', 'textStrokeWidth', 'padding', 'align', 'verticalAlign', 'text', 'width']); Kinetic.GlobalObject.addSettersGetters(Kinetic.Text, ['fontFamily', 'fontSize', 'fontStyle', 'textFill', 'textStroke', 'textStrokeWidth', 'padding', 'align', 'verticalAlign', 'text', 'width']);
Kinetic.GlobalObject.addGetters(Kinetic.Text, ['fontFamily', 'fontSize', 'fontStyle', 'textFill', 'textStroke', 'textStrokeWidth', 'padding', 'align', 'verticalAlign', 'text', 'width']);
/** /**
* set font family * set font family