zmt1.js 27 KB

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