guiSpriteCtrl_ScriptBindings.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  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->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->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->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->isStaticFrameProvider() )
  133. {
  134. // No, so warn.
  135. Con::warnf("GuiSpriteCtrl::setNamedImageFrame() - Method invalid, not in static mode.");
  136. return false;
  137. }
  138. // Set the numerical frame
  139. return object->setNamedImageFrame( argv[2] );
  140. }
  141. //------------------------------------------------------------------------------
  142. /*! Gets the current named image frame.
  143. @return The current named image frame.
  144. */
  145. ConsoleMethodWithDocs(GuiSpriteCtrl, getNamedImageFrame, ConsoleString, 2, 2, ())
  146. {
  147. // Are we in static mode?
  148. if ( !object->isStaticFrameProvider() )
  149. {
  150. // No, so warn.
  151. Con::warnf("GuiSpriteCtrl::getNamedImageFrame() - Method invalid, not in static mode.");
  152. return NULL;
  153. }
  154. // Are we using a named image frame?
  155. if ( !object->isUsingNamedImageFrame() )
  156. {
  157. // No, so warn.
  158. Con::warnf("GuiSpriteCtrl::getNamedImageFrame() - Method invalid, not using a named image frame.");
  159. return NULL;
  160. }
  161. return object->getNamedImageFrame();
  162. }
  163. //------------------------------------------------------------------------------
  164. /*! Sets the animation asset Id to display.
  165. @param animationAssetId The animation asset Id to play
  166. @return No return value.
  167. */
  168. ConsoleMethodWithDocs(GuiSpriteCtrl, setAnimation, ConsoleVoid, 3, 3, (string animationAssetId))
  169. {
  170. // Set animation.
  171. object->setAnimation( argv[2] );
  172. }
  173. //------------------------------------------------------------------------------
  174. /*! Gets the current animation asset Id.
  175. @return (string ianimationAssetId) The animation being displayed.
  176. */
  177. ConsoleMethodWithDocs(GuiSpriteCtrl, getAnimation, ConsoleString, 2, 2, ())
  178. {
  179. // Are we in static mode?
  180. if ( object->isStaticFrameProvider() )
  181. {
  182. // Yes, so warn.
  183. Con::warnf("GuiSpriteCtrl::getAnimation() - Method invalid, in static mode.");
  184. return StringTable->EmptyString;
  185. }
  186. // Get animation.
  187. return object->getAnimation();
  188. }
  189. //-----------------------------------------------------------------------------
  190. /*! Pause the current animation
  191. @param enable If true, pause the animation. If false, continue animating
  192. */
  193. ConsoleMethodWithDocs(GuiSpriteCtrl, pauseAnimation, ConsoleVoid, 3, 3, (bool enable))
  194. {
  195. // Are we in static mode?
  196. if ( object->isStaticFrameProvider() )
  197. {
  198. // Yes, so warn.
  199. Con::warnf("GuiSpriteCtrl::pauseAnimation() - Method invalid, not in dynamic (animated) mode.");
  200. return;
  201. }
  202. return static_cast<ImageFrameProvider*>(object)->pauseAnimation(dAtob(argv[2]));
  203. }
  204. //-----------------------------------------------------------------------------
  205. /*! Stop the current animation
  206. @return No return value.
  207. */
  208. ConsoleMethodWithDocs(GuiSpriteCtrl, stopAnimation, ConsoleVoid, 2, 2, ())
  209. {
  210. // Are we in static mode?
  211. if ( object->isStaticFrameProvider() )
  212. {
  213. // Yes, so warn.
  214. Con::warnf("GuiSpriteCtrl::stopAnimation() - Method invalid, not in dynamic (animated) mode.");
  215. return;
  216. }
  217. object->stopAnimation();
  218. }
  219. //-----------------------------------------------------------------------------
  220. /*! Sets the current animation frame. IMPORTANT: this is not the image frame number used in the animation!
  221. @param frame Which frame of the animation to display
  222. @return No return value.
  223. */
  224. ConsoleMethodWithDocs(GuiSpriteCtrl, setAnimationFrame, ConsoleVoid, 3, 3, (int frame))
  225. {
  226. // Are we in static mode?
  227. if ( object->isStaticFrameProvider() )
  228. {
  229. // Yes, so warn.
  230. Con::warnf("GuiSpriteCtrl::setAnimationFrame() - Method invalid, not in dynamic (animated) mode.");
  231. return;
  232. }
  233. // Set Animation Frame
  234. object->setAnimationFrame( dAtoi(argv[2]) );
  235. }
  236. //-----------------------------------------------------------------------------
  237. /*! Gets current frame index used in the animation. IMPORTANT: this is not the image frame number!
  238. @return The current numerical animation frame
  239. */
  240. ConsoleMethodWithDocs(GuiSpriteCtrl, getAnimationFrame, ConsoleInt, 2, 2, ())
  241. {
  242. // Are we in static mode?
  243. if ( object->isStaticFrameProvider() )
  244. {
  245. // Yes, so warn.
  246. Con::warnf("GuiSpriteCtrl::getAnimationFrame() - Method invalid, not in dynamic (animated) mode.");
  247. return -1;
  248. }
  249. // Get Animation Frame.
  250. return object->getAnimationFrame();
  251. }
  252. //-----------------------------------------------------------------------------
  253. /*! Gets current numerical image frame used in the animation.
  254. @return The current numerical animation frame
  255. */
  256. ConsoleMethodWithDocs(GuiSpriteCtrl, getAnimationImageFrame, ConsoleInt, 2, 2, ())
  257. {
  258. // Are we in static mode?
  259. if ( object->isStaticFrameProvider() )
  260. {
  261. // Yes, so warn.
  262. Con::warnf("GuiSpriteCtrl::getAnimationImageFrame() - Method invalid, not in dynamic (animated) mode.");
  263. return -1;
  264. }
  265. // Get the current animation asset
  266. const AnimationAsset* asset = object->getCurrentAnimation();
  267. // Are we using named animation frames?
  268. if (asset->getNamedCellsMode())
  269. {
  270. // Yes, so warn.
  271. Con::warnf("GuiSpriteCtrl::getAnimationImageFrame() - Method invalid, animation is in named cells mode.");
  272. return -1;
  273. }
  274. // Get Image Frame.
  275. return object->getCurrentAnimationFrame();
  276. }
  277. //-----------------------------------------------------------------------------
  278. /*! Gets current named image frame used in the animation.
  279. @return The current named animation frame
  280. */
  281. ConsoleMethodWithDocs(GuiSpriteCtrl, getAnimationNamedImageFrame, ConsoleString, 2, 2, ())
  282. {
  283. // Are we in static mode?
  284. if ( object->isStaticFrameProvider() )
  285. {
  286. // Yes, so warn.
  287. Con::warnf("GuiSpriteCtrl::getAnimationNamedImageFrame() - Method invalid, not in dynamic (animated) mode.");
  288. return NULL;
  289. }
  290. // Get the current animation asset
  291. const AnimationAsset* asset = object->getCurrentAnimation();
  292. // Are we using named animation frames?
  293. if (!asset->getNamedCellsMode())
  294. {
  295. // No, so warn.
  296. Con::warnf("GuiSpriteCtrl::getAnimationNamedImageFrame() - Method invalid, animation not in named cells mode.");
  297. return NULL;
  298. }
  299. // Get Image Frame.
  300. return object->getCurrentNamedAnimationFrame();
  301. }
  302. //-----------------------------------------------------------------------------
  303. /*! Gets current animation time.
  304. @return (float time) The current animation time
  305. */
  306. ConsoleMethodWithDocs(GuiSpriteCtrl, getAnimationTime, ConsoleFloat, 2, 2, ())
  307. {
  308. // Are we in static mode?
  309. if ( object->isStaticFrameProvider() )
  310. {
  311. // Yes, so warn.
  312. Con::warnf("GuiSpriteCtrl::getAnimationTime() - Method invalid, not in dynamic (animated) mode.");
  313. return 0.0f;
  314. }
  315. // Get Animation Time.
  316. return object->getCurrentAnimationTime();
  317. }
  318. //-----------------------------------------------------------------------------
  319. /*! Checks animation status.
  320. @return (bool finished) Whether or not the animation is finished
  321. */
  322. ConsoleMethodWithDocs(GuiSpriteCtrl, getIsAnimationFinished, ConsoleBool, 2, 2, ())
  323. {
  324. // Are we in static mode?
  325. if ( object->isStaticFrameProvider() )
  326. {
  327. // Yes, so warn.
  328. Con::warnf("GuiSpriteCtrl::getIsAnimationFinished() - Method invalid, not in dynamic (animated) mode.");
  329. return true;
  330. }
  331. // Return Animation Finished Status.
  332. return object->isAnimationFinished();
  333. }
  334. //-----------------------------------------------------------------------------
  335. /*! Change the rate of animation.
  336. @param timeScale Value which will scale the frame animation speed. 1 by default.
  337. */
  338. ConsoleMethodWithDocs(GuiSpriteCtrl, setAnimationTimeScale, ConsoleVoid, 3, 3, (float timeScale))
  339. {
  340. // Are we in static mode?
  341. if ( object->isStaticFrameProvider() )
  342. {
  343. // Yes, so warn.
  344. Con::warnf("GuiSpriteCtrl::setAnimationTimeScale() - Method invalid, not in dynamic (animated) mode.");
  345. return;
  346. }
  347. object->setAnimationTimeScale(dAtof(argv[2]));
  348. }
  349. //-----------------------------------------------------------------------------
  350. /*! Get the animation time scale for this control.
  351. @return (float) Returns the animation time scale for this control.
  352. */
  353. ConsoleMethodWithDocs(GuiSpriteCtrl, getAnimationTimeScale, ConsoleFloat, 2, 2, ())
  354. {
  355. // Are we in static mode?
  356. if ( object->isStaticFrameProvider() )
  357. {
  358. // Yes, so warn.
  359. Con::warnf("GuiSpriteCtrl::getAnimationTimeScale() - Method invalid, not in dynamic (animated) mode.");
  360. return 1.0f;
  361. }
  362. return object->getAnimationTimeScale();
  363. }
  364. ConsoleMethodGroupEndWithDocs(GuiSpriteCtrl)