| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- window.requestAnimationFrame || (window.requestAnimationFrame = function () {
- return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame ||
- window.oRequestAnimationFrame || window.msRequestAnimationFrame || function (a) {
- window.setTimeout(a, 1e3 / 60);
- };
- }());
- window.cancelRequestAnimationFrame || (window.cancelRequestAnimationFrame = function () {
- return window.cancelAnimationFrame || window.webkitCancelRequestAnimationFrame || window.mozCancelRequestAnimationFrame ||
- window.oCancelRequestAnimationFrame || window.msCancelRequestAnimationFrame || clearTimeout
- }());
- //工具类型文件
- CanvasSketch.lastId = 0;
- //取得id。
- CanvasSketch.getId = function (preString) {
- CanvasSketch.lastId += 1;
- return preString + CanvasSketch.lastId;
- };
- //图形的范围
- CanvasSketch.Bounds = function (x1, y1, x2, y2) {
- this.leftBottom = new CanvasSketch.Position(x1, y1);
- this.rigthTop = new CanvasSketch.Position(x2, y2);
- this.leftTop = new CanvasSketch.Position(x1, y2);
- this.rightBottom = new CanvasSketch.Position(x2, y1);
- this.left = x1;
- this.right = x2;
- this.bottom = y1;
- this.top = y2;
- };
- CanvasSketch.Bounds.prototype.getCenter = function (){
- var w = this.right - this.left;
- var h = this.top - this.bottom;
- return new CanvasSketch.Position(this.left + w/2, this.bottom + h/2);
- };
- //位置信息类
- CanvasSketch.Position = function (x, y) {
- this.x = x;
- this.y = y;
- };
- //大小类
- CanvasSketch.Size = function (w, h) {
- this.w = w;
- this.h = h;
- };
- //矢量图形的默认样式
- CanvasSketch.defaultStyle = function () {
- this.fill = true;
- this.stroke = true;
- this.pointRadius = 5;
- this.fillOpacity = 0.6;
- this.strokeOpacity = 1;
- this.fillColor = "red";
- this.strokeColor = "black";
- };
- //保存时间的this。
- CanvasSketch.bindAsEventListener = function(func, object) {
- return function(event) {
- return func.call(object, event || window.event);
- };
- };
- //阻止事件冒泡
- CanvasSketch.stopEventBubble = function(e) {
- if (e.preventDefault) {
- e.preventDefault();
- } else {
- e.returnValue = false;
- }
- if (e && e.stopPropagation)
- e.stopPropagation();
- else
- window.event.cancelBubble=true;
- };
|