Subversion Repositories Applications.papyrus

Rev

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