紫箭头.js 26 KB

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