Subversion Repositories Applications.papyrus

Rev

Rev 1372 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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