CompositeSprite_ScriptBinding.h 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854
  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. ConsoleMethod(CompositeSprite, addSprite, S32, 2, 3, "( [a] [b] [c] [d] [e] [f] ) - Adds a sprite at the specified logical position.\n"
  23. "You must specify the correct number of arguments for the selected layout mode.\n"
  24. "The created sprite will be automatically selected.\n"
  25. "@param a b c d e f Logical positions #1 & #2 and four additional and optional arguments.\n"
  26. "@return The batch Id of the added sprite or zero if not successful." )
  27. {
  28. if ( argc == 2 )
  29. return object->addSprite( SpriteBatchItem::LogicalPosition() );
  30. else
  31. return object->addSprite( SpriteBatchItem::LogicalPosition(argv[2]) );
  32. }
  33. //-----------------------------------------------------------------------------
  34. ConsoleMethod(CompositeSprite, removeSprite, bool, 2, 2, "() - Removes the selected sprite.\n"
  35. "@return Whether the sprite was removed or not." )
  36. {
  37. return object->removeSprite();
  38. }
  39. //-----------------------------------------------------------------------------
  40. ConsoleMethod(CompositeSprite, clearSprites, void, 2, 2, "() - Removes all sprites.\n"
  41. "@return No return value." )
  42. {
  43. return object->clearSprites();
  44. }
  45. //-----------------------------------------------------------------------------
  46. ConsoleMethod(CompositeSprite, getSpriteCount, S32, 2, 2, "() - Gets a count of sprites in the composite.\n"
  47. "@return The count of sprites in the composite." )
  48. {
  49. return object->getSpriteCount();
  50. }
  51. //-----------------------------------------------------------------------------
  52. ConsoleMethod(CompositeSprite, setBatchLayout, void, 3, 3, "(batchLayoutType) - Sets the batch layout type.\n"
  53. "The render sort mode is used when isolated batch mode is on.\n"
  54. "@param batchLayoutType 'none', 'rect' or 'iso' layout types are valid.\n"
  55. "@return No return value." )
  56. {
  57. // Fetch the batch layout type/
  58. CompositeSprite::BatchLayoutType batchLayoutType = CompositeSprite::getBatchLayoutTypeEnum( argv[2] );
  59. // Sanity!
  60. if ( batchLayoutType == CompositeSprite::INVALID_LAYOUT )
  61. {
  62. // Warn.
  63. Con::warnf( "CompositeSprite::setBatchLayout() - Unknown batch layout type of '%s'.", argv[2] );
  64. return;
  65. }
  66. object->setBatchLayout( batchLayoutType );
  67. }
  68. //-----------------------------------------------------------------------------
  69. ConsoleMethod(CompositeSprite, getBatchLayout, const char*, 2, 2, "() - Gets the batch layout type.\n"
  70. "@return The batch layout type." )
  71. {
  72. return CompositeSprite::getBatchLayoutTypeDescription( object->getBatchLayout() );
  73. }
  74. //-----------------------------------------------------------------------------
  75. ConsoleMethod(CompositeSprite, setBatchIsolated, void, 3, 3, "(bool batchIsolated) - Sets whether the sprites are rendered, isolated from other renderings as one batch or not.\n"
  76. "When in batch isolated mode, the sprites can be optionally sorted.\n"
  77. "@return No return value." )
  78. {
  79. // Fetch batch isolated.
  80. const bool batchIsolated = dAtob(argv[2]);
  81. object->setBatchIsolated( batchIsolated );
  82. }
  83. //-----------------------------------------------------------------------------
  84. ConsoleMethod(CompositeSprite, getBatchIsolated, bool, 2, 2, "() - Gets whether the sprites are rendered, isolated from other renderings as one batch or not.\n"
  85. "@return Whether the sprites are rendered, isolated from other renderings as one batch or not." )
  86. {
  87. return object->getBatchIsolated();
  88. }
  89. //-----------------------------------------------------------------------------
  90. ConsoleMethod(CompositeSprite, setBatchCulling, void, 3, 3, "(bool batchCulling) - Sets whether the sprites are culled.\n"
  91. "For sprites that are off-screen this is considerably faster during render at the expense of memory.\n"
  92. "For small composites with a few sprites, the overhead is probably not worth it.\n"
  93. "@return No return value." )
  94. {
  95. // Fetch batch culling..
  96. const bool batchCulling = dAtob(argv[2]);
  97. STATIC_VOID_CAST_TO(CompositeSprite, SpriteBatch, object)->setBatchCulling( batchCulling );
  98. }
  99. //-----------------------------------------------------------------------------
  100. ConsoleMethod(CompositeSprite, getBatchCulling, bool, 2, 2, "() - Gets whether the sprites are render culled or not\n"
  101. "@return Whether the sprites are rendered culled or not." )
  102. {
  103. return object->getBatchCulling();
  104. }
  105. //-----------------------------------------------------------------------------
  106. ConsoleMethod(CompositeSprite, setBatchSortMode, void, 3, 3, "(renderSortMode) - Sets the batch render sort mode.\n"
  107. "The render sort mode is used when isolated batch mode is on.\n"
  108. "@return No return value." )
  109. {
  110. // Fetch render sort mode.
  111. SceneRenderQueue::RenderSort batchSortMode = SceneRenderQueue::getRenderSortEnum( argv[2] );
  112. // Sanity!
  113. if ( batchSortMode == SceneRenderQueue::RENDER_SORT_INVALID )
  114. {
  115. // Warn.
  116. Con::warnf( "CompositeSprite::setBatchSortMode() - Unknown batch sort mode of '%s'.", argv[2] );
  117. return;
  118. }
  119. object->setBatchSortMode( batchSortMode );
  120. }
  121. //-----------------------------------------------------------------------------
  122. ConsoleMethod(CompositeSprite, getBatchSortMode, const char*, 2, 2, "() - Gets the batch render sort mode.\n"
  123. "@return The render sort mode." )
  124. {
  125. return SceneRenderQueue::getRenderSortDescription( object->getBatchSortMode() );
  126. }
  127. //-----------------------------------------------------------------------------
  128. ConsoleMethod(CompositeSprite, setDefaultSpriteStride, void, 3, 4, "(float strideX, [float strideY]]) - Sets the stride which scales the position at which sprites are created.\n"
  129. "@param strideX The default stride of the local X axis.\n"
  130. "@param strideY The default stride of the local Y axis.\n"
  131. "@return No return value.")
  132. {
  133. Vector2 stride;
  134. // Fetch element count.
  135. const U32 elementCount = Utility::mGetStringElementCount(argv[2]);
  136. // ("strideX strideY")
  137. if ( (elementCount == 2) && (argc == 3) )
  138. {
  139. stride.x = dAtof(Utility::mGetStringElement(argv[2], 0));
  140. stride.y = dAtof(Utility::mGetStringElement(argv[2], 1));
  141. }
  142. // (strideX, [strideY])
  143. else if (elementCount == 1)
  144. {
  145. stride.x = dAtof(argv[2]);
  146. if (argc > 3)
  147. stride.y = dAtof(argv[3]);
  148. else
  149. stride.y = stride.x;
  150. }
  151. // Invalid
  152. else
  153. {
  154. Con::warnf("CompositeSprite::setDefaultSpriteStride() - Invalid number of parameters!");
  155. return;
  156. }
  157. object->setDefaultSpriteStride( stride );
  158. }
  159. //-----------------------------------------------------------------------------
  160. ConsoleMethod(CompositeSprite, getDefaultSpriteStride, const char*, 2, 2, "() - Gets the stride which scales the position at which sprites are created.\n"
  161. "@return (float strideX/float strideY) The stride which scales the position at which sprites are created.")
  162. {
  163. return object->getDefaultSpriteStride().scriptThis();
  164. }
  165. //-----------------------------------------------------------------------------
  166. ConsoleMethod(CompositeSprite, setDefaultSpriteSize, void, 3, 4, "(float width, [float height]) - Sets the size at which sprites are created.\n"
  167. "@param width The default width of sprites.\n"
  168. "@param height The default height of sprites\n"
  169. "@return No return value.")
  170. {
  171. Vector2 size;
  172. // Fetch element count.
  173. const U32 elementCount = Utility::mGetStringElementCount(argv[2]);
  174. // ("width height")
  175. if ( (elementCount == 2) && (argc == 3) )
  176. {
  177. size.x = dAtof(Utility::mGetStringElement(argv[2], 0));
  178. size.y = dAtof(Utility::mGetStringElement(argv[2], 1));
  179. }
  180. // (width, [height])
  181. else if (elementCount == 1)
  182. {
  183. size.x = dAtof(argv[2]);
  184. if (argc > 3)
  185. size.y = dAtof(argv[3]);
  186. else
  187. size.y = size.x;
  188. }
  189. // Invalid
  190. else
  191. {
  192. Con::warnf("CompositeSprite::setDefaultSpriteSize() - Invalid number of parameters!");
  193. return;
  194. }
  195. object->setDefaultSpriteSize( size );
  196. }
  197. //-----------------------------------------------------------------------------
  198. ConsoleMethod(CompositeSprite, getDefaultSpriteSize, const char*, 2, 2, "() - Gets the size at which sprites are created.\n"
  199. "@return (float width/float height) The size at which sprites are created.")
  200. {
  201. return object->getDefaultSpriteSize().scriptThis();
  202. }
  203. //-----------------------------------------------------------------------------
  204. ConsoleMethod(CompositeSprite, setDefaultSpriteAngle, void, 3, 3, "(float angle) - Sets the angle at which sprites are created.\n"
  205. "@param angle The angle at which sprites are created.\n"
  206. "@return No return value.")
  207. {
  208. // Fetch angle.
  209. const F32 angle = mDegToRad( dAtof(argv[2]) );
  210. static_cast<SpriteBatch*>(object)->setDefaultSpriteAngle( angle );
  211. }
  212. //-----------------------------------------------------------------------------
  213. ConsoleMethod(CompositeSprite, getDefaultSpriteAngle, F32, 3, 3, "() - Gets the angle at which sprites are created.\n"
  214. "@return (float angle) The angle at which sprites are created.")
  215. {
  216. return mRadToDeg( static_cast<SpriteBatch*>(object)->getDefaultSpriteAngle() );
  217. }
  218. //-----------------------------------------------------------------------------
  219. ConsoleMethod(CompositeSprite, selectSprite, bool, 3, 3, "( a b [c] [d] [e] [f] ) - Selects a sprite at the specified logical position.\n"
  220. "@param a b c d e f Logical positions #1 & #2 and four additional and optional arguments.\n"
  221. "@return Whether the sprite was selected or not." )
  222. {
  223. return object->selectSprite( SpriteBatchItem::LogicalPosition(argv[2]) );
  224. }
  225. //-----------------------------------------------------------------------------
  226. ConsoleMethod(CompositeSprite, selectSpriteId, bool, 3, 3, "( int batchId ) - Selects a sprite with the specified batch Id.\n"
  227. "@param batchId The batch Id of the sprite to select.\n"
  228. "@return Whether the sprite was selected or not." )
  229. {
  230. return object->selectSpriteId( dAtoi(argv[2]) );
  231. }
  232. //-----------------------------------------------------------------------------
  233. ConsoleMethod(CompositeSprite, selectSpriteName, bool, 3, 3, "( name ) - Selects a sprite with the specified name.\n"
  234. "@param name The name of the sprite.\n"
  235. "@return Whether the sprite was selected or not." )
  236. {
  237. return object->selectSpriteName( argv[2] );
  238. }
  239. //-----------------------------------------------------------------------------
  240. ConsoleMethod(CompositeSprite, deselectSprite, void, 2, 2, "() - Deselects any selected sprite.\n"
  241. "This is not required but can be used to stop accidental changes to sprites.\n"
  242. "@return No return value." )
  243. {
  244. return object->deselectSprite();
  245. }
  246. //-----------------------------------------------------------------------------
  247. ConsoleMethod(CompositeSprite, isSpriteSelected, bool, 2, 2, "() - Checks whether a sprite is selected or not.\n"
  248. "@return Whether a sprite is selected or not." )
  249. {
  250. return object->isSpriteSelected();
  251. }
  252. //-----------------------------------------------------------------------------
  253. ConsoleMethod(CompositeSprite, setSpriteImage, void, 3, 4, "(imageAssetId, [int imageFrame]) - Sets the sprite image and optional frame.\n"
  254. "@param imageAssetId The image to set the sprite to.\n"
  255. "@param imageFrame The image frame of the imageAssetId to set the sprite to.\n"
  256. "@return No return value." )
  257. {
  258. // Fetch frame.
  259. const U32 frame = argc >=4 ? dAtoi(argv[3]) : 0;
  260. object->setSpriteImage( argv[2], frame );
  261. }
  262. //-----------------------------------------------------------------------------
  263. ConsoleMethod(CompositeSprite, getSpriteImage, const char*, 2, 2, "() - Gets the sprite image.\n"
  264. "@return The sprite image." )
  265. {
  266. return object->getSpriteImage();
  267. }
  268. //-----------------------------------------------------------------------------
  269. ConsoleMethod(CompositeSprite, setSpriteImageFrame, void, 3, 3, "(int imageFrame) - Sets the sprite image frame.\n"
  270. "@param imageFrame The image frame to set the sprite to.\n"
  271. "@return No return value." )
  272. {
  273. // Fetch frame.
  274. const U32 frame = dAtoi(argv[2]);
  275. object->setSpriteImageFrame( frame );
  276. }
  277. //-----------------------------------------------------------------------------
  278. ConsoleMethod(CompositeSprite, getSpriteImageFrame, S32, 2, 2, "() - Gets the sprite image frame.\n"
  279. "@return The sprite image frame." )
  280. {
  281. return object->getSpriteImageFrame();
  282. }
  283. //-----------------------------------------------------------------------------
  284. ConsoleMethod(CompositeSprite, setSpriteAnimation, void, 3, 4, "(animationAssetId, [bool autoRestore]) - Sets the sprite animation.\n"
  285. "@param imageAssetId The animation to set the sprite to.\n"
  286. "@param autoRestore Whether to restore any previously playing animation or not.\n"
  287. "@return No return value." )
  288. {
  289. // Fetch Auto-Restore Flag.
  290. const bool autoRestore = (argc >= 4) ? dAtob(argv[3]) : false;
  291. object->setSpriteAnimation( argv[2], autoRestore );
  292. }
  293. //-----------------------------------------------------------------------------
  294. ConsoleMethod(CompositeSprite, getSpriteAnimation, const char*, 2, 2, "() - Gets the sprite animation.\n"
  295. "@return The sprite animation." )
  296. {
  297. return object->getSpriteAnimation();
  298. }
  299. //-----------------------------------------------------------------------------
  300. ConsoleMethod(CompositeSprite, clearSpriteAsset, void, 2, 2, "() - Clears any image or animation asset from the sprite.\n"
  301. "@return No return value." )
  302. {
  303. return object->clearSpriteAsset();
  304. }
  305. //-----------------------------------------------------------------------------
  306. ConsoleMethod(CompositeSprite, setSpriteVisible, void, 3, 3, "(bool visible) - Sets whether the sprite is visible or not.\n"
  307. "@param visible Whether the sprite is visible or not.\n"
  308. "@return No return value." )
  309. {
  310. // Fetch visible.
  311. const bool visible = dAtob(argv[2]);
  312. object->setSpriteVisible( visible );
  313. }
  314. //-----------------------------------------------------------------------------
  315. ConsoleMethod(CompositeSprite, getSpriteVisible, bool, 2, 2, "() - Gets whether the sprite is visible or not.\n"
  316. "@return Whether the sprite is visible or not." )
  317. {
  318. return object->getSpriteVisible();
  319. }
  320. //-----------------------------------------------------------------------------
  321. ConsoleMethod(CompositeSprite, setSpriteLocalPosition, void, 3, 4, "(float localX, float localY) - Sets the sprites local position.\n"
  322. "@param localX The local position X.\n"
  323. "@param localY The local position Y.\n"
  324. "@return No return value." )
  325. {
  326. Vector2 localPosition;
  327. // Fetch element count.
  328. const U32 elementCount = Utility::mGetStringElementCount(argv[2]);
  329. // ("x y")
  330. if ( (elementCount == 2) && (argc == 3) )
  331. {
  332. localPosition.x = dAtof(Utility::mGetStringElement(argv[2], 0));
  333. localPosition.y = dAtof(Utility::mGetStringElement(argv[2], 1));
  334. }
  335. // (x, y)
  336. else if ( elementCount == 1 && (argc > 3) )
  337. {
  338. localPosition.x = dAtof(argv[2]);
  339. localPosition.y = dAtof(argv[3]);
  340. }
  341. // Invalid
  342. else
  343. {
  344. Con::warnf("CompositeSprite::setSpriteLocalPosition() - Invalid number of parameters!");
  345. return;
  346. }
  347. object->setSpriteLocalPosition( localPosition );
  348. }
  349. //-----------------------------------------------------------------------------
  350. ConsoleMethod(CompositeSprite, getSpriteLocalPosition, const char*, 2, 2, "() - Gets the sprite local position.\n"
  351. "@return The sprite local position." )
  352. {
  353. return object->getSpriteLocalPosition().scriptThis();
  354. }
  355. //-----------------------------------------------------------------------------
  356. ConsoleMethod(CompositeSprite, setSpriteAngle, void, 3, 3, "(float localAngle) - Sets the sprites local angle.\n"
  357. "@param localAngle The sprite local angle.\n"
  358. "@return No return value." )
  359. {
  360. // Fetch angle.
  361. const F32 angle = mDegToRad( dAtof(argv[2]) );
  362. object->setSpriteAngle( angle );
  363. }
  364. //-----------------------------------------------------------------------------
  365. ConsoleMethod(CompositeSprite, getSpriteAngle, F32, 2, 2, "() - Gets the sprite local angle.\n"
  366. "@return The sprite local angle." )
  367. {
  368. return mRadToDeg( object->getSpriteAngle() );
  369. }
  370. //-----------------------------------------------------------------------------
  371. ConsoleMethod(CompositeSprite, setSpriteDepth, void, 3, 3, "(float depth) - Sets the sprites depth.\n"
  372. "@param depth The sprite depth.\n"
  373. "@return No return value." )
  374. {
  375. // Fetch depth.
  376. const F32 depth = dAtof(argv[2]);
  377. object->setSpriteDepth( depth );
  378. }
  379. //-----------------------------------------------------------------------------
  380. ConsoleMethod(CompositeSprite, getSpriteDepth, F32, 2, 2, "() - Gets the sprite depth.\n"
  381. "@return The sprite depth." )
  382. {
  383. return object->getSpriteDepth();
  384. }
  385. //-----------------------------------------------------------------------------
  386. ConsoleMethod(CompositeSprite, setSpriteSize, void, 3, 4, "(float width, [float height]) - Sets the sprite size.\n"
  387. "@param width The sprite width.\n"
  388. "@param height The sprite height\n"
  389. "@return No return value.")
  390. {
  391. Vector2 size;
  392. // Fetch element count.
  393. const U32 elementCount = Utility::mGetStringElementCount(argv[2]);
  394. // ("width height")
  395. if ( (elementCount == 2) && (argc == 3) )
  396. {
  397. size.x = dAtof(Utility::mGetStringElement(argv[2], 0));
  398. size.y = dAtof(Utility::mGetStringElement(argv[2], 1));
  399. }
  400. // (width, [height])
  401. else if (elementCount == 1)
  402. {
  403. size.x = dAtof(argv[2]);
  404. if (argc > 3)
  405. size.y = dAtof(argv[3]);
  406. else
  407. size.y = size.x;
  408. }
  409. // Invalid
  410. else
  411. {
  412. Con::warnf("CompositeSprite::setSpriteSize() - Invalid number of parameters!");
  413. return;
  414. }
  415. object->setSpriteSize( size );
  416. }
  417. //-----------------------------------------------------------------------------
  418. ConsoleMethod(CompositeSprite, getSpriteSize, const char*, 2, 2, "() - Gets the sprite size.\n"
  419. "@return (float width/float height) The sprite size.")
  420. {
  421. return object->getSpriteSize().scriptThis();
  422. }
  423. //-----------------------------------------------------------------------------
  424. ConsoleMethod(CompositeSprite, setSpriteFlipX, void, 3, 3, "(bool flipX) - Sets whether the sprite is flipped along its local X axis or not.\n"
  425. "@param flipX Whether the sprite is flipped along its local X axis or not.\n"
  426. "@return No return value." )
  427. {
  428. // Fetch flipX.
  429. const bool flipX = dAtob(argv[2]);
  430. object->setSpriteFlipX( flipX );
  431. }
  432. //-----------------------------------------------------------------------------
  433. ConsoleMethod(CompositeSprite, getSpriteFlipX, bool, 2, 2, "() - Gets whether the sprite is flipped along its local X axis or not.\n"
  434. "@return Whether the sprite is flipped along its local X axis or not." )
  435. {
  436. return object->getSpriteFlipX();
  437. }
  438. //-----------------------------------------------------------------------------
  439. ConsoleMethod(CompositeSprite, setSpriteFlipY, void, 3, 3, "(bool flipY) - Sets whether the sprite is flipped along its local Y axis or not.\n"
  440. "@param flipY Whether the sprite is flipped along its local Y axis or not.\n"
  441. "@return No return value." )
  442. {
  443. const bool flipY = dAtob(argv[2]);
  444. object->setSpriteFlipY( flipY );
  445. }
  446. //-----------------------------------------------------------------------------
  447. ConsoleMethod(CompositeSprite, getSpriteFlipY, bool, 2, 2, "() - Gets whether the sprite is flipped along its local Y axis or not.\n"
  448. "@return Whether the sprite is flipped along its local Y axis or not." )
  449. {
  450. return object->getSpriteFlipY();
  451. }
  452. //-----------------------------------------------------------------------------
  453. ConsoleMethod(CompositeSprite, setSpriteSortPoint, void, 3, 4, "(float localX, float localY) - Sets the sprites sort point.\n"
  454. "@param localX The local sort point X.\n"
  455. "@param localY The local sort point Y.\n"
  456. "@return No return value." )
  457. {
  458. Vector2 sortPoint;
  459. // Fetch element count.
  460. const U32 elementCount = Utility::mGetStringElementCount(argv[2]);
  461. // ("x y")
  462. if ( (elementCount == 2) && (argc == 3) )
  463. {
  464. sortPoint.x = dAtof(Utility::mGetStringElement(argv[2], 0));
  465. sortPoint.y = dAtof(Utility::mGetStringElement(argv[2], 1));
  466. }
  467. // (x, y)
  468. else if ( elementCount == 1 && (argc > 3) )
  469. {
  470. sortPoint.x = dAtof(argv[2]);
  471. sortPoint.y = dAtof(argv[3]);
  472. }
  473. // Invalid
  474. else
  475. {
  476. Con::warnf("CompositeSprite::setSpriteSortPoint() - Invalid number of parameters!");
  477. return;
  478. }
  479. object->setSpriteSortPoint( sortPoint );
  480. }
  481. //-----------------------------------------------------------------------------
  482. ConsoleMethod(CompositeSprite, getSpriteSortPoint, const char*, 2, 2, "() - Gets the sprite local sort point.\n"
  483. "@return The sprite local sort point." )
  484. {
  485. return object->getSpriteSortPoint().scriptThis();
  486. }
  487. //-----------------------------------------------------------------------------
  488. ConsoleMethod(CompositeSprite, setSpriteRenderGroup, void, 3, 3, "(renderGroup) Sets the name of the render group used to sort the sprite during rendering.\n"
  489. "@param renderGroup The name of the render group to use. Defaults to nothing.\n"
  490. "@return No return value.")
  491. {
  492. object->setSpriteRenderGroup( argv[2] );
  493. }
  494. //-----------------------------------------------------------------------------
  495. ConsoleMethod(CompositeSprite, getSpriteRenderGroup, const char*, 2, 2, "() Gets the name of the render group used to sort the sprite during rendering.\n"
  496. "@return The render group used to sort the object during rendering.")
  497. {
  498. return object->getSpriteRenderGroup();
  499. }
  500. //-----------------------------------------------------------------------------
  501. ConsoleMethod(CompositeSprite, setSpriteBlendMode, void, 3, 3, "(bool blendMode) - Sets whether sprite blending is on or not.\n"
  502. "@blendMode Whether sprite blending is on or not.\n"
  503. "@return No return Value.")
  504. {
  505. // Fetch blend mode.
  506. const bool blendMode = dAtob(argv[2]);
  507. object->setSpriteBlendMode( blendMode );
  508. }
  509. //-----------------------------------------------------------------------------
  510. ConsoleMethod(CompositeSprite, getSpriteBlendMode, bool, 2, 2, "() - Gets whether sprite blending is on or not.\n"
  511. "@return (bool blendMode) Whether sprite blending is on or not.")
  512. {
  513. return object->getSpriteBlendMode();
  514. }
  515. //-----------------------------------------------------------------------------
  516. ConsoleMethod(CompositeSprite, setSpriteSrcBlendFactor, void, 3, 3, "(srcBlend) - Sets the sprite source blend factor.\n"
  517. "@param srcBlend The sprite source blend factor.\n"
  518. "@return No return Value.")
  519. {
  520. // Fetch source blend factor.
  521. GLenum blendFactor = SceneObject::getSrcBlendFactorEnum(argv[2]);
  522. object->setSpriteSrcBlendFactor( blendFactor );
  523. }
  524. //-----------------------------------------------------------------------------
  525. ConsoleMethod(CompositeSprite, getSpriteSrcBlendFactor, const char*, 2, 2, "() - Gets the sprite source blend factor.\n"
  526. "@return (srcBlend) The sprite source blend factor.")
  527. {
  528. return SceneObject::getSrcBlendFactorDescription( object->getSpriteSrcBlendFactor() );
  529. }
  530. //-----------------------------------------------------------------------------
  531. ConsoleMethod(CompositeSprite, setSpriteDstBlendFactor, void, 3, 3, "(dstBlend) - Sets the sprite destination blend factor.\n"
  532. "@param dstBlend The sprite destination blend factor.\n"
  533. "@return No return Value.")
  534. {
  535. // Fetch destination blend factor.
  536. GLenum blendFactor = SceneObject::getDstBlendFactorEnum(argv[2]);
  537. object->setSpriteDstBlendFactor( blendFactor );
  538. }
  539. //-----------------------------------------------------------------------------
  540. ConsoleMethod(CompositeSprite, getSpriteDstBlendFactor, const char*, 2, 2, "() - Gets the sprite destination blend factor.\n"
  541. "@return (dstBlend) The sprite destination blend factor.")
  542. {
  543. return SceneObject::getDstBlendFactorDescription( object->getSpriteDstBlendFactor() );
  544. }
  545. //-----------------------------------------------------------------------------
  546. ConsoleMethod(CompositeSprite, setSpriteBlendColor, void, 3, 6, "(float red, float green, float blue, [float alpha = 1.0]) or ( stockColorName ) - Sets the sprite blend color."
  547. "@param red The red value.\n"
  548. "@param green The green value.\n"
  549. "@param blue The blue value.\n"
  550. "@param alpha The alpha value.\n"
  551. "@return No return Value.")
  552. {
  553. // The colors.
  554. F32 red;
  555. F32 green;
  556. F32 blue;
  557. F32 alpha = 1.0f;
  558. // Space separated.
  559. if (argc == 3 )
  560. {
  561. // Grab the element count.
  562. const U32 elementCount = Utility::mGetStringElementCount(argv[2]);
  563. // Has a single argument been specified?
  564. if ( elementCount == 1 )
  565. {
  566. // Is a sprite selected?
  567. if ( !object->isSpriteSelected() )
  568. {
  569. // No, so warn.
  570. Con::warnf("CompositeSprite::setSpriteBlendColor() - Cannot set sprite blend color as no sprite is selected." );
  571. return;
  572. }
  573. Con::setData( TypeColorF, &const_cast<ColorF&>(object->getSpriteBlendColor()), 0, 1, &(argv[2]) );
  574. return;
  575. }
  576. // ("R G B [A]")
  577. if ((elementCount == 3) || (elementCount == 4))
  578. {
  579. // Extract the color.
  580. red = dAtof(Utility::mGetStringElement(argv[2], 0));
  581. green = dAtof(Utility::mGetStringElement(argv[2], 1));
  582. blue = dAtof(Utility::mGetStringElement(argv[2], 2));
  583. // Grab the alpha if it's there.
  584. if (elementCount > 3)
  585. alpha = dAtof(Utility::mGetStringElement(argv[2], 3));
  586. }
  587. // Invalid.
  588. else
  589. {
  590. Con::warnf("SceneObject::setBlendColor() - Invalid Number of parameters!");
  591. return;
  592. }
  593. }
  594. // (R, G, B)
  595. else if (argc >= 5)
  596. {
  597. red = dAtof(argv[2]);
  598. green = dAtof(argv[3]);
  599. blue = dAtof(argv[4]);
  600. // Grab the alpha if it's there.
  601. if (argc > 5)
  602. alpha = dAtof(argv[5]);
  603. }
  604. // Invalid.
  605. else
  606. {
  607. Con::warnf("SceneObject::setBlendColor() - Invalid Number of parameters!");
  608. return;
  609. }
  610. // Set blend color.
  611. object->setSpriteBlendColor(ColorF(red, green, blue, alpha));
  612. }
  613. //-----------------------------------------------------------------------------
  614. ConsoleMethod(CompositeSprite, getSpriteBlendColor, const char*, 2, 2, "Gets the sprite blend color\n"
  615. "@return (float red / float green / float blue / float alpha) The sprite blend color.")
  616. {
  617. // Get Blend Colour.
  618. ColorF blendColor = object->getSpriteBlendColor();
  619. // Fetch the field value.
  620. return Con::getData( TypeColorF, &blendColor, 0 );
  621. }
  622. //-----------------------------------------------------------------------------
  623. ConsoleMethod(CompositeSprite, setSpriteBlendAlpha, void, 3, 3, "(float alpha) - Sets the sprite color alpha (transparency).\n"
  624. "The alpha value specifies directly the transparency of the image. A value of 1.0 will not affect the object and a value of 0.0 will make the object completely transparent.\n"
  625. "@param alpha The alpha value.\n"
  626. "@return No return Value.")
  627. {
  628. object->setSpriteBlendAlpha( dAtof(argv[2]) );
  629. }
  630. //-----------------------------------------------------------------------------
  631. ConsoleMethod(CompositeSprite, getSpriteBlendAlpha, F32, 2, 2, "() - Gets the sprite color alpha (transparency).\n"
  632. "@return (float alpha) The alpha value, a range from 0.0 to 1.0. Less than zero if alpha testing is disabled.")
  633. {
  634. return object->getSpriteBlendAlpha();
  635. }
  636. //-----------------------------------------------------------------------------
  637. ConsoleMethod(CompositeSprite, setSpriteAlphaTest, void, 3, 3, "(float alpha) - Set the sprite alpha test.\n"
  638. "@param value Numeric value of 0.0 to 1.0 to turn on alpha testing. Less than zero to disable alpha testing."
  639. "@return No return Value.")
  640. {
  641. object->setSpriteAlphaTest(dAtof(argv[2]));
  642. }
  643. //-----------------------------------------------------------------------------
  644. ConsoleMethod(CompositeSprite, getSpriteAlphaTest, F32, 2, 2, "() - Gets the sprite alpha test.\n"
  645. "@return (S32) A value of 0 to 255 if alpha testing is enabled. <0 represents disabled alpha testing.")
  646. {
  647. return object->getSpriteAlphaTest();
  648. }
  649. //-----------------------------------------------------------------------------
  650. ConsoleMethod(CompositeSprite, setSpriteDataObject, void, 3, 3, "(object) - Set the sprite data object.\n"
  651. "NOTE: This object will be persisted alongside the composite sprite.\n"
  652. "To clear the object you can pass an empty string.\n"
  653. "@return No return Value.")
  654. {
  655. object->setSpriteDataObject( Sim::findObject( argv[2] ) );
  656. }
  657. //-----------------------------------------------------------------------------
  658. ConsoleMethod(CompositeSprite, getSpriteDataObject, const char*, 2, 2, "() - Gets the sprite data object.\n"
  659. "@return The sprite data object.")
  660. {
  661. return object->getSpriteDataObject()->getIdString();
  662. }
  663. //-----------------------------------------------------------------------------
  664. ConsoleMethod(CompositeSprite, setSpriteName, void, 3, 3, "(name) - Set the sprite name.\n"
  665. "This must be unique within this composite sprite instance. To clear the name you can pass an empty string.\n"
  666. "@return No return Value.")
  667. {
  668. object->setSpriteName( argv[2] );
  669. }
  670. //-----------------------------------------------------------------------------
  671. ConsoleMethod(CompositeSprite, getSpriteName, const char*, 2, 2, "() - Gets the sprite name.\n"
  672. "@return The sprite name.")
  673. {
  674. return object->getSpriteName();
  675. }