shape.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758
  1. if (!dojo._hasResource["dojox.gfx.shape"]) { // _hasResource checks added by
  2. // build. Do not use
  3. // _hasResource directly in your
  4. // code.
  5. dojo._hasResource["dojox.gfx.shape"] = true;
  6. dojo.provide("dojox.gfx.shape");
  7. dojo.require("dojox.gfx._base");
  8. dojo.declare("dojox.gfx.Shape", null, {
  9. // summary: a Shape object, which knows how to apply
  10. // graphical attributes and transformations
  11. constructor : function() {
  12. // rawNode: Node: underlying node
  13. this.rawNode = null;
  14. // shape: Object: an abstract shape object
  15. // (see dojox.gfx.defaultPath,
  16. // dojox.gfx.defaultPolyline,
  17. // dojox.gfx.defaultRect,
  18. // dojox.gfx.defaultEllipse,
  19. // dojox.gfx.defaultCircle,
  20. // dojox.gfx.defaultLine,
  21. // or dojox.gfx.defaultImage)
  22. this.shape = null;
  23. // matrix: dojox.gfx.Matrix2D: a transformation matrix
  24. this.matrix = null;
  25. // fillStyle: Object: a fill object
  26. // (see dojox.gfx.defaultLinearGradient,
  27. // dojox.gfx.defaultRadialGradient,
  28. // dojox.gfx.defaultPattern,
  29. // or dojo.Color)
  30. this.fillStyle = null;
  31. // strokeStyle: Object: a stroke object
  32. // (see dojox.gfx.defaultStroke)
  33. this.strokeStyle = null;
  34. // bbox: dojox.gfx.Rectangle: a bounding box of this shape
  35. // (see dojox.gfx.defaultRect)
  36. this.bbox = null;
  37. // virtual group structure
  38. // parent: Object: a parent or null
  39. // (see dojox.gfx.Surface,
  40. // dojox.gfx.shape.VirtualGroup,
  41. // or dojox.gfx.Group)
  42. this.parent = null;
  43. // parentMatrix: dojox.gfx.Matrix2D
  44. // a transformation matrix inherited from the parent
  45. this.parentMatrix = null;
  46. },
  47. // trivial getters
  48. getNode : function() {
  49. // summary: returns the current DOM Node or null
  50. return this.rawNode; // Node
  51. },
  52. getShape : function() {
  53. // summary: returns the current shape object or null
  54. // (see dojox.gfx.defaultPath,
  55. // dojox.gfx.defaultPolyline,
  56. // dojox.gfx.defaultRect,
  57. // dojox.gfx.defaultEllipse,
  58. // dojox.gfx.defaultCircle,
  59. // dojox.gfx.defaultLine,
  60. // or dojox.gfx.defaultImage)
  61. return this.shape; // Object
  62. },
  63. getTransform : function() {
  64. // summary: returns the current transformation matrix or
  65. // null
  66. return this.matrix; // dojox.gfx.Matrix2D
  67. },
  68. getFill : function() {
  69. // summary: returns the current fill object or null
  70. // (see dojox.gfx.defaultLinearGradient,
  71. // dojox.gfx.defaultRadialGradient,
  72. // dojox.gfx.defaultPattern,
  73. // or dojo.Color)
  74. return this.fillStyle; // Object
  75. },
  76. getStroke : function() {
  77. // summary: returns the current stroke object or null
  78. // (see dojox.gfx.defaultStroke)
  79. return this.strokeStyle; // Object
  80. },
  81. getParent : function() {
  82. // summary: returns the parent or null
  83. // (see dojox.gfx.Surface,
  84. // dojox.gfx.shape.VirtualGroup,
  85. // or dojox.gfx.Group)
  86. return this.parent; // Object
  87. },
  88. getBoundingBox : function() {
  89. // summary: returns the bounding box or null
  90. // (see dojox.gfx.defaultRect)
  91. return this.bbox; // dojox.gfx.Rectangle
  92. },
  93. getTransformedBoundingBox : function() {
  94. // summary: returns an array of four points or null
  95. // four points represent four corners of the untransformed
  96. // bounding box
  97. var b = this.getBoundingBox();
  98. if (!b) {
  99. return null; // null
  100. }
  101. var m = this._getRealMatrix();
  102. var r = [];
  103. var g = dojox.gfx.matrix;
  104. r.push(g.multiplyPoint(m, b.x, b.y));
  105. r.push(g.multiplyPoint(m, b.x + b.width, b.y));
  106. r.push(g.multiplyPoint(m, b.x + b.width, b.y + b.height));
  107. r.push(g.multiplyPoint(m, b.x, b.y + b.height));
  108. return r; // Array
  109. },
  110. getEventSource : function() {
  111. // summary: returns a Node, which is used as
  112. // a source of events for this shape
  113. // COULD BE RE-IMPLEMENTED BY THE RENDERER!
  114. return this.rawNode; // Node
  115. },
  116. // empty settings
  117. setShape : function(shape) {
  118. // summary: sets a shape object
  119. // (the default implementation simply ignores it)
  120. // shape: Object: a shape object
  121. // (see dojox.gfx.defaultPath,
  122. // dojox.gfx.defaultPolyline,
  123. // dojox.gfx.defaultRect,
  124. // dojox.gfx.defaultEllipse,
  125. // dojox.gfx.defaultCircle,
  126. // dojox.gfx.defaultLine,
  127. // or dojox.gfx.defaultImage)
  128. // COULD BE RE-IMPLEMENTED BY THE RENDERER!
  129. this.shape = dojox.gfx.makeParameters(this.shape, shape);
  130. this.bbox = null;
  131. return this; // self
  132. },
  133. setFill : function(fill) {
  134. // summary: sets a fill object
  135. // (the default implementation simply ignores it)
  136. // fill: Object: a fill object
  137. // (see dojox.gfx.defaultLinearGradient,
  138. // dojox.gfx.defaultRadialGradient,
  139. // dojox.gfx.defaultPattern,
  140. // or dojo.Color)
  141. // COULD BE RE-IMPLEMENTED BY THE RENDERER!
  142. if (!fill) {
  143. // don't fill
  144. this.fillStyle = null;
  145. return this; // self
  146. }
  147. var f = null;
  148. if (typeof(fill) == "object" && "type" in fill) {
  149. // gradient or pattern
  150. switch (fill.type) {
  151. case "linear" :
  152. f = dojox.gfx.makeParameters(
  153. dojox.gfx.defaultLinearGradient, fill);
  154. break;
  155. case "radial" :
  156. f = dojox.gfx.makeParameters(
  157. dojox.gfx.defaultRadialGradient, fill);
  158. break;
  159. case "pattern" :
  160. f = dojox.gfx.makeParameters(
  161. dojox.gfx.defaultPattern, fill);
  162. break;
  163. }
  164. } else {
  165. // color object
  166. f = dojox.gfx.normalizeColor(fill);
  167. }
  168. this.fillStyle = f;
  169. return this; // self
  170. },
  171. setStroke : function(stroke) {
  172. // summary: sets a stroke object
  173. // (the default implementation simply ignores it)
  174. // stroke: Object: a stroke object
  175. // (see dojox.gfx.defaultStroke)
  176. // COULD BE RE-IMPLEMENTED BY THE RENDERER!
  177. if (!stroke) {
  178. // don't stroke
  179. this.strokeStyle = null;
  180. return this; // self
  181. }
  182. // normalize the stroke
  183. if (typeof stroke == "string") {
  184. stroke = {
  185. color : stroke
  186. };
  187. }
  188. var s = this.strokeStyle = dojox.gfx.makeParameters(
  189. dojox.gfx.defaultStroke, stroke);
  190. s.color = dojox.gfx.normalizeColor(s.color);
  191. return this; // self
  192. },
  193. setTransform : function(matrix) {
  194. // summary: sets a transformation matrix
  195. // matrix: dojox.gfx.Matrix2D: a matrix or a matrix-like
  196. // object
  197. // (see an argument of dojox.gfx.Matrix2D
  198. // constructor for a list of acceptable arguments)
  199. // COULD BE RE-IMPLEMENTED BY THE RENDERER!
  200. this.matrix = dojox.gfx.matrix.clone(matrix
  201. ? dojox.gfx.matrix.normalize(matrix)
  202. : dojox.gfx.matrix.identity);
  203. return this._applyTransform(); // self
  204. },
  205. _applyTransform : function() {
  206. // summary: physically sets a matrix
  207. // COULD BE RE-IMPLEMENTED BY THE RENDERER!
  208. return this; // self
  209. },
  210. // z-index
  211. moveToFront : function() {
  212. // summary: moves a shape to front of its parent's list of
  213. // shapes
  214. var p = this.getParent();
  215. if (p) {
  216. p._moveChildToFront(this);
  217. this._moveToFront(); // execute renderer-specific
  218. // action
  219. }
  220. return this; // self
  221. },
  222. moveToBack : function() {
  223. // summary: moves a shape to back of its parent's list of
  224. // shapes
  225. var p = this.getParent();
  226. if (p) {
  227. p._moveChildToBack(this);
  228. this._moveToBack(); // execute renderer-specific action
  229. }
  230. return this;
  231. },
  232. _moveToFront : function() {
  233. // summary: renderer-specific hook, see
  234. // dojox.gfx.shape.Shape.moveToFront()
  235. // COULD BE RE-IMPLEMENTED BY THE RENDERER!
  236. },
  237. _moveToBack : function() {
  238. // summary: renderer-specific hook, see
  239. // dojox.gfx.shape.Shape.moveToFront()
  240. // COULD BE RE-IMPLEMENTED BY THE RENDERER!
  241. },
  242. // apply left & right transformation
  243. applyRightTransform : function(matrix) {
  244. // summary: multiplies the existing matrix with an argument
  245. // on right side
  246. // (this.matrix * matrix)
  247. // matrix: dojox.gfx.Matrix2D: a matrix or a matrix-like
  248. // object
  249. // (see an argument of dojox.gfx.Matrix2D
  250. // constructor for a list of acceptable arguments)
  251. return matrix
  252. ? this.setTransform([this.matrix, matrix])
  253. : this; // self
  254. },
  255. applyLeftTransform : function(matrix) {
  256. // summary: multiplies the existing matrix with an argument
  257. // on left side
  258. // (matrix * this.matrix)
  259. // matrix: dojox.gfx.Matrix2D: a matrix or a matrix-like
  260. // object
  261. // (see an argument of dojox.gfx.Matrix2D
  262. // constructor for a list of acceptable arguments)
  263. return matrix
  264. ? this.setTransform([matrix, this.matrix])
  265. : this; // self
  266. },
  267. applyTransform : function(matrix) {
  268. // summary: a shortcut for
  269. // dojox.gfx.Shape.applyRightTransform
  270. // matrix: dojox.gfx.Matrix2D: a matrix or a matrix-like
  271. // object
  272. // (see an argument of dojox.gfx.Matrix2D
  273. // constructor for a list of acceptable arguments)
  274. return matrix
  275. ? this.setTransform([this.matrix, matrix])
  276. : this; // self
  277. },
  278. // virtual group methods
  279. removeShape : function(silently) {
  280. // summary: removes the shape from its parent's list of
  281. // shapes
  282. // silently: Boolean?: if true, do not redraw a picture yet
  283. if (this.parent) {
  284. this.parent.remove(this, silently);
  285. }
  286. return this; // self
  287. },
  288. _setParent : function(parent, matrix) {
  289. // summary: sets a parent
  290. // parent: Object: a parent or null
  291. // (see dojox.gfx.Surface,
  292. // dojox.gfx.shape.VirtualGroup,
  293. // or dojox.gfx.Group)
  294. // matrix: dojox.gfx.Matrix2D:
  295. // a 2D matrix or a matrix-like object
  296. this.parent = parent;
  297. return this._updateParentMatrix(matrix); // self
  298. },
  299. _updateParentMatrix : function(matrix) {
  300. // summary: updates the parent matrix with new matrix
  301. // matrix: dojox.gfx.Matrix2D:
  302. // a 2D matrix or a matrix-like object
  303. this.parentMatrix = matrix
  304. ? dojox.gfx.matrix.clone(matrix)
  305. : null;
  306. return this._applyTransform(); // self
  307. },
  308. _getRealMatrix : function() {
  309. // summary: returns the cumulative ("real") transformation
  310. // matrix
  311. // by combining the shape's matrix with its parent's matrix
  312. var m = this.matrix;
  313. var p = this.parent;
  314. while (p) {
  315. if (p.matrix) {
  316. m = dojox.gfx.matrix.multiply(p.matrix, m);
  317. }
  318. p = p.parent;
  319. }
  320. return m; // dojox.gfx.Matrix2D
  321. }
  322. });
  323. dojox.gfx.shape._eventsProcessing = {
  324. connect : function(name, object, method) {
  325. // summary: connects a handler to an event on this shape
  326. // COULD BE RE-IMPLEMENTED BY THE RENDERER!
  327. return arguments.length > 2 ? // Object
  328. dojo.connect(this.getEventSource(), name, object, method)
  329. : dojo.connect(this.getEventSource(), name, object);
  330. },
  331. disconnect : function(token) {
  332. // summary: connects a handler by token from an event on this shape
  333. // COULD BE RE-IMPLEMENTED BY THE RENDERER!
  334. dojo.disconnect(token);
  335. }
  336. };
  337. dojo.extend(dojox.gfx.Shape, dojox.gfx.shape._eventsProcessing);
  338. dojox.gfx.shape.Container = {
  339. // summary: a container of shapes, which can be used
  340. // as a foundation for renderer-specific groups, or as a way
  341. // to logically group shapes (e.g, to propagate matricies)
  342. _init : function() {
  343. // children: Array: a list of children
  344. this.children = [];
  345. },
  346. // group management
  347. add : function(shape) {
  348. // summary: adds a shape to the list
  349. // shape: dojox.gfx.Shape: a shape
  350. var oldParent = shape.getParent();
  351. if (oldParent) {
  352. oldParent.remove(shape, true);
  353. }
  354. this.children.push(shape);
  355. return shape._setParent(this, this._getRealMatrix()); // self
  356. },
  357. remove : function(shape, silently) {
  358. // summary: removes a shape from the list
  359. // silently: Boolean?: if true, do not redraw a picture yet
  360. for (var i = 0; i < this.children.length; ++i) {
  361. if (this.children[i] == shape) {
  362. if (silently) {
  363. // skip for now
  364. } else {
  365. shape._setParent(null, null);
  366. }
  367. this.children.splice(i, 1);
  368. break;
  369. }
  370. }
  371. return this; // self
  372. },
  373. clear : function() {
  374. // summary: removes all shapes from a group/surface
  375. this.children = [];
  376. return this; // self
  377. },
  378. // moving child nodes
  379. _moveChildToFront : function(shape) {
  380. // summary: moves a shape to front of the list of shapes
  381. for (var i = 0; i < this.children.length; ++i) {
  382. if (this.children[i] == shape) {
  383. this.children.splice(i, 1);
  384. this.children.push(shape);
  385. break;
  386. }
  387. }
  388. return this; // self
  389. },
  390. _moveChildToBack : function(shape) {
  391. // summary: moves a shape to back of the list of shapes
  392. for (var i = 0; i < this.children.length; ++i) {
  393. if (this.children[i] == shape) {
  394. this.children.splice(i, 1);
  395. this.children.unshift(shape);
  396. break;
  397. }
  398. }
  399. return this; // self
  400. }
  401. };
  402. dojo.declare("dojox.gfx.shape.Surface", null, {
  403. // summary: a surface object to be used for drawings
  404. constructor : function() {
  405. // underlying node
  406. this.rawNode = null;
  407. },
  408. getEventSource : function() {
  409. // summary: returns a node, which can be used to attach
  410. // event listeners
  411. return this.rawNode; // Node
  412. },
  413. _getRealMatrix : function() {
  414. // summary: always returns the identity matrix
  415. return null; // dojox.gfx.Matrix2D
  416. }
  417. });
  418. dojo.extend(dojox.gfx.shape.Surface, dojox.gfx.shape._eventsProcessing);
  419. dojo.declare("dojox.gfx.Point", null, {
  420. // summary: a hypothetical 2D point to be used for drawings - {x, y}
  421. // description: This object is defined for documentation purposes.
  422. // You should use the naked object instead: {x: 1, y: 2}.
  423. });
  424. dojo.declare("dojox.gfx.Rectangle", null, {
  425. // summary: a hypothetical rectangle - {x, y, width, height}
  426. // description: This object is defined for documentation purposes.
  427. // You should use the naked object instead: {x: 1, y: 2, width: 100,
  428. // height: 200}.
  429. });
  430. dojo.declare("dojox.gfx.shape.Rect", dojox.gfx.Shape, {
  431. // summary: a generic rectangle
  432. constructor : function(rawNode) {
  433. // rawNode: Node: a DOM Node
  434. this.shape = dojo.clone(dojox.gfx.defaultRect);
  435. this.rawNode = rawNode;
  436. },
  437. getBoundingBox : function() {
  438. // summary: returns the bounding box (its shape in this
  439. // case)
  440. return this.shape; // dojox.gfx.Rectangle
  441. }
  442. });
  443. dojo.declare("dojox.gfx.shape.Ellipse", dojox.gfx.Shape, {
  444. // summary: a generic ellipse
  445. constructor : function(rawNode) {
  446. // rawNode: Node: a DOM Node
  447. this.shape = dojo.clone(dojox.gfx.defaultEllipse);
  448. this.rawNode = rawNode;
  449. },
  450. getBoundingBox : function() {
  451. // summary: returns the bounding box
  452. if (!this.bbox) {
  453. var shape = this.shape;
  454. this.bbox = {
  455. x : shape.cx - shape.rx,
  456. y : shape.cy - shape.ry,
  457. width : 2 * shape.rx,
  458. height : 2 * shape.ry
  459. };
  460. }
  461. return this.bbox; // dojox.gfx.Rectangle
  462. }
  463. });
  464. dojo.declare("dojox.gfx.shape.Circle", dojox.gfx.Shape, {
  465. // summary: a generic circle
  466. // (this is a helper object, which is defined for convenience)
  467. constructor : function(rawNode) {
  468. // rawNode: Node: a DOM Node
  469. this.shape = dojo.clone(dojox.gfx.defaultCircle);
  470. this.rawNode = rawNode;
  471. },
  472. getBoundingBox : function() {
  473. // summary: returns the bounding box
  474. if (!this.bbox) {
  475. var shape = this.shape;
  476. this.bbox = {
  477. x : shape.cx - shape.r,
  478. y : shape.cy - shape.r,
  479. width : 2 * shape.r,
  480. height : 2 * shape.r
  481. };
  482. }
  483. return this.bbox; // dojox.gfx.Rectangle
  484. }
  485. });
  486. dojo.declare("dojox.gfx.shape.Line", dojox.gfx.Shape, {
  487. // summary: a generic line
  488. // (this is a helper object, which is defined for convenience)
  489. constructor : function(rawNode) {
  490. // rawNode: Node: a DOM Node
  491. this.shape = dojo.clone(dojox.gfx.defaultLine);
  492. this.rawNode = rawNode;
  493. },
  494. getBoundingBox : function() {
  495. // summary: returns the bounding box
  496. if (!this.bbox) {
  497. var shape = this.shape;
  498. this.bbox = {
  499. x : Math.min(shape.x1, shape.x2),
  500. y : Math.min(shape.y1, shape.y2),
  501. width : Math.abs(shape.x2 - shape.x1),
  502. height : Math.abs(shape.y2 - shape.y1)
  503. };
  504. }
  505. return this.bbox; // dojox.gfx.Rectangle
  506. }
  507. });
  508. dojo.declare("dojox.gfx.shape.Polyline", dojox.gfx.Shape, {
  509. // summary: a generic polyline/polygon
  510. // (this is a helper object, which is defined for convenience)
  511. constructor : function(rawNode) {
  512. // rawNode: Node: a DOM Node
  513. this.shape = dojo.clone(dojox.gfx.defaultPolyline);
  514. this.rawNode = rawNode;
  515. },
  516. setShape : function(points, closed) {
  517. // summary: sets a polyline/polygon shape object
  518. // points: Object: a polyline/polygon shape object
  519. // closed: Boolean: close the polyline to make a polygon
  520. if (points && points instanceof Array) {
  521. // points: Array: an array of points
  522. dojox.gfx.Shape.prototype.setShape.call(this, {
  523. points : points
  524. });
  525. if (closed && this.shape.points.length) {
  526. this.shape.points.push(this.shape.points[0]);
  527. }
  528. } else {
  529. dojox.gfx.Shape.prototype.setShape.call(this, points);
  530. }
  531. return this; // self
  532. },
  533. getBoundingBox : function() {
  534. // summary: returns the bounding box
  535. if (!this.bbox && this.shape.points.length) {
  536. var p = this.shape.points;
  537. var l = p.length;
  538. var t = p[0];
  539. var bbox = {
  540. l : t.x,
  541. t : t.y,
  542. r : t.x,
  543. b : t.y
  544. };
  545. for (var i = 1; i < l; ++i) {
  546. t = p[i];
  547. if (bbox.l > t.x)
  548. bbox.l = t.x;
  549. if (bbox.r < t.x)
  550. bbox.r = t.x;
  551. if (bbox.t > t.y)
  552. bbox.t = t.y;
  553. if (bbox.b < t.y)
  554. bbox.b = t.y;
  555. }
  556. this.bbox = {
  557. x : bbox.l,
  558. y : bbox.t,
  559. width : bbox.r - bbox.l,
  560. height : bbox.b - bbox.t
  561. };
  562. }
  563. return this.bbox; // dojox.gfx.Rectangle
  564. }
  565. });
  566. dojo.declare("dojox.gfx.shape.Image", dojox.gfx.Shape, {
  567. // summary: a generic image
  568. // (this is a helper object, which is defined for convenience)
  569. constructor : function(rawNode) {
  570. // rawNode: Node: a DOM Node
  571. this.shape = dojo.clone(dojox.gfx.defaultImage);
  572. this.rawNode = rawNode;
  573. },
  574. getBoundingBox : function() {
  575. // summary: returns the bounding box (its shape in this
  576. // case)
  577. return this.shape; // dojox.gfx.Rectangle
  578. },
  579. setStroke : function() {
  580. // summary: ignore setting a stroke style
  581. return this; // self
  582. },
  583. setFill : function() {
  584. // summary: ignore setting a fill style
  585. return this; // self
  586. }
  587. });
  588. dojo.declare("dojox.gfx.shape.Text", dojox.gfx.Shape, {
  589. // summary: a generic text
  590. constructor : function(rawNode) {
  591. // rawNode: Node: a DOM Node
  592. this.fontStyle = null;
  593. this.shape = dojo.clone(dojox.gfx.defaultText);
  594. this.rawNode = rawNode;
  595. },
  596. setFont : function(newFont) {
  597. // summary: sets a font for text
  598. // newFont: Object: a font object (see
  599. // dojox.gfx.defaultFont) or a font string
  600. this.fontStyle = typeof newFont == "string" ? dojox.gfx
  601. .splitFontString(newFont) : dojox.gfx
  602. .makeParameters(dojox.gfx.defaultFont, newFont);
  603. this._setFont();
  604. return this; // self
  605. }
  606. });
  607. dojox.gfx.shape.Creator = {
  608. // summary: shape creators
  609. createShape : function(shape) {
  610. // summary: creates a shape object based on its type; it is meant to
  611. // be used
  612. // by group-like objects
  613. // shape: Object: a shape descriptor object
  614. switch (shape.type) {
  615. case dojox.gfx.defaultPath.type :
  616. return this.createPath(shape);
  617. case dojox.gfx.defaultRect.type :
  618. return this.createRect(shape);
  619. case dojox.gfx.defaultCircle.type :
  620. return this.createCircle(shape);
  621. case dojox.gfx.defaultEllipse.type :
  622. return this.createEllipse(shape);
  623. case dojox.gfx.defaultLine.type :
  624. return this.createLine(shape);
  625. case dojox.gfx.defaultPolyline.type :
  626. return this.createPolyline(shape);
  627. case dojox.gfx.defaultImage.type :
  628. return this.createImage(shape);
  629. case dojox.gfx.defaultText.type :
  630. return this.createText(shape);
  631. case dojox.gfx.defaultTextPath.type :
  632. return this.createTextPath(shape);
  633. }
  634. return null;
  635. },
  636. createGroup : function() {
  637. // summary: creates an SVG group shape
  638. return this.createObject(dojox.gfx.Group); // dojox.gfx.Group
  639. },
  640. createRect : function(rect) {
  641. // summary: creates an SVG rectangle shape
  642. // rect: Object: a path object (see dojox.gfx.defaultRect)
  643. return this.createObject(dojox.gfx.Rect, rect); // dojox.gfx.Rect
  644. },
  645. createEllipse : function(ellipse) {
  646. // summary: creates an SVG ellipse shape
  647. // ellipse: Object: an ellipse object (see dojox.gfx.defaultEllipse)
  648. return this.createObject(dojox.gfx.Ellipse, ellipse); // dojox.gfx.Ellipse
  649. },
  650. createCircle : function(circle) {
  651. // summary: creates an SVG circle shape
  652. // circle: Object: a circle object (see dojox.gfx.defaultCircle)
  653. return this.createObject(dojox.gfx.Circle, circle); // dojox.gfx.Circle
  654. },
  655. createLine : function(line) {
  656. // summary: creates an SVG line shape
  657. // line: Object: a line object (see dojox.gfx.defaultLine)
  658. return this.createObject(dojox.gfx.Line, line); // dojox.gfx.Line
  659. },
  660. createPolyline : function(points) {
  661. // summary: creates an SVG polyline/polygon shape
  662. // points: Object: a points object (see dojox.gfx.defaultPolyline)
  663. // or an Array of points
  664. return this.createObject(dojox.gfx.Polyline, points); // dojox.gfx.Polyline
  665. },
  666. createImage : function(image) {
  667. // summary: creates an SVG image shape
  668. // image: Object: an image object (see dojox.gfx.defaultImage)
  669. return this.createObject(dojox.gfx.Image, image); // dojox.gfx.Image
  670. },
  671. createText : function(text) {
  672. // summary: creates an SVG text shape
  673. // text: Object: a text object (see dojox.gfx.defaultText)
  674. return this.createObject(dojox.gfx.Text, text); // dojox.gfx.Text
  675. },
  676. createPath : function(path) {
  677. // summary: creates an SVG path shape
  678. // path: Object: a path object (see dojox.gfx.defaultPath)
  679. return this.createObject(dojox.gfx.Path, path); // dojox.gfx.Path
  680. },
  681. createTextPath : function(text) {
  682. // summary: creates an SVG text shape
  683. // text: Object: a textpath object (see dojox.gfx.defaultTextPath)
  684. return this.createObject(dojox.gfx.TextPath, {}).setText(text); // dojox.gfx.TextPath
  685. },
  686. createObject : function(shapeType, rawShape) {
  687. // summary: creates an instance of the passed shapeType class
  688. // shapeType: Function: a class constructor to create an instance of
  689. // rawShape: Object: properties to be passed in to the classes
  690. // "setShape" method
  691. // SHOULD BE RE-IMPLEMENTED BY THE RENDERER!
  692. return null; // dojox.gfx.Shape
  693. }
  694. };
  695. }