2012-03-07 13:45:48 +08:00
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
// Node
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
/**
|
2012-05-14 02:32:26 +08:00
|
|
|
* Node constructor. Nodes are entities that can be transformed, layered,
|
2012-03-07 13:45:48 +08:00
|
|
|
* and have events bound to them. They are the building blocks of a KineticJS
|
|
|
|
* application
|
|
|
|
* @constructor
|
|
|
|
* @param {Object} config
|
|
|
|
*/
|
|
|
|
Kinetic.Node = function(config) {
|
2012-05-27 09:40:43 +08:00
|
|
|
this.defaultNodeAttrs = {
|
2012-04-29 03:55:18 +08:00
|
|
|
visible: true,
|
2012-06-10 06:31:25 +08:00
|
|
|
listen: true,
|
2012-04-29 03:55:18 +08:00
|
|
|
name: undefined,
|
|
|
|
alpha: 1,
|
2012-03-07 13:45:48 +08:00
|
|
|
x: 0,
|
2012-04-29 03:55:18 +08:00
|
|
|
y: 0,
|
|
|
|
scale: {
|
|
|
|
x: 1,
|
|
|
|
y: 1
|
|
|
|
},
|
|
|
|
rotation: 0,
|
2012-06-10 07:13:25 +08:00
|
|
|
offset: {
|
2012-04-29 03:55:18 +08:00
|
|
|
x: 0,
|
|
|
|
y: 0
|
|
|
|
},
|
|
|
|
dragConstraint: 'none',
|
|
|
|
dragBounds: {},
|
|
|
|
draggable: false
|
2012-05-27 09:40:43 +08:00
|
|
|
};
|
2012-03-07 13:45:48 +08:00
|
|
|
|
2012-05-27 09:40:43 +08:00
|
|
|
this.setDefaultAttrs(this.defaultNodeAttrs);
|
2012-04-29 03:55:18 +08:00
|
|
|
this.eventListeners = {};
|
2012-06-10 06:31:25 +08:00
|
|
|
|
2012-06-10 07:13:25 +08:00
|
|
|
this.setAttrs(config);
|
|
|
|
|
2012-06-10 06:31:25 +08:00
|
|
|
// bind events
|
|
|
|
this.on('draggableChange.kinetic_reserved', function() {
|
|
|
|
if(this.attrs.draggable) {
|
|
|
|
this._listenDrag();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this._dragCleanup();
|
|
|
|
}
|
|
|
|
});
|
2012-06-10 07:13:25 +08:00
|
|
|
/*
|
|
|
|
* simulate draggable change event
|
|
|
|
* to init drag and drop logic from the
|
|
|
|
* above event binder
|
|
|
|
*/
|
|
|
|
this.simulate('draggableChange');
|
2012-03-07 13:45:48 +08:00
|
|
|
};
|
|
|
|
/*
|
|
|
|
* Node methods
|
|
|
|
*/
|
|
|
|
Kinetic.Node.prototype = {
|
|
|
|
/**
|
|
|
|
* bind events to the node. KineticJS supports mouseover, mousemove,
|
|
|
|
* mouseout, mousedown, mouseup, click, dblclick, touchstart, touchmove,
|
2012-06-04 03:48:13 +08:00
|
|
|
* touchend, tap, dbltap, dragstart, dragmove, and dragend. Pass in a string
|
2012-03-07 13:45:48 +08:00
|
|
|
* of event types delimmited by a space to bind multiple events at once
|
2012-03-18 01:28:25 +08:00
|
|
|
* such as 'mousedown mouseup mousemove'. include a namespace to bind an
|
|
|
|
* event by name such as 'click.foobar'.
|
2012-03-07 13:45:48 +08:00
|
|
|
* @param {String} typesStr
|
2012-05-14 02:32:26 +08:00
|
|
|
* @param {Function} handler
|
2012-03-07 13:45:48 +08:00
|
|
|
*/
|
|
|
|
on: function(typesStr, handler) {
|
2012-03-18 01:28:25 +08:00
|
|
|
var types = typesStr.split(' ');
|
2012-03-07 13:45:48 +08:00
|
|
|
/*
|
|
|
|
* loop through types and attach event listeners to
|
2012-03-18 01:28:25 +08:00
|
|
|
* each one. eg. 'click mouseover.namespace mouseout'
|
2012-03-07 13:45:48 +08:00
|
|
|
* will create three event bindings
|
|
|
|
*/
|
|
|
|
for(var n = 0; n < types.length; n++) {
|
|
|
|
var type = types[n];
|
2012-06-02 15:21:49 +08:00
|
|
|
//var event = (type.indexOf('touch') === -1) ? 'on' + type : type;
|
|
|
|
var event = type;
|
2012-03-18 01:28:25 +08:00
|
|
|
var parts = event.split('.');
|
2012-03-07 13:45:48 +08:00
|
|
|
var baseEvent = parts[0];
|
2012-03-18 01:28:25 +08:00
|
|
|
var name = parts.length > 1 ? parts[1] : '';
|
2012-03-07 13:45:48 +08:00
|
|
|
|
|
|
|
if(!this.eventListeners[baseEvent]) {
|
|
|
|
this.eventListeners[baseEvent] = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
this.eventListeners[baseEvent].push({
|
|
|
|
name: name,
|
|
|
|
handler: handler
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* remove event bindings from the node. Pass in a string of
|
|
|
|
* event types delimmited by a space to remove multiple event
|
2012-03-18 01:28:25 +08:00
|
|
|
* bindings at once such as 'mousedown mouseup mousemove'.
|
2012-03-07 13:45:48 +08:00
|
|
|
* include a namespace to remove an event binding by name
|
2012-03-18 01:28:25 +08:00
|
|
|
* such as 'click.foobar'.
|
2012-03-07 13:45:48 +08:00
|
|
|
* @param {String} typesStr
|
|
|
|
*/
|
|
|
|
off: function(typesStr) {
|
2012-03-18 01:28:25 +08:00
|
|
|
var types = typesStr.split(' ');
|
2012-03-07 13:45:48 +08:00
|
|
|
|
|
|
|
for(var n = 0; n < types.length; n++) {
|
|
|
|
var type = types[n];
|
2012-06-02 15:21:49 +08:00
|
|
|
//var event = (type.indexOf('touch') === -1) ? 'on' + type : type;
|
|
|
|
var event = type;
|
2012-03-18 01:28:25 +08:00
|
|
|
var parts = event.split('.');
|
2012-03-07 13:45:48 +08:00
|
|
|
var baseEvent = parts[0];
|
|
|
|
|
|
|
|
if(this.eventListeners[baseEvent] && parts.length > 1) {
|
|
|
|
var name = parts[1];
|
|
|
|
|
|
|
|
for(var i = 0; i < this.eventListeners[baseEvent].length; i++) {
|
|
|
|
if(this.eventListeners[baseEvent][i].name === name) {
|
|
|
|
this.eventListeners[baseEvent].splice(i, 1);
|
|
|
|
if(this.eventListeners[baseEvent].length === 0) {
|
2012-06-10 01:53:47 +08:00
|
|
|
delete this.eventListeners[baseEvent];
|
|
|
|
break;
|
2012-03-07 13:45:48 +08:00
|
|
|
}
|
2012-06-10 01:53:47 +08:00
|
|
|
i--;
|
2012-03-07 13:45:48 +08:00
|
|
|
}
|
|
|
|
}
|
2012-03-14 12:16:25 +08:00
|
|
|
}
|
|
|
|
else {
|
2012-06-10 01:53:47 +08:00
|
|
|
delete this.eventListeners[baseEvent];
|
2012-03-07 13:45:48 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2012-04-08 09:50:53 +08:00
|
|
|
/**
|
|
|
|
* get attrs
|
|
|
|
*/
|
|
|
|
getAttrs: function() {
|
|
|
|
return this.attrs;
|
|
|
|
},
|
2012-04-29 03:55:18 +08:00
|
|
|
/**
|
|
|
|
* set default attrs
|
|
|
|
* @param {Object} confic
|
|
|
|
*/
|
|
|
|
setDefaultAttrs: function(config) {
|
|
|
|
// create attrs object if undefined
|
|
|
|
if(this.attrs === undefined) {
|
|
|
|
this.attrs = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
if(config) {
|
|
|
|
for(var key in config) {
|
2012-05-13 06:15:42 +08:00
|
|
|
/*
|
|
|
|
* only set the attr if it's undefined in case
|
|
|
|
* a developer writes a custom class that extends
|
|
|
|
* a Kinetic Class such that their default property
|
|
|
|
* isn't overwritten by the Kinetic Class default
|
|
|
|
* property
|
|
|
|
*/
|
|
|
|
if(this.attrs[key] === undefined) {
|
|
|
|
this.attrs[key] = config[key];
|
|
|
|
}
|
2012-04-29 03:55:18 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2012-04-13 14:02:55 +08:00
|
|
|
/**
|
|
|
|
* set attrs
|
|
|
|
* @param {Object} config
|
|
|
|
*/
|
|
|
|
setAttrs: function(config) {
|
2012-04-28 10:42:04 +08:00
|
|
|
var go = Kinetic.GlobalObject;
|
2012-05-20 12:14:04 +08:00
|
|
|
var that = this;
|
|
|
|
|
2012-04-13 14:02:55 +08:00
|
|
|
// set properties from config
|
2012-05-20 12:14:04 +08:00
|
|
|
if(config !== undefined) {
|
2012-06-10 07:13:25 +08:00
|
|
|
|
|
|
|
function setAttrs(obj, c, level) {
|
2012-05-20 12:14:04 +08:00
|
|
|
for(var key in c) {
|
|
|
|
var val = c[key];
|
2012-04-28 10:42:04 +08:00
|
|
|
|
2012-05-27 01:57:56 +08:00
|
|
|
// if obj doesn't have the val property, then create it
|
|
|
|
if(obj[key] === undefined) {
|
|
|
|
obj[key] = {};
|
|
|
|
}
|
|
|
|
|
2012-05-20 12:14:04 +08:00
|
|
|
/*
|
2012-05-27 09:31:13 +08:00
|
|
|
* if property is a pure object (no methods), then add an empty object
|
2012-05-20 12:14:04 +08:00
|
|
|
* to the node and then traverse
|
|
|
|
*/
|
2012-05-27 09:31:13 +08:00
|
|
|
if(go._isObject(val) && !go._isArray(val) && !go._isElement(val) && !go._hasMethods(val)) {
|
2012-06-13 00:57:29 +08:00
|
|
|
/*
|
|
|
|
* since some properties can be strings or objects, e.g.
|
|
|
|
* fill, we need to first check that obj is an object
|
|
|
|
* before setting properties. If it's not an object,
|
|
|
|
* overwrite obj with an object literal
|
|
|
|
*/
|
|
|
|
if(!Kinetic.GlobalObject._isObject(obj[key])) {
|
2012-05-20 12:14:04 +08:00
|
|
|
obj[key] = {};
|
|
|
|
}
|
2012-06-13 00:57:29 +08:00
|
|
|
|
2012-06-10 07:13:25 +08:00
|
|
|
setAttrs(obj[key], val, level + 1);
|
2012-05-20 12:14:04 +08:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* add all other object types to attrs object
|
|
|
|
*/
|
|
|
|
else {
|
|
|
|
// handle special keys
|
|
|
|
switch (key) {
|
|
|
|
case 'rotationDeg':
|
2012-06-09 12:56:33 +08:00
|
|
|
that._setAttr(obj, 'rotation', c[key] * Math.PI / 180);
|
2012-06-10 01:53:47 +08:00
|
|
|
// override key for change event
|
|
|
|
key = 'rotation';
|
2012-05-20 12:14:04 +08:00
|
|
|
break;
|
2012-05-27 01:57:56 +08:00
|
|
|
/*
|
|
|
|
* includes:
|
2012-06-10 07:13:25 +08:00
|
|
|
* - node offset
|
2012-05-27 07:37:37 +08:00
|
|
|
* - fill pattern offset
|
2012-05-27 01:57:56 +08:00
|
|
|
* - shadow offset
|
|
|
|
*/
|
2012-05-20 12:14:04 +08:00
|
|
|
case 'offset':
|
2012-05-27 01:57:56 +08:00
|
|
|
var pos = go._getXY(val);
|
2012-06-09 12:56:33 +08:00
|
|
|
that._setAttr(obj[key], 'x', pos.x);
|
|
|
|
that._setAttr(obj[key], 'y', pos.y);
|
2012-05-20 12:14:04 +08:00
|
|
|
break;
|
2012-06-18 07:50:04 +08:00
|
|
|
case 'radius':
|
|
|
|
/*
|
|
|
|
* root attr radius should be an object
|
|
|
|
* while all other radius attrs should be
|
|
|
|
* a number
|
|
|
|
*/
|
|
|
|
if(level > 0) {
|
|
|
|
that._setAttr(obj, key, val);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
var pos = go._getXY(val);
|
|
|
|
that._setAttr(obj[key], 'x', pos.x);
|
|
|
|
that._setAttr(obj[key], 'y', pos.y);
|
|
|
|
}
|
|
|
|
break;
|
2012-05-20 12:14:04 +08:00
|
|
|
case 'scale':
|
2012-05-27 01:57:56 +08:00
|
|
|
var pos = go._getXY(val);
|
2012-06-09 12:56:33 +08:00
|
|
|
that._setAttr(obj[key], 'x', pos.x);
|
|
|
|
that._setAttr(obj[key], 'y', pos.y);
|
2012-05-20 12:14:04 +08:00
|
|
|
break;
|
|
|
|
case 'points':
|
2012-06-09 12:56:33 +08:00
|
|
|
that._setAttr(obj, key, go._getPoints(val));
|
2012-05-20 12:14:04 +08:00
|
|
|
break;
|
|
|
|
case 'crop':
|
|
|
|
var pos = go._getXY(val);
|
|
|
|
var size = go._getSize(val);
|
2012-06-09 12:56:33 +08:00
|
|
|
that._setAttr(obj[key], 'x', pos.x);
|
|
|
|
that._setAttr(obj[key], 'y', pos.y);
|
|
|
|
that._setAttr(obj[key], 'width', size.width);
|
|
|
|
that._setAttr(obj[key], 'height', size.height);
|
2012-05-20 12:14:04 +08:00
|
|
|
break;
|
|
|
|
default:
|
2012-06-18 07:50:04 +08:00
|
|
|
that._setAttr(obj, key, val);
|
2012-05-20 12:14:04 +08:00
|
|
|
break;
|
|
|
|
}
|
2012-06-10 01:53:47 +08:00
|
|
|
|
2012-06-10 07:13:25 +08:00
|
|
|
/*
|
|
|
|
* only fire change event for root
|
|
|
|
* level attrs
|
|
|
|
*/
|
|
|
|
if(level === 0) {
|
|
|
|
that._fireChangeEvent(key);
|
|
|
|
}
|
2012-04-28 10:42:04 +08:00
|
|
|
}
|
2012-04-13 14:02:55 +08:00
|
|
|
}
|
|
|
|
}
|
2012-06-10 07:13:25 +08:00
|
|
|
setAttrs(this.attrs, config, 0);
|
2012-04-13 14:02:55 +08:00
|
|
|
}
|
|
|
|
},
|
2012-04-15 03:04:45 +08:00
|
|
|
/**
|
2012-06-03 10:12:06 +08:00
|
|
|
* determine if shape is visible or not. Shape is visible only
|
|
|
|
* if it's visible and all of its ancestors are visible. If one ancestor
|
|
|
|
* is invisible, this means that the shape is also invisible
|
2012-04-15 03:04:45 +08:00
|
|
|
*/
|
|
|
|
isVisible: function() {
|
2012-06-03 10:12:06 +08:00
|
|
|
if(this.getParent() && !this.getParent().isVisible()) {
|
|
|
|
return false;
|
|
|
|
}
|
2012-04-15 03:04:45 +08:00
|
|
|
return this.attrs.visible;
|
|
|
|
},
|
2012-03-07 13:45:48 +08:00
|
|
|
/**
|
|
|
|
* show node
|
|
|
|
*/
|
|
|
|
show: function() {
|
2012-06-10 06:31:25 +08:00
|
|
|
this.setAttrs({
|
|
|
|
visible: true
|
|
|
|
});
|
2012-03-07 13:45:48 +08:00
|
|
|
},
|
|
|
|
/**
|
|
|
|
* hide node
|
|
|
|
*/
|
|
|
|
hide: function() {
|
2012-06-10 06:31:25 +08:00
|
|
|
this.setAttrs({
|
|
|
|
visible: false
|
|
|
|
});
|
2012-03-07 13:45:48 +08:00
|
|
|
},
|
|
|
|
/**
|
|
|
|
* get zIndex
|
|
|
|
*/
|
|
|
|
getZIndex: function() {
|
|
|
|
return this.index;
|
|
|
|
},
|
2012-04-01 06:17:36 +08:00
|
|
|
/**
|
|
|
|
* get absolute z-index by taking into account
|
|
|
|
* all parent and sibling indices
|
|
|
|
*/
|
|
|
|
getAbsoluteZIndex: function() {
|
|
|
|
var level = this.getLevel();
|
|
|
|
var stage = this.getStage();
|
|
|
|
var that = this;
|
|
|
|
var index = 0;
|
|
|
|
function addChildren(children) {
|
|
|
|
var nodes = [];
|
|
|
|
for(var n = 0; n < children.length; n++) {
|
|
|
|
var child = children[n];
|
|
|
|
index++;
|
|
|
|
|
2012-04-05 13:57:36 +08:00
|
|
|
if(child.nodeType !== 'Shape') {
|
2012-04-01 06:17:36 +08:00
|
|
|
nodes = nodes.concat(child.getChildren());
|
|
|
|
}
|
|
|
|
|
2012-04-08 11:32:24 +08:00
|
|
|
if(child._id === that._id) {
|
2012-04-01 06:17:36 +08:00
|
|
|
n = children.length;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(nodes.length > 0 && nodes[0].getLevel() <= level) {
|
|
|
|
addChildren(nodes);
|
|
|
|
}
|
|
|
|
}
|
2012-04-05 13:57:36 +08:00
|
|
|
if(that.nodeType !== 'Stage') {
|
2012-04-01 06:17:36 +08:00
|
|
|
addChildren(that.getStage().getChildren());
|
|
|
|
}
|
|
|
|
|
|
|
|
return index;
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* get node level in node tree
|
|
|
|
*/
|
|
|
|
getLevel: function() {
|
|
|
|
var level = 0;
|
|
|
|
var parent = this.parent;
|
|
|
|
while(parent) {
|
|
|
|
level++;
|
|
|
|
parent = parent.parent;
|
|
|
|
}
|
|
|
|
return level;
|
|
|
|
},
|
2012-03-07 13:45:48 +08:00
|
|
|
/**
|
2012-05-26 11:18:05 +08:00
|
|
|
* set node scale.
|
|
|
|
* @param arg
|
2012-03-07 13:45:48 +08:00
|
|
|
*/
|
2012-05-26 11:18:05 +08:00
|
|
|
setScale: function() {
|
|
|
|
this.setAttrs({
|
|
|
|
scale: arguments
|
|
|
|
});
|
2012-03-07 13:45:48 +08:00
|
|
|
},
|
|
|
|
/**
|
|
|
|
* set node position
|
2012-04-28 14:57:01 +08:00
|
|
|
* @param {Object} point
|
2012-03-07 13:45:48 +08:00
|
|
|
*/
|
2012-04-28 14:57:01 +08:00
|
|
|
setPosition: function() {
|
2012-05-14 01:46:49 +08:00
|
|
|
var pos = Kinetic.GlobalObject._getXY(arguments);
|
2012-05-26 11:18:05 +08:00
|
|
|
this.setAttrs(pos);
|
2012-03-07 13:45:48 +08:00
|
|
|
},
|
|
|
|
/**
|
|
|
|
* get node position relative to container
|
|
|
|
*/
|
|
|
|
getPosition: function() {
|
|
|
|
return {
|
2012-04-06 14:48:58 +08:00
|
|
|
x: this.attrs.x,
|
|
|
|
y: this.attrs.y
|
2012-03-07 13:45:48 +08:00
|
|
|
};
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* get absolute position relative to stage
|
|
|
|
*/
|
|
|
|
getAbsolutePosition: function() {
|
2012-03-25 11:52:17 +08:00
|
|
|
return this.getAbsoluteTransform().getTranslation();
|
2012-03-07 13:45:48 +08:00
|
|
|
},
|
2012-04-15 01:40:54 +08:00
|
|
|
/**
|
|
|
|
* set absolute position relative to stage
|
2012-04-15 07:27:00 +08:00
|
|
|
* @param {Object} pos object containing an x and
|
|
|
|
* y property
|
2012-04-15 01:40:54 +08:00
|
|
|
*/
|
2012-04-28 14:57:01 +08:00
|
|
|
setAbsolutePosition: function() {
|
2012-05-14 01:46:49 +08:00
|
|
|
var pos = Kinetic.GlobalObject._getXY(arguments);
|
2012-04-15 01:40:54 +08:00
|
|
|
/*
|
2012-04-15 07:27:00 +08:00
|
|
|
* save rotation and scale and
|
|
|
|
* then remove them from the transform
|
2012-04-15 01:40:54 +08:00
|
|
|
*/
|
|
|
|
var rot = this.attrs.rotation;
|
|
|
|
var scale = {
|
|
|
|
x: this.attrs.scale.x,
|
|
|
|
y: this.attrs.scale.y
|
|
|
|
};
|
2012-06-10 07:13:25 +08:00
|
|
|
var offset = {
|
|
|
|
x: this.attrs.offset.x,
|
|
|
|
y: this.attrs.offset.y
|
2012-04-15 07:27:00 +08:00
|
|
|
};
|
|
|
|
|
2012-04-15 01:40:54 +08:00
|
|
|
this.attrs.rotation = 0;
|
|
|
|
this.attrs.scale = {
|
|
|
|
x: 1,
|
|
|
|
y: 1
|
|
|
|
};
|
|
|
|
|
|
|
|
// unravel transform
|
|
|
|
var it = this.getAbsoluteTransform();
|
|
|
|
it.invert();
|
|
|
|
it.translate(pos.x, pos.y);
|
|
|
|
pos = {
|
|
|
|
x: this.attrs.x + it.getTranslation().x,
|
|
|
|
y: this.attrs.y + it.getTranslation().y
|
|
|
|
};
|
|
|
|
|
|
|
|
this.setPosition(pos.x, pos.y);
|
|
|
|
|
|
|
|
// restore rotation and scale
|
|
|
|
this.rotate(rot);
|
|
|
|
this.attrs.scale = {
|
|
|
|
x: scale.x,
|
|
|
|
y: scale.y
|
|
|
|
};
|
|
|
|
},
|
2012-03-07 13:45:48 +08:00
|
|
|
/**
|
|
|
|
* move node by an amount
|
|
|
|
*/
|
2012-06-10 06:31:25 +08:00
|
|
|
move: function() {
|
|
|
|
var pos = Kinetic.GlobalObject._getXY(arguments);
|
|
|
|
|
|
|
|
var x = this.getX();
|
|
|
|
var y = this.getY();
|
|
|
|
|
|
|
|
if(pos.x !== undefined) {
|
|
|
|
x += pos.x;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(pos.y !== undefined) {
|
|
|
|
y += pos.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.setAttrs({
|
|
|
|
x: x,
|
|
|
|
y: y
|
|
|
|
});
|
2012-03-07 13:45:48 +08:00
|
|
|
},
|
|
|
|
/**
|
|
|
|
* set node rotation in degrees
|
|
|
|
* @param {Number} deg
|
|
|
|
*/
|
|
|
|
setRotationDeg: function(deg) {
|
2012-06-10 06:31:25 +08:00
|
|
|
this.setRotation(deg * Math.PI / 180);
|
2012-03-07 13:45:48 +08:00
|
|
|
},
|
|
|
|
/**
|
|
|
|
* get rotation in degrees
|
|
|
|
*/
|
|
|
|
getRotationDeg: function() {
|
2012-04-06 14:48:58 +08:00
|
|
|
return this.attrs.rotation * 180 / Math.PI;
|
2012-03-07 13:45:48 +08:00
|
|
|
},
|
|
|
|
/**
|
|
|
|
* rotate node by an amount in radians
|
|
|
|
* @param {Number} theta
|
|
|
|
*/
|
|
|
|
rotate: function(theta) {
|
2012-06-10 06:31:25 +08:00
|
|
|
this.setAttrs({
|
|
|
|
rotation: this.getRotation() + theta
|
|
|
|
});
|
2012-03-07 13:45:48 +08:00
|
|
|
},
|
|
|
|
/**
|
|
|
|
* rotate node by an amount in degrees
|
|
|
|
* @param {Number} deg
|
|
|
|
*/
|
|
|
|
rotateDeg: function(deg) {
|
2012-06-10 06:31:25 +08:00
|
|
|
this.setAttrs({
|
|
|
|
rotation: this.getRotation() + (deg * Math.PI / 180)
|
|
|
|
});
|
2012-03-07 13:45:48 +08:00
|
|
|
},
|
|
|
|
/**
|
|
|
|
* listen or don't listen to events
|
2012-06-10 06:31:25 +08:00
|
|
|
* @param {Boolean} listen
|
|
|
|
*/
|
|
|
|
listen: function(listen) {
|
|
|
|
this.setAttrs({
|
|
|
|
listen: listen
|
|
|
|
});
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* is listening or not
|
2012-03-07 13:45:48 +08:00
|
|
|
*/
|
2012-06-10 06:31:25 +08:00
|
|
|
isListening: function() {
|
|
|
|
return this.attrs.listen;
|
2012-03-07 13:45:48 +08:00
|
|
|
},
|
|
|
|
/**
|
|
|
|
* move node to top
|
|
|
|
*/
|
|
|
|
moveToTop: function() {
|
|
|
|
var index = this.index;
|
|
|
|
this.parent.children.splice(index, 1);
|
|
|
|
this.parent.children.push(this);
|
|
|
|
this.parent._setChildrenIndices();
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* move node up
|
|
|
|
*/
|
|
|
|
moveUp: function() {
|
|
|
|
var index = this.index;
|
|
|
|
this.parent.children.splice(index, 1);
|
|
|
|
this.parent.children.splice(index + 1, 0, this);
|
|
|
|
this.parent._setChildrenIndices();
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* move node down
|
|
|
|
*/
|
|
|
|
moveDown: function() {
|
|
|
|
var index = this.index;
|
|
|
|
if(index > 0) {
|
|
|
|
this.parent.children.splice(index, 1);
|
|
|
|
this.parent.children.splice(index - 1, 0, this);
|
|
|
|
this.parent._setChildrenIndices();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* move node to bottom
|
|
|
|
*/
|
|
|
|
moveToBottom: function() {
|
|
|
|
var index = this.index;
|
|
|
|
this.parent.children.splice(index, 1);
|
|
|
|
this.parent.children.unshift(this);
|
|
|
|
this.parent._setChildrenIndices();
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* set zIndex
|
2012-03-12 14:01:23 +08:00
|
|
|
* @param {int} zIndex
|
2012-03-07 13:45:48 +08:00
|
|
|
*/
|
|
|
|
setZIndex: function(zIndex) {
|
|
|
|
var index = this.index;
|
|
|
|
this.parent.children.splice(index, 1);
|
|
|
|
this.parent.children.splice(zIndex, 0, this);
|
|
|
|
this.parent._setChildrenIndices();
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* get absolute alpha
|
|
|
|
*/
|
|
|
|
getAbsoluteAlpha: function() {
|
|
|
|
var absAlpha = 1;
|
|
|
|
var node = this;
|
|
|
|
// traverse upwards
|
2012-04-05 13:57:36 +08:00
|
|
|
while(node.nodeType !== 'Stage') {
|
2012-04-06 14:48:58 +08:00
|
|
|
absAlpha *= node.attrs.alpha;
|
2012-03-07 13:45:48 +08:00
|
|
|
node = node.parent;
|
|
|
|
}
|
|
|
|
return absAlpha;
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* determine if node is currently in drag and drop mode
|
|
|
|
*/
|
|
|
|
isDragging: function() {
|
|
|
|
var go = Kinetic.GlobalObject;
|
2012-04-08 11:32:24 +08:00
|
|
|
return go.drag.node !== undefined && go.drag.node._id === this._id && go.drag.moving;
|
2012-03-07 13:45:48 +08:00
|
|
|
},
|
|
|
|
/**
|
|
|
|
* move node to another container
|
2012-03-12 14:01:23 +08:00
|
|
|
* @param {Container} newContainer
|
2012-03-07 13:45:48 +08:00
|
|
|
*/
|
|
|
|
moveTo: function(newContainer) {
|
|
|
|
var parent = this.parent;
|
|
|
|
// remove from parent's children
|
|
|
|
parent.children.splice(this.index, 1);
|
|
|
|
parent._setChildrenIndices();
|
|
|
|
|
|
|
|
// add to new parent
|
|
|
|
newContainer.children.push(this);
|
|
|
|
this.index = newContainer.children.length - 1;
|
|
|
|
this.parent = newContainer;
|
|
|
|
newContainer._setChildrenIndices();
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* get parent container
|
|
|
|
*/
|
|
|
|
getParent: function() {
|
|
|
|
return this.parent;
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* get layer associated to node
|
|
|
|
*/
|
|
|
|
getLayer: function() {
|
2012-04-05 13:57:36 +08:00
|
|
|
if(this.nodeType === 'Layer') {
|
2012-03-07 13:45:48 +08:00
|
|
|
return this;
|
2012-03-14 12:16:25 +08:00
|
|
|
}
|
|
|
|
else {
|
2012-03-07 13:45:48 +08:00
|
|
|
return this.getParent().getLayer();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* get stage associated to node
|
|
|
|
*/
|
|
|
|
getStage: function() {
|
2012-04-05 13:57:36 +08:00
|
|
|
if(this.nodeType === 'Stage') {
|
2012-03-13 13:41:09 +08:00
|
|
|
return this;
|
2012-03-14 12:16:25 +08:00
|
|
|
}
|
|
|
|
else {
|
2012-04-09 02:01:31 +08:00
|
|
|
if(this.getParent() === undefined) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return this.getParent().getStage();
|
|
|
|
}
|
2012-03-13 13:41:09 +08:00
|
|
|
}
|
2012-03-07 13:45:48 +08:00
|
|
|
},
|
2012-06-02 15:21:49 +08:00
|
|
|
/**
|
|
|
|
* simulate event
|
|
|
|
* @param {String} eventType
|
|
|
|
*/
|
|
|
|
simulate: function(eventType) {
|
2012-06-09 11:57:20 +08:00
|
|
|
this._handleEvent(eventType, {});
|
2012-06-02 15:21:49 +08:00
|
|
|
},
|
2012-03-07 13:45:48 +08:00
|
|
|
/**
|
2012-06-10 07:13:25 +08:00
|
|
|
* set offset
|
2012-03-07 13:45:48 +08:00
|
|
|
* @param {Number} x
|
|
|
|
* @param {Number} y
|
|
|
|
*/
|
2012-06-10 07:13:25 +08:00
|
|
|
setOffset: function() {
|
2012-05-27 01:57:56 +08:00
|
|
|
this.setAttrs({
|
2012-06-10 07:13:25 +08:00
|
|
|
offset: arguments
|
2012-05-27 01:57:56 +08:00
|
|
|
});
|
2012-03-07 13:45:48 +08:00
|
|
|
},
|
2012-03-13 13:41:09 +08:00
|
|
|
/**
|
2012-03-14 12:16:25 +08:00
|
|
|
* transition node to another state. Any property that can accept a real
|
2012-03-20 13:44:42 +08:00
|
|
|
* number can be transitioned, including x, y, rotation, alpha, strokeWidth,
|
2012-06-10 07:13:25 +08:00
|
|
|
* radius, scale.x, scale.y, offset.x, offset.y, etc.
|
2012-03-13 13:41:09 +08:00
|
|
|
* @param {Object} config
|
2012-03-20 13:44:42 +08:00
|
|
|
* @config {Number} [duration] duration that the transition runs in seconds
|
2012-04-04 14:00:35 +08:00
|
|
|
* @config {String} [easing] easing function. can be linear, ease-in, ease-out, ease-in-out,
|
|
|
|
* back-ease-in, back-ease-out, back-ease-in-out, elastic-ease-in, elastic-ease-out,
|
|
|
|
* elastic-ease-in-out, bounce-ease-out, bounce-ease-in, bounce-ease-in-out,
|
|
|
|
* strong-ease-in, strong-ease-out, or strong-ease-in-out
|
2012-04-02 01:06:00 +08:00
|
|
|
* linear is the default
|
2012-03-20 13:44:42 +08:00
|
|
|
* @config {Function} [callback] callback function to be executed when
|
|
|
|
* transition completes
|
2012-03-13 13:41:09 +08:00
|
|
|
*/
|
|
|
|
transitionTo: function(config) {
|
2012-04-29 08:45:13 +08:00
|
|
|
var go = Kinetic.GlobalObject;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* clear transition if one is currently running for this
|
|
|
|
* node
|
|
|
|
*/
|
|
|
|
if(this.transAnim !== undefined) {
|
|
|
|
go._removeAnimation(this.transAnim);
|
|
|
|
this.transAnim = undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* create new transition
|
|
|
|
*/
|
2012-04-05 13:57:36 +08:00
|
|
|
var node = this.nodeType === 'Stage' ? this : this.getLayer();
|
2012-03-13 13:41:09 +08:00
|
|
|
var that = this;
|
2012-04-04 13:23:13 +08:00
|
|
|
var trans = new Kinetic.Transition(this, config);
|
2012-04-04 14:00:35 +08:00
|
|
|
var anim = {
|
2012-04-04 13:23:13 +08:00
|
|
|
func: function() {
|
2012-06-04 01:36:50 +08:00
|
|
|
trans._onEnterFrame();
|
2012-04-04 13:23:13 +08:00
|
|
|
},
|
2012-04-04 14:00:35 +08:00
|
|
|
node: node
|
|
|
|
};
|
2012-04-05 13:57:36 +08:00
|
|
|
|
2012-04-29 08:45:13 +08:00
|
|
|
// store reference to transition animation
|
|
|
|
this.transAnim = anim;
|
|
|
|
|
2012-04-04 14:00:35 +08:00
|
|
|
/*
|
|
|
|
* adding the animation with the addAnimation
|
|
|
|
* method auto generates an id
|
|
|
|
*/
|
2012-04-29 02:23:47 +08:00
|
|
|
go._addAnimation(anim);
|
2012-04-04 13:23:13 +08:00
|
|
|
|
2012-04-04 14:00:35 +08:00
|
|
|
// subscribe to onFinished for first tween
|
2012-04-29 10:52:45 +08:00
|
|
|
trans.onFinished = function() {
|
|
|
|
// remove animation
|
2012-04-29 08:45:13 +08:00
|
|
|
go._removeAnimation(anim);
|
2012-04-29 10:52:45 +08:00
|
|
|
that.transAnim = undefined;
|
|
|
|
|
|
|
|
// callback
|
2012-04-04 14:00:35 +08:00
|
|
|
if(config.callback !== undefined) {
|
|
|
|
config.callback();
|
|
|
|
}
|
2012-04-29 10:52:45 +08:00
|
|
|
|
|
|
|
anim.node.draw();
|
2012-04-04 14:00:35 +08:00
|
|
|
};
|
|
|
|
// auto start
|
2012-04-04 13:23:13 +08:00
|
|
|
trans.start();
|
2012-03-13 13:41:09 +08:00
|
|
|
|
2012-04-03 12:03:59 +08:00
|
|
|
go._handleAnimation();
|
2012-04-04 14:00:35 +08:00
|
|
|
|
|
|
|
return trans;
|
2012-03-13 13:41:09 +08:00
|
|
|
},
|
2012-03-24 14:39:54 +08:00
|
|
|
/**
|
2012-03-25 01:03:28 +08:00
|
|
|
* get transform of the node while taking into
|
|
|
|
* account the transforms of its parents
|
2012-03-24 14:39:54 +08:00
|
|
|
*/
|
2012-03-25 01:03:28 +08:00
|
|
|
getAbsoluteTransform: function() {
|
|
|
|
// absolute transform
|
|
|
|
var am = new Kinetic.Transform();
|
2012-03-24 14:39:54 +08:00
|
|
|
|
|
|
|
var family = [];
|
|
|
|
var parent = this.parent;
|
|
|
|
|
|
|
|
family.unshift(this);
|
|
|
|
while(parent) {
|
|
|
|
family.unshift(parent);
|
|
|
|
parent = parent.parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(var n = 0; n < family.length; n++) {
|
|
|
|
var node = family[n];
|
2012-03-25 01:03:28 +08:00
|
|
|
var m = node.getTransform();
|
2012-04-15 09:27:06 +08:00
|
|
|
|
2012-03-24 14:39:54 +08:00
|
|
|
am.multiply(m);
|
|
|
|
}
|
|
|
|
|
|
|
|
return am;
|
|
|
|
},
|
|
|
|
/**
|
2012-03-25 01:03:28 +08:00
|
|
|
* get transform of the node while not taking
|
|
|
|
* into account the transforms of its parents
|
2012-03-24 14:39:54 +08:00
|
|
|
*/
|
2012-03-25 01:03:28 +08:00
|
|
|
getTransform: function() {
|
|
|
|
var m = new Kinetic.Transform();
|
2012-03-23 04:47:37 +08:00
|
|
|
|
2012-04-06 14:48:58 +08:00
|
|
|
if(this.attrs.x !== 0 || this.attrs.y !== 0) {
|
|
|
|
m.translate(this.attrs.x, this.attrs.y);
|
2012-03-23 04:47:37 +08:00
|
|
|
}
|
2012-04-06 14:48:58 +08:00
|
|
|
if(this.attrs.rotation !== 0) {
|
|
|
|
m.rotate(this.attrs.rotation);
|
2012-03-23 04:47:37 +08:00
|
|
|
}
|
2012-04-06 14:48:58 +08:00
|
|
|
if(this.attrs.scale.x !== 1 || this.attrs.scale.y !== 1) {
|
|
|
|
m.scale(this.attrs.scale.x, this.attrs.scale.y);
|
2012-03-23 04:47:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return m;
|
|
|
|
},
|
2012-06-09 16:47:41 +08:00
|
|
|
_fireChangeEvent: function(attr) {
|
2012-06-10 06:31:25 +08:00
|
|
|
this._handleEvent(attr + 'Change', {});
|
2012-06-09 16:47:41 +08:00
|
|
|
},
|
2012-06-09 12:56:33 +08:00
|
|
|
_setAttr: function(obj, attr, val) {
|
|
|
|
if(val !== undefined) {
|
|
|
|
obj[attr] = val;
|
|
|
|
}
|
|
|
|
},
|
2012-05-27 15:07:36 +08:00
|
|
|
_listenDrag: function() {
|
2012-04-02 10:38:30 +08:00
|
|
|
this._dragCleanup();
|
2012-03-07 13:45:48 +08:00
|
|
|
var go = Kinetic.GlobalObject;
|
|
|
|
var that = this;
|
2012-03-18 01:28:25 +08:00
|
|
|
this.on('mousedown.initdrag touchstart.initdrag', function(evt) {
|
2012-06-02 15:21:49 +08:00
|
|
|
that._initDrag();
|
2012-03-07 13:45:48 +08:00
|
|
|
});
|
|
|
|
},
|
2012-05-27 15:07:36 +08:00
|
|
|
_initDrag: function() {
|
2012-06-02 15:21:49 +08:00
|
|
|
var go = Kinetic.GlobalObject;
|
2012-05-27 15:07:36 +08:00
|
|
|
var stage = this.getStage();
|
|
|
|
var pos = stage.getUserPosition();
|
2012-06-08 15:42:48 +08:00
|
|
|
|
2012-05-27 15:07:36 +08:00
|
|
|
if(pos) {
|
|
|
|
var m = this.getTransform().getTranslation();
|
|
|
|
var am = this.getAbsoluteTransform().getTranslation();
|
|
|
|
go.drag.node = this;
|
|
|
|
go.drag.offset.x = pos.x - this.getAbsoluteTransform().getTranslation().x;
|
|
|
|
go.drag.offset.y = pos.y - this.getAbsoluteTransform().getTranslation().y;
|
|
|
|
}
|
|
|
|
},
|
2012-03-07 13:45:48 +08:00
|
|
|
/**
|
|
|
|
* remove drag and drop event listener
|
|
|
|
*/
|
|
|
|
_dragCleanup: function() {
|
2012-03-18 01:28:25 +08:00
|
|
|
this.off('mousedown.initdrag');
|
|
|
|
this.off('touchstart.initdrag');
|
2012-03-07 13:45:48 +08:00
|
|
|
},
|
|
|
|
/**
|
2012-06-08 15:42:48 +08:00
|
|
|
* handle node event
|
2012-03-07 13:45:48 +08:00
|
|
|
*/
|
2012-06-08 15:42:48 +08:00
|
|
|
_handleEvent: function(eventType, evt) {
|
2012-04-05 13:57:36 +08:00
|
|
|
if(this.nodeType === 'Shape') {
|
2012-03-26 03:45:46 +08:00
|
|
|
evt.shape = this;
|
|
|
|
}
|
2012-06-08 15:42:48 +08:00
|
|
|
|
2012-03-19 02:24:57 +08:00
|
|
|
var stage = this.getStage();
|
2012-06-10 06:31:25 +08:00
|
|
|
var mouseoverNode = stage ? stage.mouseoverShape : null;
|
|
|
|
var mouseoutNode = stage ? stage.mouseoutShape : null;
|
2012-06-08 15:42:48 +08:00
|
|
|
var el = this.eventListeners;
|
2012-03-19 02:24:57 +08:00
|
|
|
var okayToRun = true;
|
2012-03-07 13:45:48 +08:00
|
|
|
|
2012-03-19 02:24:57 +08:00
|
|
|
/*
|
|
|
|
* determine if event handler should be skipped by comparing
|
|
|
|
* parent nodes
|
|
|
|
*/
|
2012-06-08 15:42:48 +08:00
|
|
|
if(eventType === 'mouseover' && mouseoutNode && mouseoutNode._id === this._id) {
|
2012-03-19 02:24:57 +08:00
|
|
|
okayToRun = false;
|
|
|
|
}
|
2012-06-08 15:42:48 +08:00
|
|
|
else if(eventType === 'mouseout' && mouseoverNode && mouseoverNode._id === this._id) {
|
2012-03-19 02:24:57 +08:00
|
|
|
okayToRun = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(el[eventType] && okayToRun) {
|
|
|
|
var events = el[eventType];
|
|
|
|
for(var i = 0; i < events.length; i++) {
|
2012-06-08 15:42:48 +08:00
|
|
|
events[i].handler.apply(this, [evt]);
|
2012-03-07 13:45:48 +08:00
|
|
|
}
|
|
|
|
}
|
2012-03-19 02:24:57 +08:00
|
|
|
|
|
|
|
var mouseoverParent = mouseoverNode ? mouseoverNode.parent : undefined;
|
|
|
|
var mouseoutParent = mouseoutNode ? mouseoutNode.parent : undefined;
|
|
|
|
|
|
|
|
// simulate event bubbling
|
2012-06-08 15:42:48 +08:00
|
|
|
if(!evt.cancelBubble && this.parent && this.parent.nodeType !== 'Stage') {
|
|
|
|
this._handleEvent.call(this.parent, eventType, evt);
|
2012-03-19 02:24:57 +08:00
|
|
|
}
|
2012-03-07 13:45:48 +08:00
|
|
|
}
|
2012-03-12 14:01:23 +08:00
|
|
|
};
|
2012-06-11 04:07:09 +08:00
|
|
|
|
|
|
|
// add setters and getters
|
2012-06-19 13:02:13 +08:00
|
|
|
Kinetic.GlobalObject.addSetters(Kinetic.Node, ['x', 'y', 'detectionType', 'rotation', 'alpha', 'name', 'id', 'draggable', 'dragConstraint', 'dragBounds']);
|
|
|
|
Kinetic.GlobalObject.addGetters(Kinetic.Node, ['scale', 'x', 'y', 'detectionType', 'rotation', 'alpha', 'name', 'id', 'draggable', 'offset', 'dragConstraint', 'dragBounds']);
|
2012-06-11 04:07:09 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* set node x position
|
2012-06-14 17:19:51 +08:00
|
|
|
* @name setX
|
|
|
|
* @methodOf Kinetic.Node.prototype
|
2012-06-11 04:07:09 +08:00
|
|
|
* @param {Number} x
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* set node y position
|
2012-06-14 17:19:51 +08:00
|
|
|
* @name setY
|
|
|
|
* @methodOf Kinetic.Node.prototype
|
2012-06-11 04:07:09 +08:00
|
|
|
* @param {Number} y
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* set detection type
|
2012-06-14 17:19:51 +08:00
|
|
|
* @name setDetectionType
|
|
|
|
* @methodOf Kinetic.Node.prototype
|
2012-06-11 04:07:09 +08:00
|
|
|
* @param {String} type can be "path" or "pixel"
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* set node rotation in radians
|
2012-06-14 17:19:51 +08:00
|
|
|
* @name setRotation
|
|
|
|
* @methodOf Kinetic.Node.prototype
|
2012-06-11 04:07:09 +08:00
|
|
|
* @param {Number} theta
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* set alpha. Alpha values range from 0 to 1.
|
|
|
|
* A node with an alpha of 0 is fully transparent, and a node
|
|
|
|
* with an alpha of 1 is fully opaque
|
2012-06-14 17:19:51 +08:00
|
|
|
* @name setAlpha
|
|
|
|
* @methodOf Kinetic.Node.prototype
|
2012-06-11 04:07:09 +08:00
|
|
|
* @param {Object} alpha
|
|
|
|
*/
|
|
|
|
|
2012-06-19 13:02:13 +08:00
|
|
|
/**
|
|
|
|
* set draggable
|
|
|
|
* @name setDraggable
|
|
|
|
* @methodOf Kinetic.Node.prototype
|
|
|
|
* @param {String} draggable
|
|
|
|
*/
|
|
|
|
|
2012-06-11 04:07:09 +08:00
|
|
|
/**
|
|
|
|
* set drag constraint
|
2012-06-14 17:19:51 +08:00
|
|
|
* @name setDragConstraint
|
|
|
|
* @methodOf Kinetic.Node.prototype
|
2012-06-11 04:07:09 +08:00
|
|
|
* @param {String} constraint
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* set drag bounds
|
2012-06-14 17:19:51 +08:00
|
|
|
* @name setDragBounds
|
|
|
|
* @methodOf Kinetic.Node.prototype
|
2012-06-11 04:07:09 +08:00
|
|
|
* @param {Object} bounds
|
|
|
|
* @config {Number} [left] left bounds position
|
|
|
|
* @config {Number} [top] top bounds position
|
|
|
|
* @config {Number} [right] right bounds position
|
|
|
|
* @config {Number} [bottom] bottom bounds position
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get scale
|
2012-06-14 17:19:51 +08:00
|
|
|
* @name getScale
|
|
|
|
* @methodOf Kinetic.Node.prototype
|
2012-06-11 04:07:09 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get node x position
|
2012-06-14 17:19:51 +08:00
|
|
|
* @name getX
|
|
|
|
* @methodOf Kinetic.Node.prototype
|
2012-06-11 04:07:09 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get node y position
|
2012-06-14 17:19:51 +08:00
|
|
|
* @name getY
|
|
|
|
* @methodOf Kinetic.Node.prototype
|
2012-06-11 04:07:09 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get detection type
|
2012-06-14 17:19:51 +08:00
|
|
|
* @name getDetectionType
|
|
|
|
* @methodOf Kinetic.Node.prototype
|
2012-06-11 04:07:09 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get rotation in radians
|
2012-06-14 17:19:51 +08:00
|
|
|
* @name getRotation
|
|
|
|
* @methodOf Kinetic.Node.prototype
|
2012-06-11 04:07:09 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get alpha. Alpha values range from 0 to 1.
|
|
|
|
* A node with an alpha of 0 is fully transparent, and a node
|
|
|
|
* with an alpha of 1 is fully opaque
|
2012-06-14 17:19:51 +08:00
|
|
|
* @name getAlpha
|
|
|
|
* @methodOf Kinetic.Node.prototype
|
2012-06-11 04:07:09 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get name
|
2012-06-14 17:19:51 +08:00
|
|
|
* @name getName
|
|
|
|
* @methodOf Kinetic.Node.prototype
|
2012-06-11 04:07:09 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get id
|
2012-06-14 17:19:51 +08:00
|
|
|
* @name getId
|
|
|
|
* @methodOf Kinetic.Node.prototype
|
2012-06-11 04:07:09 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2012-06-14 17:19:51 +08:00
|
|
|
* get offset
|
|
|
|
* @name getOffset
|
|
|
|
* @methodOf Kinetic.Node.prototype
|
2012-06-11 04:07:09 +08:00
|
|
|
*/
|
|
|
|
|
2012-06-19 13:02:13 +08:00
|
|
|
/**
|
|
|
|
* get draggable
|
|
|
|
* @name getDraggable
|
|
|
|
* @methodOf Kinetic.Node.prototype
|
|
|
|
*/
|
|
|
|
|
2012-06-11 04:07:09 +08:00
|
|
|
/**
|
|
|
|
* get drag constraint
|
2012-06-14 17:19:51 +08:00
|
|
|
* @name getDragConstraint
|
|
|
|
* @methodOf Kinetic.Node.prototype
|
2012-06-11 04:07:09 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get drag bounds
|
2012-06-14 17:19:51 +08:00
|
|
|
* @name getDragBounds
|
|
|
|
* @methodOf Kinetic.Node.prototype
|
2012-06-11 04:07:09 +08:00
|
|
|
*/
|