粗线.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722
  1. ht.lib = ht.lib || {};
  2. if (!ht.lib['粗线']) {
  3. ht.lib['粗线'] = function (x, y, width, height, angle, localVarObj, localDynamicVar, nodename) {
  4. _ratio = GD.getRatioWithRotation(0, ratio);
  5. ht.lib['粗线'].superClass.constructor.apply(this);
  6. this.localVarObj = localVarObj;
  7. this.localDynamicVar = localDynamicVar;
  8. this.childNodes = [];
  9. this._styleObject = {};
  10. this._originWidth = 1451*_ratio.ratioX;
  11. this._originHeight = 1*_ratio.ratioY;
  12. this._baseClass = "ht.lib.粗线";
  13. this._background = new ht.Node();
  14. this._background.setWidth(this._originWidth);
  15. this._background.setHeight(this._originHeight);
  16. this._background.setPosition(this._originWidth/2, this._originHeight/2);
  17. this._background.setImage({
  18. width: width,
  19. height: height,
  20. clip: true,
  21. comps: [
  22. {
  23. type: 'rect',
  24. background: 'rgba(0,255,0,0)',
  25. rect: [0,0,width, height]
  26. }
  27. ]
  28. });
  29. this._background.__parentLib = nodename;
  30. this._background.isLibBackground = true;
  31. this.childNodes.push(this._background);
  32. dataModel.add(this._background);
  33. /*@PageBackgroundInit@*/
  34. /*@PageBeforeInit@*/
  35. var Lib_粗线Node0points=[0, 0,1451, 0],
  36. Lib_粗线Node0rect=ht.Default.unionPoint([{x:0,y:0},{x:1451,y:0}]),
  37. Lib_粗线Node0compspts=[];
  38. _ratio = GD.getRatioWithRotation(0, ratio);
  39. var _startratio = GD.getRatioWithRotation(3.14159265358979, ratio),
  40. _endratio = GD.getRatioWithRotation(0, ratio);
  41. for(var i=0;i<Lib_粗线Node0points.length;i++){
  42. if(i%2==0){
  43. Lib_粗线Node0compspts.push(Lib_粗线Node0points[i]-Lib_粗线Node0rect.x);
  44. }else{
  45. Lib_粗线Node0compspts.push(Lib_粗线Node0points[i]-Lib_粗线Node0rect.y);
  46. }
  47. }
  48. var Lib_粗线Node0ptslength=Lib_粗线Node0compspts.length;
  49. if (Lib_粗线Node0rect.height === 0) {
  50. Lib_粗线Node0compspts[0] -= 0;
  51. Lib_粗线Node0compspts[Lib_粗线Node0ptslength-2] += 0;
  52. } else if (Lib_粗线Node0rect.width === 0){
  53. Lib_粗线Node0compspts[1] -= 0;
  54. Lib_粗线Node0compspts[Lib_粗线Node0ptslength-1] += 0;
  55. } else {
  56. Lib_粗线Node0compspts[0] -= 0;
  57. Lib_粗线Node0compspts[1] -= 0;
  58. Lib_粗线Node0compspts[Lib_粗线Node0ptslength-2] += 0;
  59. Lib_粗线Node0compspts[Lib_粗线Node0ptslength-1] += 0;
  60. }
  61. Lib_粗线Node0 = new ht.Node();
  62. Lib_粗线Node0.borderWidth = 3;
  63. Lib_粗线Node0rect.width = Lib_粗线Node0rect.width === 0 ? 0.0001 : Lib_粗线Node0rect.width;
  64. Lib_粗线Node0rect.height = Lib_粗线Node0rect.height === 0 ? 0.0001 : Lib_粗线Node0rect.height;
  65. var Lib_粗线Node0endCompspts = [Lib_粗线Node0compspts[Lib_粗线Node0ptslength-2],Lib_粗线Node0compspts[Lib_粗线Node0ptslength-1],0,0];
  66. var Lib_粗线Node0startCompspts = [Lib_粗线Node0compspts[0],Lib_粗线Node0compspts[1],0,0];
  67. Lib_粗线Node0.setImage(GD.getPolyLineJSON());
  68. Lib_粗线Node0.setPosition(Lib_粗线Node0rect.x+Lib_粗线Node0rect.width/2,Lib_粗线Node0rect.y+Lib_粗线Node0rect.height/2);
  69. Lib_粗线Node0.setSize(Lib_粗线Node0rect.width,Lib_粗线Node0rect.height);
  70. Lib_粗线Node0.setStyle("opacity",1);
  71. Lib_粗线Node0.s({'pixelPerfect':true});
  72. Lib_粗线Node0borderwidth=3;
  73. Lib_粗线Node0.setRotation(0);
  74. dataModel.add(Lib_粗线Node0);
  75. Lib_粗线Node0.a('node.points',Lib_粗线Node0compspts);
  76. Lib_粗线Node0.a('node.segments',[1,2]);
  77. Lib_粗线Node0.a('node.color','rgba(255,0,255,1)');
  78. Lib_粗线Node0.a('node.borderPattern',getDashStyle("@borderPattern@"));
  79. Lib_粗线Node0.a('node.borderColor','rgba(255,0,255,1)');
  80. Lib_粗线Node0.a('node.background','rgba(255,0,255,1)');
  81. Lib_粗线Node0.a('node.gradient','');
  82. Lib_粗线Node0.a('node.gradientcolor','rgba(255,0,255,1)');
  83. Lib_粗线Node0.a('node.endCompspts',Lib_粗线Node0endCompspts);
  84. Lib_粗线Node0.a('node.startCompspts',Lib_粗线Node0startCompspts);
  85. (function (node, img, compspts, endCompspts, startCompspts) {
  86. var position = node.getPosition(),
  87. w = node.getWidth()*_ratio.ratioX,
  88. h = node.getHeight()*_ratio.ratioY;
  89. function resetPoints(rx, ry) {
  90. for (var i = 0, len = compspts.length; i < len; i++) {
  91. if (i%2 === 0) {
  92. compspts[i]*=rx;
  93. } else {
  94. compspts[i]*=ry;
  95. }
  96. }
  97. endCompspts[0] = compspts[compspts.length-2];
  98. endCompspts[1] = compspts[compspts.length-1];
  99. endCompspts[2] *= rx;
  100. endCompspts[3] *= ry;
  101. node.a('node.offsetEndY', -(endCompspts[3]*0.5));
  102. node.a('node.offsetEndX', -(endCompspts[2]*0.5));
  103. startCompspts[0] = compspts[0];
  104. startCompspts[1] = compspts[1];
  105. startCompspts[2] *= rx;
  106. startCompspts[3] *= ry;
  107. node.a('node.offsetStartY', -(startCompspts[3]*0.5));
  108. node.a('node.offsetStartX', -(startCompspts[2]*0.5));
  109. node.a('node.endRotation', GD.calcRotationByStartAndEnd(compspts[i-4], compspts[i-3], compspts[i-2], compspts[i-1]));
  110. node.a('node.startRotation', GD.calcRotationByStartAndEnd(compspts[0], compspts[1], compspts[2], compspts[3]) + Math.PI);
  111. }
  112. node.setSize(w, h);
  113. node.setPosition(position.x * ratio.ratioX, position.y * ratio.ratioY);
  114. node.a('node.width', w);
  115. node.a('node.height', h);
  116. resetPoints(_ratio.ratioX, _ratio.ratioY);
  117. node.borderWidth = 3;
  118. node.a('node.borderwidth',node.borderWidth);
  119. node._nodename = 'Lib_粗线Node0';
  120. node._nodeType = 'line';
  121. zoomNodeList.push({
  122. node: node,
  123. attr: 'node.borderwidth'
  124. });
  125. var setWidth = node.setWidth,
  126. setHeight = node.setHeight,
  127. timer, rx = 1, ry = 1;
  128. node.setWidth = function (width) {
  129. var _width = this.getWidth();
  130. rx = width / _width;
  131. node.a('node.width', width);
  132. setWidth.apply(this, arguments);
  133. resetPoints(rx, 1);
  134. }
  135. node.setHeight = function (height) {
  136. var _height = this.getHeight();
  137. ry = height / _height;
  138. node.a('node.height', height);
  139. setHeight.apply(this, arguments);
  140. resetPoints(1, ry);
  141. }
  142. })(Lib_粗线Node0, Lib_粗线Node0.getImage(), Lib_粗线Node0compspts, Lib_粗线Node0endCompspts, Lib_粗线Node0startCompspts);
  143. /*@GraphList@*/
  144. /*@PageInit@*/
  145. var localVarObj = this.localVarObj;
  146. var localDynamicVarObj = this.localDynamicVar();
  147. this['Lib_粗线Node0'] = Lib_粗线Node0;
  148. Lib_粗线Node0.__parentLib = nodename;
  149. Lib_粗线Node0.__parent = this;
  150. this.childNodes.push(Lib_粗线Node0);
  151. /*@ControlContextMenu@*/
  152. /*@Declare@*/
  153. this.init(x, y, width, height, angle);
  154. };
  155. ht.Default.def('ht.lib.粗线', Object, {
  156. refresh10ms: function () {
  157. var localVarObj = this.localVarObj;
  158. var localDynamicVarObj = this.localDynamicVar();
  159. var Lib_粗线Node0= this.Lib_粗线Node0;
  160. /*@refresh10ms@*/
  161. },
  162. refresh100ms: function () {
  163. var localVarObj = this.localVarObj;
  164. var localDynamicVarObj = this.localDynamicVar();
  165. var Lib_粗线Node0= this.Lib_粗线Node0;
  166. /*@refresh100ms@*/
  167. },
  168. refresh500ms: function () {
  169. var localVarObj = this.localVarObj;
  170. var localDynamicVarObj = this.localDynamicVar();
  171. var Lib_粗线Node0= this.Lib_粗线Node0;
  172. /*@refresh500ms@*/
  173. },
  174. refresh1s: function () {
  175. var Counter1s = arguments[0] || 0;
  176. var localVarObj = this.localVarObj;
  177. var localDynamicVarObj = this.localDynamicVar();
  178. var Lib_粗线Node0= this.Lib_粗线Node0;
  179. /*@refresh1s@*/
  180. },
  181. refresh5s: function () {
  182. var localVarObj = this.localVarObj;
  183. var localDynamicVarObj = this.localDynamicVar();
  184. var Lib_粗线Node0= this.Lib_粗线Node0;
  185. /*@refresh5s@*/
  186. },
  187. /*@PageDynamic@*/
  188. onEvent: function (e, data, type, origin, offset, objMouseOn, ctm) {
  189. var localVarObj = this.localVarObj;
  190. var localDynamicVarObj = this.localDynamicVar();
  191. var Lib_粗线Node0= this.Lib_粗线Node0;
  192. if (type === 'click') {
  193. /*@EvnentClicked@*/
  194. } else if (type === 'mousedown') {
  195. mouseX=e.clientX;
  196. mouseY=e.clientY;
  197. /*@EvnentMouseDown@*/
  198. } else if (type === 'mouseup') {
  199. /*@EvnentMouseUp@*/
  200. } else if (type === 'mousemove') {
  201. var mouseX, mouseY, position, zoom;
  202. position=origin.getLogicalPoint(e);
  203. zoom = graphView.getZoom();
  204. if (origin === graphView) {
  205. mouseX= position.x + origin.tx();
  206. mouseY = position.y + origin.ty();
  207. } else {
  208. offset = offset || {x: 0, y: 0};
  209. mouseX = position.x / zoom + offset.x + origin.tx();
  210. mouseY = position.y / zoom + offset.y + origin.ty();
  211. }
  212. /*@EvnentMouseLeave@*/
  213. /*@EvnentMouseOver@*/
  214. } else if (type === 'keydown') {
  215. /*@EvnentKeyDown@*/
  216. } else if (type === 'contextmenu') {
  217. /*@Declare@*/
  218. /*@SetNodeContextMenu@*/
  219. /*@SetPageContextMenu@*/
  220. }
  221. /*@LibEvent@*/
  222. },
  223. getBaseClass: function () {
  224. return this._baseClass;
  225. },
  226. getWidth: function () {
  227. return this._width;
  228. },
  229. getHeight: function () {
  230. return this._height;
  231. },
  232. getSize: function () {
  233. return {
  234. width: this._width,
  235. height: this._height
  236. }
  237. },
  238. setWidth: function (width) {
  239. if (width === undefined || width === null || width != width) {
  240. return ;
  241. }
  242. var originWidth = this._width;
  243. var ratio = width / originWidth;
  244. var childNodes = this.childNodes, childNode, p, op = this.getPosition(), w, cw, ox, rotation = this.getRotation();
  245. for (var i = 0, len = childNodes.length; i < len; i++) {
  246. childNode = childNodes[i];
  247. p = childNode.getPosition();
  248. cw = childNode.getWidth();
  249. w = cw >=2 ? cw * ratio : cw;
  250. childNode.setWidth(w);
  251. ox = op.x + (p.x - op.x) * ratio;
  252. childNode.setPosition(ox, p.y);
  253. rotation = GD.calcRotation(rotation);
  254. if (rotation === 0 || rotation === Math.PI) {
  255. // 图元未旋转
  256. ox = op.x + (p.x - op.x)*ratio;
  257. childNode.setPosition(ox, p.y);
  258. } else if (rotation === 90 * Math.PI / 180) {
  259. // 图元旋转以后
  260. ox = op.y + (p.y - op.y)*ratio;
  261. childNode.setPosition(p.x, ox);
  262. }
  263. }
  264. this._width = width;
  265. this._originWidth = width;
  266. this._ratioX = ratio;
  267. return this;
  268. },
  269. setHeight: function (height) {
  270. if (height === undefined || height === null || height != height) {
  271. return ;
  272. }
  273. var originHeight = this._height;
  274. var ratio = height / originHeight;
  275. var childNodes = this.childNodes, childNode, p, op = this.getPosition(), h, ch, oy, rotation = this.getRotation();
  276. for (var i = 0, len = childNodes.length; i < len; i++) {
  277. childNode = childNodes[i];
  278. p = childNode.getPosition();
  279. ch = childNode.getHeight();
  280. h = ch >=2 ? ch * ratio : ch;
  281. childNode.setHeight(h);
  282. rotation = GD.calcRotation(rotation);
  283. if (rotation === 0 || rotation === Math.PI) {
  284. // 图元未旋转
  285. oy = op.y + (p.y - op.y)*ratio;
  286. childNode.setPosition(p.x, oy);
  287. } else if (rotation === 90 * Math.PI / 180) {
  288. // 图元旋转以后
  289. oy = op.x + (p.x - op.x)*ratio;
  290. childNode.setPosition(oy, p.y);
  291. }
  292. }
  293. this._height = height;
  294. this._originHeight = height;
  295. this._ratioY = ratio;
  296. return this;
  297. },
  298. setSize: function (size) {
  299. // var args = Array.prototype.slice.call(arguments, 0);
  300. // var height, width;
  301. // if (args.length === 0) {
  302. // return ;
  303. // }else if (args.length === 1) {
  304. // height = args[0].height;
  305. // width = args[0].width;
  306. // } else {
  307. // width = args[0];
  308. // height = args[1];
  309. // }
  310. // var wh = GD.getRatioWithRotation(angle, wid)
  311. // this.setHeight(height);
  312. // this.setWidth(width);
  313. // return this;
  314. var args = Array.prototype.slice.call(arguments, 0);
  315. var height, width;
  316. if (args.length === 0) {
  317. return ;
  318. }else if (args.length === 1) {
  319. height = args[0].height;
  320. width = args[0].width;
  321. angle = 0;
  322. } else if (args.length === 2) {
  323. if (typeof args[0] === 'object') {
  324. width = args[0].width;
  325. height = args[0].height;
  326. angle = args[1] || 0;
  327. } else {
  328. width = args[0];
  329. height = args[1];
  330. angle = 0;
  331. }
  332. } else if (args.length === 3) {
  333. width = args[0];
  334. height = args[1];
  335. angle = args[2] || 0;
  336. }
  337. var wh = GD.getRatioWithRotation(0, width, height);
  338. this.setHeight(wh.ratioY);
  339. this.setWidth(wh.ratioX);
  340. return this;
  341. },
  342. getPosition: function () {
  343. return {
  344. x: this._x,
  345. y: this._y
  346. }
  347. },
  348. setPosition: function () {
  349. var args = Array.prototype.slice.call(arguments, 0), x, y;
  350. if (args.length === 0) {
  351. return this;
  352. } else if (args.length === 1) {
  353. if (typeof args[0] != 'object') {
  354. return this;
  355. }
  356. x = args[0].x;
  357. y = args[0].y;
  358. } else {
  359. x = args[0];
  360. y = args[1];
  361. }
  362. if ((x !== 0 && !x) || (y !== 0 && !y)) {
  363. return this;
  364. }
  365. // var childNodes = this.childNodes, offset, childNode, p;
  366. // for (var i = 0, len = childNodes.length; i < len; i++) {
  367. // childNode = childNodes[i];
  368. // p = childNode.getPosition();
  369. // childNode.setPosition(x - (this._x-p.x)*this._ratioX, y - (this._y-p.y)*this._ratioY);
  370. // }
  371. // this._x = x;
  372. // this._y = y;
  373. // return this;
  374. var childNodes, childNode, background, offset = {}, op, cp;
  375. childNodes = this.childNodes;
  376. background = this._background;
  377. op = background.getPosition();
  378. offset.x = x - op.x;
  379. offset.y = y - op.y;
  380. for (var i = 0, len = childNodes.length; i < len; i++) {
  381. childNode = childNodes[i];
  382. cp = childNode.getPosition();
  383. childNode.setPosition(cp.x + offset.x, cp.y + offset.y);
  384. }
  385. this._x = x;
  386. this._y = y;
  387. this._position = {x: x, y: y};
  388. return this;
  389. },
  390. getStyle: function (key) {
  391. if (!key) {
  392. return undefined;
  393. }
  394. return this._styleObject[key];
  395. },
  396. setStyle: function (key, value, force) {
  397. var childNodes = this.childNodes, childNode;
  398. for (var i = 0, len = childNodes.length; i < len; i++) {
  399. childNode = childNodes[i];
  400. if (key === '2d.visible') {
  401. if (value === graphView.isVisible(childNode)) {
  402. continue;
  403. }
  404. if (!value) {
  405. childNode._savedIsVisible = graphView.isVisible(childNode);
  406. childNode.s({
  407. '2d.visible': false
  408. })
  409. } else {
  410. childNode.s({
  411. '2d.visible': childNode._savedIsVisible
  412. })
  413. }
  414. continue;
  415. }
  416. childNode.s({
  417. key: value
  418. });
  419. }
  420. this._styleObject[key] = value;
  421. return this;
  422. },
  423. calcSize: function () {
  424. var background = this._background;
  425. var position = background.getPosition(),
  426. width = background.getWidth(),
  427. height = background.getHeight();
  428. this._width = width;
  429. this._height = height;
  430. this._x = position.x;
  431. this._y = position.y;
  432. this._position = {
  433. x: this._x,
  434. y: this._y
  435. }
  436. return this;
  437. return this;
  438. },
  439. s: function (styleObj, force) {
  440. var args = Array.prototype.slice.call(arguments, 0);
  441. var styleObj;
  442. if (args.length === 0) {
  443. return this;
  444. } else if (args.length === 1) {
  445. styleObj = args[0];
  446. } else {
  447. this.setStyle(args[0], args[1]);
  448. return this;
  449. }
  450. for (var key in styleObj) {
  451. if (!styleObj.hasOwnProperty(key)) {
  452. continue;
  453. }
  454. this.setStyle(key, styleObj[key], force);
  455. }
  456. return this;
  457. },
  458. init: function (x, y, width, height, angle) {
  459. var that = this;
  460. this.calcSize();
  461. (function (width, height, angle) {
  462. // that.setSize(width, height, angle);
  463. // var wh = GD.getRatioWithRotation(angle, width, height);
  464. // width = wh.ratioX;
  465. // height = wh.ratioY;
  466. var originHeight = that._height;
  467. var originWidth = that._width;
  468. var ratioY = height / originHeight;
  469. var ratioX = width / originWidth;
  470. var childNodes = that.childNodes,
  471. childNode,p, op = that.getPosition(), h, ch, oy, w, cw, ox, name, borderRatio, borderWidth;
  472. for (var i = 0, len = childNodes.length; i < len; i++) {
  473. childNode = childNodes[i];
  474. p = childNode.getPosition();
  475. childNode.originHeight = childNode.originHeight || childNode.getHeight();
  476. ch = childNode.getHeight();
  477. cw = childNode.getWidth();
  478. if (ch > 2) {
  479. h = ch * ratioY;
  480. childNode.setHeight(h);
  481. }
  482. if (cw > 2) {
  483. w = cw * ratioX;
  484. childNode.setWidth(w);
  485. }
  486. borderRatio = (ratioX + ratioY)*0.5;
  487. if (childNode._nodeType === 'line') { // 如果是线,
  488. if (childNode.getWidth() > childNode.getHeight()) {
  489. borderRatio = ratioX;
  490. } else {
  491. borderRatio = ratioY;
  492. }
  493. }
  494. name = childNode._nodename;
  495. // if (childNode.borderWidth && name && ch > 2 && cw > 2) {
  496. // borderWidth = childNode.borderWidth / borderRatio;
  497. // if (borderWidth > ch*0.5 || borderWidth > cw *0.5) {
  498. // // borderWidth = childNode.borderWidth;
  499. // }
  500. // childNode.borderWidth = borderWidth;
  501. // childNode.a(name + '.borderwidth', borderWidth);
  502. // }
  503. }
  504. that._height = height;
  505. that._originHeight = height;
  506. that._ratioY = ratioY;
  507. that._width = width;
  508. that._originWidth = width;
  509. that._ratioX = ratioX;
  510. })(width, height, angle);
  511. that._x = width / 2;
  512. that._y = height / 2;
  513. that._rotation = 0;
  514. // that.setPosition(x, y);
  515. (function (x, y) {
  516. var childNodes = that.childNodes, offset, childNode;
  517. var w2 = that.getWidth() / 2, h2 = that.getHeight()/2;
  518. for (var i = 0, len = childNodes.length; i < len; i++) {
  519. childNode = childNodes[i];
  520. offset = childNode.getPosition();
  521. childNode.setPosition(x + offset.x * that._ratioX - w2, y + offset.y * that._ratioY - h2);
  522. }
  523. that._x = x;
  524. that._y = y;
  525. })(x, y);
  526. // setTimeout(that.addEVent, 1000);
  527. },
  528. setRotation: function (angle) {
  529. var that = this, _angle = that.getRotation();
  530. if (angle!==0 && !angle || angle === _angle) {
  531. return this;
  532. }
  533. var childNodes = this.childNodes, childNode, p = this.getPosition(), px = p.x, py = p.y;
  534. for (var i = 0, len = childNodes.length; i < len; i++) {
  535. childNode = childNodes[i];
  536. var x = childNode.getPosition().x - px;
  537. var y = childNode.getPosition().y - py;
  538. childNode.setPosition(Math.cos(angle-_angle) * x - Math.sin(angle-_angle) * y + px, Math.cos(angle-_angle) * y + Math.sin(angle-_angle) * x + py);
  539. childNode.setRotation(angle);
  540. }
  541. this._rotation = angle;
  542. return this;
  543. },
  544. getRotation: function () {
  545. return this._rotation;
  546. },
  547. setScale: function (sx, sy) {
  548. var that = this,
  549. childNodes = this.childNodes,
  550. childNode;
  551. if (sx === undefined || sx === null) return ;
  552. if (sy === undefined || sy === null) {
  553. sy = sx;
  554. }
  555. for (var i = 0, len = childNodes.length; i < len; i++) {
  556. childNode = childNodes[i];
  557. if (typeof childNode.setScale === 'function') {
  558. childNode.setScale(sx, sy);
  559. }
  560. }
  561. },
  562. getScale: function () {
  563. return this._background.getScale();
  564. },
  565. setScaleX: function (sx) {
  566. if (sx === undefined || sx === null) return;
  567. var that = this,
  568. childNodes = this.childNodes,
  569. childNode;
  570. for (var i = 0, len = childNodes.length; i < len; i++) {
  571. childNode = childNodes[i];
  572. if (typeof childNode.setScaleX === 'function') {
  573. childNode.setScaleX(sx);
  574. }
  575. }
  576. },
  577. setScaleY: function (sy) {
  578. if (sy === undefined || sy === null) return;
  579. var that = this,
  580. childNodes = this.childNodes,
  581. childNode;
  582. for (var i = 0, len = childNodes.length; i < len; i++) {
  583. childNode = childNodes[i];
  584. if (typeof childNode.setScaleY === 'function') {
  585. childNode.setScaleY(sy);
  586. }
  587. }
  588. },
  589. getScaleX: function () {
  590. return this._background.getScaleX();
  591. },
  592. getScaleY: function () {
  593. return this._background.getScaleY();
  594. },
  595. evert: function () {
  596. var that = this,
  597. childNodes = this.childNodes,
  598. background = this._background,
  599. bp = background.getPosition(),
  600. bx = bp.x,
  601. by = bp.y,
  602. childNode, distanceX, distanceY, x, y, p, nx, ny;
  603. for (var i = 0, len = childNodes.length; i < len; i++) {
  604. childNode = childNodes[i];
  605. p = childNode.getPosition();
  606. x = p.x;
  607. y = p.y;
  608. distanceX = bx - x;
  609. distanceY = by - y;
  610. nx = bx + distanceX;
  611. ny = by + distanceY;
  612. childNode.setPosition(nx, ny);
  613. if (typeof childNode.setScale === 'function') {
  614. if (!(childNode._disallowEvert === true))
  615. childNode.setScale(-1, -1);
  616. }
  617. }
  618. },
  619. evertX: function () {
  620. var that = this,
  621. childNodes = this.childNodes,
  622. background = this._background,
  623. bx = background.getPosition().x,
  624. childNode, distance, x, p, nx;
  625. for (var i = 0, len = childNodes.length; i < len; i++) {
  626. childNode = childNodes[i];
  627. p = childNode.getPosition();
  628. x = p.x;
  629. distance = bx - x;
  630. nx = bx + distance;
  631. childNode.setPosition(nx, p.y);
  632. if (typeof childNode.setScaleX === 'function') {
  633. if (!(childNode._disallowEvert === true))
  634. childNode.setScaleX(-1);
  635. }
  636. }
  637. },
  638. evertY: function () {
  639. var that = this,
  640. childNodes = this.childNodes,
  641. background = this._background,
  642. by = background.getPosition().y,
  643. childNode, distance, y, p, ny;
  644. for (var i = 0, len = childNodes.length; i < len; i++) {
  645. childNode = childNodes[i];
  646. p = childNode.getPosition();
  647. y = p.y;
  648. distance = by - y;
  649. ny = by + distance;
  650. childNode.setPosition(p.x, ny);
  651. if (typeof childNode.setScaleY === 'function') {
  652. if (!(childNode._disallowEvert === true))
  653. childNode.setScaleY(-1);
  654. }
  655. }
  656. },
  657. attr: function (key, value) {
  658. var _attrObj = this._attrObj || {};
  659. if (arguments.length === 1) {
  660. return _attrObj[key];
  661. }
  662. var childNodes = this.childNodes, childNode;
  663. _attrObj[key] = value;
  664. for (var i = 0; childNode = childNodes[i++];) {
  665. if (typeof childNode.a === 'function') {
  666. childNode.a(key, value);
  667. }
  668. }
  669. },
  670. a: function () {
  671. return this.attr.apply(this, arguments);
  672. }
  673. });
  674. }