major refactor of directory structure. Killed Util directory. Created Util.js file instead. Moved general purpose methods from Global to Util

This commit is contained in:
Eric Rowell
2013-05-07 23:51:02 -07:00
parent e2d6993c89
commit 76a399bfc0
31 changed files with 312 additions and 307 deletions

View File

@@ -4,7 +4,7 @@ require 'uglifier'
class Build < Thor
# This is the list of files to concatenate. The first file will appear at the top of the final file. All files are relative to the lib directory.
FILES = [
"src/Global.js", "src/util/Type.js", "src/Canvas.js", "src/util/Transform.js", "src/util/Collection.js",
"src/Global.js", "src/Util.js", "src/Canvas.js",
"src/Node.js", "src/Animation.js", "src/DragAndDrop.js", "src/Container.js", "src/Shape.js", "src/Stage.js", "src/Layer.js", "src/Group.js",
"src/shapes/Rect.js", "src/shapes/Circle.js", "src/shapes/Wedge.js", "src/shapes/Ellipse.js", "src/shapes/Image.js", "src/shapes/Polygon.js", "src/shapes/Text.js", "src/shapes/Line.js", "src/shapes/Spline.js", "src/shapes/Blob.js", "src/shapes/Sprite.js",
"src/filters/Grayscale.js", "src/filters/Brighten.js", "src/filters/Invert.js", "src/filters/Blur.js", "src/filters/Mask.js",
@@ -14,7 +14,7 @@ class Build < Thor
UNIT_TESTS = [
"tests/js/unit/animationTests.js",
"tests/js/unit/globalTests.js",
"tests/js/unit/typeTests.js",
"tests/js/unit/utilTests.js",
"tests/js/unit/nodeTests.js",
"tests/js/unit/stageTests.js",
"tests/js/unit/containerTests.js",

View File

@@ -32,7 +32,7 @@
lays = null;
}
// if passing in an array of Layers
else if (Kinetic.Type._isArray(layers)) {
else if (Kinetic.Util._isArray(layers)) {
lays = layers;
}
// if passing in a Layer

View File

@@ -143,7 +143,7 @@
return this.element.toDataURL();
}
catch(e) {
Kinetic.Global.warn('Unable to get data URL. ' + e.message)
Kinetic.Util.warn('Unable to get data URL. ' + e.message)
return '';
}
}
@@ -242,7 +242,7 @@
}
};
Kinetic.Global.extend(Kinetic.Canvas2D, Kinetic.Canvas);
Kinetic.Util.extend(Kinetic.Canvas2D, Kinetic.Canvas);
Kinetic.SceneCanvas = function(config) {
Kinetic.Canvas2D.call(this, config);
@@ -427,7 +427,7 @@
}
}
};
Kinetic.Global.extend(Kinetic.SceneCanvas, Kinetic.Canvas2D);
Kinetic.Util.extend(Kinetic.SceneCanvas, Kinetic.Canvas2D);
Kinetic.HitCanvas = function(config) {
Kinetic.Canvas2D.call(this, config);
@@ -456,6 +456,6 @@
}
}
};
Kinetic.Global.extend(Kinetic.HitCanvas, Kinetic.Canvas2D);
Kinetic.Util.extend(Kinetic.HitCanvas, Kinetic.Canvas2D);
})();

View File

@@ -7,7 +7,7 @@
* {{NodeParams}}
* {{ContainerParams}}
*/
Kinetic.Global.addMethods(Kinetic.Container, {
Kinetic.Util.addMethods(Kinetic.Container, {
_containerInit: function(config) {
this.children = [];
Kinetic.Node.call(this, config);
@@ -169,7 +169,7 @@
* @param {Object} point
*/
getIntersections: function() {
var pos = Kinetic.Type._getXY(Array.prototype.slice.call(arguments));
var pos = Kinetic.Util._getXY(Array.prototype.slice.call(arguments));
var arr = [];
var shapes = this.get('Shape');
@@ -244,7 +244,7 @@
}
});
Kinetic.Global.extend(Kinetic.Container, Kinetic.Node);
Kinetic.Util.extend(Kinetic.Container, Kinetic.Node);
// add getters setters
Kinetic.Node.addGetterSetter(Kinetic.Container, 'clipFunc');

View File

@@ -71,19 +71,7 @@ var Kinetic = {};
names: {},
//shapes hash. rgb keys and shape values
shapes: {},
/**
* @method addMethods adds methods to a constructor prototype
* @methodOf Kinetic.Global
* @param {Function} constructor
* @param {Object} methods
*/
addMethods: function(constructor, methods) {
var key;
for (key in methods) {
constructor.prototype[key] = methods[key];
}
},
/**
* @method isDragging returns whether or not drag and drop
* is currently active
@@ -120,22 +108,6 @@ var Kinetic = {};
return !!dd.node;
}
},
warn: function(str) {
/*
* IE9 on Windows7 64bit will throw a JS error
* if we don't use window.console in the conditional
*/
if(window.console && console.warn) {
console.warn('Kinetic warning: ' + str);
}
},
extend: function(c1, c2) {
for(var key in c2.prototype) {
if(!( key in c1.prototype)) {
c1.prototype[key] = c2.prototype[key];
}
}
},
_addId: function(node, id) {
if(id !== undefined) {
this.ids[id] = node;

View File

@@ -7,7 +7,7 @@
* {{NodeParams}}
* {{ContainerParams}}
*/
Kinetic.Global.addMethods(Kinetic.Group, {
Kinetic.Util.addMethods(Kinetic.Group, {
_initGroup: function(config) {
this.nodeType = 'Group';
this.createAttrs();
@@ -15,5 +15,5 @@
Kinetic.Container.call(this, config);
}
});
Kinetic.Global.extend(Kinetic.Group, Kinetic.Container);
Kinetic.Util.extend(Kinetic.Group, Kinetic.Container);
})();

View File

@@ -10,7 +10,7 @@
* {{NodeParams}}
* {{ContainerParams}}
*/
Kinetic.Global.addMethods(Kinetic.Layer, {
Kinetic.Util.addMethods(Kinetic.Layer, {
_initLayer: function(config) {
this.nodeType = 'Layer';
this.createAttrs();
@@ -27,14 +27,14 @@
* @methodOf Kinetic.Layer.prototype
*/
getIntersection: function() {
var pos = Kinetic.Type._getXY(Array.prototype.slice.call(arguments)),
var pos = Kinetic.Util._getXY(Array.prototype.slice.call(arguments)),
p, colorKey, shape;
if(this.isVisible() && this.isListening()) {
p = this.hitCanvas.context.getImageData(pos.x | 0, pos.y | 0, 1, 1).data;
// this indicates that a hit pixel may have been found
if(p[3] === 255) {
colorKey = Kinetic.Type._rgbToHex(p[0], p[1], p[2]);
colorKey = Kinetic.Util._rgbToHex(p[0], p[1], p[2]);
shape = Kinetic.Global.shapes[colorKey];
return {
shape: shape,
@@ -180,12 +180,12 @@
var stage = this.getStage(), canvas = this.getCanvas(), element = canvas.element;
Kinetic.Node.prototype.remove.call(this);
if(stage && canvas && Kinetic.Type._isInDocument(element)) {
if(stage && canvas && Kinetic.Util._isInDocument(element)) {
stage.content.removeChild(element);
}
}
});
Kinetic.Global.extend(Kinetic.Layer, Kinetic.Container);
Kinetic.Util.extend(Kinetic.Layer, Kinetic.Container);
// add getters and setters
Kinetic.Node.addGetterSetter(Kinetic.Layer, 'clearBeforeDraw', true);

View File

@@ -41,7 +41,7 @@
* {{NodeParams}}
*/
Kinetic.Global.addMethods(Kinetic.Node, {
Kinetic.Util.addMethods(Kinetic.Node, {
_nodeInit: function(config) {
this._id = Kinetic.Global.idCounter++;
this.eventListeners = {};
@@ -172,8 +172,8 @@
* @param {String} attr
*/
getAttr: function(attr) {
var method = GET + Kinetic.Type._capitalize(attr);
if(Kinetic.Type._isFunction(this[method])) {
var method = GET + Kinetic.Util._capitalize(attr);
if(Kinetic.Util._isFunction(this[method])) {
return this[method]();
}
// otherwise get directly
@@ -210,9 +210,9 @@
if(config) {
for(key in config) {
method = SET + Kinetic.Type._capitalize(key);
method = SET + Kinetic.Util._capitalize(key);
// use setter if available
if(Kinetic.Type._isFunction(this[method])) {
if(Kinetic.Util._isFunction(this[method])) {
this[method](config[key]);
}
// otherwise set directly
@@ -352,7 +352,7 @@
* @param {Number} y
*/
setPosition: function() {
var pos = Kinetic.Type._getXY([].slice.call(arguments));
var pos = Kinetic.Util._getXY([].slice.call(arguments));
this.setAttr(X, pos.x);
this.setAttr(Y, pos.y);
},
@@ -387,7 +387,7 @@
* @param {Number} y
*/
setAbsolutePosition: function() {
var pos = Kinetic.Type._getXY([].slice.call(arguments)),
var pos = Kinetic.Util._getXY([].slice.call(arguments)),
trans = this._clearTransform(),
it;
@@ -418,7 +418,7 @@
* @param {Number} y
*/
move: function() {
var pos = Kinetic.Type._getXY([].slice.call(arguments)),
var pos = Kinetic.Util._getXY([].slice.call(arguments)),
x = this.getX(),
y = this.getY();
@@ -467,7 +467,7 @@
* @param {Number} deg
*/
rotateDeg: function(deg) {
this.setRotation(this.getRotation() + Kinetic.Type._degToRad(deg));
this.setRotation(this.getRotation() + Kinetic.Util._degToRad(deg));
},
/**
* move node to the top of its siblings
@@ -564,7 +564,7 @@
* @methodOf Kinetic.Node.prototype
*/
toObject: function() {
var type = Kinetic.Type,
var type = Kinetic.Util,
obj = {},
attrs = this.getAttrs(),
key, val;
@@ -800,7 +800,7 @@
* is very high quality
*/
toImage: function(config) {
Kinetic.Type._getImage(this.toDataURL(config), function(img) {
Kinetic.Util._getImage(this.toDataURL(config), function(img) {
config.callback(img);
});
},
@@ -813,7 +813,7 @@
*/
setSize: function() {
// set stage dimensions
var size = Kinetic.Type._getSize(Array.prototype.slice.call(arguments));
var size = Kinetic.Util._getSize(Array.prototype.slice.call(arguments));
this.setWidth(size.width);
this.setHeight(size.height);
},
@@ -898,7 +898,7 @@
this.cachedTransform = null;
},
_fireBeforeChangeEvent: function(attr, oldVal, newVal) {
this._handleEvent(BEFORE + Kinetic.Type._capitalize(attr) + CHANGE, {
this._handleEvent(BEFORE + Kinetic.Util._capitalize(attr) + CHANGE, {
oldVal: oldVal,
newVal: newVal
});
@@ -1053,32 +1053,32 @@
this.addColorComponentSetter(constructor, attr, B);
};
Kinetic.Node.addColorRGBGetter = function(constructor, attr) {
var method = GET + Kinetic.Type._capitalize(attr) + RGB;
var method = GET + Kinetic.Util._capitalize(attr) + RGB;
constructor.prototype[method] = function() {
return Kinetic.Type.getRGB(this.attrs[attr]);
return Kinetic.Util.getRGB(this.attrs[attr]);
};
};
Kinetic.Node.addColorRGBSetter = function(constructor, attr) {
var method = SET + Kinetic.Type._capitalize(attr) + RGB;
var method = SET + Kinetic.Util._capitalize(attr) + RGB;
constructor.prototype[method] = function(obj) {
var r = obj && obj.r !== undefined ? obj.r | 0 : this.getAttr(attr + UPPER_R),
g = obj && obj.g !== undefined ? obj.g | 0 : this.getAttr(attr + UPPER_G),
b = obj && obj.b !== undefined ? obj.b | 0 : this.getAttr(attr + UPPER_B);
this.setAttr(attr, HASH + Kinetic.Type._rgbToHex(r, g, b));
this.setAttr(attr, HASH + Kinetic.Util._rgbToHex(r, g, b));
};
};
Kinetic.Node.addColorComponentGetter = function(constructor, attr, c) {
var prefix = GET + Kinetic.Type._capitalize(attr),
method = prefix + Kinetic.Type._capitalize(c);
var prefix = GET + Kinetic.Util._capitalize(attr),
method = prefix + Kinetic.Util._capitalize(c);
constructor.prototype[method] = function() {
return this[prefix + RGB]()[c];
};
};
Kinetic.Node.addColorComponentSetter = function(constructor, attr, c) {
var prefix = SET + Kinetic.Type._capitalize(attr),
method = prefix + Kinetic.Type._capitalize(c);
var prefix = SET + Kinetic.Util._capitalize(attr),
method = prefix + Kinetic.Util._capitalize(c);
constructor.prototype[method] = function(val) {
var obj = {};
obj[c] = val;
@@ -1087,7 +1087,7 @@
};
Kinetic.Node.addSetter = function(constructor, attr, isTransform) {
var that = this,
method = SET + Kinetic.Type._capitalize(attr);
method = SET + Kinetic.Util._capitalize(attr);
constructor.prototype[method] = function(val) {
this.setAttr(attr, val);
@@ -1098,10 +1098,10 @@
};
Kinetic.Node.addPointSetter = function(constructor, attr) {
var that = this,
baseMethod = SET + Kinetic.Type._capitalize(attr);
baseMethod = SET + Kinetic.Util._capitalize(attr);
constructor.prototype[baseMethod] = function() {
var pos = Kinetic.Type._getXY([].slice.call(arguments)),
var pos = Kinetic.Util._getXY([].slice.call(arguments)),
oldVal = this.attrs[attr];
x = 0,
y = 0;
@@ -1123,7 +1123,7 @@
};
Kinetic.Node.addRotationSetter = function(constructor, attr, isTransform) {
var that = this,
method = SET + Kinetic.Type._capitalize(attr);
method = SET + Kinetic.Util._capitalize(attr);
// radians
constructor.prototype[method] = function(val) {
@@ -1134,7 +1134,7 @@
};
// degrees
constructor.prototype[method + DEG] = function(deg) {
this.setAttr(attr, Kinetic.Type._degToRad(deg));
this.setAttr(attr, Kinetic.Util._degToRad(deg));
if (isTransform) {
this.cachedTransform = null;
}
@@ -1142,7 +1142,7 @@
};
Kinetic.Node.addGetter = function(constructor, attr, def) {
var that = this,
method = GET + Kinetic.Type._capitalize(attr);
method = GET + Kinetic.Util._capitalize(attr);
constructor.prototype[method] = function(arg) {
var val = this.attrs[attr];
@@ -1155,7 +1155,7 @@
};
Kinetic.Node.addPointGetter = function(constructor, attr) {
var that = this,
baseMethod = GET + Kinetic.Type._capitalize(attr);
baseMethod = GET + Kinetic.Util._capitalize(attr);
constructor.prototype[baseMethod] = function(arg) {
var that = this;
@@ -1167,7 +1167,7 @@
};
Kinetic.Node.addRotationGetter = function(constructor, attr, def) {
var that = this,
method = GET + Kinetic.Type._capitalize(attr);
method = GET + Kinetic.Util._capitalize(attr);
// radians
constructor.prototype[method] = function() {
@@ -1183,7 +1183,7 @@
if (val === undefined) {
val = def;
}
return Kinetic.Type._radToDeg(val);
return Kinetic.Util._radToDeg(val);
};
};
/**

View File

@@ -21,7 +21,7 @@
context.stroke();
}
Kinetic.Global.addMethods(Kinetic.Shape, {
Kinetic.Util.addMethods(Kinetic.Shape, {
_initShape: function(config) {
this.nodeType = 'Shape';
this._fillFunc = _fillFunc;
@@ -34,7 +34,7 @@
var key;
while(true) {
key = Kinetic.Type.getRandomColor();
key = Kinetic.Util.getRandomColor();
if(key && !( key in shapes)) {
break;
}
@@ -94,7 +94,7 @@
* element is the y component
*/
intersects: function() {
var pos = Kinetic.Type._getXY(Array.prototype.slice.call(arguments));
var pos = Kinetic.Util._getXY(Array.prototype.slice.call(arguments));
var stage = this.getStage();
var hitCanvas = stage.hitCanvas;
hitCanvas.clear();
@@ -212,7 +212,7 @@
}
}
});
Kinetic.Global.extend(Kinetic.Shape, Kinetic.Node);
Kinetic.Util.extend(Kinetic.Shape, Kinetic.Node);
// add getters and setters
Kinetic.Node.addColorGetterSetter(Kinetic.Shape, 'stroke');

View File

@@ -45,7 +45,7 @@
* {{ContainerParams}}
*/
Kinetic.Global.addMethods(Kinetic.Stage, {
Kinetic.Util.addMethods(Kinetic.Stage, {
_initStage: function(config) {
this.createAttrs();
// call super constructor
@@ -138,7 +138,7 @@
var content = this.content;
Kinetic.Node.prototype.remove.call(this);
if(content && Kinetic.Type._isInDocument(content)) {
if(content && Kinetic.Util._isInDocument(content)) {
this.getContainer().removeChild(content);
}
},
@@ -251,7 +251,7 @@
var cb = config.callback;
config.callback = function(dataUrl) {
Kinetic.Type._getImage(dataUrl, function(img) {
Kinetic.Util._getImage(dataUrl, function(img) {
cb(img);
});
};
@@ -264,7 +264,7 @@
* @param {Object} pos point object
*/
getIntersection: function() {
var pos = Kinetic.Type._getXY(Array.prototype.slice.call(arguments)),
var pos = Kinetic.Util._getXY(Array.prototype.slice.call(arguments)),
layers = this.getChildren(),
len = layers.length,
end = len - 1,
@@ -599,7 +599,7 @@
}
}
});
Kinetic.Global.extend(Kinetic.Stage, Kinetic.Container);
Kinetic.Util.extend(Kinetic.Stage, Kinetic.Container);
// add getters and setters
Kinetic.Node.addGetter(Kinetic.Stage, 'container');

View File

@@ -1,3 +1,190 @@
(function() {
/**
* Collection constructor. Collection extends
* Array. This class is used in conjunction with get()
* @constructor
*/
Kinetic.Collection = function() {
var args = [].slice.call(arguments), length = args.length, i = 0;
this.length = length;
for(; i < length; i++) {
this[i] = args[i];
}
return this;
}
Kinetic.Collection.prototype = new Array();
/**
* iterate through node array
* @name each
* @methodOf Kinetic.Collection.prototype
* @param {Function} func
*/
Kinetic.Collection.prototype.each = function(func) {
for(var n = 0; n < this.length; n++) {
func(this[n], n);
}
};
Kinetic.Collection.mapMethods = function(arr) {
var leng = arr.length,
n;
for(n = 0; n < leng; n++) {
// induce scope
(function(i) {
var method = arr[i];
Kinetic.Collection.prototype[method] = function() {
var len = this.length,
i;
args = [].slice.call(arguments);
for(i = 0; i < len; i++) {
this[i][method].apply(this[i], args);
}
};
})(n);
}
};
})();
(function() {
/*
* Last updated November 2011
* By Simon Sarris
* www.simonsarris.com
* sarris@acm.org
*
* Free to use and distribute at will
* So long as you are nice to people, etc
*/
/*
* The usage of this class was inspired by some of the work done by a forked
* project, KineticJS-Ext by Wappworks, which is based on Simon's Transform
* class.
*/
/**
* Transform constructor
* @constructor
*/
Kinetic.Transform = function() {
this.m = [1, 0, 0, 1, 0, 0];
}
Kinetic.Transform.prototype = {
/**
* Apply translation
* @param {Number} x
* @param {Number} y
*/
translate: function(x, y) {
this.m[4] += this.m[0] * x + this.m[2] * y;
this.m[5] += this.m[1] * x + this.m[3] * y;
},
/**
* Apply scale
* @param {Number} sx
* @param {Number} sy
*/
scale: function(sx, sy) {
this.m[0] *= sx;
this.m[1] *= sx;
this.m[2] *= sy;
this.m[3] *= sy;
},
/**
* Apply rotation
* @param {Number} rad Angle in radians
*/
rotate: function(rad) {
var c = Math.cos(rad);
var s = Math.sin(rad);
var m11 = this.m[0] * c + this.m[2] * s;
var m12 = this.m[1] * c + this.m[3] * s;
var m21 = this.m[0] * -s + this.m[2] * c;
var m22 = this.m[1] * -s + this.m[3] * c;
this.m[0] = m11;
this.m[1] = m12;
this.m[2] = m21;
this.m[3] = m22;
},
/**
* Returns the translation
* @returns {Object} 2D point(x, y)
*/
getTranslation: function() {
return {
x: this.m[4],
y: this.m[5]
};
},
/**
* Apply skew
* @param {Number} sx
* @param {Number} sy
*/
skew: function(sx, sy) {
var m11 = this.m[0] + this.m[2] * sy;
var m12 = this.m[1] + this.m[3] * sy;
var m21 = this.m[2] + this.m[0] * sx;
var m22 = this.m[3] + this.m[1] * sx;
this.m[0] = m11;
this.m[1] = m12;
this.m[2] = m21;
this.m[3] = m22;
},
/**
* Transform multiplication
* @param {Kinetic.Transform} matrix
*/
multiply: function(matrix) {
var m11 = this.m[0] * matrix.m[0] + this.m[2] * matrix.m[1];
var m12 = this.m[1] * matrix.m[0] + this.m[3] * matrix.m[1];
var m21 = this.m[0] * matrix.m[2] + this.m[2] * matrix.m[3];
var m22 = this.m[1] * matrix.m[2] + this.m[3] * matrix.m[3];
var dx = this.m[0] * matrix.m[4] + this.m[2] * matrix.m[5] + this.m[4];
var dy = this.m[1] * matrix.m[4] + this.m[3] * matrix.m[5] + this.m[5];
this.m[0] = m11;
this.m[1] = m12;
this.m[2] = m21;
this.m[3] = m22;
this.m[4] = dx;
this.m[5] = dy;
},
/**
* Invert the matrix
*/
invert: function() {
var d = 1 / (this.m[0] * this.m[3] - this.m[1] * this.m[2]);
var m0 = this.m[3] * d;
var m1 = -this.m[1] * d;
var m2 = -this.m[2] * d;
var m3 = this.m[0] * d;
var m4 = d * (this.m[2] * this.m[5] - this.m[3] * this.m[4]);
var m5 = d * (this.m[1] * this.m[4] - this.m[0] * this.m[5]);
this.m[0] = m0;
this.m[1] = m1;
this.m[2] = m2;
this.m[3] = m3;
this.m[4] = m4;
this.m[5] = m5;
},
/**
* return matrix
*/
getMatrix: function() {
return this.m;
}
};
})();
(function() {
// CONSTANTS
var CANVAS = 'canvas',
@@ -37,7 +224,7 @@
/*
* utilities that handle data type detection, conversion, and manipulation
*/
Kinetic.Type = {
Kinetic.Util = {
/*
* cherry-picked utilities from underscore.js
*/
@@ -391,6 +578,35 @@
},
_capitalize: function(str) {
return str.charAt(0).toUpperCase() + str.slice(1);
},
warn: function(str) {
/*
* IE9 on Windows7 64bit will throw a JS error
* if we don't use window.console in the conditional
*/
if(window.console && console.warn) {
console.warn('Kinetic warning: ' + str);
}
},
extend: function(c1, c2) {
for(var key in c2.prototype) {
if(!( key in c1.prototype)) {
c1.prototype[key] = c2.prototype[key];
}
}
},
/**
* @method addMethods adds methods to a constructor prototype
* @methodOf Kinetic.Global
* @param {Function} constructor
* @param {Object} methods
*/
addMethods: function(constructor, methods) {
var key;
for (key in methods) {
constructor.prototype[key] = methods[key];
}
},
};
})();

View File

@@ -116,7 +116,7 @@
* @methodOf Kinetic.Label.prototype
*/
Kinetic.Global.extend(Kinetic.Label, Kinetic.Group);
Kinetic.Util.extend(Kinetic.Label, Kinetic.Group);
Kinetic.Node.addGetterSetter(Kinetic.Label, 'text');
Kinetic.Node.addGetterSetter(Kinetic.Label, 'rect');
@@ -190,7 +190,7 @@
}
};
Kinetic.Global.extend(Kinetic.LabelRect, Kinetic.Shape);
Kinetic.Util.extend(Kinetic.LabelRect, Kinetic.Shape);
Kinetic.Node.addGetterSetter(Kinetic.LabelRect, 'pointerDirection', NONE);
/**

View File

@@ -72,7 +72,7 @@
canvas.fillStroke(this);
}
};
Kinetic.Global.extend(Kinetic.Path, Kinetic.Shape);
Kinetic.Util.extend(Kinetic.Path, Kinetic.Shape);
Kinetic.Path.getLineLength = function(x1, y1, x2, y2) {
return Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));

View File

@@ -36,7 +36,7 @@
canvas.fillStroke(this);
}
};
Kinetic.Global.extend(Kinetic.RegularPolygon, Kinetic.Shape);
Kinetic.Util.extend(Kinetic.RegularPolygon, Kinetic.Shape);
// add getters setters
Kinetic.Node.addGetterSetter(Kinetic.RegularPolygon, 'radius', 0);

View File

@@ -40,7 +40,7 @@
canvas.fillStroke(this);
}
};
Kinetic.Global.extend(Kinetic.Star, Kinetic.Shape);
Kinetic.Util.extend(Kinetic.Star, Kinetic.Shape);
// add getters setters
Kinetic.Node.addGetterSetter(Kinetic.Star, 'numPoints', 0);

View File

@@ -309,7 +309,7 @@
// map TextPath methods to Text
Kinetic.TextPath.prototype._getContextFont = Kinetic.Text.prototype._getContextFont;
Kinetic.Global.extend(Kinetic.TextPath, Kinetic.Shape);
Kinetic.Util.extend(Kinetic.TextPath, Kinetic.Shape);
// add setters and getters
Kinetic.Node.addGetterSetter(Kinetic.TextPath, 'fontFamily', CALIBRI);

View File

@@ -62,5 +62,5 @@
}
};
Kinetic.Global.extend(Kinetic.Blob, Kinetic.Spline);
Kinetic.Util.extend(Kinetic.Blob, Kinetic.Spline);
})();

View File

@@ -42,7 +42,7 @@
this.setRadius(height / 2);
}
};
Kinetic.Global.extend(Kinetic.Circle, Kinetic.Shape);
Kinetic.Util.extend(Kinetic.Circle, Kinetic.Shape);
// add getters setters
Kinetic.Node.addGetterSetter(Kinetic.Circle, 'radius', 0);

View File

@@ -52,7 +52,7 @@
});
}
};
Kinetic.Global.extend(Kinetic.Ellipse, Kinetic.Shape);
Kinetic.Util.extend(Kinetic.Ellipse, Kinetic.Shape);
// add getters setters
Kinetic.Node.addPointGetterSetter(Kinetic.Ellipse, 'radius', 0);

View File

@@ -132,7 +132,7 @@
}
catch(e) {
this.clearFilter();
Kinetic.Global.warn('Unable to apply filter. ' + e.message);
Kinetic.Util.warn('Unable to apply filter. ' + e.message);
}
},
/**
@@ -156,11 +156,11 @@
*/
setCrop: function() {
var config = [].slice.call(arguments),
pos = Kinetic.Type._getXY(config),
size = Kinetic.Type._getSize(config),
both = Kinetic.Type._merge(pos, size);
pos = Kinetic.Util._getXY(config),
size = Kinetic.Util._getSize(config),
both = Kinetic.Util._merge(pos, size);
this.setAttr(CROP, Kinetic.Type._merge(both, this.getCrop()));
this.setAttr(CROP, Kinetic.Util._merge(both, this.getCrop()));
},
/**
* create image hit region which enables more accurate hit detection mapping of the image
@@ -187,7 +187,7 @@
try {
imageData = context.getImageData(0, 0, width, height);
data = imageData.data;
rgbColorKey = Kinetic.Type._hexToRgb(this.colorKey);
rgbColorKey = Kinetic.Util._hexToRgb(this.colorKey);
// replace non transparent pixels with color key
for(i = 0, n = data.length; i < n; i += 4) {
@@ -198,7 +198,7 @@
}
}
Kinetic.Type._getImage(imageData, function(imageObj) {
Kinetic.Util._getImage(imageData, function(imageObj) {
that.imageHitRegion = imageObj;
if(callback) {
callback();
@@ -206,7 +206,7 @@
});
}
catch(e) {
Kinetic.Global.warn('Unable to create image hit region. ' + e.message);
Kinetic.Util.warn('Unable to create image hit region. ' + e.message);
}
},
/**
@@ -234,7 +234,7 @@
}
}
};
Kinetic.Global.extend(Kinetic.Image, Kinetic.Shape);
Kinetic.Util.extend(Kinetic.Image, Kinetic.Shape);
Kinetic.Node.addFilterGetterSetter = function(constructor, attr, def) {
@@ -244,7 +244,7 @@
Kinetic.Node.addFilterSetter = function(constructor, attr) {
var that = this,
method = SET + Kinetic.Type._capitalize(attr);
method = SET + Kinetic.Util._capitalize(attr);
constructor.prototype[method] = function(val) {
this.setAttr(attr, val);

View File

@@ -42,7 +42,7 @@
* of Numbers. e.g. [{x:1,y:2},{x:3,y:4}] or [1,2,3,4]
*/
setPoints: function(val) {
this.setAttr('points', Kinetic.Type._getPoints(val));
this.setAttr('points', Kinetic.Util._getPoints(val));
},
/**
* get points array
@@ -55,5 +55,5 @@
return this.attrs.points || [];
}
};
Kinetic.Global.extend(Kinetic.Line, Kinetic.Shape);
Kinetic.Util.extend(Kinetic.Line, Kinetic.Shape);
})();

View File

@@ -40,7 +40,7 @@
* of Numbers. e.g. [{x:1,y:2},{x:3,y:4}] or [1,2,3,4]
*/
setPoints: function(val) {
this.setAttr('points', Kinetic.Type._getPoints(val));
this.setAttr('points', Kinetic.Util._getPoints(val));
},
/**
* get points array
@@ -53,5 +53,5 @@
return this.attrs.points || [];
}
};
Kinetic.Global.extend(Kinetic.Polygon, Kinetic.Shape);
Kinetic.Util.extend(Kinetic.Polygon, Kinetic.Shape);
})();

View File

@@ -48,7 +48,7 @@
}
};
Kinetic.Global.extend(Kinetic.Rect, Kinetic.Shape);
Kinetic.Util.extend(Kinetic.Rect, Kinetic.Shape);
Kinetic.Node.addGetterSetter(Kinetic.Rect, 'cornerRadius', 0);

View File

@@ -100,7 +100,7 @@
this.allPoints = allPoints;
}
};
Kinetic.Global.extend(Kinetic.Spline, Kinetic.Line);
Kinetic.Util.extend(Kinetic.Spline, Kinetic.Line);
// add getters setters
Kinetic.Node.addGetter(Kinetic.Spline, 'tension', 1);

View File

@@ -117,7 +117,7 @@
}
}
};
Kinetic.Global.extend(Kinetic.Sprite, Kinetic.Shape);
Kinetic.Util.extend(Kinetic.Sprite, Kinetic.Shape);
// add getters setters
Kinetic.Node.addGetterSetter(Kinetic.Sprite, 'animation');

View File

@@ -139,7 +139,7 @@
* @param {String} text
*/
setText: function(text) {
var str = Kinetic.Type._isString(text) ? text : text.toString();
var str = Kinetic.Util._isString(text) ? text : text.toString();
this.setAttr(TEXT, str);
},
/**
@@ -309,7 +309,7 @@
this.textWidth = textWidth;
}
};
Kinetic.Global.extend(Kinetic.Text, Kinetic.Shape);
Kinetic.Util.extend(Kinetic.Text, Kinetic.Shape);
// add getters setters
Kinetic.Node.addGetterSetter(Kinetic.Text, 'fontFamily', CALIBRI);

View File

@@ -33,13 +33,13 @@
canvas.fillStroke(this);
},
setAngleDeg: function(deg) {
this.setAngle(Kinetic.Type._degToRad(deg));
this.setAngle(Kinetic.Util._degToRad(deg));
},
getAngleDeg: function() {
return Kinetic.Type._radToDeg(this.getAngle());
return Kinetic.Util._radToDeg(this.getAngle());
}
};
Kinetic.Global.extend(Kinetic.Wedge, Kinetic.Shape);
Kinetic.Util.extend(Kinetic.Wedge, Kinetic.Shape);
// add getters setters
Kinetic.Node.addGetterSetter(Kinetic.Wedge, 'radius', 0);

View File

@@ -1,49 +0,0 @@
(function() {
/**
* Collection constructor. Collection extends
* Array. This class is used in conjunction with get()
* @constructor
*/
Kinetic.Collection = function() {
var args = [].slice.call(arguments), length = args.length, i = 0;
this.length = length;
for(; i < length; i++) {
this[i] = args[i];
}
return this;
}
Kinetic.Collection.prototype = new Array();
/**
* iterate through node array
* @name each
* @methodOf Kinetic.Collection.prototype
* @param {Function} func
*/
Kinetic.Collection.prototype.each = function(func) {
for(var n = 0; n < this.length; n++) {
func(this[n], n);
}
};
Kinetic.Collection.mapMethods = function(arr) {
var leng = arr.length,
n;
for(n = 0; n < leng; n++) {
// induce scope
(function(i) {
var method = arr[i];
Kinetic.Collection.prototype[method] = function() {
var len = this.length,
i;
args = [].slice.call(arguments);
for(i = 0; i < len; i++) {
this[i][method].apply(this[i], args);
}
};
})(n);
}
};
})();

View File

@@ -1,134 +0,0 @@
(function() {
/*
* Last updated November 2011
* By Simon Sarris
* www.simonsarris.com
* sarris@acm.org
*
* Free to use and distribute at will
* So long as you are nice to people, etc
*/
/*
* The usage of this class was inspired by some of the work done by a forked
* project, KineticJS-Ext by Wappworks, which is based on Simon's Transform
* class.
*/
/**
* Transform constructor
* @constructor
*/
Kinetic.Transform = function() {
this.m = [1, 0, 0, 1, 0, 0];
}
Kinetic.Transform.prototype = {
/**
* Apply translation
* @param {Number} x
* @param {Number} y
*/
translate: function(x, y) {
this.m[4] += this.m[0] * x + this.m[2] * y;
this.m[5] += this.m[1] * x + this.m[3] * y;
},
/**
* Apply scale
* @param {Number} sx
* @param {Number} sy
*/
scale: function(sx, sy) {
this.m[0] *= sx;
this.m[1] *= sx;
this.m[2] *= sy;
this.m[3] *= sy;
},
/**
* Apply rotation
* @param {Number} rad Angle in radians
*/
rotate: function(rad) {
var c = Math.cos(rad);
var s = Math.sin(rad);
var m11 = this.m[0] * c + this.m[2] * s;
var m12 = this.m[1] * c + this.m[3] * s;
var m21 = this.m[0] * -s + this.m[2] * c;
var m22 = this.m[1] * -s + this.m[3] * c;
this.m[0] = m11;
this.m[1] = m12;
this.m[2] = m21;
this.m[3] = m22;
},
/**
* Returns the translation
* @returns {Object} 2D point(x, y)
*/
getTranslation: function() {
return {
x: this.m[4],
y: this.m[5]
};
},
/**
* Apply skew
* @param {Number} sx
* @param {Number} sy
*/
skew: function(sx, sy) {
var m11 = this.m[0] + this.m[2] * sy;
var m12 = this.m[1] + this.m[3] * sy;
var m21 = this.m[2] + this.m[0] * sx;
var m22 = this.m[3] + this.m[1] * sx;
this.m[0] = m11;
this.m[1] = m12;
this.m[2] = m21;
this.m[3] = m22;
},
/**
* Transform multiplication
* @param {Kinetic.Transform} matrix
*/
multiply: function(matrix) {
var m11 = this.m[0] * matrix.m[0] + this.m[2] * matrix.m[1];
var m12 = this.m[1] * matrix.m[0] + this.m[3] * matrix.m[1];
var m21 = this.m[0] * matrix.m[2] + this.m[2] * matrix.m[3];
var m22 = this.m[1] * matrix.m[2] + this.m[3] * matrix.m[3];
var dx = this.m[0] * matrix.m[4] + this.m[2] * matrix.m[5] + this.m[4];
var dy = this.m[1] * matrix.m[4] + this.m[3] * matrix.m[5] + this.m[5];
this.m[0] = m11;
this.m[1] = m12;
this.m[2] = m21;
this.m[3] = m22;
this.m[4] = dx;
this.m[5] = dy;
},
/**
* Invert the matrix
*/
invert: function() {
var d = 1 / (this.m[0] * this.m[3] - this.m[1] * this.m[2]);
var m0 = this.m[3] * d;
var m1 = -this.m[1] * d;
var m2 = -this.m[2] * d;
var m3 = this.m[0] * d;
var m4 = d * (this.m[2] * this.m[5] - this.m[3] * this.m[4]);
var m5 = d * (this.m[1] * this.m[4] - this.m[0] * this.m[5]);
this.m[0] = m0;
this.m[1] = m1;
this.m[2] = m2;
this.m[3] = m3;
this.m[4] = m4;
this.m[5] = m5;
},
/**
* return matrix
*/
getMatrix: function() {
return this.m;
}
};
})();

View File

@@ -34,7 +34,7 @@ Test.Modules.IMAGE = {
test(darth.getHeight() === 100, 'height should be 100');
test(darth.getOffset().x === 50, 'center offset x should be 50');
test(darth.getOffset().y === 30, 'center offset y should be 30');
test(Kinetic.Type._isElement(darth.getImage()), 'darth image should be an element');
test(Kinetic.Util._isElement(darth.getImage()), 'darth image should be an element');
var crop = null;
crop = darth.getCrop();

View File

@@ -1,32 +1,32 @@
Test.Modules.TYPE = {
Test.Modules.UTIL = {
'getRGB()': function() {
var rgb = {};
// color strings
rgb = Kinetic.Type.getRGB('red');
rgb = Kinetic.Util.getRGB('red');
test(rgb.r === 255, 'color string r should be 255');
test(rgb.g === 0, 'color string g should be 0');
test(rgb.b === 0, 'color string b should be 0');
rgb = Kinetic.Type.getRGB('pink');
rgb = Kinetic.Util.getRGB('pink');
test(rgb.r === 255, 'color string r should be 255');
test(rgb.g === 192, 'color string g should be 192');
test(rgb.b === 203, 'color string b should be 203');
// hex
rgb = Kinetic.Type.getRGB('#00ff00');
rgb = Kinetic.Util.getRGB('#00ff00');
test(rgb.r === 0, 'hex r should be 0');
test(rgb.g === 255, 'hex g should be 255');
test(rgb.b === 0, 'hex b should be 0');
// rgb color string
rgb = Kinetic.Type.getRGB('rgb(255, 192, 203)');
rgb = Kinetic.Util.getRGB('rgb(255, 192, 203)');
test(rgb.r === 255, 'rgb string r should be 255');
test(rgb.g === 192, 'rgb string g should be 192');
test(rgb.b === 203, 'rgb string b should be 203');
// default
rgb = Kinetic.Type.getRGB('not a color');
rgb = Kinetic.Util.getRGB('not a color');
test(rgb.r === 0, 'default r should be 0');
test(rgb.g === 0, 'default g should be 0');
test(rgb.b === 0, 'default b should be 0');