guiSpriteCtrl_ScriptBindings.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. ConsoleMethodGroupBeginWithDocs(GuiSpriteCtrl, GuiControl)
  23. /*! Gets whether the control is in static or dynamic (animated) mode.
  24. @return Returns whether the control is in static or dynamic (animated) mode.
  25. */
  26. ConsoleMethodWithDocs(GuiSpriteCtrl, isStaticFrameProvider, ConsoleBool, 2, 2, ())
  27. {
  28. return object->isStaticFrameProvider();
  29. }
  30. //------------------------------------------------------------------------------
  31. /*! Gets whether the control is using a numerical or named image frame.
  32. @return Returns true when using a named frame, false when using a numerical index.
  33. */
  34. ConsoleMethodWithDocs(GuiSpriteCtrl, isUsingNamedImageFrame, ConsoleBool, 2, 2, ())
  35. {
  36. return object->isUsingNamedImageFrame();
  37. }
  38. //-----------------------------------------------------------------------------
  39. /*! Sets the control image and optionally the frame.
  40. @param imageAssetId The image asset Id to display
  41. @param frame The numerical or named frame of the image to display
  42. @return Returns true on success.
  43. */
  44. ConsoleMethodWithDocs(GuiSpriteCtrl, setImage, ConsoleBool, 3, 4, (imageAssetId, [frame]))
  45. {
  46. // Was a frame specified?
  47. if (argc >= 4)
  48. {
  49. // Was it a number or a string?
  50. if (!dIsalpha(*argv[3]))
  51. {
  52. // Fetch the numerical frame and set the image
  53. const U32 frame = argc >= 4 ? dAtoi(argv[3]) : 0;
  54. return object->setImage( argv[2], frame );
  55. }
  56. else
  57. {
  58. // Set the image and pass the named frame string
  59. return object->setImage( argv[2], argv[3] );
  60. }
  61. }
  62. else
  63. {
  64. // Frame was not specified, use default 0 and set the image
  65. const U32 frame = 0;
  66. return object->setImage( argv[2], frame );
  67. }
  68. }
  69. //------------------------------------------------------------------------------
  70. /*! Gets current image asset Id.
  71. @return (string imageAssetId) The image being displayed.
  72. */
  73. ConsoleMethodWithDocs(GuiSpriteCtrl, getImage, ConsoleString, 2, 2, ())
  74. {
  75. // Are we in static mode?
  76. if ( !object->isStaticFrameProvider() )
  77. {
  78. // No, so warn.
  79. Con::warnf("GuiSpriteCtrl::getImage() - Method invalid, not in static mode.");
  80. return StringTable->EmptyString;
  81. }
  82. // Get image.
  83. return object->getImage();
  84. }
  85. //-----------------------------------------------------------------------------
  86. /*! Sets the image frame to use as the image.
  87. @param imageFrame The image frame to use as the image.
  88. @return No return value.
  89. */
  90. ConsoleMethodWithDocs(GuiSpriteCtrl, setImageFrame, ConsoleBool, 3, 3, (int imageFrame))
  91. {
  92. // Are we in static mode?
  93. if ( object->usesAsset() && !object->isStaticFrameProvider() )
  94. {
  95. // No, so warn.
  96. Con::warnf("GuiSpriteCtrl::setImageFrame() - Method invalid, not in static mode.");
  97. return false;
  98. }
  99. return object->setImageFrame( dAtoi(argv[2]) );
  100. }
  101. //------------------------------------------------------------------------------
  102. /*! Gets current numerical image frame.
  103. @return (int frame) The numerical frame currently being displayed.
  104. */
  105. ConsoleMethodWithDocs(GuiSpriteCtrl, getImageFrame, ConsoleInt, 2, 2, ())
  106. {
  107. // Are we in static mode?
  108. if (object->usesAsset() && !object->isStaticFrameProvider() )
  109. {
  110. // No, so warn.
  111. Con::warnf("GuiSpriteCtrl::getImageFrame() - Method invalid, not in static mode.");
  112. return -1;
  113. }
  114. // Are we using a named image frame?
  115. if (object->usesAsset() && object->isUsingNamedImageFrame() )
  116. {
  117. // Yes, so warn.
  118. Con::warnf("GuiSpriteCtrl::getImageFrame() - Method invalid, using a named image frame.");
  119. return -1;
  120. }
  121. // Get image frame.
  122. return object->getImageFrame();
  123. }
  124. //------------------------------------------------------------------------------
  125. /*! Sets the image frame using a named string.
  126. @param frame The named frame to display
  127. @return Returns true on success.
  128. */
  129. ConsoleMethodWithDocs(GuiSpriteCtrl, setNamedImageFrame, ConsoleBool, 3, 3, (frame))
  130. {
  131. // Are we in static mode?
  132. if ( object->usesAsset() && !object->isStaticFrameProvider() )
  133. {
  134. // No, so warn.
  135. Con::warnf("GuiSpriteCtrl::setNamedImageFrame() - Method invalid, not in static mode.");
  136. return false;
  137. }
  138. // Are we using a bitmap?
  139. if (!object->usesAsset())
  140. {
  141. // No, so warn.
  142. Con::warnf("GuiSpriteCtrl::setNamedImageFrame() - Method invalid, using bitmaps.");
  143. return false;
  144. }
  145. // Set the numerical frame
  146. return object->setNamedImageFrame( argv[2] );
  147. }
  148. //------------------------------------------------------------------------------
  149. /*! Gets the current named image frame.
  150. @return The current named image frame.
  151. */
  152. ConsoleMethodWithDocs(GuiSpriteCtrl, getNamedImageFrame, ConsoleString, 2, 2, ())
  153. {
  154. // Are we in static mode?
  155. if ( object->usesAsset() && !object->isStaticFrameProvider() )
  156. {
  157. // No, so warn.
  158. Con::warnf("GuiSpriteCtrl::getNamedImageFrame() - Method invalid, not in static mode.");
  159. return NULL;
  160. }
  161. // Are we using a named image frame?
  162. if (object->usesAsset() && !object->isUsingNamedImageFrame() )
  163. {
  164. // No, so warn.
  165. Con::warnf("GuiSpriteCtrl::getNamedImageFrame() - Method invalid, not using a named image frame.");
  166. return NULL;
  167. }
  168. //Are we using a bitmap?
  169. if (!object->usesAsset())
  170. {
  171. // Yes, so warn.
  172. Con::warnf("GuiSpriteCtrl::getNamedImageFrame() - Method invalid, using a bitmap.");
  173. return NULL;
  174. }
  175. return object->getNamedImageFrame();
  176. }
  177. //------------------------------------------------------------------------------
  178. /*! Sets the animation asset Id to display.
  179. @param animationAssetId The animation asset Id to play
  180. @return No return value.
  181. */
  182. ConsoleMethodWithDocs(GuiSpriteCtrl, setAnimation, ConsoleVoid, 3, 3, (string animationAssetId))
  183. {
  184. // Set animation.
  185. object->setAnimation( argv[2] );
  186. }
  187. //------------------------------------------------------------------------------
  188. /*! Gets the current animation asset Id.
  189. @return (string ianimationAssetId) The animation being displayed.
  190. */
  191. ConsoleMethodWithDocs(GuiSpriteCtrl, getAnimation, ConsoleString, 2, 2, ())
  192. {
  193. // Are we in static mode?
  194. if ( object->usesAsset() && object->isStaticFrameProvider() )
  195. {
  196. // Yes, so warn.
  197. Con::warnf("GuiSpriteCtrl::getAnimation() - Method invalid, in static mode.");
  198. return StringTable->EmptyString;
  199. }
  200. //Are we using a bitmap?
  201. if (!object->usesAsset())
  202. {
  203. // Yes, so warn.
  204. Con::warnf("GuiSpriteCtrl::getAnimation() - Method invalid, using a bitmap.");
  205. return StringTable->EmptyString;
  206. }
  207. // Get animation.
  208. return object->getAnimation();
  209. }
  210. //-----------------------------------------------------------------------------
  211. /*! Pause the current animation
  212. @param enable If true, pause the animation. If false, continue animating
  213. */
  214. ConsoleMethodWithDocs(GuiSpriteCtrl, pauseAnimation, ConsoleVoid, 3, 3, (bool enable))
  215. {
  216. // Are we in static mode?
  217. if ( object->usesAsset() && object->isStaticFrameProvider() )
  218. {
  219. // Yes, so warn.
  220. Con::warnf("GuiSpriteCtrl::pauseAnimation() - Method invalid, not in dynamic (animated) mode.");
  221. return;
  222. }
  223. //Are we using a bitmap?
  224. if (!object->usesAsset())
  225. {
  226. // Yes, so warn.
  227. Con::warnf("GuiSpriteCtrl::pauseAnimation() - Method invalid, using a bitmap.");
  228. return;
  229. }
  230. return static_cast<ImageFrameProvider*>(object)->pauseAnimation(dAtob(argv[2]));
  231. }
  232. //-----------------------------------------------------------------------------
  233. /*! Stop the current animation
  234. @return No return value.
  235. */
  236. ConsoleMethodWithDocs(GuiSpriteCtrl, stopAnimation, ConsoleVoid, 2, 2, ())
  237. {
  238. // Are we in static mode?
  239. if ( object->usesAsset() && object->isStaticFrameProvider() )
  240. {
  241. // Yes, so warn.
  242. Con::warnf("GuiSpriteCtrl::stopAnimation() - Method invalid, not in dynamic (animated) mode.");
  243. return;
  244. }
  245. //Are we using a bitmap?
  246. if (!object->usesAsset())
  247. {
  248. // Yes, so warn.
  249. Con::warnf("GuiSpriteCtrl::stopAnimation() - Method invalid, using a bitmap.");
  250. return;
  251. }
  252. object->stopAnimation();
  253. }
  254. //-----------------------------------------------------------------------------
  255. /*! Sets the current animation frame. IMPORTANT: this is not the image frame number used in the animation!
  256. @param frame Which frame of the animation to display
  257. @return No return value.
  258. */
  259. ConsoleMethodWithDocs(GuiSpriteCtrl, setAnimationFrame, ConsoleVoid, 3, 3, (int frame))
  260. {
  261. // Are we in static mode?
  262. if ( object->usesAsset() && object->isStaticFrameProvider() )
  263. {
  264. // Yes, so warn.
  265. Con::warnf("GuiSpriteCtrl::setAnimationFrame() - Method invalid, not in dynamic (animated) mode.");
  266. return;
  267. }
  268. //Are we using a bitmap?
  269. if (!object->usesAsset())
  270. {
  271. // Yes, so warn.
  272. Con::warnf("GuiSpriteCtrl::setAnimationFrame() - Method invalid, using a bitmap.");
  273. return;
  274. }
  275. // Set Animation Frame
  276. object->setAnimationFrame( dAtoi(argv[2]) );
  277. }
  278. //-----------------------------------------------------------------------------
  279. /*! Gets current frame index used in the animation. IMPORTANT: this is not the image frame number!
  280. @return The current numerical animation frame
  281. */
  282. ConsoleMethodWithDocs(GuiSpriteCtrl, getAnimationFrame, ConsoleInt, 2, 2, ())
  283. {
  284. // Are we in static mode?
  285. if ( object->usesAsset() && object->isStaticFrameProvider() )
  286. {
  287. // Yes, so warn.
  288. Con::warnf("GuiSpriteCtrl::getAnimationFrame() - Method invalid, not in dynamic (animated) mode.");
  289. return -1;
  290. }
  291. //Are we using a bitmap?
  292. if (!object->usesAsset())
  293. {
  294. // Yes, so warn.
  295. Con::warnf("GuiSpriteCtrl::getAnimationFrame() - Method invalid, using a bitmap.");
  296. return NULL;
  297. }
  298. // Get Animation Frame.
  299. return object->getAnimationFrame();
  300. }
  301. //-----------------------------------------------------------------------------
  302. /*! Gets current numerical image frame used in the animation.
  303. @return The current numerical animation frame
  304. */
  305. ConsoleMethodWithDocs(GuiSpriteCtrl, getAnimationImageFrame, ConsoleInt, 2, 2, ())
  306. {
  307. // Are we in static mode?
  308. if ( object->usesAsset() && object->isStaticFrameProvider() )
  309. {
  310. // Yes, so warn.
  311. Con::warnf("GuiSpriteCtrl::getAnimationImageFrame() - Method invalid, not in dynamic (animated) mode.");
  312. return -1;
  313. }
  314. //Are we using a bitmap?
  315. if (!object->usesAsset())
  316. {
  317. // Yes, so warn.
  318. Con::warnf("GuiSpriteCtrl::getAnimationImageFrame() - Method invalid, using a bitmap.");
  319. return -1;
  320. }
  321. // Get the current animation asset
  322. const AnimationAsset* asset = object->getCurrentAnimation();
  323. // Are we using named animation frames?
  324. if (asset->getNamedCellsMode())
  325. {
  326. // Yes, so warn.
  327. Con::warnf("GuiSpriteCtrl::getAnimationImageFrame() - Method invalid, animation is in named cells mode.");
  328. return -1;
  329. }
  330. // Get Image Frame.
  331. return object->getCurrentAnimationFrame();
  332. }
  333. //-----------------------------------------------------------------------------
  334. /*! Gets current named image frame used in the animation.
  335. @return The current named animation frame
  336. */
  337. ConsoleMethodWithDocs(GuiSpriteCtrl, getAnimationNamedImageFrame, ConsoleString, 2, 2, ())
  338. {
  339. //Are we using a bitmap?
  340. if (!object->usesAsset())
  341. {
  342. // Yes, so warn.
  343. Con::warnf("GuiSpriteCtrl::getAnimationNamedImageFrame() - Method invalid, using a bitmap.");
  344. return NULL;
  345. }
  346. // Are we in static mode?
  347. if ( object->isStaticFrameProvider() )
  348. {
  349. // Yes, so warn.
  350. Con::warnf("GuiSpriteCtrl::getAnimationNamedImageFrame() - Method invalid, not in dynamic (animated) mode.");
  351. return NULL;
  352. }
  353. // Get the current animation asset
  354. const AnimationAsset* asset = object->getCurrentAnimation();
  355. // Are we using named animation frames?
  356. if (!asset->getNamedCellsMode())
  357. {
  358. // No, so warn.
  359. Con::warnf("GuiSpriteCtrl::getAnimationNamedImageFrame() - Method invalid, animation not in named cells mode.");
  360. return NULL;
  361. }
  362. // Get Image Frame.
  363. return object->getCurrentNamedAnimationFrame();
  364. }
  365. //-----------------------------------------------------------------------------
  366. /*! Gets current animation time.
  367. @return (float time) The current animation time
  368. */
  369. ConsoleMethodWithDocs(GuiSpriteCtrl, getAnimationTime, ConsoleFloat, 2, 2, ())
  370. {
  371. //Are we using a bitmap?
  372. if (!object->usesAsset())
  373. {
  374. // Yes, so warn.
  375. Con::warnf("GuiSpriteCtrl::getAnimationTime() - Method invalid, using a bitmap.");
  376. return 0.0f;
  377. }
  378. // Are we in static mode?
  379. if ( object->isStaticFrameProvider() )
  380. {
  381. // Yes, so warn.
  382. Con::warnf("GuiSpriteCtrl::getAnimationTime() - Method invalid, not in dynamic (animated) mode.");
  383. return 0.0f;
  384. }
  385. // Get Animation Time.
  386. return object->getCurrentAnimationTime();
  387. }
  388. //-----------------------------------------------------------------------------
  389. /*! Checks animation status.
  390. @return (bool finished) Whether or not the animation is finished
  391. */
  392. ConsoleMethodWithDocs(GuiSpriteCtrl, getIsAnimationFinished, ConsoleBool, 2, 2, ())
  393. {
  394. //Are we using a bitmap?
  395. if (!object->usesAsset())
  396. {
  397. // Yes, so warn.
  398. Con::warnf("GuiSpriteCtrl::getAnimationFinished() - Method invalid, using a bitmap.");
  399. return true;
  400. }
  401. // Are we in static mode?
  402. if ( object->isStaticFrameProvider() )
  403. {
  404. // Yes, so warn.
  405. Con::warnf("GuiSpriteCtrl::getIsAnimationFinished() - Method invalid, not in dynamic (animated) mode.");
  406. return true;
  407. }
  408. // Return Animation Finished Status.
  409. return object->isAnimationFinished();
  410. }
  411. //-----------------------------------------------------------------------------
  412. /*! Change the rate of animation.
  413. @param timeScale Value which will scale the frame animation speed. 1 by default.
  414. */
  415. ConsoleMethodWithDocs(GuiSpriteCtrl, setAnimationTimeScale, ConsoleVoid, 3, 3, (float timeScale))
  416. {
  417. //Are we using a bitmap?
  418. if (!object->usesAsset())
  419. {
  420. // Yes, so warn.
  421. Con::warnf("GuiSpriteCtrl::setAnimationTimeScale() - Method invalid, using a bitmap.");
  422. return;
  423. }
  424. // Are we in static mode?
  425. if ( object->isStaticFrameProvider() )
  426. {
  427. // Yes, so warn.
  428. Con::warnf("GuiSpriteCtrl::setAnimationTimeScale() - Method invalid, not in dynamic (animated) mode.");
  429. return;
  430. }
  431. object->setAnimationTimeScale(dAtof(argv[2]));
  432. }
  433. //-----------------------------------------------------------------------------
  434. /*! Get the animation time scale for this control.
  435. @return (float) Returns the animation time scale for this control.
  436. */
  437. ConsoleMethodWithDocs(GuiSpriteCtrl, getAnimationTimeScale, ConsoleFloat, 2, 2, ())
  438. {
  439. //Are we using a bitmap?
  440. if (!object->usesAsset())
  441. {
  442. // Yes, so warn.
  443. Con::warnf("GuiSpriteCtrl::getAnimationTimeScale() - Method invalid, using a bitmap.");
  444. return -1;
  445. }
  446. // Are we in static mode?
  447. if ( object->isStaticFrameProvider() )
  448. {
  449. // Yes, so warn.
  450. Con::warnf("GuiSpriteCtrl::getAnimationTimeScale() - Method invalid, not in dynamic (animated) mode.");
  451. return 1.0f;
  452. }
  453. return object->getAnimationTimeScale();
  454. }
  455. /*! Sets the amount to offset the image from its actual position. The image will not exceed the bounds of the content area.
  456. @param x/y The space-delimited x and y values to offset the image by.
  457. @return No return value.
  458. */
  459. ConsoleMethodWithDocs(GuiSpriteCtrl, setPositionOffset, ConsoleVoid, 3, 3, "(Vector2 x y)")
  460. {
  461. if (argc != 3)
  462. {
  463. Con::warnf("GuiSpriteCtrl::setPositionOffset() - Invalid number of parameters!");
  464. return;
  465. }
  466. const U32 posCount = Utility::mGetStringElementCount(argv[2]);
  467. if (posCount != 2)
  468. {
  469. Con::warnf("GuiSpriteCtrl::setPositionOffset() - Position requires x and y");
  470. return;
  471. }
  472. object->setPositionOffset(dAtoi(Utility::mGetStringElement(argv[2], 0)),
  473. dAtoi(Utility::mGetStringElement(argv[2], 0)));
  474. }
  475. /*! Gets the amount to offset the image from its actual position. The offset may be greater than the movement of the image becuase of the bounds of the content area.
  476. @return The space-delimited x and y values to offset the image by.
  477. */
  478. ConsoleMethodWithDocs(GuiSpriteCtrl, getPositionOffset, ConsoleString, 2, 2, "()")
  479. {
  480. char *retBuffer = Con::getReturnBuffer(64);
  481. const Point2I &off = object->getPositionOffset();
  482. dSprintf(retBuffer, 64, "%d %d", off.x, off.y);
  483. return retBuffer;
  484. }
  485. /*! Sets the size of the image. The image will not exceed the bounds of the content area.
  486. @param x/y The space-delimited x and y values of the image size.
  487. @return No return value.
  488. */
  489. ConsoleMethodWithDocs(GuiSpriteCtrl, setImageSize, ConsoleVoid, 3, 3, "(Vector2 x y)")
  490. {
  491. if (argc != 3)
  492. {
  493. Con::warnf("GuiSpriteCtrl::setImageSize() - Invalid number of parameters!");
  494. return;
  495. }
  496. const U32 posCount = Utility::mGetStringElementCount(argv[2]);
  497. if (posCount != 2)
  498. {
  499. Con::warnf("GuiSpriteCtrl::setImageSize() - Size requires x and y");
  500. return;
  501. }
  502. object->setImageSize(Point2I(dAtoi(Utility::mGetStringElement(argv[2], 0)),
  503. dAtoi(Utility::mGetStringElement(argv[2], 0))));
  504. }
  505. /*! Gets the size of the image.
  506. @return The space-delimited x and y values of the image size.
  507. */
  508. ConsoleMethodWithDocs(GuiSpriteCtrl, getImageSize, ConsoleString, 2, 2, "()")
  509. {
  510. char *retBuffer = Con::getReturnBuffer(64);
  511. const Point2I &size = object->getImageSize();
  512. dSprintf(retBuffer, 64, "%d %d", size.x, size.y);
  513. return retBuffer;
  514. }
  515. /*! Sets the color that should be used to display the image.
  516. @param r/g/b/a The space-delimited red, green, blue, and alpha values between 0 and 255.
  517. @return No return value.
  518. */
  519. ConsoleMethodWithDocs(GuiSpriteCtrl, setImageColor, ConsoleVoid, 3, 3, "(color red/green/blue/[alpha])")
  520. {
  521. if (argc != 3)
  522. {
  523. Con::warnf("GuiSpriteCtrl::setImageColor() - Invalid number of parameters!");
  524. return;
  525. }
  526. const U32 colorCount = Utility::mGetStringElementCount(argv[2]);
  527. if (colorCount == 1)
  528. {
  529. // Is this a stock color name?
  530. if (!StockColor::isColor(argv[2]))
  531. {
  532. // No, so warn.
  533. Con::warnf("GuiSpriteCtrl::setImageColor() - Invalid single argument of '%s' could not be interpreted as a stock color name.", argv[2]);
  534. return;
  535. }
  536. // Set stock color (if it's invalid we'll get the default.
  537. object->setImageColor(ColorI(argv[2]));
  538. return;
  539. }
  540. if (colorCount != 3 && colorCount != 4)
  541. {
  542. Con::warnf("GuiSpriteCtrl::setImageColor() - Colors require 4 values between 0 and 255 (red, green, blue, alpha)!");
  543. return;
  544. }
  545. U8 red, green, blue, alpha;
  546. red = dAtoi(Utility::mGetStringElement(argv[2], 0));
  547. green = dAtoi(Utility::mGetStringElement(argv[2], 1));
  548. blue = dAtoi(Utility::mGetStringElement(argv[2], 2));
  549. alpha = colorCount == 4 ? dAtoi(Utility::mGetStringElement(argv[2], 3)) : 255;
  550. object->setImageColor(ColorI(red, green, blue, alpha));
  551. }
  552. /*! Gets the current image color.
  553. @return The space-delimited red, green, blue, and alpha values of the color.
  554. */
  555. ConsoleMethodWithDocs(GuiSpriteCtrl, getImageColor, ConsoleString, 2, 2, "()")
  556. {
  557. char *retBuffer = Con::getReturnBuffer(64);
  558. const ColorI &color = object->getImageColor();
  559. dSprintf(retBuffer, 64, "%d %d %d %d", color.red, color.green, color.blue, color.alpha);
  560. return retBuffer;
  561. }
  562. /*! Sets if the bitmap should be broken into multiple frames based on the color of the first pixel.
  563. @param isSingle If true, the bitmap has one and only one frame. If false, the top left pixel color will be used to divide the bitmap into frames.
  564. @return No return value.
  565. */
  566. ConsoleMethodWithDocs(GuiSpriteCtrl, setSingleFrameBitmap, ConsoleVoid, 3, 3, "(bool isSingle)")
  567. {
  568. //Are we using an asset?
  569. if (object->usesAsset())
  570. {
  571. // Yes, so warn.
  572. Con::warnf("GuiSpriteCtrl::setSingleFrameBitmap() - Method invalid, using an asset.");
  573. return;
  574. }
  575. if (argc != 3)
  576. {
  577. Con::warnf("GuiSpriteCtrl::setSingleFrameBitmap() - Invalid number of parameters!");
  578. return;
  579. }
  580. object->setSingleFrameBitmap(dAtob(argv[2]));
  581. }
  582. /*! Gets if the bitmap should be broken into multiple frames based on the color of the first pixel.
  583. @return Returns true if there's only one frame for the bitmap and false otherwise.
  584. */
  585. ConsoleMethodWithDocs(GuiSpriteCtrl, getSingleFrameBitmap, ConsoleBool, 2, 2, "()")
  586. {
  587. //Are we using a asset?
  588. if (object->usesAsset())
  589. {
  590. // Yes, so warn.
  591. Con::warnf("GuiSpriteCtrl::getSingleFrameBitmap() - Method invalid, using an asset.");
  592. return true;
  593. }
  594. return object->getSingleFrameBitmap();
  595. }
  596. /*! Sets if the image should tile across the content area of the control.
  597. @param tileImage If true, the image will tile. If false, it will display a single copy of the image.
  598. @return No return value.
  599. */
  600. ConsoleMethodWithDocs(GuiSpriteCtrl, setTileImage, ConsoleVoid, 3, 3, "(bool tileImage)")
  601. {
  602. if (argc != 3)
  603. {
  604. Con::warnf("GuiSpriteCtrl::setTileImage() - Invalid number of parameters!");
  605. return;
  606. }
  607. object->setTileImage(dAtob(argv[2]));
  608. }
  609. /*! Gets if the image will tile across the content area of the control.
  610. @return True if tiling is on and false otherwise.
  611. */
  612. ConsoleMethodWithDocs(GuiSpriteCtrl, getTileImage, ConsoleBool, 2, 2, "()")
  613. {
  614. return object->getTileImage();
  615. }
  616. /*! Sets if the image should take the entire content area.
  617. @param fullSize If true, the image will take the entire content area. False will cause the image to use the image size.
  618. @return No return value.
  619. */
  620. ConsoleMethodWithDocs(GuiSpriteCtrl, setFullSize, ConsoleVoid, 3, 3, "(bool fullSize)")
  621. {
  622. if (argc != 3)
  623. {
  624. Con::warnf("GuiSpriteCtrl::setFullSize() - Invalid number of parameters!");
  625. return;
  626. }
  627. object->setFullSize(dAtob(argv[2]));
  628. }
  629. /*! Gets if the image will take the entire content area.
  630. @return True if using the entire content area and false otherwise.
  631. */
  632. ConsoleMethodWithDocs(GuiSpriteCtrl, getFullSize, ConsoleBool, 2, 2, "()")
  633. {
  634. return object->getFullSize();
  635. }
  636. /*! Sets if the image should keep its aspect ratio.
  637. @param constrain If true, maintain its aspect ratio. False otherwise.
  638. @return No return value.
  639. */
  640. ConsoleMethodWithDocs(GuiSpriteCtrl, setConstrainProportions, ConsoleVoid, 3, 3, "(bool constrain)")
  641. {
  642. if (argc != 3)
  643. {
  644. Con::warnf("GuiSpriteCtrl::setConstrainProportions() - Invalid number of parameters!");
  645. return;
  646. }
  647. object->setConstrainProportions(dAtob(argv[2]));
  648. }
  649. /*! Gets if the image will maintain its aspect ratio.
  650. @return True it will constrain proportions and false otherwise.
  651. */
  652. ConsoleMethodWithDocs(GuiSpriteCtrl, getConstrainProportions, ConsoleBool, 2, 2, "()")
  653. {
  654. return object->getConstrainProportions();
  655. }
  656. /*! Animates the position offset from its current value to a target value over time.
  657. @param x/y The space-delimited x and y values to change the image offset to.
  658. @param time The time in miliseconds it should take to complete the transformation.
  659. @param ease The optional easing function that should be applied to the the animation. Defaults to linear.
  660. @return No return value.
  661. */
  662. ConsoleMethodWithDocs(GuiSpriteCtrl, moveTo, ConsoleVoid, 4, 5, "(Vector2 x y, int time, [EasingFunction ease])")
  663. {
  664. if (argc != 4 && argc != 5)
  665. {
  666. Con::warnf("GuiSpriteCtrl::moveTo() - Invalid number of parameters!");
  667. return;
  668. }
  669. const U32 posCount = Utility::mGetStringElementCount(argv[2]);
  670. if (posCount != 2)
  671. {
  672. Con::warnf("GuiSpriteCtrl::moveTo() - Position requires x and y");
  673. return;
  674. }
  675. EasingFunction ease = Linear;
  676. if (argc == 5)
  677. {
  678. for (U32 i = 0; i < (sizeof(easingEnums) / sizeof(EnumTable::Enums)); i++)
  679. {
  680. if (dStricmp(easingEnums[i].label, argv[4]) == 0)
  681. ease = (EasingFunction)easingEnums[i].index;
  682. }
  683. }
  684. object->moveTo(dAtoi(Utility::mGetStringElement(argv[2], 0)),
  685. dAtoi(Utility::mGetStringElement(argv[2], 0)),
  686. dAtoi(argv[3]), ease);
  687. }
  688. /*! Animates the image size from its current value to a target value over time.
  689. @param x/y The space-delimited x and y values to change the image size to. Note that the image will not exceed the content area of the control.
  690. @param time The time in miliseconds it should take to complete the transformation.
  691. @param ease The optional easing function that should be applied to the the animation. Defaults to linear.
  692. @return No return value.
  693. */
  694. ConsoleMethodWithDocs(GuiSpriteCtrl, growTo, ConsoleVoid, 4, 5, "(Vector2 x y, int time, [EasingFunction ease])")
  695. {
  696. if (argc != 4 && argc != 5)
  697. {
  698. Con::warnf("GuiSpriteCtrl::growTo() - Invalid number of parameters!");
  699. return;
  700. }
  701. const U32 posCount = Utility::mGetStringElementCount(argv[2]);
  702. if (posCount != 2)
  703. {
  704. Con::warnf("GuiSpriteCtrl::growTo() - Position requires x and y");
  705. return;
  706. }
  707. EasingFunction ease = Linear;
  708. if (argc == 5)
  709. {
  710. for (U32 i = 0; i < (sizeof(easingEnums) / sizeof(EnumTable::Enums)); i++)
  711. {
  712. if (dStricmp(easingEnums[i].label, argv[4]) == 0)
  713. ease = (EasingFunction)easingEnums[i].index;
  714. }
  715. }
  716. object->growTo(dAtoi(Utility::mGetStringElement(argv[2], 0)),
  717. dAtoi(Utility::mGetStringElement(argv[2], 0)),
  718. dAtoi(argv[3]), ease);
  719. }
  720. /*! Animates the image color from its current value to a target value over time.
  721. @param red/green/blue/alpha The space-delimited color values to change the image color to. Color values should be between 0 and 255.
  722. @param time The time in miliseconds it should take to complete the transformation.
  723. @param ease The optional easing function that should be applied to the the animation. Defaults to linear.
  724. @return No return value.
  725. */
  726. ConsoleMethodWithDocs(GuiSpriteCtrl, fadeTo, ConsoleVoid, 4, 5, "(Vector2 x y, int time, [EasingFunction ease])")
  727. {
  728. if (argc != 4 && argc != 5)
  729. {
  730. Con::warnf("GuiSpriteCtrl::fadeTo() - Invalid number of parameters!");
  731. return;
  732. }
  733. EasingFunction ease = Linear;
  734. if (argc == 5)
  735. {
  736. for (U32 i = 0; i < (sizeof(easingEnums) / sizeof(EnumTable::Enums)); i++)
  737. {
  738. if (dStricmp(easingEnums[i].label, argv[4]) == 0)
  739. ease = (EasingFunction)easingEnums[i].index;
  740. }
  741. }
  742. const U32 colorCount = Utility::mGetStringElementCount(argv[2]);
  743. if (colorCount == 1)
  744. {
  745. // Is this a stock color name?
  746. if (!StockColor::isColor(argv[2]))
  747. {
  748. // No, so warn.
  749. Con::warnf("GuiSpriteCtrl::fadeTo() - Invalid single argument of '%s' could not be interpreted as a stock color name.", argv[2]);
  750. return;
  751. }
  752. // Set stock color (if it's invalid we'll get the default).
  753. object->fadeTo(ColorI(argv[2]), dAtoi(argv[3]), ease);
  754. return;
  755. }
  756. if (colorCount != 4)
  757. {
  758. Con::warnf("GuiSpriteCtrl::fadeTo() - Color requires 4 values between 0 and 255 (red, green, blue, alpha)");
  759. return;
  760. }
  761. object->fadeTo(ColorI(dAtof(Utility::mGetStringElement(argv[2], 0)),
  762. dAtof(Utility::mGetStringElement(argv[2], 1)),
  763. dAtof(Utility::mGetStringElement(argv[2], 2)),
  764. dAtof(Utility::mGetStringElement(argv[2], 3))),
  765. dAtoi(argv[3]), ease);
  766. }
  767. ConsoleMethodGroupEndWithDocs(GuiSpriteCtrl)