PageRenderTime 55ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/modules/ui/source/temple/ui/layout/liquid/LiquidMovieClip.as

http://templelibrary.googlecode.com/
ActionScript | 641 lines | 338 code | 69 blank | 234 comment | 54 complexity | 433f9d75e9d65295c3dcea0d381938ed MD5 | raw file
  1. /*
  2. * Temple Library for ActionScript 3.0
  3. * Copyright Š MediaMonks B.V.
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. * 3. All advertising materials mentioning features or use of this software
  14. * must display the following acknowledgement:
  15. * This product includes software developed by MediaMonks B.V.
  16. * 4. Neither the name of MediaMonks B.V. nor the
  17. * names of its contributors may be used to endorse or promote products
  18. * derived from this software without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY MEDIAMONKS B.V. ''AS IS'' AND ANY
  21. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  22. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  23. * DISCLAIMED. IN NO EVENT SHALL MEDIAMONKS B.V. BE LIABLE FOR ANY
  24. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  25. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  26. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  27. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  28. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  29. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. *
  31. *
  32. * Note: This license does not apply to 3rd party classes inside the Temple
  33. * repository with their own license!
  34. */
  35. package temple.ui.layout.liquid
  36. {
  37. import temple.core.debug.IDebuggable;
  38. import temple.core.display.CoreMovieClip;
  39. import temple.utils.FrameDelay;
  40. import flash.display.DisplayObject;
  41. import flash.geom.Point;
  42. /**
  43. * The LiquidMovieClip extends the CoreMovieClip but has already LiquidBehavior implemented.
  44. * All liquid properties are also available on the LiquidMovieClip.
  45. *
  46. * <p>If the LiquidMovieClip is set as component, all liquid properties can be set in the Component Inspector in the Flash IDE</p>
  47. *
  48. * @see temple.ui.layout.liquid.LiquidBehavior
  49. *
  50. * @includeExample LiquidExample.as
  51. *
  52. * @author Thijs Broerse
  53. */
  54. public class LiquidMovieClip extends CoreMovieClip implements ILiquidObject, IDebuggable
  55. {
  56. private var _liquidBehavior:LiquidBehavior;
  57. private var _debug:Boolean;
  58. public function LiquidMovieClip(relatedObject:ILiquidObject = null)
  59. {
  60. construct::liquidMovieClip(relatedObject);
  61. }
  62. /**
  63. * @private
  64. */
  65. construct function liquidMovieClip(relatedObject:ILiquidObject):void
  66. {
  67. this._liquidBehavior = new LiquidBehavior(this, relatedObject);
  68. // Call init after a framedelay, so all inspetables are already set
  69. new FrameDelay(this.initLiquid);
  70. }
  71. /**
  72. * @inheritDoc
  73. */
  74. public function get left():Number
  75. {
  76. return this._liquidBehavior ? this._liquidBehavior.left : NaN;
  77. }
  78. /**
  79. * @inheritDoc
  80. */
  81. public function set left(value:Number):void
  82. {
  83. this.liquidBehavior.left = value;
  84. }
  85. /**
  86. * @private
  87. */
  88. [Inspectable(name="Left", type="String")]
  89. public function set inspectableLeft(value:String):void
  90. {
  91. if (value != '' && !isNaN(Number(value)))
  92. {
  93. this.left = Number(value);
  94. }
  95. }
  96. /**
  97. * @inheritDoc
  98. */
  99. public function get right():Number
  100. {
  101. return this._liquidBehavior ? this._liquidBehavior.right : NaN;
  102. }
  103. /**
  104. * @inheritDoc
  105. */
  106. public function set right(value:Number):void
  107. {
  108. this.liquidBehavior.right = value;
  109. }
  110. /**
  111. * @private
  112. */
  113. [Inspectable(name="Right", type="String")]
  114. public function set inspectableRight(value:String):void
  115. {
  116. if (value != '' && !isNaN(Number(value)))
  117. {
  118. this.right = Number(value);
  119. }
  120. }
  121. /**
  122. * @inheritDoc
  123. */
  124. public function get horizontalCenter():Number
  125. {
  126. return this._liquidBehavior ? this._liquidBehavior.horizontalCenter : NaN;
  127. }
  128. /**
  129. * @inheritDoc
  130. */
  131. public function set horizontalCenter(value:Number):void
  132. {
  133. this.liquidBehavior.horizontalCenter = value;
  134. }
  135. /**
  136. * @private
  137. */
  138. [Inspectable(name="Horizontal center", type="String")]
  139. public function set inspectableHorizontalCenter(value:String):void
  140. {
  141. if (value != '' && !isNaN(Number(value)))
  142. {
  143. this.horizontalCenter = Number(value);
  144. }
  145. }
  146. /**
  147. * @inheritDoc
  148. */
  149. public function get relativeX():Number
  150. {
  151. return this.liquidBehavior.relativeX;
  152. }
  153. /**
  154. * @inheritDoc
  155. */
  156. public function set relativeX(value:Number):void
  157. {
  158. this.liquidBehavior.relativeX = value;
  159. }
  160. /**
  161. * @private
  162. */
  163. [Inspectable(name="Relative X", type="String")]
  164. public function set inspectableRelativeX(value:String):void
  165. {
  166. if (value != '' && !isNaN(Number(value)))
  167. {
  168. this.relativeX = Number(value);
  169. }
  170. }
  171. /**
  172. * @inheritDoc
  173. */
  174. public function get minimalWidth():Number
  175. {
  176. return this._liquidBehavior ? this._liquidBehavior.minimalWidth : NaN;
  177. }
  178. /**
  179. * @inheritDoc
  180. */
  181. public function set minimalWidth(value:Number):void
  182. {
  183. if (this.liquidBehavior) this.liquidBehavior.minimalWidth = value;
  184. }
  185. /**
  186. * @private
  187. */
  188. [Inspectable(name="Minimal width", type="String")]
  189. public function set inspectableMinimalWidth(value:String):void
  190. {
  191. if (value != '' && !isNaN(Number(value)))
  192. {
  193. this.minimalWidth = Number(value);
  194. }
  195. }
  196. /**
  197. * @inheritDoc
  198. */
  199. public function get relativeWidth():Number
  200. {
  201. return this._liquidBehavior ? this._liquidBehavior.relativeWidth : NaN;
  202. }
  203. /**
  204. * @inheritDoc
  205. */
  206. public function set relativeWidth(value:Number):void
  207. {
  208. if (this.liquidBehavior) this.liquidBehavior.relativeWidth = value;
  209. }
  210. /**
  211. * @private
  212. */
  213. [Inspectable(name="Relative Width", type="String")]
  214. public function set inspectableRelativeWidth(value:String):void
  215. {
  216. if (value != '' && !isNaN(Number(value)))
  217. {
  218. this.liquidBehavior.relativeWidth = Number(value);
  219. }
  220. else if (value.indexOf('%'))
  221. {
  222. value = value.replace('%', '');
  223. if (value != '' && !isNaN(Number(value)))
  224. {
  225. this.liquidBehavior.relativeWidth = Number(value) * 0.01;
  226. }
  227. }
  228. }
  229. /**
  230. * @inheritDoc
  231. */
  232. public function get absoluteWidth():Number
  233. {
  234. return this._liquidBehavior.absoluteWidth;
  235. }
  236. /**
  237. * @inheritDoc
  238. */
  239. public function set absoluteWidth(value:Number):void
  240. {
  241. this._liquidBehavior.absoluteWidth = value;
  242. }
  243. /**
  244. * @inheritDoc
  245. */
  246. public function get top():Number
  247. {
  248. return this._liquidBehavior ? this._liquidBehavior.top : NaN;
  249. }
  250. /**
  251. * @inheritDoc
  252. */
  253. public function set top(value:Number):void
  254. {
  255. this.liquidBehavior.top = value;
  256. }
  257. /**
  258. * @private
  259. */
  260. [Inspectable(name="Top", type="String")]
  261. public function set inspectableTop(value:String):void
  262. {
  263. if (value != '' && !isNaN(Number(value)))
  264. {
  265. this.top = Number(value);
  266. }
  267. }
  268. /**
  269. * @inheritDoc
  270. */
  271. public function get bottom():Number
  272. {
  273. return this._liquidBehavior ? this._liquidBehavior.bottom : NaN;
  274. }
  275. /**
  276. * @inheritDoc
  277. */
  278. public function set bottom(value:Number):void
  279. {
  280. this.liquidBehavior.bottom = value;
  281. }
  282. /**
  283. * @private
  284. */
  285. [Inspectable(name="Bottom", type="String")]
  286. public function set inspectableBottom(value:String):void
  287. {
  288. if (value != '' && !isNaN(Number(value)))
  289. {
  290. this.bottom = Number(value);
  291. }
  292. }
  293. /**
  294. * @inheritDoc
  295. */
  296. public function get verticalCenter():Number
  297. {
  298. return this._liquidBehavior ? this._liquidBehavior.verticalCenter : NaN;
  299. }
  300. /**
  301. * @inheritDoc
  302. */
  303. public function set verticalCenter(value:Number):void
  304. {
  305. this.liquidBehavior.verticalCenter = value;
  306. }
  307. /**
  308. * @private
  309. */
  310. [Inspectable(name="Vertical center", type="String")]
  311. public function set inspectableVerticalCenter(value:String):void
  312. {
  313. if (value != '' && !isNaN(Number(value)))
  314. {
  315. this.verticalCenter = Number(value);
  316. }
  317. }
  318. /**
  319. * @inheritDoc
  320. */
  321. public function get relativeY():Number
  322. {
  323. return this.liquidBehavior.relativeY;
  324. }
  325. /**
  326. * @inheritDoc
  327. */
  328. public function set relativeY(value:Number):void
  329. {
  330. this.liquidBehavior.relativeY = value;
  331. }
  332. /**
  333. * @private
  334. */
  335. [Inspectable(name="Relative Y", type="String")]
  336. public function set inspectableRelativeY(value:String):void
  337. {
  338. if (value != '' && !isNaN(Number(value)))
  339. {
  340. this.relativeY = Number(value);
  341. }
  342. }
  343. /**
  344. * @inheritDoc
  345. */
  346. public function get absoluteHeight():Number
  347. {
  348. return this._liquidBehavior.absoluteHeight;
  349. }
  350. /**
  351. * @inheritDoc
  352. */
  353. public function set absoluteHeight(value:Number):void
  354. {
  355. this._liquidBehavior.absoluteHeight = value;
  356. }
  357. /**
  358. * @inheritDoc
  359. */
  360. public function get minimalHeight():Number
  361. {
  362. return this._liquidBehavior ? this._liquidBehavior.minimalHeight : NaN;
  363. }
  364. /**
  365. * @inheritDoc
  366. */
  367. public function set minimalHeight(value:Number):void
  368. {
  369. if (this.liquidBehavior) this.liquidBehavior.minimalHeight = value;
  370. }
  371. /**
  372. * @private
  373. */
  374. [Inspectable(name="Minimal height", type="String")]
  375. public function set inspectableMinimalHeight(value:String):void
  376. {
  377. if (value != '' && !isNaN(Number(value)))
  378. {
  379. this.minimalHeight = Number(value);
  380. }
  381. }
  382. /**
  383. * @inheritDoc
  384. */
  385. public function get relativeHeight():Number
  386. {
  387. return this._liquidBehavior ? this._liquidBehavior.relativeHeight : NaN;
  388. }
  389. /**
  390. * @inheritDoc
  391. */
  392. public function set relativeHeight(value:Number):void
  393. {
  394. if (this.liquidBehavior) this.liquidBehavior.relativeHeight = value;
  395. }
  396. /**
  397. * @private
  398. */
  399. [Inspectable(name="Relative Height", type="String")]
  400. public function set inspectableRelativeHeight(value:String):void
  401. {
  402. if (value != '' && !isNaN(Number(value)))
  403. {
  404. this.liquidBehavior.relativeHeight = Number(value);
  405. }
  406. else if (value.indexOf('%'))
  407. {
  408. value = value.replace('%', '');
  409. if (value != '' && !isNaN(Number(value)))
  410. {
  411. this.liquidBehavior.relativeHeight = Number(value) * 0.01;
  412. }
  413. }
  414. }
  415. /**
  416. * @inheritDoc
  417. */
  418. public function get relatedObject():ILiquidRelatedObject
  419. {
  420. return this._liquidBehavior ? this._liquidBehavior.relatedObject : null;
  421. }
  422. /**
  423. * @inheritDoc
  424. */
  425. public function set relatedObject(value:ILiquidRelatedObject):void
  426. {
  427. this.liquidBehavior.relatedObject = value;
  428. }
  429. /**
  430. * @inheritDoc
  431. */
  432. public function update():void
  433. {
  434. if (this._liquidBehavior) this._liquidBehavior.update();
  435. }
  436. /**
  437. * @inheritDoc
  438. */
  439. public function isLiquid():Boolean
  440. {
  441. return this._liquidBehavior ? this._liquidBehavior.isLiquid() : false;
  442. }
  443. /**
  444. * @inheritDoc
  445. */
  446. public function get resetRelatedScale():Boolean
  447. {
  448. return this._liquidBehavior ? this._liquidBehavior.resetRelatedScale : false;
  449. }
  450. /**
  451. * @inheritDoc
  452. */
  453. public function set resetRelatedScale(value:Boolean):void
  454. {
  455. if (this._liquidBehavior) this._liquidBehavior.resetRelatedScale = value;
  456. }
  457. /**
  458. * @inheritDoc
  459. */
  460. public function get offset():Point
  461. {
  462. return this._liquidBehavior ? this._liquidBehavior.offset : null;
  463. }
  464. /**
  465. * If set to true all values will be rounded to pixels
  466. */
  467. public function get snapToPixels():Boolean
  468. {
  469. return this._liquidBehavior ? this._liquidBehavior.snapToPixels : false;
  470. }
  471. /**
  472. * @private
  473. */
  474. [Inspectable(name="Snap to pixels", type="Boolean", defaultValue="true")]
  475. public function set snapToPixels(value:Boolean):void
  476. {
  477. if (this._liquidBehavior) this._liquidBehavior.snapToPixels = value;
  478. }
  479. /**
  480. * @inheritDoc
  481. */
  482. public function get keepAspectRatio():Boolean
  483. {
  484. return this._liquidBehavior ? this._liquidBehavior.keepAspectRatio : false;
  485. }
  486. /**
  487. * @inheritDoc
  488. */
  489. [Inspectable(name="Keep aspect ratio", type="Boolean", defaultValue="false")]
  490. public function set keepAspectRatio(value:Boolean):void
  491. {
  492. this.liquidBehavior.keepAspectRatio = value;
  493. }
  494. /**
  495. * @inheritDoc
  496. */
  497. public function get adjustRelated():Boolean
  498. {
  499. return this._liquidBehavior ? this._liquidBehavior.adjustRelated : true;
  500. }
  501. /**
  502. * @inheritDoc
  503. */
  504. public function set adjustRelated(value:Boolean):void
  505. {
  506. this.liquidBehavior.adjustRelated = value;
  507. }
  508. /**
  509. * @inheritDoc
  510. */
  511. public function get displayObject():DisplayObject
  512. {
  513. return this;
  514. }
  515. /**
  516. * Indicates if the LiquidBehavior is enabled
  517. */
  518. public function get liquidEnabled():Boolean
  519. {
  520. return this._liquidBehavior ? this._liquidBehavior.enabled : false;
  521. }
  522. /**
  523. * @private
  524. */
  525. [Inspectable(name="Liquid enabled", type="Boolean", defaultValue="true")]
  526. public function set liquidEnabled(value:Boolean):void
  527. {
  528. this.liquidBehavior.enabled = value;
  529. }
  530. /**
  531. * Returns a reference of the LiquidBehavior.
  532. * The LiquidBehavior is only created when it's actually needed.
  533. */
  534. public function get liquidBehavior():LiquidBehavior
  535. {
  536. return this._liquidBehavior;
  537. }
  538. /**
  539. * @inheritDoc
  540. */
  541. public function get debug():Boolean
  542. {
  543. return this._debug;
  544. }
  545. /**
  546. * @inheritDoc
  547. */
  548. [Inspectable(name="Debug", type="Boolean", defaultValue="false")]
  549. public function set debug(value:Boolean):void
  550. {
  551. this.liquidBehavior.debug = this._debug = value;
  552. }
  553. /**
  554. * Initializes the liquid behavior
  555. */
  556. protected function initLiquid():void
  557. {
  558. if (this.isLiquid())
  559. {
  560. this._liquidBehavior.init();
  561. }
  562. }
  563. /**
  564. * @inheritDoc
  565. */
  566. override public function destruct():void
  567. {
  568. this._liquidBehavior = null;
  569. super.destruct();
  570. }
  571. }
  572. }