mirror of
https://github.com/konvajs/konva.git
synced 2025-06-28 03:24:49 +08:00
89 lines
2.5 KiB
JavaScript
89 lines
2.5 KiB
JavaScript
![]() |
///////////////////////////////////////////////////////////////////////
|
||
|
// Global Object
|
||
|
///////////////////////////////////////////////////////////////////////
|
||
|
/**
|
||
|
* Kinetic Namespace
|
||
|
* @namespace
|
||
|
*/
|
||
|
var Kinetic = {};
|
||
|
/**
|
||
|
* Kinetic Global Object
|
||
|
* @property {Object} GlobalObjet
|
||
|
*/
|
||
|
Kinetic.GlobalObject = {
|
||
|
stages: [],
|
||
|
idCounter: 0,
|
||
|
isAnimating: false,
|
||
|
frame: {
|
||
|
time: 0,
|
||
|
timeDiff: 0,
|
||
|
lastTime: 0
|
||
|
},
|
||
|
drag: {
|
||
|
moving: false,
|
||
|
node: undefined,
|
||
|
offset: {
|
||
|
x: 0,
|
||
|
y: 0
|
||
|
}
|
||
|
},
|
||
|
extend: function(obj1, obj2) {
|
||
|
for(var key in obj2.prototype) {
|
||
|
if(obj2.prototype.hasOwnProperty(key)) {
|
||
|
obj1.prototype[key] = obj2.prototype[key];
|
||
|
}
|
||
|
}
|
||
|
},
|
||
|
_isaCanvasAnimating: function() {
|
||
|
for(var n = 0; n < this.stages.length; n++) {
|
||
|
if(this.stages[n].isAnimating) {
|
||
|
return true;
|
||
|
}
|
||
|
}
|
||
|
return false;
|
||
|
},
|
||
|
_runFrames: function() {
|
||
|
for(var n = 0; n < this.stages.length; n++) {
|
||
|
if(this.stages[n].isAnimating) {
|
||
|
this.stages[n].onFrameFunc(this.frame);
|
||
|
}
|
||
|
}
|
||
|
},
|
||
|
_updateFrameObject: function() {
|
||
|
var date = new Date();
|
||
|
var time = date.getTime();
|
||
|
if(this.frame.lastTime === 0) {
|
||
|
this.frame.lastTime = time;
|
||
|
} else {
|
||
|
this.frame.timeDiff = time - this.frame.lastTime;
|
||
|
this.frame.lastTime = time;
|
||
|
this.frame.time += this.frame.timeDiff;
|
||
|
}
|
||
|
},
|
||
|
_animationLoop: function() {
|
||
|
if(this.isAnimating) {
|
||
|
this._updateFrameObject();
|
||
|
this._runFrames();
|
||
|
var that = this;
|
||
|
requestAnimFrame(function() {
|
||
|
that._animationLoop();
|
||
|
});
|
||
|
}
|
||
|
},
|
||
|
_handleAnimation: function() {
|
||
|
var that = this;
|
||
|
if(!this.isAnimating && this._isaCanvasAnimating()) {
|
||
|
this.isAnimating = true;
|
||
|
that._animationLoop();
|
||
|
} else if(this.isAnimating && !this._isaCanvasAnimating()) {
|
||
|
this.isAnimating = false;
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
|
||
|
window.requestAnimFrame = (function(callback) {
|
||
|
return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame ||
|
||
|
function(callback) {
|
||
|
window.setTimeout(callback, 1000 / 60);
|
||
|
};
|
||
|
})();
|