📄 canvas.js
字号:
// Description: js.graphics.Canvas 类;画布(封装VML)
// Author: Changhua.Wan
// Version: 2004.020208
_package("js.graphics");
_import("js.graphics.Point");
_import("js.graphics.Pen");
_import("js.graphics.Brush");
_import("js.util.Vector");
function js.graphics.Canvas(elementObj, left, top, width, height) {
this.pen = new js.graphics.Pen();
this.brush = new js.graphics.Brush();
this.currPoint = new js.graphics.Point();
this.parentContainer = null;
this.group = null;
this.elements = new js.util.Vector();
this.clear = function() {
var _es = this.elements.toArray();
for (var i = 0; i < _es.length; i++)
this.remove(_es[i]);
};
this.add = function(_obj) {
this.group.appendChild(_obj);
this.elements.add(_obj);
};
this.remove = function(_obj) {
this.group.removeChild(_obj);
this.elements.remove(_obj);
};
this.left = 0;
this.top = 0;
this.width = 400;
this.height = 300;
this.initialize(elementObj, left, top, width, height);
}
var _p=js.graphics.Canvas._extends("js.lang.Object");
_p.initialize = function(elementObj, left, top, width, height) {
try {
if (typeof(elementObj) == "object")
this.parentContainer = elementObj;
else if (typeof(elementObj) == "string" && document.all[elementObj] != null)
this.parentContainer = document.all[elementObj];
else
this.parentContainer = document.body;
if (typeof(left) == "undefined")
this.left = 0;
else
this.left = parseInt(left, 10);
if (typeof(top) == "undefined")
this.top = 0;
else
this.top = parseInt(top, 10);
if (typeof(width) == "undefined")
this.width = this.parentContainer.clientWidth;
else
this.width = parseInt(width, 10);
if (typeof(height) == "undefined")
this.height = this.parentContainer.clientHeight;
else
this.height = parseInt(height, 10);
this.group = document.createElement('v:group');
this.group.style.left = this.left;
this.group.style.top = this.top;
this.group.style.width = this.width;
this.group.style.height = this.height;
this.group.coordsize = this.width + ',' + this.height;
this.group.style.position = 'absolute';
this.parentContainer.appendChild(this.group);
} catch(ex) {
_throw(0x0902, this.className
+ "初始化出错{"
+ ex.description
+ "}"
);
}
};
_p.moveTo = function(x, y) {
this.currPoint.x = x;
this.currPoint.y = y;
};
_p.lineTo = function(x, y) {
var line = this.pen.createLine();
line.position = 'absolute'; // ['absolute'|'relative']
line.from = this.currPoint.toString();
this.moveTo(x, y);
line.to = this.currPoint.toString();
this.add(line);
return line;
};
_p.polyLine = function(points) {
var polyline = this.pen.createPolyLine();
polyline.position = 'absolute';
polyline.points = points;
this.add(polyline);
return line;
}
_p.rect = function(_left, _top, _width, _height) {
var _rect = this.pen.createRect(_width, _height);
_rect.style.left = _left;
_rect.style.top = _top;
if (this.brush.color != null)
_rect.fillcolor = this.brush.color;
_rect.style.position = 'absolute';
this.add(_rect);
return _rect;
};
_p.roundRect = function(_left, _top, _width, _height) {
var _rect = this.pen.createRoundRect(_width, _height);
_rect.style.left = _left;
_rect.style.top = _top;
if (this.brush.color != null)
_rect.fillcolor = this.brush.color;
_rect.style.position = 'absolute';
this.add(_rect);
return _rect;
};
_p.oval = function(_left, _top, _width, _height) {
var _oval = this.pen.createOval(_width,_height);
_oval.style.top = _top;
_oval.style.left = _left;
if (this.brush.color != null)
_oval.fillcolor = this.brush.color;
_oval.style.position = 'absolute';
this.add(_oval);
return _oval;
};
_p.curve = function(_points) {
var _curve = this.pen.createCurve(_points);
_curve.style.position = 'absolute';
this.add(_curve);
return _curve;
};
_p.arc = function(_left, _top, _width, _height, _startangle, _endangle) {
var _arc = this.pen.createArc(_width, _height, _startangle, _endangle);
_arc.style.left = _left;
_arc.style.top = _top;
_arc.style.position = 'absolute';
this.add(_curve);
return _curve;
};
_p.shape = function(_left, _top, _width, _height, _path) {
var _shape = this.pen.createShape(_width, _height, _path);
_shape.style.position = 'absolute';
_shape.style.left = _left;
_shape.style.top = _top;
if (this.brush.color != null)
_shape.fillcolor = this.brush.color;
this.add(_shape);
return _shape;
};
_p.outText = function(x, y, text) {
var _textbox = document.createElement('v:textbox');
_textbox.style.left = x;
_textbox.style.top = y;
_textbox.innerText = text;
_textbox.style.color = this.pen.color;
_textbox.style.fontSize = this.pen.fontSize;
_textbox.style.position = 'absolute';
this.add(_textbox);
return _textbox;
};
_p.outImage = function(x, y, w, h, src) {
var _image = document.createElement('v:image');
_image.style.left = x;
_image.style.top = y;
_image.style.width = w;
_image.style.height = h;
_image.src = src;
_image.style.position = 'absolute';
this.add(_image);
return image;
}
/*@cc_on @*/
/*@if (!@_graphics_inited) @*/
try {
document.namespaces.add("v");
} catch(ex) {
if (document.body == null)
document.write("<?xml:namespace prefix=\"v\"/>");
else
_throw(0x0901,"js.graphics.Canvas 加载失败,必须在head中被加载!");
}
document.createStyleSheet().addRule("v\\:*", "{behavior=url(#default#VML)}");
/*@set @_graphics_inited = true; @*/
/*@end @*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -