ImageAsset_ScriptBinding.h 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038
  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(ImageAsset, AssetBase)
  23. /*! Sets the image file (bitmap file).
  24. @return No return value.
  25. */
  26. ConsoleMethodWithDocs(ImageAsset, setImageFile, ConsoleVoid, 3, 3, (ImageFile))
  27. {
  28. object->setImageFile( argv[2] );
  29. }
  30. //-----------------------------------------------------------------------------
  31. /*! Gets the image file.
  32. @return Returns the bitmap image file, typically as an absolute path.
  33. */
  34. ConsoleMethodWithDocs(ImageAsset, getImageFile, ConsoleString, 2, 2, ())
  35. {
  36. return object->getImageFile();
  37. }
  38. //-----------------------------------------------------------------------------
  39. /*! Gets the image file.
  40. @return Returns the bitmap image file as a path relative to the asset file.
  41. */
  42. ConsoleMethodWithDocs(ImageAsset, getRelativeImageFile, ConsoleString, 2, 2, ())
  43. {
  44. return object->getRelativeImageFile();
  45. }
  46. //------------------------------------------------------------------------------
  47. /*! Sets the filter mode.
  48. @return No return value.
  49. */
  50. ConsoleMethodWithDocs(ImageAsset, setFilterMode, ConsoleVoid, 3, 3, (mode))
  51. {
  52. // Fetch Texture Filter Mode.
  53. const ImageAsset::TextureFilterMode filterMode = ImageAsset::getFilterModeEnum( argv[2] );
  54. // Valid Filter?
  55. if ( filterMode == ImageAsset::FILTER_INVALID )
  56. {
  57. // Warn.
  58. Con::warnf("ImageAsset::setFilterMode() - Invalid Filter Mode Specified! (%s)", argv[2] );
  59. // Finish Here.
  60. return;
  61. }
  62. // Set Filter Mode.
  63. object->setFilterMode( filterMode );
  64. }
  65. //------------------------------------------------------------------------------
  66. /*! Gets the filter mode.
  67. @return The filter mode.
  68. */
  69. ConsoleMethodWithDocs(ImageAsset, getFilterMode, ConsoleString, 2, 2, ())
  70. {
  71. return ImageAsset::getFilterModeDescription( object->getFilterMode() );
  72. }
  73. //-----------------------------------------------------------------------------
  74. /*! Sets whether 16-bit image is forced or not.
  75. @return No return value.
  76. */
  77. ConsoleMethodWithDocs(ImageAsset, setForce16Bit, ConsoleVoid, 3, 3, (force16Bit?))
  78. {
  79. object->setForce16Bit( dAtob(argv[2]) );
  80. }
  81. //-----------------------------------------------------------------------------
  82. /*! Gets whether 16-bit image is forced or not.
  83. @return Whether 16-bit image is forced or not.
  84. */
  85. ConsoleMethodWithDocs(ImageAsset, getForce16Bit, ConsoleBool, 2, 2, ())
  86. {
  87. return object->getForce16Bit();
  88. }
  89. //-----------------------------------------------------------------------------
  90. /*! Sets whether CELL row order should be used or not.
  91. @return No return value.
  92. */
  93. ConsoleMethodWithDocs(ImageAsset, setCellRowOrder, ConsoleVoid, 3, 3, (rowOrder?))
  94. {
  95. object->setCellRowOrder( dAtob(argv[2]) );
  96. }
  97. //-----------------------------------------------------------------------------
  98. /*! Gets whether CELL row order should be used or not.
  99. @return Whether CELL row order should be used or not.
  100. */
  101. ConsoleMethodWithDocs(ImageAsset, getCellRowOrder, ConsoleBool, 2, 2, ())
  102. {
  103. return object->getCellRowOrder();
  104. }
  105. //-----------------------------------------------------------------------------
  106. /*! Sets the CELL offset X.
  107. @return No return value.
  108. */
  109. ConsoleMethodWithDocs(ImageAsset, setCellOffsetX, ConsoleVoid, 3, 3, (offsetX))
  110. {
  111. object->setCellOffsetX( dAtoi(argv[2]) );
  112. }
  113. //-----------------------------------------------------------------------------
  114. /*! Gets the CELL offset X.
  115. @return The CELL offset X.
  116. */
  117. ConsoleMethodWithDocs(ImageAsset, getCellOffsetX, ConsoleInt, 2, 2, ())
  118. {
  119. return object->getCellOffsetX();
  120. }
  121. //-----------------------------------------------------------------------------
  122. /*! Sets the CELL offset Y.
  123. @return No return value.
  124. */
  125. ConsoleMethodWithDocs(ImageAsset, setCellOffsetY, ConsoleVoid, 3, 3, (offsetY))
  126. {
  127. object->setCellOffsetY( dAtoi(argv[2]) );
  128. }
  129. //-----------------------------------------------------------------------------
  130. /*! Gets the CELL offset Y.
  131. @return The CELL offset Y.
  132. */
  133. ConsoleMethodWithDocs(ImageAsset, getCellOffsetY, ConsoleInt, 2, 2, ())
  134. {
  135. return object->getCellOffsetY();
  136. }
  137. //-----------------------------------------------------------------------------
  138. /*! Sets the CELL stride X.
  139. @return No return value.
  140. */
  141. ConsoleMethodWithDocs(ImageAsset, setCellStrideX, ConsoleVoid, 3, 3, (strideX))
  142. {
  143. object->setCellStrideX( dAtoi(argv[2]) );
  144. }
  145. //-----------------------------------------------------------------------------
  146. /*! Gets the CELL stride X.
  147. @return The CELL stride X.
  148. */
  149. ConsoleMethodWithDocs(ImageAsset, getCellStrideX, ConsoleInt, 2, 2, ())
  150. {
  151. return object->getCellStrideX();
  152. }
  153. //-----------------------------------------------------------------------------
  154. /*! Sets the CELL stride Y.
  155. @return No return value.
  156. */
  157. ConsoleMethodWithDocs(ImageAsset, setCellStrideY, ConsoleVoid, 3, 3, (strideY))
  158. {
  159. object->setCellStrideY( dAtoi(argv[2]) );
  160. }
  161. //-----------------------------------------------------------------------------
  162. /*! Gets the CELL stride Y.
  163. @return The CELL stride Y.
  164. */
  165. ConsoleMethodWithDocs(ImageAsset, getCellStrideY, ConsoleInt, 2, 2, ())
  166. {
  167. return object->getCellStrideY();
  168. }
  169. //-----------------------------------------------------------------------------
  170. /*! Sets the CELL count X.
  171. @return No return value.
  172. */
  173. ConsoleMethodWithDocs(ImageAsset, setCellCountX, ConsoleVoid, 3, 3, (countX))
  174. {
  175. object->setCellCountX( dAtoi(argv[2]) );
  176. }
  177. //-----------------------------------------------------------------------------
  178. /*! Gets the CELL count X.
  179. @return The CELL count X.
  180. */
  181. ConsoleMethodWithDocs(ImageAsset, getCellCountX, ConsoleInt, 2, 2, ())
  182. {
  183. return object->getCellCountX();
  184. }
  185. //-----------------------------------------------------------------------------
  186. /*! Sets the CELL count Y.
  187. @return No return value.
  188. */
  189. ConsoleMethodWithDocs(ImageAsset, setCellCountY, ConsoleVoid, 3, 3, (countY))
  190. {
  191. object->setCellCountY( dAtoi(argv[2]) );
  192. }
  193. //-----------------------------------------------------------------------------
  194. /*! Gets the CELL count Y.
  195. @return The CELL count Y.
  196. */
  197. ConsoleMethodWithDocs(ImageAsset, getCellCountY, ConsoleInt, 2, 2, ())
  198. {
  199. return object->getCellCountY();
  200. }
  201. //-----------------------------------------------------------------------------
  202. /*! Sets the CELL width.
  203. @return No return value.
  204. */
  205. ConsoleMethodWithDocs(ImageAsset, setCellWidth, ConsoleVoid, 3, 3, (Width))
  206. {
  207. object->setCellWidth( dAtoi(argv[2]) );
  208. }
  209. //-----------------------------------------------------------------------------
  210. /*! Gets the CELL width.
  211. @return The CELL width.
  212. */
  213. ConsoleMethodWithDocs(ImageAsset, getCellWidth, ConsoleInt, 2, 2, ())
  214. {
  215. return object->getCellWidth();
  216. }
  217. //-----------------------------------------------------------------------------
  218. /*! Sets the CELL height.
  219. @return No return value.
  220. */
  221. ConsoleMethodWithDocs(ImageAsset, setCellHeight, ConsoleVoid, 3, 3, (Height))
  222. {
  223. object->setCellHeight( dAtoi(argv[2]) );
  224. }
  225. //-----------------------------------------------------------------------------
  226. /*! Gets the CELL height.
  227. @return The CELL height.
  228. */
  229. ConsoleMethodWithDocs(ImageAsset, getCellHeight, ConsoleInt, 2, 2, ())
  230. {
  231. return object->getCellHeight();
  232. }
  233. //-----------------------------------------------------------------------------
  234. /*! Gets the image width.
  235. @return The image width.
  236. */
  237. ConsoleMethodWithDocs(ImageAsset, getImageWidth, ConsoleInt, 2, 2, ())
  238. {
  239. return object->getImageWidth();
  240. }
  241. //-----------------------------------------------------------------------------
  242. /*! Gets the image height.
  243. @return The image width.
  244. */
  245. ConsoleMethodWithDocs(ImageAsset, getImageHeight, ConsoleInt, 2, 2, ())
  246. {
  247. return object->getImageHeight();
  248. }
  249. //-----------------------------------------------------------------------------
  250. /*! Gets the image size.
  251. @return The image size.
  252. */
  253. ConsoleMethodWithDocs(ImageAsset, getImageSize, ConsoleString, 2, 2, ())
  254. {
  255. // Create Returnable Buffer.
  256. char* pBuffer = Con::getReturnBuffer(32);
  257. // Format Buffer.
  258. dSprintf(pBuffer, 32, "%d %d", object->getImageWidth(), object->getImageHeight());
  259. // Return Buffer.
  260. return pBuffer;
  261. }
  262. //-----------------------------------------------------------------------------
  263. /*! Gets whether the image has a power-of-two dimensions or not.
  264. @return Whether the image has a power-of-two dimensions or not.
  265. */
  266. ConsoleMethodWithDocs(ImageAsset, getIsImagePOT, ConsoleBool, 2, 2, ())
  267. {
  268. return isPow2( object->getImageWidth() ) && isPow2( object->getImageHeight() );
  269. }
  270. //-----------------------------------------------------------------------------
  271. /*! Gets the frame count.
  272. @return The frame count.
  273. */
  274. ConsoleMethodWithDocs(ImageAsset, getFrameCount, ConsoleInt, 2, 2, ())
  275. {
  276. return object->getFrameCount();
  277. }
  278. //-----------------------------------------------------------------------------
  279. /*! Gets the specified frames size.
  280. @param frame The frame number to use.
  281. @return The specified frames size.
  282. */
  283. ConsoleMethodWithDocs(ImageAsset, getFrameSize, ConsoleString, 3, 3, (int frame))
  284. {
  285. // Fetch Frame.
  286. const S32 frame = dAtoi(argv[2]);
  287. // Check Frame.
  288. if ( frame < 0 || frame >= (S32)object->getFrameCount() )
  289. {
  290. // Warn.
  291. Con::warnf("ImageAsset::getFrameSize() - Invalid Frame; Allowed range is 0 to %d", object->getFrameCount()-1 );
  292. // Finish Here.
  293. return NULL;
  294. }
  295. // Fetch Selected Frame Pixel Area.
  296. const ImageAsset::FrameArea::PixelArea& framePixelArea = object->getImageFrameArea( frame ).mPixelArea;
  297. // Create Returnable Buffer.
  298. char* pBuffer = Con::getReturnBuffer(32);
  299. // Format Buffer.
  300. dSprintf(pBuffer, 32, "%d %d", framePixelArea.mPixelWidth, framePixelArea.mPixelHeight );
  301. // Return Velocity.
  302. return pBuffer;
  303. }
  304. //-----------------------------------------------------------------------------
  305. /*! Clears all explicit cells.
  306. The image asset stays in explicit mode however with no explicit cells a single full-frame cell becomes default.
  307. @return Whether the operation was successful or not.
  308. */
  309. ConsoleMethodWithDocs(ImageAsset, clearExplicitCells, ConsoleBool, 2, 2, ())
  310. {
  311. return object->clearExplicitCells();
  312. }
  313. //-----------------------------------------------------------------------------
  314. /*! Add an explicit cell.
  315. @param cellOffsetX The offset in the X axis to the top-left of the cell.
  316. @param cellOffsetY The offset in the Y axis to the top-left of the cell.
  317. @param cellWidth The width of the cell.
  318. @param cellHeight The height of the cell.
  319. @param cellName The name of the cell's region.
  320. The image asset must be in explicit mode for this operation to succeed.
  321. @return Whether the operation was successful or not.
  322. */
  323. ConsoleMethodWithDocs(ImageAsset, addExplicitCell, ConsoleBool, 7, 7, (int cellOffsetX, int cellOffsetY, int cellWidth, int cellHeight, string cellName))
  324. {
  325. // Fetch offsets.
  326. const S32 cellOffsetX = dAtoi( argv[2] );
  327. const S32 cellOffsetY = dAtoi( argv[3] );
  328. // Fetch dimensions.
  329. const S32 cellWidth = dAtoi( argv[4] );
  330. const S32 cellHeight = dAtoi (argv[5] );
  331. return object->addExplicitCell( cellOffsetX, cellOffsetY, cellWidth, cellHeight, argv[6] );
  332. }
  333. //-----------------------------------------------------------------------------
  334. /*! Insert an explicit cell at the specified index.
  335. @param cellIndex The zero-based index to insert the cell. This will work when no cells are present. If the index is beyond the cell count then the cell is simply added.
  336. @param cellOffsetX The offset in the X axis to the top-left of the cell.
  337. @param cellOffsetY The offset in the Y axis to the top-left of the cell.
  338. @param cellWidth The width of the cell.
  339. @param cellHeight The height of the cell.
  340. @param cellName The name of the cell's region.
  341. The image asset must be in explicit mode for this operation to succeed.
  342. @return Whether the operation was successful or not.
  343. */
  344. ConsoleMethodWithDocs(ImageAsset, insertExplicitCell, ConsoleBool, 8, 8, (int cellIndex, int cellOffsetX, int cellOffsetY, int cellWidth, int cellHeight, string cellName))
  345. {
  346. // Fetch cell index.
  347. const S32 cellIndex = dAtoi( argv[2] );
  348. // Fetch offsets.
  349. const S32 cellOffsetX = dAtoi( argv[3] );
  350. const S32 cellOffsetY = dAtoi( argv[4] );
  351. // Fetch dimensions.
  352. const S32 cellWidth = dAtoi( argv[5] );
  353. const S32 cellHeight = dAtoi (argv[6] );
  354. return object->insertExplicitCell( cellIndex, cellOffsetX, cellOffsetY, cellWidth, cellHeight, argv[7] );
  355. }
  356. //-----------------------------------------------------------------------------
  357. /*! Remove an explicit cell from the specified index.
  358. @param cellIndex The zero-based index to remove the cell from.
  359. @return Whether the operation was successful or not.
  360. */
  361. ConsoleMethodWithDocs(ImageAsset, removeExplicitCell, ConsoleBool, 3, 3, (int cellIndex))
  362. {
  363. // Fetch cell index.
  364. const S32 cellIndex = dAtoi( argv[2] );
  365. return object->removeExplicitCell( cellIndex );
  366. }
  367. //-----------------------------------------------------------------------------
  368. /*! Set an explicit cell at the specified index.
  369. @param cellIndex The zero-based index to set the cell.
  370. @param cellOffsetX The offset in the X axis to the top-left of the cell.
  371. @param cellOffsetY The offset in the Y axis to the top-left of the cell.
  372. @param cellWidth The width of the cell.
  373. @param cellHeight The height of the cell.
  374. @param cellName The name of the cell's region.
  375. The image asset must be in explicit mode for this operation to succeed.
  376. @return Whether the operation was successful or not.
  377. */
  378. ConsoleMethodWithDocs(ImageAsset, setExplicitCell, ConsoleBool, 8, 8, (int cellIndex, int cellOffsetX, int cellOffsetY, int cellWidth, int cellHeight, string cellName))
  379. {
  380. // Fetch cell index.
  381. const S32 cellIndex = dAtoi( argv[2] );
  382. // Fetch offsets.
  383. const S32 cellOffsetX = dAtoi( argv[3] );
  384. const S32 cellOffsetY = dAtoi( argv[4] );
  385. // Fetch dimensions.
  386. const S32 cellWidth = dAtoi( argv[5] );
  387. const S32 cellHeight = dAtoi (argv[6] );
  388. return object->setExplicitCell( cellIndex, cellOffsetX, cellOffsetY, cellWidth, cellHeight, argv[7] );
  389. }
  390. //-----------------------------------------------------------------------------
  391. /*! Gets the explicit cell count.
  392. @return The explicit cell count.
  393. */
  394. ConsoleMethodWithDocs(ImageAsset, getExplicitCellCount, ConsoleInt, 2, 2, ())
  395. {
  396. return object->getExplicitCellCount();
  397. }
  398. //-----------------------------------------------------------------------------
  399. /*! Gets the CELL offset in Explicit Mode.
  400. @param cell The cell index or cell name to use to find the specific offset.
  401. @return The specified CELL width.
  402. */
  403. ConsoleMethodWithDocs(ImageAsset, getExplicitCellOffset, ConsoleString, 3, 3, (cell))
  404. {
  405. // Was it a number or a string?
  406. if (!dIsalpha(*argv[2]))
  407. {
  408. // Using cell index.
  409. const S32 cellIndex = dAtoi(argv[2]);
  410. return object->getExplicitCellOffset(cellIndex).scriptThis();
  411. }
  412. else
  413. {
  414. // Using cell name.
  415. ImageAsset::FrameArea& frameRegion = object->getCellByName(argv[2]);
  416. const Vector2 offset = frameRegion.mPixelArea.mPixelOffset;
  417. return offset.scriptThis();
  418. }
  419. }
  420. //-----------------------------------------------------------------------------
  421. /*! Gets the CELL width in Explicit Mode.
  422. @param cell The cell index or cell name to use to find the specific width.
  423. @return The specified CELL width.
  424. */
  425. ConsoleMethodWithDocs(ImageAsset, getExplicitCellWidth, ConsoleInt, 3, 3, (cell))
  426. {
  427. S32 cellIndex;
  428. // Was it a number or a string?
  429. if (!dIsalpha(*argv[2]))
  430. {
  431. // Using cell index.
  432. cellIndex = dAtoi(argv[2]);
  433. return object->getExplicitCellWidth(cellIndex);
  434. }
  435. else
  436. {
  437. // Using cell name.
  438. ImageAsset::FrameArea& frameRegion = object->getCellByName(argv[2]);
  439. return frameRegion.mPixelArea.mPixelWidth;
  440. }
  441. }
  442. //-----------------------------------------------------------------------------
  443. /*! Gets the CELL height in Explicit Mode.
  444. @param cell The cell index or cell name to use to find the specific height.
  445. @return The specified CELL height.
  446. */
  447. ConsoleMethodWithDocs(ImageAsset, getExplicitCellHeight, ConsoleInt, 3, 3, (cell))
  448. {
  449. S32 cellIndex;
  450. // Was it a number or a string?
  451. if (!dIsalpha(*argv[2]))
  452. {
  453. // Using cell index.
  454. cellIndex = dAtoi(argv[2]);
  455. return object->getExplicitCellHeight(cellIndex);
  456. }
  457. else
  458. {
  459. // Using cell name.
  460. ImageAsset::FrameArea& frameRegion = object->getCellByName(argv[2]);
  461. return frameRegion.mPixelArea.mPixelHeight;
  462. }
  463. }
  464. //-----------------------------------------------------------------------------
  465. /*! Gets the CELL region name in Explicit Mode.
  466. @param cell The cell index to use to find the specific name.
  467. @return The specified CELL region name.
  468. */
  469. ConsoleMethodWithDocs(ImageAsset, getExplicitCellName, ConsoleString, 3, 3, (cell))
  470. {
  471. // Fetch cell index.
  472. const S32 cellIndex = dAtoi(argv[2]);
  473. return object->getExplicitCellName(cellIndex);
  474. }
  475. //-----------------------------------------------------------------------------
  476. /*! Gets the CELL index number in Explicit Mode.
  477. @param cellName The cell name to use to find the specific index.
  478. @return The specified CELL index number or -1 if no such cell exists.
  479. */
  480. ConsoleMethodWithDocs(ImageAsset, getExplicitCellIndex, ConsoleInt, 3, 3, (cellName))
  481. {
  482. return object->getExplicitCellIndex( argv[2] );
  483. }
  484. /*! Gets the status of Explicit mode
  485. @return Returns true if ExplicitMode is on, false otherwise.
  486. */
  487. ConsoleMethodWithDocs(ImageAsset, getExplicitMode, ConsoleBool, 2, 2, ())
  488. {
  489. return object->getExplicitMode();
  490. }
  491. /*! Sets Explicit Mode
  492. @param explicitMode Whether to set Explicit Mode or disable it
  493. @return No return value.
  494. */
  495. ConsoleMethodWithDocs(ImageAsset, setExplicitMode, ConsoleVoid, 3, 3, (explicitMode))
  496. {
  497. object->setExplicitMode(dAtob(argv[2]));
  498. }
  499. /*! Adds a layer to the ImageAsset
  500. @param imageFile The file for the image to layer over the texture.
  501. @param position The position for the layer to be at with (0, 0) in the top left corner.
  502. @param blendColor The blending color to be applied to this new layer.
  503. @param doRedraw Optional value that prevents a redraw of the texture when false. Defaults to true.
  504. @return No return value.
  505. */
  506. ConsoleMethodWithDocs(ImageAsset, addLayer, ConsoleVoid, 5, 6, (imageFile, position, blendColor, [doRedraw]))
  507. {
  508. if (argc < 5)
  509. {
  510. Con::warnf("ImageAsset::addLayer() - Invalid number of parameters!");
  511. return;
  512. }
  513. F32 x, y;
  514. x = 0.0f;
  515. y = 0.0f;
  516. if (Utility::mGetStringElementCount(argv[3]) >= 2)
  517. {
  518. x = dAtof(Utility::mGetStringElement(argv[3], 0));
  519. y = dAtof(Utility::mGetStringElement(argv[3], 1));
  520. }
  521. Point2I pos(x, y);
  522. const U32 colorCount = Utility::mGetStringElementCount(argv[4]);
  523. if (colorCount != 4)
  524. {
  525. Con::warnf("Scene::addLayer() - Invalid color! Colors require four values (red / green / blue / alpha)!");
  526. return;
  527. }
  528. ColorF blendColor = ColorF(dAtof(Utility::mGetStringElement(argv[4], 0)),
  529. dAtof(Utility::mGetStringElement(argv[4], 1)),
  530. dAtof(Utility::mGetStringElement(argv[4], 2)),
  531. dAtof(Utility::mGetStringElement(argv[4], 3)));
  532. bool redraw = true;
  533. if (argc == 6)
  534. {
  535. redraw = dAtob(argv[5]);
  536. }
  537. object->addLayer(argv[2], pos, blendColor, redraw);
  538. }
  539. /*! Inserts a layer into the stack of layers on a texture at a given index.
  540. @param index The one-based index to insert the new layer at. Must be less or equal to the number of layers.
  541. @param imageFile The file for the image to layer over the texture.
  542. @param position The position for the layer to be at with (0, 0) in the top left corner.
  543. @param blendColor The blending color to be applied to this new layer.
  544. @param doRedraw Optional value that prevents a redraw of the texture when false. Defaults to true.
  545. @return No return value.
  546. */
  547. ConsoleMethodWithDocs(ImageAsset, insertLayer, ConsoleVoid, 6, 7, (index, imageFile, position, blendColor, [doRedraw]))
  548. {
  549. if (argc < 6)
  550. {
  551. Con::warnf("ImageAsset::insertLayer() - Invalid number of parameters!");
  552. return;
  553. }
  554. U32 index = dAtoi(argv[2]);
  555. F32 x, y;
  556. x = 0.0f;
  557. y = 0.0f;
  558. if (Utility::mGetStringElementCount(argv[4]) >= 2)
  559. {
  560. x = dAtof(Utility::mGetStringElement(argv[4], 0));
  561. y = dAtof(Utility::mGetStringElement(argv[4], 1));
  562. }
  563. Point2I pos(x, y);
  564. const U32 colorCount = Utility::mGetStringElementCount(argv[5]);
  565. if (colorCount != 4)
  566. {
  567. Con::warnf("Scene::insertLayer() - Invalid color! Colors require four values (red / green / blue / alpha)!");
  568. return;
  569. }
  570. ColorF blendColor = ColorF(dAtof(Utility::mGetStringElement(argv[5], 0)),
  571. dAtof(Utility::mGetStringElement(argv[5], 1)),
  572. dAtof(Utility::mGetStringElement(argv[5], 2)),
  573. dAtof(Utility::mGetStringElement(argv[5], 3)));
  574. bool redraw = true;
  575. if (argc == 7)
  576. {
  577. redraw = dAtob(argv[6]);
  578. }
  579. object->insertLayer(index, argv[3], pos, blendColor, redraw);
  580. }
  581. /*! Removes a layer from a texture at a given index.
  582. @param index The one-based index to remove the new layer from. Must be less or equal to the number of layers.
  583. @param doRedraw Optional value that prevents a redraw of the texture when false. Defaults to true.
  584. @return No return value.
  585. */
  586. ConsoleMethodWithDocs(ImageAsset, removeLayer, ConsoleVoid, 3, 4, (index, [doRedraw]))
  587. {
  588. if (argc < 3)
  589. {
  590. Con::warnf("ImageAsset::removeLayer() - Invalid number of parameters!");
  591. return;
  592. }
  593. U32 index = dAtoi(argv[2]);
  594. bool redraw = true;
  595. if (argc == 4)
  596. {
  597. redraw = dAtob(argv[3]);
  598. }
  599. object->removeLayer(index, redraw);
  600. }
  601. /*! Moves the layer at the index forward.
  602. @param index The one-based index to move forward. Must be less or equal to the number of layers.
  603. @param doRedraw Optional value that prevents a redraw of the texture when false. Defaults to true.
  604. @return No return value.
  605. */
  606. ConsoleMethodWithDocs(ImageAsset, moveLayerForward, ConsoleVoid, 3, 4, (index, [doRedraw]))
  607. {
  608. if (argc < 3)
  609. {
  610. Con::warnf("ImageAsset::moveLayerForward() - Invalid number of parameters!");
  611. return;
  612. }
  613. U32 index = dAtoi(argv[2]);
  614. bool redraw = true;
  615. if (argc == 4)
  616. {
  617. redraw = dAtob(argv[3]);
  618. }
  619. object->moveLayerForward(index, redraw);
  620. }
  621. /*! Moves the layer at the index backward.
  622. @param index The one-based index to move backward. Must be less or equal to the number of layers.
  623. @param doRedraw Optional value that prevents a redraw of the texture when false. Defaults to true.
  624. @return No return value.
  625. */
  626. ConsoleMethodWithDocs(ImageAsset, moveLayerBackward, ConsoleVoid, 3, 4, (index, [doRedraw]))
  627. {
  628. if (argc < 3)
  629. {
  630. Con::warnf("ImageAsset::moveLayerBackward() - Invalid number of parameters!");
  631. return;
  632. }
  633. U32 index = dAtoi(argv[2]);
  634. bool redraw = true;
  635. if (argc == 4)
  636. {
  637. redraw = dAtob(argv[3]);
  638. }
  639. object->moveLayerBackward(index, redraw);
  640. }
  641. /*! Moves the layer at the index to the front.
  642. @param index The one-based index to move to the front. Must be less or equal to the number of layers.
  643. @param doRedraw Optional value that prevents a redraw of the texture when false. Defaults to true.
  644. @return No return value.
  645. */
  646. ConsoleMethodWithDocs(ImageAsset, moveLayerToFront, ConsoleVoid, 3, 4, (index, [doRedraw]))
  647. {
  648. if (argc < 3)
  649. {
  650. Con::warnf("ImageAsset::moveLayerToFront() - Invalid number of parameters!");
  651. return;
  652. }
  653. U32 index = dAtoi(argv[2]);
  654. bool redraw = true;
  655. if (argc == 4)
  656. {
  657. redraw = dAtob(argv[3]);
  658. }
  659. object->moveLayerToFront(index, redraw);
  660. }
  661. /*! Moves the layer at the index to the back.
  662. @param index The one-based index to move to the back. Must be less or equal to the number of layers.
  663. @param doRedraw Optional value that prevents a redraw of the texture when false. Defaults to true.
  664. @return No return value.
  665. */
  666. ConsoleMethodWithDocs(ImageAsset, moveLayerToBack, ConsoleVoid, 3, 4, (index, [doRedraw]))
  667. {
  668. if (argc < 3)
  669. {
  670. Con::warnf("ImageAsset::moveLayerToBack() - Invalid number of parameters!");
  671. return;
  672. }
  673. U32 index = dAtoi(argv[2]);
  674. bool redraw = true;
  675. if (argc == 4)
  676. {
  677. redraw = dAtob(argv[3]);
  678. }
  679. object->moveLayerToBack(index, redraw);
  680. }
  681. /*! Sets the image for a layer at the given index.
  682. @param index The one-based index to move to the back. Must be less or equal to the number of layers.
  683. @param image The path to an image to be used by the layer.
  684. @param doRedraw Optional value that prevents a redraw of the texture when false. Defaults to true.
  685. @return No return value.
  686. */
  687. ConsoleMethodWithDocs(ImageAsset, setLayerImage, ConsoleVoid, 4, 5, (index, image, [doRedraw]))
  688. {
  689. if (argc < 4)
  690. {
  691. Con::warnf("ImageAsset::setLayerImage() - Invalid number of parameters!");
  692. return;
  693. }
  694. U32 index = dAtoi(argv[2]);
  695. bool redraw = true;
  696. if (argc == 5)
  697. {
  698. redraw = dAtob(argv[4]);
  699. }
  700. object->setLayerImage(index, argv[3], redraw);
  701. }
  702. /*! Sets the position for a layer at the given index.
  703. @param index The one-based index to move to the back. Must be less or equal to the number of layers.
  704. @param position The space-deliminated (x, y) position to place the image with the top left corner as (0, 0). The layer can safely overflow the bounds of the original image.
  705. @param doRedraw Optional value that prevents a redraw of the texture when false. Defaults to true.
  706. @return No return value.
  707. */
  708. ConsoleMethodWithDocs(ImageAsset, setLayerPosition, ConsoleVoid, 4, 5, (index, position, [doRedraw]))
  709. {
  710. if (argc < 4)
  711. {
  712. Con::warnf("ImageAsset::setLayerPosition() - Invalid number of parameters!");
  713. return;
  714. }
  715. U32 index = dAtoi(argv[2]);
  716. F32 x, y;
  717. x = 0.0f;
  718. y = 0.0f;
  719. if (Utility::mGetStringElementCount(argv[3]) >= 2)
  720. {
  721. x = dAtof(Utility::mGetStringElement(argv[3], 0));
  722. y = dAtof(Utility::mGetStringElement(argv[3], 1));
  723. }
  724. Point2I pos(x, y);
  725. bool redraw = true;
  726. if (argc == 5)
  727. {
  728. redraw = dAtob(argv[4]);
  729. }
  730. object->setLayerPosition(index, pos, redraw);
  731. }
  732. /*! Sets the blend color for a layer at the given index.
  733. @param index The one-based index to move to the back. Must be less or equal to the number of layers.
  734. @param blendColor The space-deliminated color used to blend the layer. Requires four decimal values between 0 and 1 that represent red, green, blue, and alpha.
  735. @param doRedraw Optional value that prevents a redraw of the texture when false. Defaults to true.
  736. @return No return value.
  737. */
  738. ConsoleMethodWithDocs(ImageAsset, setLayerBlendColor, ConsoleVoid, 4, 5, (index, blendColor, [doRedraw]))
  739. {
  740. if (argc < 4)
  741. {
  742. Con::warnf("ImageAsset::setLayerBlendColor() - Invalid number of parameters!");
  743. return;
  744. }
  745. U32 index = dAtoi(argv[2]);
  746. const U32 colorCount = Utility::mGetStringElementCount(argv[3]);
  747. if (colorCount != 4)
  748. {
  749. Con::warnf("Scene::setLayerBlendColor() - Invalid color! Colors require four values (red / green / blue / alpha)!");
  750. return;
  751. }
  752. ColorF blendColor = ColorF(dAtof(Utility::mGetStringElement(argv[3], 0)),
  753. dAtof(Utility::mGetStringElement(argv[3], 1)),
  754. dAtof(Utility::mGetStringElement(argv[3], 2)),
  755. dAtof(Utility::mGetStringElement(argv[3], 3)));
  756. bool redraw = true;
  757. if (argc == 5)
  758. {
  759. redraw = dAtob(argv[4]);
  760. }
  761. object->setLayerBlendColor(index, blendColor, redraw);
  762. }
  763. /*! Returns the number of layers.
  764. @return The number of layers used by the texture. Zero if only the base texture is used.
  765. */
  766. ConsoleMethodWithDocs(ImageAsset, getLayerCount, ConsoleInt, 2, 2, ())
  767. {
  768. return object->getLayerCount();
  769. }
  770. /*! Returns image used for a given layer.
  771. @param index The one-based index to move to the back. Must be less or equal to the number of layers.
  772. @return The path to the image file.
  773. */
  774. ConsoleMethodWithDocs(ImageAsset, getLayerImage, ConsoleString, 3, 3, (index))
  775. {
  776. if (argc < 3)
  777. {
  778. Con::warnf("ImageAsset::getLayerImage() - Invalid number of parameters!");
  779. return StringTable->EmptyString;
  780. }
  781. U32 index = dAtoi(argv[2]);
  782. return object->getLayerImage(index);
  783. }
  784. /*! Returns position for a given layer.
  785. @param index The one-based index to move to the back. Must be less or equal to the number of layers.
  786. @return (int y, int x) The layer position.
  787. */
  788. ConsoleMethodWithDocs(ImageAsset, getLayerPosition, ConsoleString, 3, 3, (index))
  789. {
  790. if (argc < 3)
  791. {
  792. Con::warnf("ImageAsset::getLayerPosition() - Invalid number of parameters!");
  793. return StringTable->EmptyString;
  794. }
  795. U32 index = dAtoi(argv[2]);
  796. char* retBuffer = Con::getReturnBuffer(64);
  797. const Point2I& pos = object->getLayerPosition(index);
  798. dSprintf(retBuffer, 64, "%d %d", pos.x, pos.y);
  799. return retBuffer;
  800. }
  801. /*! Returns the blend color for a given layer.
  802. @param index The one-based index to move to the back. Must be less or equal to the number of layers.
  803. @return (float red / float green / float blue / float alpha) The layer blend color.
  804. */
  805. ConsoleMethodWithDocs(ImageAsset, getLayerBlendColor, ConsoleString, 3, 3, (index))
  806. {
  807. if (argc < 3)
  808. {
  809. Con::warnf("ImageAsset::getLayerBlendColor() - Invalid number of parameters!");
  810. return StringTable->EmptyString;
  811. }
  812. U32 index = dAtoi(argv[2]);
  813. return object->getLayerBlendColor(index).scriptThis();
  814. }
  815. /*! Forces the texture to redraw its layers. Redrawing can be expensive and is automatically done on every change to a layer unless prevented.
  816. @return No return value.
  817. */
  818. ConsoleMethodWithDocs(ImageAsset, forceRedraw, ConsoleVoid, 2, 2, ())
  819. {
  820. if (object->getLayerCount() > 0)
  821. {
  822. object->forceRedrawImage();
  823. }
  824. }
  825. /*! Sets the blend color for the base image when using layers.
  826. @param blendColor The space-deliminated color used to blend the layer. Requires four decimal values between 0 and 1 that represent red, green, blue, and alpha.
  827. @param doRedraw Optional value that prevents a redraw of the texture when false. Defaults to true.
  828. @return No return value.
  829. */
  830. ConsoleMethodWithDocs(ImageAsset, setBlendColor, ConsoleVoid, 3, 4, (blendColor, [doRedraw]))
  831. {
  832. if (argc < 3)
  833. {
  834. Con::warnf("ImageAsset::setBlendColor() - Invalid number of parameters!");
  835. return;
  836. }
  837. const U32 colorCount = Utility::mGetStringElementCount(argv[2]);
  838. if (colorCount != 4)
  839. {
  840. Con::warnf("Scene::setBlendColor() - Invalid color! Colors require four values (red / green / blue / alpha)!");
  841. return;
  842. }
  843. ColorF blendColor = ColorF(dAtof(Utility::mGetStringElement(argv[2], 0)),
  844. dAtof(Utility::mGetStringElement(argv[2], 1)),
  845. dAtof(Utility::mGetStringElement(argv[2], 2)),
  846. dAtof(Utility::mGetStringElement(argv[2], 3)));
  847. bool redraw = true;
  848. if (argc == 4)
  849. {
  850. redraw = dAtob(argv[3]);
  851. }
  852. object->setBlendColor(blendColor, redraw);
  853. }
  854. /*! Returns the blend color for the base texture when using layers.
  855. @return (float red / float green / float blue / float alpha) The base blend color.
  856. */
  857. ConsoleMethodWithDocs(ImageAsset, getBlendColor, ConsoleString, 2, 2, ())
  858. {
  859. return object->getBlendColor().scriptThis();
  860. }
  861. ConsoleMethodGroupEndWithDocs(ImageAsset)