CompositeSprite_ScriptBinding.h 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192
  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) - Sets the sprite animation.\n"
  285. "@param imageAssetId The animation to set the sprite to.\n"
  286. "@return No return value." )
  287. {
  288. object->setSpriteAnimation( argv[2] );
  289. }
  290. //-----------------------------------------------------------------------------
  291. ConsoleMethod(CompositeSprite, getSpriteAnimation, const char*, 2, 2, "() - Gets the sprite animation.\n"
  292. "@return The sprite animation." )
  293. {
  294. return object->getSpriteAnimation();
  295. }
  296. //-----------------------------------------------------------------------------
  297. ConsoleMethod(CompositeSprite, clearSpriteAsset, void, 2, 2, "() - Clears any image or animation asset from the sprite.\n"
  298. "@return No return value." )
  299. {
  300. return object->clearSpriteAsset();
  301. }
  302. //-----------------------------------------------------------------------------
  303. ConsoleMethod(CompositeSprite, setSpriteVisible, void, 3, 3, "(bool visible) - Sets whether the sprite is visible or not.\n"
  304. "@param visible Whether the sprite is visible or not.\n"
  305. "@return No return value." )
  306. {
  307. // Fetch visible.
  308. const bool visible = dAtob(argv[2]);
  309. object->setSpriteVisible( visible );
  310. }
  311. //-----------------------------------------------------------------------------
  312. ConsoleMethod(CompositeSprite, getSpriteVisible, bool, 2, 2, "() - Gets whether the sprite is visible or not.\n"
  313. "@return Whether the sprite is visible or not." )
  314. {
  315. return object->getSpriteVisible();
  316. }
  317. //-----------------------------------------------------------------------------
  318. ConsoleMethod(CompositeSprite, setSpriteLocalPosition, void, 3, 4, "(float localX, float localY) - Sets the sprites local position.\n"
  319. "@param localX The local position X.\n"
  320. "@param localY The local position Y.\n"
  321. "@return No return value." )
  322. {
  323. Vector2 localPosition;
  324. // Fetch element count.
  325. const U32 elementCount = Utility::mGetStringElementCount(argv[2]);
  326. // ("x y")
  327. if ( (elementCount == 2) && (argc == 3) )
  328. {
  329. localPosition.x = dAtof(Utility::mGetStringElement(argv[2], 0));
  330. localPosition.y = dAtof(Utility::mGetStringElement(argv[2], 1));
  331. }
  332. // (x, y)
  333. else if ( elementCount == 1 && (argc > 3) )
  334. {
  335. localPosition.x = dAtof(argv[2]);
  336. localPosition.y = dAtof(argv[3]);
  337. }
  338. // Invalid
  339. else
  340. {
  341. Con::warnf("CompositeSprite::setSpriteLocalPosition() - Invalid number of parameters!");
  342. return;
  343. }
  344. object->setSpriteLocalPosition( localPosition );
  345. }
  346. //-----------------------------------------------------------------------------
  347. ConsoleMethod(CompositeSprite, getSpriteLocalPosition, const char*, 2, 2, "() - Gets the sprite local position.\n"
  348. "@return The sprite local position." )
  349. {
  350. return object->getSpriteLocalPosition().scriptThis();
  351. }
  352. //-----------------------------------------------------------------------------
  353. ConsoleMethod(CompositeSprite, setSpriteAngle, void, 3, 3, "(float localAngle) - Sets the sprites local angle.\n"
  354. "@param localAngle The sprite local angle.\n"
  355. "@return No return value." )
  356. {
  357. // Fetch angle.
  358. const F32 angle = mDegToRad( dAtof(argv[2]) );
  359. object->setSpriteAngle( angle );
  360. }
  361. //-----------------------------------------------------------------------------
  362. ConsoleMethod(CompositeSprite, getSpriteAngle, F32, 2, 2, "() - Gets the sprite local angle.\n"
  363. "@return The sprite local angle." )
  364. {
  365. return mRadToDeg( object->getSpriteAngle() );
  366. }
  367. //-----------------------------------------------------------------------------
  368. ConsoleMethod(CompositeSprite, setSpriteDepth, void, 3, 3, "(float depth) - Sets the sprites depth.\n"
  369. "@param depth The sprite depth.\n"
  370. "@return No return value." )
  371. {
  372. // Fetch depth.
  373. const F32 depth = dAtof(argv[2]);
  374. object->setSpriteDepth( depth );
  375. }
  376. //-----------------------------------------------------------------------------
  377. ConsoleMethod(CompositeSprite, getSpriteDepth, F32, 2, 2, "() - Gets the sprite depth.\n"
  378. "@return The sprite depth." )
  379. {
  380. return object->getSpriteDepth();
  381. }
  382. //-----------------------------------------------------------------------------
  383. ConsoleMethod(CompositeSprite, setSpriteSize, void, 3, 4, "(float width, [float height]) - Sets the sprite size.\n"
  384. "@param width The sprite width.\n"
  385. "@param height The sprite height\n"
  386. "@return No return value.")
  387. {
  388. Vector2 size;
  389. // Fetch element count.
  390. const U32 elementCount = Utility::mGetStringElementCount(argv[2]);
  391. // ("width height")
  392. if ( (elementCount == 2) && (argc == 3) )
  393. {
  394. size.x = dAtof(Utility::mGetStringElement(argv[2], 0));
  395. size.y = dAtof(Utility::mGetStringElement(argv[2], 1));
  396. }
  397. // (width, [height])
  398. else if (elementCount == 1)
  399. {
  400. size.x = dAtof(argv[2]);
  401. if (argc > 3)
  402. size.y = dAtof(argv[3]);
  403. else
  404. size.y = size.x;
  405. }
  406. // Invalid
  407. else
  408. {
  409. Con::warnf("CompositeSprite::setSpriteSize() - Invalid number of parameters!");
  410. return;
  411. }
  412. object->setSpriteSize( size );
  413. }
  414. //-----------------------------------------------------------------------------
  415. ConsoleMethod(CompositeSprite, getSpriteSize, const char*, 2, 2, "() - Gets the sprite size.\n"
  416. "@return (float width/float height) The sprite size.")
  417. {
  418. return object->getSpriteSize().scriptThis();
  419. }
  420. //-----------------------------------------------------------------------------
  421. ConsoleMethod(CompositeSprite, setSpriteFlipX, void, 3, 3, "(bool flipX) - Sets whether the sprite is flipped along its local X axis or not.\n"
  422. "@param flipX Whether the sprite is flipped along its local X axis or not.\n"
  423. "@return No return value." )
  424. {
  425. // Fetch flipX.
  426. const bool flipX = dAtob(argv[2]);
  427. object->setSpriteFlipX( flipX );
  428. }
  429. //-----------------------------------------------------------------------------
  430. ConsoleMethod(CompositeSprite, getSpriteFlipX, bool, 2, 2, "() - Gets whether the sprite is flipped along its local X axis or not.\n"
  431. "@return Whether the sprite is flipped along its local X axis or not." )
  432. {
  433. return object->getSpriteFlipX();
  434. }
  435. //-----------------------------------------------------------------------------
  436. ConsoleMethod(CompositeSprite, setSpriteFlipY, void, 3, 3, "(bool flipY) - Sets whether the sprite is flipped along its local Y axis or not.\n"
  437. "@param flipY Whether the sprite is flipped along its local Y axis or not.\n"
  438. "@return No return value." )
  439. {
  440. const bool flipY = dAtob(argv[2]);
  441. object->setSpriteFlipY( flipY );
  442. }
  443. //-----------------------------------------------------------------------------
  444. ConsoleMethod(CompositeSprite, getSpriteFlipY, bool, 2, 2, "() - Gets whether the sprite is flipped along its local Y axis or not.\n"
  445. "@return Whether the sprite is flipped along its local Y axis or not." )
  446. {
  447. return object->getSpriteFlipY();
  448. }
  449. //-----------------------------------------------------------------------------
  450. ConsoleMethod(CompositeSprite, setSpriteSortPoint, void, 3, 4, "(float localX, float localY) - Sets the sprites sort point.\n"
  451. "@param localX The local sort point X.\n"
  452. "@param localY The local sort point Y.\n"
  453. "@return No return value." )
  454. {
  455. Vector2 sortPoint;
  456. // Fetch element count.
  457. const U32 elementCount = Utility::mGetStringElementCount(argv[2]);
  458. // ("x y")
  459. if ( (elementCount == 2) && (argc == 3) )
  460. {
  461. sortPoint.x = dAtof(Utility::mGetStringElement(argv[2], 0));
  462. sortPoint.y = dAtof(Utility::mGetStringElement(argv[2], 1));
  463. }
  464. // (x, y)
  465. else if ( elementCount == 1 && (argc > 3) )
  466. {
  467. sortPoint.x = dAtof(argv[2]);
  468. sortPoint.y = dAtof(argv[3]);
  469. }
  470. // Invalid
  471. else
  472. {
  473. Con::warnf("CompositeSprite::setSpriteSortPoint() - Invalid number of parameters!");
  474. return;
  475. }
  476. object->setSpriteSortPoint( sortPoint );
  477. }
  478. //-----------------------------------------------------------------------------
  479. ConsoleMethod(CompositeSprite, getSpriteSortPoint, const char*, 2, 2, "() - Gets the sprite local sort point.\n"
  480. "@return The sprite local sort point." )
  481. {
  482. return object->getSpriteSortPoint().scriptThis();
  483. }
  484. //-----------------------------------------------------------------------------
  485. ConsoleMethod(CompositeSprite, setSpriteRenderGroup, void, 3, 3, "(renderGroup) Sets the name of the render group used to sort the sprite during rendering.\n"
  486. "@param renderGroup The name of the render group to use. Defaults to nothing.\n"
  487. "@return No return value.")
  488. {
  489. object->setSpriteRenderGroup( argv[2] );
  490. }
  491. //-----------------------------------------------------------------------------
  492. ConsoleMethod(CompositeSprite, getSpriteRenderGroup, const char*, 2, 2, "() Gets the name of the render group used to sort the sprite during rendering.\n"
  493. "@return The render group used to sort the object during rendering.")
  494. {
  495. return object->getSpriteRenderGroup();
  496. }
  497. //-----------------------------------------------------------------------------
  498. ConsoleMethod(CompositeSprite, setSpriteBlendMode, void, 3, 3, "(bool blendMode) - Sets whether sprite blending is on or not.\n"
  499. "@blendMode Whether sprite blending is on or not.\n"
  500. "@return No return Value.")
  501. {
  502. // Fetch blend mode.
  503. const bool blendMode = dAtob(argv[2]);
  504. object->setSpriteBlendMode( blendMode );
  505. }
  506. //-----------------------------------------------------------------------------
  507. ConsoleMethod(CompositeSprite, getSpriteBlendMode, bool, 2, 2, "() - Gets whether sprite blending is on or not.\n"
  508. "@return (bool blendMode) Whether sprite blending is on or not.")
  509. {
  510. return object->getSpriteBlendMode();
  511. }
  512. //-----------------------------------------------------------------------------
  513. ConsoleMethod(CompositeSprite, setSpriteSrcBlendFactor, void, 3, 3, "(srcBlend) - Sets the sprite source blend factor.\n"
  514. "@param srcBlend The sprite source blend factor.\n"
  515. "@return No return Value.")
  516. {
  517. // Fetch source blend factor.
  518. GLenum blendFactor = SceneObject::getSrcBlendFactorEnum(argv[2]);
  519. object->setSpriteSrcBlendFactor( blendFactor );
  520. }
  521. //-----------------------------------------------------------------------------
  522. ConsoleMethod(CompositeSprite, getSpriteSrcBlendFactor, const char*, 2, 2, "() - Gets the sprite source blend factor.\n"
  523. "@return (srcBlend) The sprite source blend factor.")
  524. {
  525. return SceneObject::getSrcBlendFactorDescription( object->getSpriteSrcBlendFactor() );
  526. }
  527. //-----------------------------------------------------------------------------
  528. ConsoleMethod(CompositeSprite, setSpriteDstBlendFactor, void, 3, 3, "(dstBlend) - Sets the sprite destination blend factor.\n"
  529. "@param dstBlend The sprite destination blend factor.\n"
  530. "@return No return Value.")
  531. {
  532. // Fetch destination blend factor.
  533. GLenum blendFactor = SceneObject::getDstBlendFactorEnum(argv[2]);
  534. object->setSpriteDstBlendFactor( blendFactor );
  535. }
  536. //-----------------------------------------------------------------------------
  537. ConsoleMethod(CompositeSprite, getSpriteDstBlendFactor, const char*, 2, 2, "() - Gets the sprite destination blend factor.\n"
  538. "@return (dstBlend) The sprite destination blend factor.")
  539. {
  540. return SceneObject::getDstBlendFactorDescription( object->getSpriteDstBlendFactor() );
  541. }
  542. //-----------------------------------------------------------------------------
  543. ConsoleMethod(CompositeSprite, setSpriteBlendColor, void, 3, 6, "(float red, float green, float blue, [float alpha = 1.0]) or ( stockColorName ) - Sets the sprite blend color."
  544. "@param red The red value.\n"
  545. "@param green The green value.\n"
  546. "@param blue The blue value.\n"
  547. "@param alpha The alpha value.\n"
  548. "@return No return Value.")
  549. {
  550. // The colors.
  551. F32 red;
  552. F32 green;
  553. F32 blue;
  554. F32 alpha = 1.0f;
  555. // Space separated.
  556. if (argc == 3 )
  557. {
  558. // Grab the element count.
  559. const U32 elementCount = Utility::mGetStringElementCount(argv[2]);
  560. // Has a single argument been specified?
  561. if ( elementCount == 1 )
  562. {
  563. // Is a sprite selected?
  564. if ( !object->isSpriteSelected() )
  565. {
  566. // No, so warn.
  567. Con::warnf("CompositeSprite::setSpriteBlendColor() - Cannot set sprite blend color as no sprite is selected." );
  568. return;
  569. }
  570. Con::setData( TypeColorF, &const_cast<ColorF&>(object->getSpriteBlendColor()), 0, 1, &(argv[2]) );
  571. return;
  572. }
  573. // ("R G B [A]")
  574. if ((elementCount == 3) || (elementCount == 4))
  575. {
  576. // Extract the color.
  577. red = dAtof(Utility::mGetStringElement(argv[2], 0));
  578. green = dAtof(Utility::mGetStringElement(argv[2], 1));
  579. blue = dAtof(Utility::mGetStringElement(argv[2], 2));
  580. // Grab the alpha if it's there.
  581. if (elementCount > 3)
  582. alpha = dAtof(Utility::mGetStringElement(argv[2], 3));
  583. }
  584. // Invalid.
  585. else
  586. {
  587. Con::warnf("SceneObject::setBlendColor() - Invalid Number of parameters!");
  588. return;
  589. }
  590. }
  591. // (R, G, B)
  592. else if (argc >= 5)
  593. {
  594. red = dAtof(argv[2]);
  595. green = dAtof(argv[3]);
  596. blue = dAtof(argv[4]);
  597. // Grab the alpha if it's there.
  598. if (argc > 5)
  599. alpha = dAtof(argv[5]);
  600. }
  601. // Invalid.
  602. else
  603. {
  604. Con::warnf("SceneObject::setBlendColor() - Invalid Number of parameters!");
  605. return;
  606. }
  607. // Set blend color.
  608. object->setSpriteBlendColor(ColorF(red, green, blue, alpha));
  609. }
  610. //-----------------------------------------------------------------------------
  611. ConsoleMethod(CompositeSprite, getSpriteBlendColor, const char*, 2, 2, "Gets the sprite blend color\n"
  612. "@return (float red / float green / float blue / float alpha) The sprite blend color.")
  613. {
  614. // Get Blend Colour.
  615. ColorF blendColor = object->getSpriteBlendColor();
  616. // Fetch the field value.
  617. return Con::getData( TypeColorF, &blendColor, 0 );
  618. }
  619. //-----------------------------------------------------------------------------
  620. ConsoleMethod(CompositeSprite, setSpriteBlendAlpha, void, 3, 3, "(float alpha) - Sets the sprite color alpha (transparency).\n"
  621. "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"
  622. "@param alpha The alpha value.\n"
  623. "@return No return Value.")
  624. {
  625. object->setSpriteBlendAlpha( dAtof(argv[2]) );
  626. }
  627. //-----------------------------------------------------------------------------
  628. ConsoleMethod(CompositeSprite, getSpriteBlendAlpha, F32, 2, 2, "() - Gets the sprite color alpha (transparency).\n"
  629. "@return (float alpha) The alpha value, a range from 0.0 to 1.0. Less than zero if alpha testing is disabled.")
  630. {
  631. return object->getSpriteBlendAlpha();
  632. }
  633. //-----------------------------------------------------------------------------
  634. ConsoleMethod(CompositeSprite, setSpriteAlphaTest, void, 3, 3, "(float alpha) - Set the sprite alpha test.\n"
  635. "@param value Numeric value of 0.0 to 1.0 to turn on alpha testing. Less than zero to disable alpha testing."
  636. "@return No return Value.")
  637. {
  638. object->setSpriteAlphaTest(dAtof(argv[2]));
  639. }
  640. //-----------------------------------------------------------------------------
  641. ConsoleMethod(CompositeSprite, getSpriteAlphaTest, F32, 2, 2, "() - Gets the sprite alpha test.\n"
  642. "@return (S32) A value of 0 to 255 if alpha testing is enabled. <0 represents disabled alpha testing.")
  643. {
  644. return object->getSpriteAlphaTest();
  645. }
  646. //-----------------------------------------------------------------------------
  647. ConsoleMethod(CompositeSprite, setSpriteDataObject, void, 3, 3, "(object) - Set the sprite data object.\n"
  648. "NOTE: This object will be persisted alongside the composite sprite.\n"
  649. "To clear the object you can pass an empty string.\n"
  650. "@return No return Value.")
  651. {
  652. object->setSpriteDataObject( Sim::findObject( argv[2] ) );
  653. }
  654. //-----------------------------------------------------------------------------
  655. ConsoleMethod(CompositeSprite, getSpriteDataObject, const char*, 2, 2, "() - Gets the sprite data object.\n"
  656. "@return The sprite data object.")
  657. {
  658. return object->getSpriteDataObject()->getIdString();
  659. }
  660. //-----------------------------------------------------------------------------
  661. ConsoleMethod(CompositeSprite, setSpriteName, void, 3, 3, "(name) - Set the sprite name.\n"
  662. "This must be unique within this composite sprite instance. To clear the name you can pass an empty string.\n"
  663. "@return No return Value.")
  664. {
  665. object->setSpriteName( argv[2] );
  666. }
  667. //-----------------------------------------------------------------------------
  668. ConsoleMethod(CompositeSprite, getSpriteName, const char*, 2, 2, "() - Gets the sprite name.\n"
  669. "@return The sprite name.")
  670. {
  671. return object->getSpriteName();
  672. }
  673. //-----------------------------------------------------------------------------
  674. ConsoleMethod(CompositeSprite, pickPoint, const char*, 3, 4, "(x / y ) Picks sprites intersecting the specified point with optional group/layer masks.\n"
  675. "@param x/y The coordinate of the point as either (\"x y\") or (x,y)\n"
  676. "@return Returns list of sprite Ids.")
  677. {
  678. // Fetch sprite batch query and clear results.
  679. SpriteBatchQuery* pSpriteBatchQuery = object->getSpriteBatchQuery( true );
  680. // Is the sprite batch query available?
  681. if ( pSpriteBatchQuery == NULL )
  682. {
  683. // No, so warn.
  684. Con::warnf( "CompositeSprite::pickPoint() - Cannot pick sprites if clipping mode is off." );
  685. // Return nothing.
  686. return NULL;
  687. }
  688. // The point.
  689. Vector2 point;
  690. // The index of the first optional parameter.
  691. U32 firstArg;
  692. // Grab the number of elements in the first parameter.
  693. U32 elementCount = Utility::mGetStringElementCount(argv[2]);
  694. // ("x y")
  695. if ((elementCount == 2) && (argc < 8))
  696. {
  697. point = Utility::mGetStringElementVector(argv[2]);
  698. firstArg = 3;
  699. }
  700. // (x, y)
  701. else if ((elementCount == 1) && (argc > 3))
  702. {
  703. point = Vector2(dAtof(argv[2]), dAtof(argv[3]));
  704. firstArg = 4;
  705. }
  706. // Invalid
  707. else
  708. {
  709. Con::warnf("CompositeSprite::pickPoint() - Invalid number of parameters!");
  710. return NULL;
  711. }
  712. // Fetch the render transform.
  713. const b2Transform& renderTransform = object->getRenderTransform();
  714. // Transform into local space.
  715. point = b2MulT( renderTransform, point );
  716. // Perform query.
  717. pSpriteBatchQuery->renderQueryPoint( point );
  718. // Fetch result count.
  719. const U32 resultCount = pSpriteBatchQuery->getQueryResultsCount();
  720. // Finish if no results.
  721. if (resultCount == 0 )
  722. return NULL;
  723. // Fetch results.
  724. typeSpriteBatchQueryResultVector& queryResults = pSpriteBatchQuery->getQueryResults();
  725. // Set Max Buffer Size.
  726. const U32 maxBufferSize = 4096;
  727. // Create Returnable Buffer.
  728. char* pBuffer = Con::getReturnBuffer(maxBufferSize);
  729. // Set Buffer Counter.
  730. U32 bufferCount = 0;
  731. // Add picked sprites.
  732. for ( U32 n = 0; n < resultCount; n++ )
  733. {
  734. // Output Object ID.
  735. bufferCount += dSprintf( pBuffer + bufferCount, maxBufferSize-bufferCount, "%d ", queryResults[n].mpSpriteBatchItem->getBatchId() );
  736. // Finish early if we run out of buffer space.
  737. if ( bufferCount >= maxBufferSize )
  738. {
  739. // Warn.
  740. Con::warnf("CompositeSprite::pickPoint() - Too many items picked to return to scripts!");
  741. break;
  742. }
  743. }
  744. // Clear sprite batch query.
  745. pSpriteBatchQuery->clearQuery();
  746. // Return buffer.
  747. return pBuffer;
  748. }
  749. //-----------------------------------------------------------------------------
  750. ConsoleMethod(CompositeSprite, pickArea, const char*, 4, 6, "(startx/y, endx/y ) Picks sprites intersecting the specified area with optional group/layer masks.\n"
  751. "@param startx/y The coordinates of the start point as either (\"x y\") or (x,y)\n"
  752. "@param endx/y The coordinates of the end point as either (\"x y\") or (x,y)\n"
  753. "@return Returns list of sprite Ids.")
  754. {
  755. // Fetch sprite batch query and clear results.
  756. SpriteBatchQuery* pSpriteBatchQuery = object->getSpriteBatchQuery( true );
  757. // Is the sprite batch query available?
  758. if ( pSpriteBatchQuery == NULL )
  759. {
  760. // No, so warn.
  761. Con::warnf( "CompositeSprite::pickArea() - Cannot pick sprites if clipping mode is off." );
  762. // Return nothing.
  763. return NULL;
  764. }
  765. // Upper left and lower right bound.
  766. Vector2 v1, v2;
  767. // The index of the first optional parameter.
  768. U32 firstArg;
  769. // Grab the number of elements in the first two parameters.
  770. U32 elementCount1 = Utility::mGetStringElementCount(argv[2]);
  771. U32 elementCount2 = 1;
  772. if (argc > 3)
  773. elementCount2 = Utility::mGetStringElementCount(argv[3]);
  774. // ("x1 y1 x2 y2")
  775. if ((elementCount1 == 4) && (argc < 9))
  776. {
  777. v1 = Utility::mGetStringElementVector(argv[2]);
  778. v2 = Utility::mGetStringElementVector(argv[2], 2);
  779. firstArg = 3;
  780. }
  781. // ("x1 y1", "x2 y2")
  782. else if ((elementCount1 == 2) && (elementCount2 == 2) && (argc > 3) && (argc < 10))
  783. {
  784. v1 = Utility::mGetStringElementVector(argv[2]);
  785. v2 = Utility::mGetStringElementVector(argv[3]);
  786. firstArg = 4;
  787. }
  788. // (x1, y1, x2, y2)
  789. else if (argc > 5)
  790. {
  791. v1 = Vector2(dAtof(argv[2]), dAtof(argv[3]));
  792. v2 = Vector2(dAtof(argv[4]), dAtof(argv[5]));
  793. firstArg = 6;
  794. }
  795. // Invalid
  796. else
  797. {
  798. Con::warnf("CompositeSprite::pickArea() - Invalid number of parameters!");
  799. return NULL;
  800. }
  801. // Fetch the render transform.
  802. const b2Transform& renderTransform = object->getRenderTransform();
  803. // Translate into local space.
  804. v1 -= renderTransform.p;
  805. v2 -= renderTransform.p;
  806. // Calculate normalized AABB.
  807. b2AABB aabb;
  808. aabb.lowerBound.x = getMin( v1.x, v2.x );
  809. aabb.lowerBound.y = getMin( v1.y, v2.y );
  810. aabb.upperBound.x = getMax( v1.x, v2.x );
  811. aabb.upperBound.y = getMax( v1.y, v2.y );
  812. // Rotate the AABB into local space.
  813. CoreMath::mRotateAABB( aabb, -renderTransform.q.GetAngle(), aabb );
  814. // Perform query.
  815. pSpriteBatchQuery->renderQueryArea( aabb );
  816. // Fetch result count.
  817. const U32 resultCount = pSpriteBatchQuery->getQueryResultsCount();
  818. // Finish if no results.
  819. if (resultCount == 0 )
  820. return NULL;
  821. // Fetch results.
  822. typeSpriteBatchQueryResultVector& queryResults = pSpriteBatchQuery->getQueryResults();
  823. // Set Max Buffer Size.
  824. const U32 maxBufferSize = 4096;
  825. // Create Returnable Buffer.
  826. char* pBuffer = Con::getReturnBuffer(maxBufferSize);
  827. // Set Buffer Counter.
  828. U32 bufferCount = 0;
  829. // Add picked objects.
  830. for ( U32 n = 0; n < resultCount; n++ )
  831. {
  832. // Output Object ID.
  833. bufferCount += dSprintf( pBuffer + bufferCount, maxBufferSize-bufferCount, "%d ", queryResults[n].mpSpriteBatchItem->getBatchId() );
  834. // Finish early if we run out of buffer space.
  835. if ( bufferCount >= maxBufferSize )
  836. {
  837. // Warn.
  838. Con::warnf("CompositeSprite::pickArea() - Too many items picked to return to scripts!");
  839. break;
  840. }
  841. }
  842. // Clear sprite batch query.
  843. pSpriteBatchQuery->clearQuery();
  844. // Return buffer.
  845. return pBuffer;
  846. }
  847. //-----------------------------------------------------------------------------
  848. ConsoleMethod(CompositeSprite, pickRay, const char*, 4, 6, "(startx/y, endx/y) Picks sprites intersecting the specified ray with optional group/layer masks.\n"
  849. "@param startx/y The coordinates of the start point as either (\"x y\") or (x,y)\n"
  850. "@param endx/y The coordinates of the end point as either (\"x y\") or (x,y)\n"
  851. "@return Returns list of sprite Ids")
  852. {
  853. // Fetch sprite batch query and clear results.
  854. SpriteBatchQuery* pSpriteBatchQuery = object->getSpriteBatchQuery( true );
  855. // Is the sprite batch query available?
  856. if ( pSpriteBatchQuery == NULL )
  857. {
  858. // No, so warn.
  859. Con::warnf( "CompositeSprite::pickRay() - Cannot pick sprites if clipping mode is off." );
  860. // Return nothing.
  861. return NULL;
  862. }
  863. // Upper left and lower right bound.
  864. Vector2 v1, v2;
  865. // The index of the first optional parameter.
  866. U32 firstArg;
  867. // Grab the number of elements in the first two parameters.
  868. U32 elementCount1 = Utility::mGetStringElementCount(argv[2]);
  869. U32 elementCount2 = 1;
  870. if (argc > 3)
  871. elementCount2 = Utility::mGetStringElementCount(argv[3]);
  872. // ("x1 y1 x2 y2")
  873. if ((elementCount1 == 4) && (argc < 9))
  874. {
  875. v1 = Utility::mGetStringElementVector(argv[2]);
  876. v2 = Utility::mGetStringElementVector(argv[2], 2);
  877. firstArg = 3;
  878. }
  879. // ("x1 y1", "x2 y2")
  880. else if ((elementCount1 == 2) && (elementCount2 == 2) && (argc > 3) && (argc < 10))
  881. {
  882. v1 = Utility::mGetStringElementVector(argv[2]);
  883. v2 = Utility::mGetStringElementVector(argv[3]);
  884. firstArg = 4;
  885. }
  886. // (x1, y1, x2, y2)
  887. else if (argc > 5)
  888. {
  889. v1 = Vector2(dAtof(argv[2]), dAtof(argv[3]));
  890. v2 = Vector2(dAtof(argv[4]), dAtof(argv[5]));
  891. firstArg = 6;
  892. }
  893. // Invalid
  894. else
  895. {
  896. Con::warnf("CompositeSprite::pickRay() - Invalid number of parameters!");
  897. return NULL;
  898. }
  899. // Fetch the render transform.
  900. const b2Transform& renderTransform = object->getRenderTransform();
  901. // Transform into local space.
  902. v1 = b2MulT( renderTransform, v1 );
  903. v2 = b2MulT( renderTransform, v2 );
  904. // Perform query.
  905. pSpriteBatchQuery->renderQueryRay( v1, v2 );
  906. // Sanity!
  907. AssertFatal( pSpriteBatchQuery->getIsRaycastQueryResult(), "Invalid non-ray-cast query result returned." );
  908. // Fetch result count.
  909. const U32 resultCount = pSpriteBatchQuery->getQueryResultsCount();
  910. // Finish if no results.
  911. if (resultCount == 0 )
  912. return NULL;
  913. // Sort ray-cast result.
  914. pSpriteBatchQuery->sortRaycastQueryResult();
  915. // Fetch results.
  916. typeSpriteBatchQueryResultVector& queryResults = pSpriteBatchQuery->getQueryResults();
  917. // Set Max Buffer Size.
  918. const U32 maxBufferSize = 4096;
  919. // Create Returnable Buffer.
  920. char* pBuffer = Con::getReturnBuffer(maxBufferSize);
  921. // Set Buffer Counter.
  922. U32 bufferCount = 0;
  923. // Add Picked Objects to List.
  924. for ( U32 n = 0; n < resultCount; n++ )
  925. {
  926. // Output Object ID.
  927. bufferCount += dSprintf( pBuffer + bufferCount, maxBufferSize-bufferCount, "%d ", queryResults[n].mpSpriteBatchItem->getBatchId() );
  928. // Finish early if we run out of buffer space.
  929. if ( bufferCount >= maxBufferSize )
  930. {
  931. // Warn.
  932. Con::warnf("CompositeSprite::pickRay() - Too many items picked to return to scripts!");
  933. break;
  934. }
  935. }
  936. // Clear sprite batch query.
  937. pSpriteBatchQuery->clearQuery();
  938. // Return buffer.
  939. return pBuffer;
  940. }