Subversion Repositories Applications.papyrus

Rev

Rev 1318 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1318 Rev 1422
1
/*
1
/*
2
	Copyright (c) 2004-2006, The Dojo Foundation
2
	Copyright (c) 2004-2006, The Dojo Foundation
3
	All Rights Reserved.
3
	All Rights Reserved.
4
 
4
 
5
	Licensed under the Academic Free License version 2.1 or above OR the
5
	Licensed under the Academic Free License version 2.1 or above OR the
6
	modified BSD license. For more information on Dojo licensing, see:
6
	modified BSD license. For more information on Dojo licensing, see:
7
 
7
 
8
		http://dojotoolkit.org/community/licensing.shtml
8
		http://dojotoolkit.org/community/licensing.shtml
9
*/
9
*/
-
 
10
 
-
 
11
 
10
 
12
 
11
dojo.provide("dojo.gfx.shape");
13
dojo.provide("dojo.gfx.shape");
12
dojo.require("dojo.lang.declare");
14
dojo.require("dojo.lang.declare");
13
dojo.require("dojo.gfx.common");
15
dojo.require("dojo.gfx.common");
14
dojo.declare("dojo.gfx.Shape", null, {initializer:function () {
16
dojo.declare("dojo.gfx.Shape", null, {initializer:function () {
15
	this.rawNode = null;
17
	this.rawNode = null;
16
	this.shape = null;
18
	this.shape = null;
17
	this.matrix = null;
19
	this.matrix = null;
18
	this.fillStyle = null;
20
	this.fillStyle = null;
19
	this.strokeStyle = null;
21
	this.strokeStyle = null;
20
	this.bbox = null;
22
	this.bbox = null;
21
	this.parent = null;
23
	this.parent = null;
22
	this.parentMatrix = null;
24
	this.parentMatrix = null;
23
}, getNode:function () {
25
}, getNode:function () {
24
	return this.rawNode;
26
	return this.rawNode;
25
}, getShape:function () {
27
}, getShape:function () {
26
	return this.shape;
28
	return this.shape;
27
}, getTransform:function () {
29
}, getTransform:function () {
28
	return this.matrix;
30
	return this.matrix;
29
}, getFill:function () {
31
}, getFill:function () {
30
	return this.fillStyle;
32
	return this.fillStyle;
31
}, getStroke:function () {
33
}, getStroke:function () {
32
	return this.strokeStyle;
34
	return this.strokeStyle;
33
}, getParent:function () {
35
}, getParent:function () {
34
	return this.parent;
36
	return this.parent;
35
}, getBoundingBox:function () {
37
}, getBoundingBox:function () {
36
	return this.bbox;
38
	return this.bbox;
37
}, getEventSource:function () {
39
}, getEventSource:function () {
38
	return this.rawNode;
40
	return this.rawNode;
39
}, setShape:function (shape) {
41
}, setShape:function (shape) {
40
	return this;
42
	return this;
41
}, setFill:function (fill) {
43
}, setFill:function (fill) {
42
	return this;
44
	return this;
43
}, setStroke:function (stroke) {
45
}, setStroke:function (stroke) {
44
	return this;
46
	return this;
45
}, moveToFront:function () {
47
}, moveToFront:function () {
46
	return this;
48
	return this;
47
}, moveToBack:function () {
49
}, moveToBack:function () {
48
	return this;
50
	return this;
49
}, setTransform:function (matrix) {
51
}, setTransform:function (matrix) {
50
	this.matrix = dojo.gfx.matrix.clone(matrix ? dojo.gfx.matrix.normalize(matrix) : dojo.gfx.identity, true);
52
	this.matrix = dojo.gfx.matrix.clone(matrix ? dojo.gfx.matrix.normalize(matrix) : dojo.gfx.identity, true);
51
	return this._applyTransform();
53
	return this._applyTransform();
52
}, applyRightTransform:function (matrix) {
54
}, applyRightTransform:function (matrix) {
53
	return matrix ? this.setTransform([this.matrix, matrix]) : this;
55
	return matrix ? this.setTransform([this.matrix, matrix]) : this;
54
}, applyLeftTransform:function (matrix) {
56
}, applyLeftTransform:function (matrix) {
55
	return matrix ? this.setTransform([matrix, this.matrix]) : this;
57
	return matrix ? this.setTransform([matrix, this.matrix]) : this;
56
}, applyTransform:function (matrix) {
58
}, applyTransform:function (matrix) {
57
	return matrix ? this.setTransform([this.matrix, matrix]) : this;
59
	return matrix ? this.setTransform([this.matrix, matrix]) : this;
58
}, remove:function (silently) {
60
}, remove:function (silently) {
59
	if (this.parent) {
61
	if (this.parent) {
60
		this.parent.remove(this, silently);
62
		this.parent.remove(this, silently);
61
	}
63
	}
62
	return this;
64
	return this;
63
}, _setParent:function (parent, matrix) {
65
}, _setParent:function (parent, matrix) {
64
	this.parent = parent;
66
	this.parent = parent;
65
	return this._updateParentMatrix(matrix);
67
	return this._updateParentMatrix(matrix);
66
}, _updateParentMatrix:function (matrix) {
68
}, _updateParentMatrix:function (matrix) {
67
	this.parentMatrix = matrix ? dojo.gfx.matrix.clone(matrix) : null;
69
	this.parentMatrix = matrix ? dojo.gfx.matrix.clone(matrix) : null;
68
	return this._applyTransform();
70
	return this._applyTransform();
69
}, _getRealMatrix:function () {
71
}, _getRealMatrix:function () {
70
	return this.parentMatrix ? new dojo.gfx.matrix.Matrix2D([this.parentMatrix, this.matrix]) : this.matrix;
72
	return this.parentMatrix ? new dojo.gfx.matrix.Matrix2D([this.parentMatrix, this.matrix]) : this.matrix;
71
}});
73
}});
72
dojo.declare("dojo.gfx.shape.VirtualGroup", dojo.gfx.Shape, {initializer:function () {
74
dojo.declare("dojo.gfx.shape.VirtualGroup", dojo.gfx.Shape, {initializer:function () {
73
	this.children = [];
75
	this.children = [];
74
}, add:function (shape) {
76
}, add:function (shape) {
75
	var oldParent = shape.getParent();
77
	var oldParent = shape.getParent();
76
	if (oldParent) {
78
	if (oldParent) {
77
		oldParent.remove(shape, true);
79
		oldParent.remove(shape, true);
78
	}
80
	}
79
	this.children.push(shape);
81
	this.children.push(shape);
80
	return shape._setParent(this, this._getRealMatrix());
82
	return shape._setParent(this, this._getRealMatrix());
81
}, remove:function (shape, silently) {
83
}, remove:function (shape, silently) {
82
	for (var i = 0; i < this.children.length; ++i) {
84
	for (var i = 0; i < this.children.length; ++i) {
83
		if (this.children[i] == shape) {
85
		if (this.children[i] == shape) {
84
			if (silently) {
86
			if (silently) {
85
			} else {
87
			} else {
86
				shape._setParent(null, null);
88
				shape._setParent(null, null);
87
			}
89
			}
88
			this.children.splice(i, 1);
90
			this.children.splice(i, 1);
89
			break;
91
			break;
90
		}
92
		}
91
	}
93
	}
92
	return this;
94
	return this;
93
}, _applyTransform:function () {
95
}, _applyTransform:function () {
94
	var matrix = this._getRealMatrix();
96
	var matrix = this._getRealMatrix();
95
	for (var i = 0; i < this.children.length; ++i) {
97
	for (var i = 0; i < this.children.length; ++i) {
96
		this.children[i]._updateParentMatrix(matrix);
98
		this.children[i]._updateParentMatrix(matrix);
97
	}
99
	}
98
	return this;
100
	return this;
99
}});
101
}});
100
dojo.declare("dojo.gfx.shape.Rect", dojo.gfx.Shape, {initializer:function (rawNode) {
102
dojo.declare("dojo.gfx.shape.Rect", dojo.gfx.Shape, {initializer:function (rawNode) {
101
	this.shape = dojo.lang.shallowCopy(dojo.gfx.defaultRect, true);
103
	this.shape = dojo.lang.shallowCopy(dojo.gfx.defaultRect, true);
102
	this.attach(rawNode);
104
	this.attach(rawNode);
103
}, getBoundingBox:function () {
105
}, getBoundingBox:function () {
104
	return this.shape;
106
	return this.shape;
105
}});
107
}});
106
dojo.declare("dojo.gfx.shape.Ellipse", dojo.gfx.Shape, {initializer:function (rawNode) {
108
dojo.declare("dojo.gfx.shape.Ellipse", dojo.gfx.Shape, {initializer:function (rawNode) {
107
	this.shape = dojo.lang.shallowCopy(dojo.gfx.defaultEllipse, true);
109
	this.shape = dojo.lang.shallowCopy(dojo.gfx.defaultEllipse, true);
108
	this.attach(rawNode);
110
	this.attach(rawNode);
109
}, getBoundingBox:function () {
111
}, getBoundingBox:function () {
110
	if (!this.bbox) {
112
	if (!this.bbox) {
111
		var shape = this.shape;
113
		var shape = this.shape;
112
		this.bbox = {x:shape.cx - shape.rx, y:shape.cy - shape.ry, width:2 * shape.rx, height:2 * shape.ry};
114
		this.bbox = {x:shape.cx - shape.rx, y:shape.cy - shape.ry, width:2 * shape.rx, height:2 * shape.ry};
113
	}
115
	}
114
	return this.bbox;
116
	return this.bbox;
115
}});
117
}});
116
dojo.declare("dojo.gfx.shape.Circle", dojo.gfx.Shape, {initializer:function (rawNode) {
118
dojo.declare("dojo.gfx.shape.Circle", dojo.gfx.Shape, {initializer:function (rawNode) {
117
	this.shape = dojo.lang.shallowCopy(dojo.gfx.defaultCircle, true);
119
	this.shape = dojo.lang.shallowCopy(dojo.gfx.defaultCircle, true);
118
	this.attach(rawNode);
120
	this.attach(rawNode);
119
}, getBoundingBox:function () {
121
}, getBoundingBox:function () {
120
	if (!this.bbox) {
122
	if (!this.bbox) {
121
		var shape = this.shape;
123
		var shape = this.shape;
122
		this.bbox = {x:shape.cx - shape.r, y:shape.cy - shape.r, width:2 * shape.r, height:2 * shape.r};
124
		this.bbox = {x:shape.cx - shape.r, y:shape.cy - shape.r, width:2 * shape.r, height:2 * shape.r};
123
	}
125
	}
124
	return this.bbox;
126
	return this.bbox;
125
}});
127
}});
126
dojo.declare("dojo.gfx.shape.Line", dojo.gfx.Shape, {initializer:function (rawNode) {
128
dojo.declare("dojo.gfx.shape.Line", dojo.gfx.Shape, {initializer:function (rawNode) {
127
	this.shape = dojo.lang.shallowCopy(dojo.gfx.defaultLine, true);
129
	this.shape = dojo.lang.shallowCopy(dojo.gfx.defaultLine, true);
128
	this.attach(rawNode);
130
	this.attach(rawNode);
129
}, getBoundingBox:function () {
131
}, getBoundingBox:function () {
130
	if (!this.bbox) {
132
	if (!this.bbox) {
131
		var shape = this.shape;
133
		var shape = this.shape;
132
		this.bbox = {x:Math.min(shape.x1, shape.x2), y:Math.min(shape.y1, shape.y2), width:Math.abs(shape.x2 - shape.x1), height:Math.abs(shape.y2 - shape.y1)};
134
		this.bbox = {x:Math.min(shape.x1, shape.x2), y:Math.min(shape.y1, shape.y2), width:Math.abs(shape.x2 - shape.x1), height:Math.abs(shape.y2 - shape.y1)};
133
	}
135
	}
134
	return this.bbox;
136
	return this.bbox;
135
}});
137
}});
136
dojo.declare("dojo.gfx.shape.Polyline", dojo.gfx.Shape, {initializer:function (rawNode) {
138
dojo.declare("dojo.gfx.shape.Polyline", dojo.gfx.Shape, {initializer:function (rawNode) {
137
	this.shape = dojo.lang.shallowCopy(dojo.gfx.defaultPolyline, true);
139
	this.shape = dojo.lang.shallowCopy(dojo.gfx.defaultPolyline, true);
138
	this.attach(rawNode);
140
	this.attach(rawNode);
139
}, getBoundingBox:function () {
141
}, getBoundingBox:function () {
140
	if (!this.bbox && this.shape.points.length) {
142
	if (!this.bbox && this.shape.points.length) {
141
		var p = this.shape.points;
143
		var p = this.shape.points;
142
		var l = p.length;
144
		var l = p.length;
143
		var t = p[0];
145
		var t = p[0];
144
		var bbox = {l:t.x, t:t.y, r:t.x, b:t.y};
146
		var bbox = {l:t.x, t:t.y, r:t.x, b:t.y};
145
		for (var i = 1; i < l; ++i) {
147
		for (var i = 1; i < l; ++i) {
146
			t = p[i];
148
			t = p[i];
147
			if (bbox.l > t.x) {
149
			if (bbox.l > t.x) {
148
				bbox.l = t.x;
150
				bbox.l = t.x;
149
			}
151
			}
150
			if (bbox.r < t.x) {
152
			if (bbox.r < t.x) {
151
				bbox.r = t.x;
153
				bbox.r = t.x;
152
			}
154
			}
153
			if (bbox.t > t.y) {
155
			if (bbox.t > t.y) {
154
				bbox.t = t.y;
156
				bbox.t = t.y;
155
			}
157
			}
156
			if (bbox.b < t.y) {
158
			if (bbox.b < t.y) {
157
				bbox.b = t.y;
159
				bbox.b = t.y;
158
			}
160
			}
159
		}
161
		}
160
		this.bbox = {x:bbox.l, y:bbox.t, width:bbox.r - bbox.l, height:bbox.b - bbox.t};
162
		this.bbox = {x:bbox.l, y:bbox.t, width:bbox.r - bbox.l, height:bbox.b - bbox.t};
161
	}
163
	}
162
	return this.bbox;
164
	return this.bbox;
163
}});
165
}});
164
dojo.declare("dojo.gfx.shape.Image", dojo.gfx.Shape, {initializer:function (rawNode) {
166
dojo.declare("dojo.gfx.shape.Image", dojo.gfx.Shape, {initializer:function (rawNode) {
165
	this.shape = dojo.lang.shallowCopy(dojo.gfx.defaultImage, true);
167
	this.shape = dojo.lang.shallowCopy(dojo.gfx.defaultImage, true);
166
	this.attach(rawNode);
168
	this.attach(rawNode);
167
}, getBoundingBox:function () {
169
}, getBoundingBox:function () {
168
	if (!this.bbox) {
170
	if (!this.bbox) {
169
		var shape = this.shape;
171
		var shape = this.shape;
170
		this.bbox = {x:0, y:0, width:shape.width, height:shape.height};
172
		this.bbox = {x:0, y:0, width:shape.width, height:shape.height};
171
	}
173
	}
172
	return this.bbox;
174
	return this.bbox;
173
}});
175
}});
174
 
176