CompositeSprite_ScriptBinding.h 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589
  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(CompositeSprite, SceneObject)
  23. /*! Adds a sprite at the specified logical position.
  24. You must specify the correct number of arguments for the selected layout mode.
  25. The created sprite will be automatically selected.
  26. @param a b c d e f Logical positions #1 & #2 and four additional and optional arguments.
  27. @return The batch Id of the added sprite or zero if not successful.
  28. */
  29. ConsoleMethodWithDocs(CompositeSprite, addSprite, ConsoleInt, 2, 3, ( [a] [b] [c] [d] [e] [f] ))
  30. {
  31. if ( argc == 2 )
  32. return object->addSprite( SpriteBatchItem::LogicalPosition() );
  33. else
  34. return object->addSprite( SpriteBatchItem::LogicalPosition(argv[2]) );
  35. }
  36. //-----------------------------------------------------------------------------
  37. /*! Removes the selected sprite.
  38. @return Whether the sprite was removed or not.
  39. */
  40. ConsoleMethodWithDocs(CompositeSprite, removeSprite, ConsoleBool, 2, 2, ())
  41. {
  42. return object->removeSprite();
  43. }
  44. //-----------------------------------------------------------------------------
  45. /*! Removes all sprites.
  46. @return No return value.
  47. */
  48. ConsoleMethodWithDocs(CompositeSprite, clearSprites, ConsoleVoid, 2, 2, ())
  49. {
  50. return object->clearSprites();
  51. }
  52. //-----------------------------------------------------------------------------
  53. /*! Gets a count of sprites in the composite.
  54. @return The count of sprites in the composite.
  55. */
  56. ConsoleMethodWithDocs(CompositeSprite, getSpriteCount, ConsoleInt, 2, 2, ())
  57. {
  58. return object->getSpriteCount();
  59. }
  60. //-----------------------------------------------------------------------------
  61. /*! Sets the batch layout type.
  62. The render sort mode is used when isolated batch mode is on.
  63. @param batchLayoutType 'none', 'rect' or 'iso' layout types are valid.
  64. @return No return value.
  65. */
  66. ConsoleMethodWithDocs(CompositeSprite, setBatchLayout, ConsoleVoid, 3, 3, (batchLayoutType))
  67. {
  68. // Fetch the batch layout type/
  69. CompositeSprite::BatchLayoutType batchLayoutType = CompositeSprite::getBatchLayoutTypeEnum( argv[2] );
  70. // Sanity!
  71. if ( batchLayoutType == CompositeSprite::INVALID_LAYOUT )
  72. {
  73. // Warn.
  74. Con::warnf( "CompositeSprite::setBatchLayout() - Unknown batch layout type of '%s'.", argv[2] );
  75. return;
  76. }
  77. object->setBatchLayout( batchLayoutType );
  78. }
  79. //-----------------------------------------------------------------------------
  80. /*! Gets the batch layout type.
  81. @return The batch layout type.
  82. */
  83. ConsoleMethodWithDocs(CompositeSprite, getBatchLayout, ConsoleString, 2, 2, ())
  84. {
  85. return CompositeSprite::getBatchLayoutTypeDescription( object->getBatchLayout() );
  86. }
  87. //-----------------------------------------------------------------------------
  88. /*! Sets whether the sprites are rendered, isolated from other renderings as one batch or not.
  89. When in batch isolated mode, the sprites can be optionally sorted.
  90. @return No return value.
  91. */
  92. ConsoleMethodWithDocs(CompositeSprite, setBatchIsolated, ConsoleVoid, 3, 3, (bool batchIsolated))
  93. {
  94. // Fetch batch isolated.
  95. const bool batchIsolated = dAtob(argv[2]);
  96. object->setBatchIsolated( batchIsolated );
  97. }
  98. //-----------------------------------------------------------------------------
  99. /*! Gets whether the sprites are rendered, isolated from other renderings as one batch or not.
  100. @return Whether the sprites are rendered, isolated from other renderings as one batch or not.
  101. */
  102. ConsoleMethodWithDocs(CompositeSprite, getBatchIsolated, ConsoleBool, 2, 2, ())
  103. {
  104. return object->getBatchIsolated();
  105. }
  106. //-----------------------------------------------------------------------------
  107. /*! Sets whether the sprites are culled.
  108. For sprites that are off-screen this is considerably faster during render at the expense of memory.
  109. For small composites with a few sprites, the overhead is probably not worth it.
  110. @return No return value.
  111. */
  112. ConsoleMethodWithDocs(CompositeSprite, setBatchCulling, ConsoleVoid, 3, 3, (bool batchCulling))
  113. {
  114. // Fetch batch culling..
  115. const bool batchCulling = dAtob(argv[2]);
  116. STATIC_VOID_CAST_TO(CompositeSprite, SpriteBatch, object)->setBatchCulling( batchCulling );
  117. }
  118. //-----------------------------------------------------------------------------
  119. /*! Gets whether the sprites are render culled or not
  120. @return Whether the sprites are rendered culled or not.
  121. */
  122. ConsoleMethodWithDocs(CompositeSprite, getBatchCulling, ConsoleBool, 2, 2, ())
  123. {
  124. return object->getBatchCulling();
  125. }
  126. //-----------------------------------------------------------------------------
  127. /*! Sets the batch render sort mode.
  128. The render sort mode is used when isolated batch mode is on.
  129. @return No return value.
  130. */
  131. ConsoleMethodWithDocs(CompositeSprite, setBatchSortMode, ConsoleVoid, 3, 3, (renderSortMode))
  132. {
  133. // Fetch render sort mode.
  134. SceneRenderQueue::RenderSort batchSortMode = SceneRenderQueue::getRenderSortEnum( argv[2] );
  135. // Sanity!
  136. if ( batchSortMode == SceneRenderQueue::RENDER_SORT_INVALID )
  137. {
  138. // Warn.
  139. Con::warnf( "CompositeSprite::setBatchSortMode() - Unknown batch sort mode of '%s'.", argv[2] );
  140. return;
  141. }
  142. object->setBatchSortMode( batchSortMode );
  143. }
  144. //-----------------------------------------------------------------------------
  145. /*! Gets the batch render sort mode.
  146. @return The render sort mode.
  147. */
  148. ConsoleMethodWithDocs(CompositeSprite, getBatchSortMode, ConsoleString, 2, 2, ())
  149. {
  150. return SceneRenderQueue::getRenderSortDescription( object->getBatchSortMode() );
  151. }
  152. //-----------------------------------------------------------------------------
  153. /*! Sets the stride which scales the position at which sprites are created.
  154. @param strideX The default stride of the local X axis.
  155. @param strideY The default stride of the local Y axis.
  156. @return No return value.
  157. */
  158. ConsoleMethodWithDocs(CompositeSprite, setDefaultSpriteStride, ConsoleVoid, 3, 4, (float strideX, [float strideY]]))
  159. {
  160. Vector2 stride;
  161. // Fetch element count.
  162. const U32 elementCount = Utility::mGetStringElementCount(argv[2]);
  163. // ("strideX strideY")
  164. if ( (elementCount == 2) && (argc == 3) )
  165. {
  166. stride.x = dAtof(Utility::mGetStringElement(argv[2], 0));
  167. stride.y = dAtof(Utility::mGetStringElement(argv[2], 1));
  168. }
  169. // (strideX, [strideY])
  170. else if (elementCount == 1)
  171. {
  172. stride.x = dAtof(argv[2]);
  173. if (argc > 3)
  174. stride.y = dAtof(argv[3]);
  175. else
  176. stride.y = stride.x;
  177. }
  178. // Invalid
  179. else
  180. {
  181. Con::warnf("CompositeSprite::setDefaultSpriteStride() - Invalid number of parameters!");
  182. return;
  183. }
  184. object->setDefaultSpriteStride( stride );
  185. }
  186. //-----------------------------------------------------------------------------
  187. /*! Gets the stride which scales the position at which sprites are created.
  188. @return (float strideX/float strideY) The stride which scales the position at which sprites are created.
  189. */
  190. ConsoleMethodWithDocs(CompositeSprite, getDefaultSpriteStride, ConsoleString, 2, 2, ())
  191. {
  192. return object->getDefaultSpriteStride().scriptThis();
  193. }
  194. //-----------------------------------------------------------------------------
  195. /*! Sets the size at which sprites are created.
  196. @param width The default width of sprites.
  197. @param height The default height of sprites
  198. @return No return value.
  199. */
  200. ConsoleMethodWithDocs(CompositeSprite, setDefaultSpriteSize, ConsoleVoid, 3, 4, (float width, [float height]))
  201. {
  202. Vector2 size;
  203. // Fetch element count.
  204. const U32 elementCount = Utility::mGetStringElementCount(argv[2]);
  205. // ("width height")
  206. if ( (elementCount == 2) && (argc == 3) )
  207. {
  208. size.x = dAtof(Utility::mGetStringElement(argv[2], 0));
  209. size.y = dAtof(Utility::mGetStringElement(argv[2], 1));
  210. }
  211. // (width, [height])
  212. else if (elementCount == 1)
  213. {
  214. size.x = dAtof(argv[2]);
  215. if (argc > 3)
  216. size.y = dAtof(argv[3]);
  217. else
  218. size.y = size.x;
  219. }
  220. // Invalid
  221. else
  222. {
  223. Con::warnf("CompositeSprite::setDefaultSpriteSize() - Invalid number of parameters!");
  224. return;
  225. }
  226. object->setDefaultSpriteSize( size );
  227. }
  228. //-----------------------------------------------------------------------------
  229. /*! Gets the size at which sprites are created.
  230. @return (float width/float height) The size at which sprites are created.
  231. */
  232. ConsoleMethodWithDocs(CompositeSprite, getDefaultSpriteSize, ConsoleString, 2, 2, ())
  233. {
  234. return object->getDefaultSpriteSize().scriptThis();
  235. }
  236. //-----------------------------------------------------------------------------
  237. /*! Sets the angle at which sprites are created.
  238. @param angle The angle at which sprites are created.
  239. @return No return value.
  240. */
  241. ConsoleMethodWithDocs(CompositeSprite, setDefaultSpriteAngle, ConsoleVoid, 3, 3, (float angle))
  242. {
  243. // Fetch angle.
  244. const F32 angle = mDegToRad( dAtof(argv[2]) );
  245. static_cast<SpriteBatch*>(object)->setDefaultSpriteAngle( angle );
  246. }
  247. //-----------------------------------------------------------------------------
  248. /*! Gets the angle at which sprites are created.
  249. @return (float angle) The angle at which sprites are created.
  250. */
  251. ConsoleMethodWithDocs(CompositeSprite, getDefaultSpriteAngle, ConsoleFloat, 3, 3, ())
  252. {
  253. return mRadToDeg( static_cast<SpriteBatch*>(object)->getDefaultSpriteAngle() );
  254. }
  255. //-----------------------------------------------------------------------------
  256. /*! Selects a sprite at the specified logical position.
  257. @param a b c d e f Logical positions #1 & #2 and four additional and optional arguments.
  258. @return Whether the sprite was selected or not.
  259. */
  260. ConsoleMethodWithDocs(CompositeSprite, selectSprite, ConsoleBool, 3, 3, ( a b [c] [d] [e] [f] ))
  261. {
  262. return object->selectSprite( SpriteBatchItem::LogicalPosition(argv[2]) );
  263. }
  264. //-----------------------------------------------------------------------------
  265. /*! Selects a sprite with the specified batch Id.
  266. @param batchId The batch Id of the sprite to select.
  267. @return Whether the sprite was selected or not.
  268. */
  269. ConsoleMethodWithDocs(CompositeSprite, selectSpriteId, ConsoleBool, 3, 3, ( int batchId ))
  270. {
  271. return object->selectSpriteId( dAtoi(argv[2]) );
  272. }
  273. //-----------------------------------------------------------------------------
  274. /*! Selects a sprite with the specified name.
  275. @param name The name of the sprite.
  276. @return Whether the sprite was selected or not.
  277. */
  278. ConsoleMethodWithDocs(CompositeSprite, selectSpriteName, ConsoleBool, 3, 3, ( name ))
  279. {
  280. return object->selectSpriteName( argv[2] );
  281. }
  282. //-----------------------------------------------------------------------------
  283. /*! Deselects any selected sprite.
  284. This is not required but can be used to stop accidental changes to sprites.
  285. @return No return value.
  286. */
  287. ConsoleMethodWithDocs(CompositeSprite, deselectSprite, ConsoleVoid, 2, 2, ())
  288. {
  289. return object->deselectSprite();
  290. }
  291. //-----------------------------------------------------------------------------
  292. /*! Checks whether a sprite is selected or not.
  293. @return Whether a sprite is selected or not.
  294. */
  295. ConsoleMethodWithDocs(CompositeSprite, isSpriteSelected, ConsoleBool, 2, 2, ())
  296. {
  297. return object->isSpriteSelected();
  298. }
  299. //-----------------------------------------------------------------------------
  300. /*! Sets the sprite image and optional frame.
  301. @param imageAssetId The image to set the sprite to.
  302. @param imageFrame The image frame of the imageAssetId to set the sprite to.
  303. @return No return value.
  304. */
  305. ConsoleMethodWithDocs(CompositeSprite, setSpriteImage, ConsoleVoid, 3, 4, (imageAssetId, [imageFrame]))
  306. {
  307. // Was a frame specified?
  308. if (argc >= 4)
  309. {
  310. // Was it a number or a string?
  311. if (!dIsalpha(*argv[3]))
  312. {
  313. // Fetch the numerical frame and set the image
  314. const U32 frame = argc >= 4 ? dAtoi(argv[3]) : 0;
  315. object->setSpriteImage( argv[2], frame );
  316. }
  317. else
  318. {
  319. // Set the image and pass the named frame string
  320. object->setSpriteImage( argv[2], argv[3] );
  321. }
  322. }
  323. else
  324. {
  325. // Frame was not specified, use default 0 and set the image
  326. const U32 frame = 0;
  327. object->setSpriteImage( argv[2], frame );
  328. }
  329. }
  330. //-----------------------------------------------------------------------------
  331. /*! Gets the sprite image.
  332. @return The sprite image.
  333. */
  334. ConsoleMethodWithDocs(CompositeSprite, getSpriteImage, ConsoleString, 2, 2, ())
  335. {
  336. return object->getSpriteImage();
  337. }
  338. //-----------------------------------------------------------------------------
  339. /*! Sets the sprite image frame.
  340. @param imageFrame The image frame to set the sprite to.
  341. @return No return value.
  342. */
  343. ConsoleMethodWithDocs(CompositeSprite, setSpriteImageFrame, ConsoleVoid, 3, 3, (int imageFrame))
  344. {
  345. // Fetch frame.
  346. const U32 frame = dAtoi(argv[2]);
  347. object->setSpriteImageFrame( frame );
  348. }
  349. //-----------------------------------------------------------------------------
  350. /*! Gets the sprite image frame.
  351. @return The sprite image frame.
  352. */
  353. ConsoleMethodWithDocs(CompositeSprite, getSpriteImageFrame, ConsoleInt, 2, 2, ())
  354. {
  355. return object->getSpriteImageFrame();
  356. }
  357. //-----------------------------------------------------------------------------
  358. /*! Sets the sprite named image frame.
  359. @param namedFrame The named image frame to set the sprite to.
  360. @return No return value.
  361. */
  362. ConsoleMethodWithDocs(CompositeSprite, setSpriteNamedImageFrame, ConsoleVoid, 3, 3, (namedFrame))
  363. {
  364. object->setSpriteNamedImageFrame( argv[2] );
  365. }
  366. //-----------------------------------------------------------------------------
  367. /*! Gets the sprite named image frame.
  368. @return The sprite named image frame.
  369. */
  370. ConsoleMethodWithDocs(CompositeSprite, getSpriteNamedImageFrame, ConsoleString, 2, 2, ())
  371. {
  372. return object->getSpriteNamedImageFrame();
  373. }
  374. //-----------------------------------------------------------------------------
  375. /*! Sets the sprite animation.
  376. @param imageAssetId The animation to set the sprite to.
  377. @return No return value.
  378. */
  379. ConsoleMethodWithDocs(CompositeSprite, setSpriteAnimation, ConsoleVoid, 3, 4, (animationAssetId))
  380. {
  381. object->setSpriteAnimation( argv[2] );
  382. }
  383. //-----------------------------------------------------------------------------
  384. /*! Gets the sprite animation.
  385. @return The sprite animation.
  386. */
  387. ConsoleMethodWithDocs(CompositeSprite, getSpriteAnimation, ConsoleString, 2, 2, ())
  388. {
  389. return object->getSpriteAnimation();
  390. }
  391. //-----------------------------------------------------------------------------
  392. /*! Sets the current animation frame for the selected sprite. IMPORTANT: this is not the image frame number used in the animation!
  393. @param frame Which frame of the animation to display
  394. @return No return value.
  395. */
  396. ConsoleMethodWithDocs(CompositeSprite, setSpriteAnimationFrame, ConsoleVoid, 3, 3, (int animationFrame))
  397. {
  398. // Fetch frame.
  399. const U32 frame = dAtoi(argv[2]);
  400. object->setSpriteAnimationFrame(frame);
  401. }
  402. //-----------------------------------------------------------------------------
  403. /*! Gets current frame index used in the animation for the selected sprite. IMPORTANT: this is not the image frame number!
  404. @return The current numerical animation frame for the selected sprite
  405. */
  406. ConsoleMethodWithDocs(CompositeSprite, getSpriteAnimationFrame, ConsoleInt, 2, 2, ())
  407. {
  408. return object->getSpriteAnimationFrame();
  409. }
  410. //-----------------------------------------------------------------------------
  411. /*! Clears any image or animation asset from the sprite.
  412. @return No return value.
  413. */
  414. ConsoleMethodWithDocs(CompositeSprite, clearSpriteAsset, ConsoleVoid, 2, 2, ())
  415. {
  416. return object->clearSpriteAsset();
  417. }
  418. //-----------------------------------------------------------------------------
  419. /*! Sets whether the sprite is visible or not.
  420. @param visible Whether the sprite is visible or not.
  421. @return No return value.
  422. */
  423. ConsoleMethodWithDocs(CompositeSprite, setSpriteVisible, ConsoleVoid, 3, 3, (bool visible))
  424. {
  425. // Fetch visible.
  426. const bool visible = dAtob(argv[2]);
  427. object->setSpriteVisible( visible );
  428. }
  429. //-----------------------------------------------------------------------------
  430. /*! Gets whether the sprite is visible or not.
  431. @return Whether the sprite is visible or not.
  432. */
  433. ConsoleMethodWithDocs(CompositeSprite, getSpriteVisible, ConsoleBool, 2, 2, ())
  434. {
  435. return object->getSpriteVisible();
  436. }
  437. //-----------------------------------------------------------------------------
  438. /*! Sets the sprites local position.
  439. @param localX The local position X.
  440. @param localY The local position Y.
  441. @return No return value.
  442. */
  443. ConsoleMethodWithDocs(CompositeSprite, setSpriteLocalPosition, ConsoleVoid, 3, 4, (float localX, float localY))
  444. {
  445. Vector2 localPosition;
  446. // Fetch element count.
  447. const U32 elementCount = Utility::mGetStringElementCount(argv[2]);
  448. // ("x y")
  449. if ( (elementCount == 2) && (argc == 3) )
  450. {
  451. localPosition.x = dAtof(Utility::mGetStringElement(argv[2], 0));
  452. localPosition.y = dAtof(Utility::mGetStringElement(argv[2], 1));
  453. }
  454. // (x, y)
  455. else if ( elementCount == 1 && (argc > 3) )
  456. {
  457. localPosition.x = dAtof(argv[2]);
  458. localPosition.y = dAtof(argv[3]);
  459. }
  460. // Invalid
  461. else
  462. {
  463. Con::warnf("CompositeSprite::setSpriteLocalPosition() - Invalid number of parameters!");
  464. return;
  465. }
  466. object->setSpriteLocalPosition( localPosition );
  467. object->setSpatialDirty();
  468. }
  469. //-----------------------------------------------------------------------------
  470. /*! Gets the sprite local position.
  471. @return The sprite local position.
  472. */
  473. ConsoleMethodWithDocs(CompositeSprite, getSpriteLocalPosition, ConsoleString, 2, 2, ())
  474. {
  475. return object->getSpriteLocalPosition().scriptThis();
  476. }
  477. //-----------------------------------------------------------------------------
  478. /*! Gets the sprite logical position.
  479. @return The sprite logical position.
  480. */
  481. ConsoleMethodWithDocs(CompositeSprite, getSpriteLogicalPosition, ConsoleString, 2, 2, ())
  482. {
  483. return object->getSpriteLogicalPosition().getString();
  484. }
  485. //-----------------------------------------------------------------------------
  486. /*! Sets the sprites local angle.
  487. @param localAngle The sprite local angle.
  488. @return No return value.
  489. */
  490. ConsoleMethodWithDocs(CompositeSprite, setSpriteAngle, ConsoleVoid, 3, 3, (float localAngle))
  491. {
  492. // Fetch angle.
  493. const F32 angle = mDegToRad( dAtof(argv[2]) );
  494. object->setSpriteAngle( angle );
  495. }
  496. //-----------------------------------------------------------------------------
  497. /*! Gets the sprite local angle.
  498. @return The sprite local angle.
  499. */
  500. ConsoleMethodWithDocs(CompositeSprite, getSpriteAngle, ConsoleFloat, 2, 2, ())
  501. {
  502. return mRadToDeg( object->getSpriteAngle() );
  503. }
  504. //-----------------------------------------------------------------------------
  505. /*! Sets the sprites depth.
  506. @param depth The sprite depth.
  507. @return No return value.
  508. */
  509. ConsoleMethodWithDocs(CompositeSprite, setSpriteDepth, ConsoleVoid, 3, 3, (float depth))
  510. {
  511. // Fetch depth.
  512. const F32 depth = dAtof(argv[2]);
  513. object->setSpriteDepth( depth );
  514. }
  515. //-----------------------------------------------------------------------------
  516. /*! Gets the sprite depth.
  517. @return The sprite depth.
  518. */
  519. ConsoleMethodWithDocs(CompositeSprite, getSpriteDepth, ConsoleFloat, 2, 2, ())
  520. {
  521. return object->getSpriteDepth();
  522. }
  523. //-----------------------------------------------------------------------------
  524. /*! Sets the sprite size.
  525. @param width The sprite width.
  526. @param height The sprite height
  527. @return No return value.
  528. */
  529. ConsoleMethodWithDocs(CompositeSprite, setSpriteSize, ConsoleVoid, 3, 4, (float width, [float height]))
  530. {
  531. Vector2 size;
  532. // Fetch element count.
  533. const U32 elementCount = Utility::mGetStringElementCount(argv[2]);
  534. // ("width height")
  535. if ( (elementCount == 2) && (argc == 3) )
  536. {
  537. size.x = dAtof(Utility::mGetStringElement(argv[2], 0));
  538. size.y = dAtof(Utility::mGetStringElement(argv[2], 1));
  539. }
  540. // (width, [height])
  541. else if (elementCount == 1)
  542. {
  543. size.x = dAtof(argv[2]);
  544. if (argc > 3)
  545. size.y = dAtof(argv[3]);
  546. else
  547. size.y = size.x;
  548. }
  549. // Invalid
  550. else
  551. {
  552. Con::warnf("CompositeSprite::setSpriteSize() - Invalid number of parameters!");
  553. return;
  554. }
  555. object->setSpriteSize( size );
  556. }
  557. //-----------------------------------------------------------------------------
  558. /*! Gets the sprite size.
  559. @return (float width/float height) The sprite size.
  560. */
  561. ConsoleMethodWithDocs(CompositeSprite, getSpriteSize, ConsoleString, 2, 2, ())
  562. {
  563. return object->getSpriteSize().scriptThis();
  564. }
  565. //-----------------------------------------------------------------------------
  566. /*! Sets whether the sprite is flipped along its local X axis or not.
  567. @param flipX Whether the sprite is flipped along its local X axis or not.
  568. @return No return value.
  569. */
  570. ConsoleMethodWithDocs(CompositeSprite, setSpriteFlipX, ConsoleVoid, 3, 3, (bool flipX))
  571. {
  572. // Fetch flipX.
  573. const bool flipX = dAtob(argv[2]);
  574. object->setSpriteFlipX( flipX );
  575. }
  576. //-----------------------------------------------------------------------------
  577. /*! Gets whether the sprite is flipped along its local X axis or not.
  578. @return Whether the sprite is flipped along its local X axis or not.
  579. */
  580. ConsoleMethodWithDocs(CompositeSprite, getSpriteFlipX, ConsoleBool, 2, 2, ())
  581. {
  582. return object->getSpriteFlipX();
  583. }
  584. //-----------------------------------------------------------------------------
  585. /*! Sets whether the sprite is flipped along its local Y axis or not.
  586. @param flipY Whether the sprite is flipped along its local Y axis or not.
  587. @return No return value.
  588. */
  589. ConsoleMethodWithDocs(CompositeSprite, setSpriteFlipY, ConsoleVoid, 3, 3, (bool flipY))
  590. {
  591. const bool flipY = dAtob(argv[2]);
  592. object->setSpriteFlipY( flipY );
  593. }
  594. //-----------------------------------------------------------------------------
  595. /*! Gets whether the sprite is flipped along its local Y axis or not.
  596. @return Whether the sprite is flipped along its local Y axis or not.
  597. */
  598. ConsoleMethodWithDocs(CompositeSprite, getSpriteFlipY, ConsoleBool, 2, 2, ())
  599. {
  600. return object->getSpriteFlipY();
  601. }
  602. //-----------------------------------------------------------------------------
  603. /*! Sets the sprites sort point.
  604. @param localX The local sort point X.
  605. @param localY The local sort point Y.
  606. @return No return value.
  607. */
  608. ConsoleMethodWithDocs(CompositeSprite, setSpriteSortPoint, ConsoleVoid, 3, 4, (float localX, float localY))
  609. {
  610. Vector2 sortPoint;
  611. // Fetch element count.
  612. const U32 elementCount = Utility::mGetStringElementCount(argv[2]);
  613. // ("x y")
  614. if ( (elementCount == 2) && (argc == 3) )
  615. {
  616. sortPoint.x = dAtof(Utility::mGetStringElement(argv[2], 0));
  617. sortPoint.y = dAtof(Utility::mGetStringElement(argv[2], 1));
  618. }
  619. // (x, y)
  620. else if ( elementCount == 1 && (argc > 3) )
  621. {
  622. sortPoint.x = dAtof(argv[2]);
  623. sortPoint.y = dAtof(argv[3]);
  624. }
  625. // Invalid
  626. else
  627. {
  628. Con::warnf("CompositeSprite::setSpriteSortPoint() - Invalid number of parameters!");
  629. return;
  630. }
  631. object->setSpriteSortPoint( sortPoint );
  632. }
  633. //-----------------------------------------------------------------------------
  634. /*! Gets the sprite local sort point.
  635. @return The sprite local sort point.
  636. */
  637. ConsoleMethodWithDocs(CompositeSprite, getSpriteSortPoint, ConsoleString, 2, 2, ())
  638. {
  639. return object->getSpriteSortPoint().scriptThis();
  640. }
  641. //-----------------------------------------------------------------------------
  642. /*! Sets the name of the render group used to sort the sprite during rendering.
  643. @param renderGroup The name of the render group to use. Defaults to nothing.
  644. @return No return value.
  645. */
  646. ConsoleMethodWithDocs(CompositeSprite, setSpriteRenderGroup, ConsoleVoid, 3, 3, (renderGroup))
  647. {
  648. object->setSpriteRenderGroup( argv[2] );
  649. }
  650. //-----------------------------------------------------------------------------
  651. /*! Gets the name of the render group used to sort the sprite during rendering.
  652. @return The render group used to sort the object during rendering.
  653. */
  654. ConsoleMethodWithDocs(CompositeSprite, getSpriteRenderGroup, ConsoleString, 2, 2, ())
  655. {
  656. return object->getSpriteRenderGroup();
  657. }
  658. //-----------------------------------------------------------------------------
  659. /*! Sets whether sprite blending is on or not.
  660. @blendMode Whether sprite blending is on or not.
  661. @return No return Value.
  662. */
  663. ConsoleMethodWithDocs(CompositeSprite, setSpriteBlendMode, ConsoleVoid, 3, 3, (bool blendMode))
  664. {
  665. // Fetch blend mode.
  666. const bool blendMode = dAtob(argv[2]);
  667. object->setSpriteBlendMode( blendMode );
  668. }
  669. //-----------------------------------------------------------------------------
  670. /*! Gets whether sprite blending is on or not.
  671. @return (bool blendMode) Whether sprite blending is on or not.
  672. */
  673. ConsoleMethodWithDocs(CompositeSprite, getSpriteBlendMode, ConsoleBool, 2, 2, ())
  674. {
  675. return object->getSpriteBlendMode();
  676. }
  677. //-----------------------------------------------------------------------------
  678. /*! Sets the sprite source blend factor.
  679. @param srcBlend The sprite source blend factor.
  680. @return No return Value.
  681. */
  682. ConsoleMethodWithDocs(CompositeSprite, setSpriteSrcBlendFactor, ConsoleVoid, 3, 3, (srcBlend))
  683. {
  684. // Fetch source blend factor.
  685. GLenum blendFactor = SceneObject::getSrcBlendFactorEnum(argv[2]);
  686. object->setSpriteSrcBlendFactor( blendFactor );
  687. }
  688. //-----------------------------------------------------------------------------
  689. /*! Gets the sprite source blend factor.
  690. @return (srcBlend) The sprite source blend factor.
  691. */
  692. ConsoleMethodWithDocs(CompositeSprite, getSpriteSrcBlendFactor, ConsoleString, 2, 2, ())
  693. {
  694. return SceneObject::getSrcBlendFactorDescription( object->getSpriteSrcBlendFactor() );
  695. }
  696. //-----------------------------------------------------------------------------
  697. /*! Sets the sprite destination blend factor.
  698. @param dstBlend The sprite destination blend factor.
  699. @return No return Value.
  700. */
  701. ConsoleMethodWithDocs(CompositeSprite, setSpriteDstBlendFactor, ConsoleVoid, 3, 3, (dstBlend))
  702. {
  703. // Fetch destination blend factor.
  704. GLenum blendFactor = SceneObject::getDstBlendFactorEnum(argv[2]);
  705. object->setSpriteDstBlendFactor( blendFactor );
  706. }
  707. //-----------------------------------------------------------------------------
  708. /*! Gets the sprite destination blend factor.
  709. @return (dstBlend) The sprite destination blend factor.
  710. */
  711. ConsoleMethodWithDocs(CompositeSprite, getSpriteDstBlendFactor, ConsoleString, 2, 2, ())
  712. {
  713. return SceneObject::getDstBlendFactorDescription( object->getSpriteDstBlendFactor() );
  714. }
  715. //-----------------------------------------------------------------------------
  716. /*! Sets whether sprite uses complex colors or not.
  717. @complexColor Whether sprite complex color is on or not.
  718. @return No return Value.
  719. */
  720. ConsoleMethodWithDocs(CompositeSprite, setSpriteUseComplexColor, ConsoleVoid, 3, 3, (bool complexColor))
  721. {
  722. // Fetch blend mode.
  723. const bool complex = dAtob(argv[2]);
  724. object->setSpriteUseComplexColor(complex);
  725. }
  726. //-----------------------------------------------------------------------------
  727. /*! Gets whether sprite uses complex colors or not.
  728. @return (bool complexColor) Whether sprite complex color is on or not.
  729. */
  730. ConsoleMethodWithDocs(CompositeSprite, getSpriteUseComplexColor, ConsoleBool, 2, 2, ())
  731. {
  732. return object->getSpriteUseComplexColor();
  733. }
  734. //-----------------------------------------------------------------------------
  735. /*! or ( stockColorName ) - Sets the sprite blend color.
  736. @param red The red value.
  737. @param green The green value.
  738. @param blue The blue value.
  739. @param alpha The alpha value.
  740. @return No return Value.
  741. */
  742. ConsoleMethodWithDocs(CompositeSprite, setSpriteBlendColor, ConsoleVoid, 3, 6, (float red, float green, float blue, [float alpha = 1.0]))
  743. {
  744. // The colors.
  745. F32 red;
  746. F32 green;
  747. F32 blue;
  748. F32 alpha = 1.0f;
  749. // Space separated.
  750. if (argc == 3 )
  751. {
  752. // Grab the element count.
  753. const U32 elementCount = Utility::mGetStringElementCount(argv[2]);
  754. // Has a single argument been specified?
  755. if ( elementCount == 1 )
  756. {
  757. // Is a sprite selected?
  758. if ( !object->isSpriteSelected() )
  759. {
  760. // No, so warn.
  761. Con::warnf("CompositeSprite::setSpriteBlendColor() - Cannot set sprite blend color as no sprite is selected." );
  762. return;
  763. }
  764. Con::setData( TypeColorF, &const_cast<ColorF&>(object->getSpriteBlendColor()), 0, 1, &(argv[2]) );
  765. return;
  766. }
  767. // ("R G B [A]")
  768. if ((elementCount == 3) || (elementCount == 4))
  769. {
  770. // Extract the color.
  771. red = dAtof(Utility::mGetStringElement(argv[2], 0));
  772. green = dAtof(Utility::mGetStringElement(argv[2], 1));
  773. blue = dAtof(Utility::mGetStringElement(argv[2], 2));
  774. // Grab the alpha if it's there.
  775. if (elementCount > 3)
  776. alpha = dAtof(Utility::mGetStringElement(argv[2], 3));
  777. }
  778. // Invalid.
  779. else
  780. {
  781. Con::warnf("SceneObject::setBlendColor() - Invalid Number of parameters!");
  782. return;
  783. }
  784. }
  785. // (R, G, B)
  786. else if (argc >= 5)
  787. {
  788. red = dAtof(argv[2]);
  789. green = dAtof(argv[3]);
  790. blue = dAtof(argv[4]);
  791. // Grab the alpha if it's there.
  792. if (argc > 5)
  793. alpha = dAtof(argv[5]);
  794. }
  795. // Invalid.
  796. else
  797. {
  798. Con::warnf("SceneObject::setBlendColor() - Invalid Number of parameters!");
  799. return;
  800. }
  801. // Set blend color.
  802. object->setSpriteBlendColor(ColorF(red, green, blue, alpha));
  803. }
  804. //-----------------------------------------------------------------------------
  805. /*! Gets the sprite blend color
  806. @param allowColorNames Whether to allow stock color names to be returned or not. Optional: Defaults to false.
  807. @return (float red / float green / float blue / float alpha) The sprite blend color.
  808. */
  809. ConsoleMethodWithDocs(CompositeSprite, getSpriteBlendColor, ConsoleString, 2, 3, (allowColorNames))
  810. {
  811. // Get Blend color.
  812. ColorF blendColor = object->getSpriteBlendColor();
  813. // Fetch allow color names flag.
  814. const bool allowColorNames = (argc > 2) ? dAtob(argv[2] ) : false;
  815. // Are color names allowed?
  816. if ( allowColorNames )
  817. {
  818. // Yes, so fetch the field value.
  819. return Con::getData( TypeColorF, &blendColor, 0 );
  820. }
  821. // No, so fetch the raw color values.
  822. return blendColor.scriptThis();
  823. }
  824. //-----------------------------------------------------------------------------
  825. /*! Sets the sprite complex color.
  826. @param topLeft The topLeft color space separated.
  827. @param topLeft The topRight color space separated.
  828. @param topLeft The bottomRight color space separated.
  829. @param topLeft The bottomLeft color space separated.
  830. @return No return Value.
  831. */
  832. ConsoleMethodWithDocs(CompositeSprite, setSpriteComplexColor, ConsoleVoid, 6, 6, (topLeft, topRight, bottomRight, bottomLeft))
  833. {
  834. // The corners.
  835. ColorF corner0;
  836. ColorF corner1;
  837. ColorF corner2;
  838. ColorF corner3;
  839. // Space separated.
  840. if (argc == 6)
  841. {
  842. // Grab the element count.
  843. const U32 elementCount0 = Utility::mGetStringElementCount(argv[2]);
  844. if (elementCount0 == 3)
  845. {
  846. corner0 = ColorF(dAtof(Utility::mGetStringElement(argv[2], 0)), dAtof(Utility::mGetStringElement(argv[2], 1)), dAtof(Utility::mGetStringElement(argv[2], 2)));
  847. }
  848. else if (elementCount0 == 4)
  849. {
  850. corner0 = ColorF(dAtof(Utility::mGetStringElement(argv[2], 0)), dAtof(Utility::mGetStringElement(argv[2], 1)), dAtof(Utility::mGetStringElement(argv[2], 2)), dAtof(Utility::mGetStringElement(argv[2], 3)));
  851. }
  852. else
  853. {
  854. Con::warnf("CompositeSprite::setSpriteComplexColor() - Top Left Corner has Invalid Number of arguments!");
  855. return;
  856. }
  857. // Grab the element count.
  858. const U32 elementCount1 = Utility::mGetStringElementCount(argv[3]);
  859. if (elementCount1 == 3)
  860. {
  861. corner1 = ColorF(dAtof(Utility::mGetStringElement(argv[3], 0)), dAtof(Utility::mGetStringElement(argv[3], 1)), dAtof(Utility::mGetStringElement(argv[3], 2)));
  862. }
  863. else if (elementCount1 == 4)
  864. {
  865. corner1 = ColorF(dAtof(Utility::mGetStringElement(argv[3], 0)), dAtof(Utility::mGetStringElement(argv[3], 1)), dAtof(Utility::mGetStringElement(argv[3], 2)), dAtof(Utility::mGetStringElement(argv[3], 3)));
  866. }
  867. else
  868. {
  869. Con::warnf("CompositeSprite::setSpriteComplexColor() - Top Right Corner has Invalid Number of arguments!");
  870. return;
  871. }
  872. // Grab the element count.
  873. const U32 elementCount2 = Utility::mGetStringElementCount(argv[4]);
  874. if (elementCount2 == 3)
  875. {
  876. corner2 = ColorF(dAtof(Utility::mGetStringElement(argv[4], 0)), dAtof(Utility::mGetStringElement(argv[4], 1)), dAtof(Utility::mGetStringElement(argv[4], 2)));
  877. }
  878. else if (elementCount2 == 4)
  879. {
  880. corner2 = ColorF(dAtof(Utility::mGetStringElement(argv[4], 0)), dAtof(Utility::mGetStringElement(argv[4], 1)), dAtof(Utility::mGetStringElement(argv[4], 2)), dAtof(Utility::mGetStringElement(argv[4], 3)));
  881. }
  882. else
  883. {
  884. Con::warnf("CompositeSprite::setSpriteComplexColor() - Bottom Right Corner has Invalid Number of arguments!");
  885. return;
  886. }
  887. // Grab the element count.
  888. const U32 elementCount3 = Utility::mGetStringElementCount(argv[5]);
  889. if (elementCount3 == 3)
  890. {
  891. corner3 = ColorF(dAtof(Utility::mGetStringElement(argv[5], 0)), dAtof(Utility::mGetStringElement(argv[5], 1)), dAtof(Utility::mGetStringElement(argv[5], 2)));
  892. }
  893. else if (elementCount3 == 4)
  894. {
  895. corner3 = ColorF(dAtof(Utility::mGetStringElement(argv[5], 0)), dAtof(Utility::mGetStringElement(argv[5], 1)), dAtof(Utility::mGetStringElement(argv[5], 2)), dAtof(Utility::mGetStringElement(argv[5], 3)));
  896. }
  897. else
  898. {
  899. Con::warnf("CompositeSprite::setSpriteComplexColor() - Bottom Left Corner has Invalid Number of arguments!");
  900. return;
  901. }
  902. // Set blend color.
  903. object->setSpriteComplexColor(corner0, corner1, corner2, corner3);
  904. }
  905. // Invalid.
  906. else
  907. {
  908. Con::warnf("CompositeSprite::setSpriteComplexColor() - Invalid Number of parameters!");
  909. return;
  910. }
  911. }
  912. //-----------------------------------------------------------------------------
  913. /*! Gets the sprite complex color
  914. @param cornerID The cornerID whose color will be returned (1 - 4).
  915. @return (float red / float green / float blue / float alpha) The sprite corner blend color.
  916. */
  917. ConsoleMethodWithDocs(CompositeSprite, getSpriteComplexColor, ConsoleString, 3, 3, (cornerID))
  918. {
  919. S8 cornerID = dAtoi(argv[2]);
  920. // Get Blend color.
  921. ColorF blendColor = object->getSpriteComplexColor(cornerID);
  922. // No, so fetch the raw color values.
  923. return blendColor.scriptThis();
  924. }
  925. //-----------------------------------------------------------------------------
  926. /*! Sets the sprite color alpha (transparency).
  927. 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.
  928. @param alpha The alpha value.
  929. @return No return Value.
  930. */
  931. ConsoleMethodWithDocs(CompositeSprite, setSpriteBlendAlpha, ConsoleVoid, 3, 3, (float alpha))
  932. {
  933. object->setSpriteBlendAlpha( dAtof(argv[2]) );
  934. }
  935. //-----------------------------------------------------------------------------
  936. /*! Gets the sprite color alpha (transparency).
  937. @return (float alpha) The alpha value, a range from 0.0 to 1.0. Less than zero if alpha testing is disabled.
  938. */
  939. ConsoleMethodWithDocs(CompositeSprite, getSpriteBlendAlpha, ConsoleFloat, 2, 2, ())
  940. {
  941. return object->getSpriteBlendAlpha();
  942. }
  943. //-----------------------------------------------------------------------------
  944. /*! Set the sprite alpha test.
  945. @param value Numeric value of 0.0 to 1.0 to turn on alpha testing. Less than zero to disable alpha testing.
  946. @return No return Value.
  947. */
  948. ConsoleMethodWithDocs(CompositeSprite, setSpriteAlphaTest, ConsoleVoid, 3, 3, (float alpha))
  949. {
  950. object->setSpriteAlphaTest(dAtof(argv[2]));
  951. }
  952. //-----------------------------------------------------------------------------
  953. /*! Gets the sprite alpha test.
  954. @return (S32) A value of 0 to 255 if alpha testing is enabled. <0 represents disabled alpha testing.
  955. */
  956. ConsoleMethodWithDocs(CompositeSprite, getSpriteAlphaTest, ConsoleFloat, 2, 2, ())
  957. {
  958. return object->getSpriteAlphaTest();
  959. }
  960. //-----------------------------------------------------------------------------
  961. /*! Set the sprite data object.
  962. NOTE: This object will be persisted alongside the composite sprite.
  963. To clear the object you can pass an empty string.
  964. @return No return Value.
  965. */
  966. ConsoleMethodWithDocs(CompositeSprite, setSpriteDataObject, ConsoleVoid, 3, 3, (object))
  967. {
  968. object->setSpriteDataObject( Sim::findObject( argv[2] ) );
  969. }
  970. //-----------------------------------------------------------------------------
  971. /*! Gets the sprite data object.
  972. @return The sprite data object.
  973. */
  974. ConsoleMethodWithDocs(CompositeSprite, getSpriteDataObject, ConsoleString, 2, 2, ())
  975. {
  976. return object->getSpriteDataObject()->getIdString();
  977. }
  978. //-----------------------------------------------------------------------------
  979. /*! Set the sprite user data field.
  980. @param data A space separated string containing the data you wish to store.
  981. @return No return Value.
  982. */
  983. ConsoleMethodWithDocs(CompositeSprite, setSpriteUserData, ConsoleVoid, 3, 3, (data))
  984. {
  985. StringTableEntry userData = StringTable->insert(argv[2]);
  986. object->setUserData( (void*)userData );
  987. }
  988. //-----------------------------------------------------------------------------
  989. /*! Gets the sprite user data.
  990. @return The sprite user data.
  991. */
  992. ConsoleMethodWithDocs(CompositeSprite, getSpriteUserData, ConsoleString, 2, 2, ())
  993. {
  994. const char* userData = (const char*) object->getUserData();
  995. return userData;
  996. }
  997. //-----------------------------------------------------------------------------
  998. /*! Set the sprite name.
  999. This must be unique within this composite sprite instance. To clear the name you can pass an empty string.
  1000. @return No return Value.
  1001. */
  1002. ConsoleMethodWithDocs(CompositeSprite, setSpriteName, ConsoleVoid, 3, 3, (name))
  1003. {
  1004. object->setSpriteName( argv[2] );
  1005. }
  1006. //-----------------------------------------------------------------------------
  1007. /*! Gets the sprite name.
  1008. @return The sprite name.
  1009. */
  1010. ConsoleMethodWithDocs(CompositeSprite, getSpriteName, ConsoleString, 2, 2, ())
  1011. {
  1012. return object->getSpriteName();
  1013. }
  1014. //-----------------------------------------------------------------------------
  1015. /*! Gets the SpriteBatchId of the currently selected sprite.
  1016. @returns The SpriteBatchId
  1017. */
  1018. ConsoleMethodWithDocs(CompositeSprite, getSpriteId, ConsoleInt, 2, 2, ())
  1019. {
  1020. return object->getSpriteId();
  1021. }
  1022. //-----------------------------------------------------------------------------
  1023. /*! Picks sprites intersecting the specified point with optional group/layer masks.
  1024. @param x/y The coordinate of the point as either (\x y\ or (x,y)
  1025. @return Returns list of sprite Ids.
  1026. */
  1027. ConsoleMethodWithDocs(CompositeSprite, pickPoint, ConsoleString, 3, 4, (x / y ))
  1028. {
  1029. // Fetch sprite batch query and clear results.
  1030. SpriteBatchQuery* pSpriteBatchQuery = object->getSpriteBatchQuery( true );
  1031. // Is the sprite batch query available?
  1032. if ( pSpriteBatchQuery == NULL )
  1033. {
  1034. // No, so warn.
  1035. Con::warnf( "CompositeSprite::pickPoint() - Cannot pick sprites if clipping mode is off." );
  1036. // Return nothing.
  1037. return NULL;
  1038. }
  1039. // The point.
  1040. Vector2 point;
  1041. // The index of the first optional parameter.
  1042. U32 firstArg;
  1043. // Grab the number of elements in the first parameter.
  1044. U32 elementCount = Utility::mGetStringElementCount(argv[2]);
  1045. // ("x y")
  1046. if ((elementCount == 2) && (argc < 8))
  1047. {
  1048. point = Utility::mGetStringElementVector(argv[2]);
  1049. firstArg = 3;
  1050. }
  1051. // (x, y)
  1052. else if ((elementCount == 1) && (argc > 3))
  1053. {
  1054. point = Vector2(dAtof(argv[2]), dAtof(argv[3]));
  1055. firstArg = 4;
  1056. }
  1057. // Invalid
  1058. else
  1059. {
  1060. Con::warnf("CompositeSprite::pickPoint() - Invalid number of parameters!");
  1061. return NULL;
  1062. }
  1063. // Fetch the render transform.
  1064. const b2Transform& renderTransform = object->getRenderTransform();
  1065. // Transform into local space.
  1066. point = b2MulT( renderTransform, point );
  1067. // Perform query.
  1068. pSpriteBatchQuery->queryPoint( point, true );
  1069. // Fetch result count.
  1070. const U32 resultCount = pSpriteBatchQuery->getQueryResultsCount();
  1071. // Finish if no results.
  1072. if (resultCount == 0 )
  1073. return NULL;
  1074. // Fetch results.
  1075. typeSpriteBatchQueryResultVector& queryResults = pSpriteBatchQuery->getQueryResults();
  1076. // Set Max Buffer Size.
  1077. const U32 maxBufferSize = 4096;
  1078. // Create Returnable Buffer.
  1079. char* pBuffer = Con::getReturnBuffer(maxBufferSize);
  1080. // Set Buffer Counter.
  1081. U32 bufferCount = 0;
  1082. // Add picked sprites.
  1083. for ( U32 n = 0; n < resultCount; n++ )
  1084. {
  1085. // Output Object ID.
  1086. bufferCount += dSprintf( pBuffer + bufferCount, maxBufferSize-bufferCount, "%d ", queryResults[n].mpSpriteBatchItem->getBatchId() );
  1087. // Finish early if we run out of buffer space.
  1088. if ( bufferCount >= maxBufferSize )
  1089. {
  1090. // Warn.
  1091. Con::warnf("CompositeSprite::pickPoint() - Too many items picked to return to scripts!");
  1092. break;
  1093. }
  1094. }
  1095. // Clear sprite batch query.
  1096. pSpriteBatchQuery->clearQuery();
  1097. // Return buffer.
  1098. return pBuffer;
  1099. }
  1100. //-----------------------------------------------------------------------------
  1101. /*! Picks sprites intersecting the specified area with optional group/layer masks.
  1102. @param startx/y The coordinates of the start point as either (\x y\ or (x,y)
  1103. @param endx/y The coordinates of the end point as either (\x y\ or (x,y)
  1104. @return Returns list of sprite Ids.
  1105. */
  1106. ConsoleMethodWithDocs(CompositeSprite, pickArea, ConsoleString, 4, 6, (startx/y, endx/y ))
  1107. {
  1108. // Fetch sprite batch query and clear results.
  1109. SpriteBatchQuery* pSpriteBatchQuery = object->getSpriteBatchQuery( true );
  1110. // Is the sprite batch query available?
  1111. if ( pSpriteBatchQuery == NULL )
  1112. {
  1113. // No, so warn.
  1114. Con::warnf( "CompositeSprite::pickArea() - Cannot pick sprites if clipping mode is off." );
  1115. // Return nothing.
  1116. return NULL;
  1117. }
  1118. // Upper left and lower right bound.
  1119. Vector2 v1, v2;
  1120. // The index of the first optional parameter.
  1121. U32 firstArg;
  1122. // Grab the number of elements in the first two parameters.
  1123. U32 elementCount1 = Utility::mGetStringElementCount(argv[2]);
  1124. U32 elementCount2 = 1;
  1125. if (argc > 3)
  1126. elementCount2 = Utility::mGetStringElementCount(argv[3]);
  1127. // ("x1 y1 x2 y2")
  1128. if ((elementCount1 == 4) && (argc < 9))
  1129. {
  1130. v1 = Utility::mGetStringElementVector(argv[2]);
  1131. v2 = Utility::mGetStringElementVector(argv[2], 2);
  1132. firstArg = 3;
  1133. }
  1134. // ("x1 y1", "x2 y2")
  1135. else if ((elementCount1 == 2) && (elementCount2 == 2) && (argc > 3) && (argc < 10))
  1136. {
  1137. v1 = Utility::mGetStringElementVector(argv[2]);
  1138. v2 = Utility::mGetStringElementVector(argv[3]);
  1139. firstArg = 4;
  1140. }
  1141. // (x1, y1, x2, y2)
  1142. else if (argc > 5)
  1143. {
  1144. v1 = Vector2(dAtof(argv[2]), dAtof(argv[3]));
  1145. v2 = Vector2(dAtof(argv[4]), dAtof(argv[5]));
  1146. firstArg = 6;
  1147. }
  1148. // Invalid
  1149. else
  1150. {
  1151. Con::warnf("CompositeSprite::pickArea() - Invalid number of parameters!");
  1152. return NULL;
  1153. }
  1154. // Calculate normalized AABB.
  1155. b2AABB aabb;
  1156. aabb.lowerBound.x = getMin( v1.x, v2.x );
  1157. aabb.lowerBound.y = getMin( v1.y, v2.y );
  1158. aabb.upperBound.x = getMax( v1.x, v2.x );
  1159. aabb.upperBound.y = getMax( v1.y, v2.y );
  1160. // Calculate local OOBB.
  1161. b2Vec2 localOOBB[4];
  1162. CoreMath::mAABBtoOOBB( aabb, localOOBB );
  1163. CoreMath::mCalculateInverseOOBB( localOOBB, object->getRenderTransform(), localOOBB );
  1164. // Calculate local AABB.
  1165. b2AABB localAABB;
  1166. CoreMath::mOOBBtoAABB( localOOBB, localAABB );
  1167. // Convert OOBB to a PolygonShape
  1168. b2PolygonShape oobb_polygon;
  1169. oobb_polygon.Set(localOOBB, 4);
  1170. // Perform query.
  1171. pSpriteBatchQuery->queryOOBB( localAABB, oobb_polygon, true );
  1172. // Fetch result count.
  1173. const U32 resultCount = pSpriteBatchQuery->getQueryResultsCount();
  1174. // Finish if no results.
  1175. if (resultCount == 0 )
  1176. return NULL;
  1177. // Fetch results.
  1178. typeSpriteBatchQueryResultVector& queryResults = pSpriteBatchQuery->getQueryResults();
  1179. // Set Max Buffer Size.
  1180. const U32 maxBufferSize = 4096;
  1181. // Create Returnable Buffer.
  1182. char* pBuffer = Con::getReturnBuffer(maxBufferSize);
  1183. // Set Buffer Counter.
  1184. U32 bufferCount = 0;
  1185. // Add picked objects.
  1186. for ( U32 n = 0; n < resultCount; n++ )
  1187. {
  1188. // Output Object ID.
  1189. bufferCount += dSprintf( pBuffer + bufferCount, maxBufferSize-bufferCount, "%d ", queryResults[n].mpSpriteBatchItem->getBatchId() );
  1190. // Finish early if we run out of buffer space.
  1191. if ( bufferCount >= maxBufferSize )
  1192. {
  1193. // Warn.
  1194. Con::warnf("CompositeSprite::pickArea() - Too many items picked to return to scripts!");
  1195. break;
  1196. }
  1197. }
  1198. // Clear sprite batch query.
  1199. pSpriteBatchQuery->clearQuery();
  1200. // Return buffer.
  1201. return pBuffer;
  1202. }
  1203. //-----------------------------------------------------------------------------
  1204. /*! Picks sprites intersecting the specified ray with optional group/layer masks.
  1205. @param startx/y The coordinates of the start point as either (\x y\ or (x,y)
  1206. @param endx/y The coordinates of the end point as either (\x y\ or (x,y)
  1207. @return Returns list of sprite Ids
  1208. */
  1209. ConsoleMethodWithDocs(CompositeSprite, pickRay, ConsoleString, 4, 6, (startx/y, endx/y))
  1210. {
  1211. // Fetch sprite batch query and clear results.
  1212. SpriteBatchQuery* pSpriteBatchQuery = object->getSpriteBatchQuery( true );
  1213. // Is the sprite batch query available?
  1214. if ( pSpriteBatchQuery == NULL )
  1215. {
  1216. // No, so warn.
  1217. Con::warnf( "CompositeSprite::pickRay() - Cannot pick sprites if clipping mode is off." );
  1218. // Return nothing.
  1219. return NULL;
  1220. }
  1221. // Upper left and lower right bound.
  1222. Vector2 v1, v2;
  1223. // The index of the first optional parameter.
  1224. U32 firstArg;
  1225. // Grab the number of elements in the first two parameters.
  1226. U32 elementCount1 = Utility::mGetStringElementCount(argv[2]);
  1227. U32 elementCount2 = 1;
  1228. if (argc > 3)
  1229. elementCount2 = Utility::mGetStringElementCount(argv[3]);
  1230. // ("x1 y1 x2 y2")
  1231. if ((elementCount1 == 4) && (argc < 9))
  1232. {
  1233. v1 = Utility::mGetStringElementVector(argv[2]);
  1234. v2 = Utility::mGetStringElementVector(argv[2], 2);
  1235. firstArg = 3;
  1236. }
  1237. // ("x1 y1", "x2 y2")
  1238. else if ((elementCount1 == 2) && (elementCount2 == 2) && (argc > 3) && (argc < 10))
  1239. {
  1240. v1 = Utility::mGetStringElementVector(argv[2]);
  1241. v2 = Utility::mGetStringElementVector(argv[3]);
  1242. firstArg = 4;
  1243. }
  1244. // (x1, y1, x2, y2)
  1245. else if (argc > 5)
  1246. {
  1247. v1 = Vector2(dAtof(argv[2]), dAtof(argv[3]));
  1248. v2 = Vector2(dAtof(argv[4]), dAtof(argv[5]));
  1249. firstArg = 6;
  1250. }
  1251. // Invalid
  1252. else
  1253. {
  1254. Con::warnf("CompositeSprite::pickRay() - Invalid number of parameters!");
  1255. return NULL;
  1256. }
  1257. // Fetch the render transform.
  1258. const b2Transform& renderTransform = object->getRenderTransform();
  1259. // Transform into local space.
  1260. v1 = b2MulT( renderTransform, v1 );
  1261. v2 = b2MulT( renderTransform, v2 );
  1262. // Perform query.
  1263. pSpriteBatchQuery->queryRay( v1, v2, true );
  1264. // Sanity!
  1265. AssertFatal( pSpriteBatchQuery->getIsRaycastQueryResult(), "Invalid non-ray-cast query result returned." );
  1266. // Fetch result count.
  1267. const U32 resultCount = pSpriteBatchQuery->getQueryResultsCount();
  1268. // Finish if no results.
  1269. if (resultCount == 0 )
  1270. return NULL;
  1271. // Sort ray-cast result.
  1272. pSpriteBatchQuery->sortRaycastQueryResult();
  1273. // Fetch results.
  1274. typeSpriteBatchQueryResultVector& queryResults = pSpriteBatchQuery->getQueryResults();
  1275. // Set Max Buffer Size.
  1276. const U32 maxBufferSize = 4096;
  1277. // Create Returnable Buffer.
  1278. char* pBuffer = Con::getReturnBuffer(maxBufferSize);
  1279. // Set Buffer Counter.
  1280. U32 bufferCount = 0;
  1281. // Add Picked Objects to List.
  1282. for ( U32 n = 0; n < resultCount; n++ )
  1283. {
  1284. // Output Object ID.
  1285. bufferCount += dSprintf( pBuffer + bufferCount, maxBufferSize-bufferCount, "%d ", queryResults[n].mpSpriteBatchItem->getBatchId() );
  1286. // Finish early if we run out of buffer space.
  1287. if ( bufferCount >= maxBufferSize )
  1288. {
  1289. // Warn.
  1290. Con::warnf("CompositeSprite::pickRay() - Too many items picked to return to scripts!");
  1291. break;
  1292. }
  1293. }
  1294. // Clear sprite batch query.
  1295. pSpriteBatchQuery->clearQuery();
  1296. // Return buffer.
  1297. return pBuffer;
  1298. }
  1299. ConsoleMethodGroupEndWithDocs(CompositeSprite)