ImageAsset_ScriptBinding.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  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.
  33. */
  34. ConsoleMethodWithDocs(ImageAsset, getImageFile, ConsoleString, 2, 2, ())
  35. {
  36. return object->getImageFile();
  37. }
  38. //------------------------------------------------------------------------------
  39. /*! Sets the filter mode.
  40. @return No return value.
  41. */
  42. ConsoleMethodWithDocs(ImageAsset, setFilterMode, ConsoleVoid, 3, 3, (mode))
  43. {
  44. // Fetch Texture Filter Mode.
  45. const ImageAsset::TextureFilterMode filterMode = ImageAsset::getFilterModeEnum( argv[2] );
  46. // Valid Filter?
  47. if ( filterMode == ImageAsset::FILTER_INVALID )
  48. {
  49. // Warn.
  50. Con::warnf("ImageAsset::setFilterMode() - Invalid Filter Mode Specified! (%s)", argv[2] );
  51. // Finish Here.
  52. return;
  53. }
  54. // Set Filter Mode.
  55. object->setFilterMode( filterMode );
  56. }
  57. //------------------------------------------------------------------------------
  58. /*! Gets the filter mode.
  59. @return The filter mode.
  60. */
  61. ConsoleMethodWithDocs(ImageAsset, getFilterMode, ConsoleString, 2, 2, ())
  62. {
  63. return ImageAsset::getFilterModeDescription( object->getFilterMode() );
  64. }
  65. //-----------------------------------------------------------------------------
  66. /*! Sets whether 16-bit image is forced or not.
  67. @return No return value.
  68. */
  69. ConsoleMethodWithDocs(ImageAsset, setForce16Bit, ConsoleVoid, 3, 3, (force16Bit?))
  70. {
  71. object->setForce16Bit( dAtob(argv[2]) );
  72. }
  73. //-----------------------------------------------------------------------------
  74. /*! Gets whether 16-bit image is forced or not.
  75. @return Whether 16-bit image is forced or not.
  76. */
  77. ConsoleMethodWithDocs(ImageAsset, getForce16Bit, ConsoleBool, 2, 2, ())
  78. {
  79. return object->getForce16Bit();
  80. }
  81. //-----------------------------------------------------------------------------
  82. /*! Sets whether CELL row order should be used or not.
  83. @return No return value.
  84. */
  85. ConsoleMethodWithDocs(ImageAsset, setCellRowOrder, ConsoleVoid, 3, 3, (rowOrder?))
  86. {
  87. object->setCellRowOrder( dAtob(argv[2]) );
  88. }
  89. //-----------------------------------------------------------------------------
  90. /*! Gets whether CELL row order should be used or not.
  91. @return Whether CELL row order should be used or not.
  92. */
  93. ConsoleMethodWithDocs(ImageAsset, getCellRowOrder, ConsoleBool, 2, 2, ())
  94. {
  95. return object->getCellRowOrder();
  96. }
  97. //-----------------------------------------------------------------------------
  98. /*! Sets the CELL offset X.
  99. @return No return value.
  100. */
  101. ConsoleMethodWithDocs(ImageAsset, setCellOffsetX, ConsoleVoid, 3, 3, (offsetX))
  102. {
  103. object->setCellOffsetX( dAtoi(argv[2]) );
  104. }
  105. //-----------------------------------------------------------------------------
  106. /*! Gets the CELL offset X.
  107. @return The CELL offset X.
  108. */
  109. ConsoleMethodWithDocs(ImageAsset, getCellOffsetX, ConsoleInt, 2, 2, ())
  110. {
  111. return object->getCellOffsetX();
  112. }
  113. //-----------------------------------------------------------------------------
  114. /*! Sets the CELL offset Y.
  115. @return No return value.
  116. */
  117. ConsoleMethodWithDocs(ImageAsset, setCellOffsetY, ConsoleVoid, 3, 3, (offsetY))
  118. {
  119. object->setCellOffsetY( dAtoi(argv[2]) );
  120. }
  121. //-----------------------------------------------------------------------------
  122. /*! Gets the CELL offset Y.
  123. @return The CELL offset Y.
  124. */
  125. ConsoleMethodWithDocs(ImageAsset, getCellOffsetY, ConsoleInt, 2, 2, ())
  126. {
  127. return object->getCellOffsetY();
  128. }
  129. //-----------------------------------------------------------------------------
  130. /*! Sets the CELL stride X.
  131. @return No return value.
  132. */
  133. ConsoleMethodWithDocs(ImageAsset, setCellStrideX, ConsoleVoid, 3, 3, (strideX))
  134. {
  135. object->setCellStrideX( dAtoi(argv[2]) );
  136. }
  137. //-----------------------------------------------------------------------------
  138. /*! Gets the CELL stride X.
  139. @return The CELL stride X.
  140. */
  141. ConsoleMethodWithDocs(ImageAsset, getCellStrideX, ConsoleInt, 2, 2, ())
  142. {
  143. return object->getCellStrideX();
  144. }
  145. //-----------------------------------------------------------------------------
  146. /*! Sets the CELL stride Y.
  147. @return No return value.
  148. */
  149. ConsoleMethodWithDocs(ImageAsset, setCellStrideY, ConsoleVoid, 3, 3, (strideY))
  150. {
  151. object->setCellStrideY( dAtoi(argv[2]) );
  152. }
  153. //-----------------------------------------------------------------------------
  154. /*! Gets the CELL stride Y.
  155. @return The CELL stride Y.
  156. */
  157. ConsoleMethodWithDocs(ImageAsset, getCellStrideY, ConsoleInt, 2, 2, ())
  158. {
  159. return object->getCellStrideY();
  160. }
  161. //-----------------------------------------------------------------------------
  162. /*! Sets the CELL count X.
  163. @return No return value.
  164. */
  165. ConsoleMethodWithDocs(ImageAsset, setCellCountX, ConsoleVoid, 3, 3, (countX))
  166. {
  167. object->setCellCountX( dAtoi(argv[2]) );
  168. }
  169. //-----------------------------------------------------------------------------
  170. /*! Gets the CELL count X.
  171. @return The CELL count X.
  172. */
  173. ConsoleMethodWithDocs(ImageAsset, getCellCountX, ConsoleInt, 2, 2, ())
  174. {
  175. return object->getCellCountX();
  176. }
  177. //-----------------------------------------------------------------------------
  178. /*! Sets the CELL count Y.
  179. @return No return value.
  180. */
  181. ConsoleMethodWithDocs(ImageAsset, setCellCountY, ConsoleVoid, 3, 3, (countY))
  182. {
  183. object->setCellCountY( dAtoi(argv[2]) );
  184. }
  185. //-----------------------------------------------------------------------------
  186. /*! Gets the CELL count Y.
  187. @return The CELL count Y.
  188. */
  189. ConsoleMethodWithDocs(ImageAsset, getCellCountY, ConsoleInt, 2, 2, ())
  190. {
  191. return object->getCellCountY();
  192. }
  193. //-----------------------------------------------------------------------------
  194. /*! Sets the CELL width.
  195. @return No return value.
  196. */
  197. ConsoleMethodWithDocs(ImageAsset, setCellWidth, ConsoleVoid, 3, 3, (Width))
  198. {
  199. object->setCellWidth( dAtoi(argv[2]) );
  200. }
  201. //-----------------------------------------------------------------------------
  202. /*! Gets the CELL width.
  203. @return The CELL width.
  204. */
  205. ConsoleMethodWithDocs(ImageAsset, getCellWidth, ConsoleInt, 2, 2, ())
  206. {
  207. return object->getCellWidth();
  208. }
  209. //-----------------------------------------------------------------------------
  210. /*! Sets the CELL height.
  211. @return No return value.
  212. */
  213. ConsoleMethodWithDocs(ImageAsset, setCellHeight, ConsoleVoid, 3, 3, (Height))
  214. {
  215. object->setCellHeight( dAtoi(argv[2]) );
  216. }
  217. //-----------------------------------------------------------------------------
  218. /*! Gets the CELL height.
  219. @return The CELL height.
  220. */
  221. ConsoleMethodWithDocs(ImageAsset, getCellHeight, ConsoleInt, 2, 2, ())
  222. {
  223. return object->getCellHeight();
  224. }
  225. //-----------------------------------------------------------------------------
  226. /*! Gets the image width.
  227. @return The image width.
  228. */
  229. ConsoleMethodWithDocs(ImageAsset, getImageWidth, ConsoleInt, 2, 2, ())
  230. {
  231. return object->getImageWidth();
  232. }
  233. //-----------------------------------------------------------------------------
  234. /*! Gets the image height.
  235. @return The image width.
  236. */
  237. ConsoleMethodWithDocs(ImageAsset, getImageHeight, ConsoleInt, 2, 2, ())
  238. {
  239. return object->getImageHeight();
  240. }
  241. //-----------------------------------------------------------------------------
  242. /*! Gets the image size.
  243. @return The image size.
  244. */
  245. ConsoleMethodWithDocs(ImageAsset, getImageSize, ConsoleString, 2, 2, ())
  246. {
  247. // Create Returnable Buffer.
  248. char* pBuffer = Con::getReturnBuffer(32);
  249. // Format Buffer.
  250. dSprintf(pBuffer, 32, "%d %d", object->getImageWidth(), object->getImageHeight());
  251. // Return Buffer.
  252. return pBuffer;
  253. }
  254. //-----------------------------------------------------------------------------
  255. /*! Gets whether the image has a power-of-two dimensions or not.
  256. @return Whether the image has a power-of-two dimensions or not.
  257. */
  258. ConsoleMethodWithDocs(ImageAsset, getIsImagePOT, ConsoleBool, 2, 2, ())
  259. {
  260. return isPow2( object->getImageWidth() ) && isPow2( object->getImageHeight() );
  261. }
  262. //-----------------------------------------------------------------------------
  263. /*! Gets the frame count.
  264. @return The frame count.
  265. */
  266. ConsoleMethodWithDocs(ImageAsset, getFrameCount, ConsoleInt, 2, 2, ())
  267. {
  268. return object->getFrameCount();
  269. }
  270. //-----------------------------------------------------------------------------
  271. /*! Gets the specified frames size.
  272. @param frame The frame number to use.
  273. @return The specified frames size.
  274. */
  275. ConsoleMethodWithDocs(ImageAsset, getFrameSize, ConsoleString, 3, 3, (int frame))
  276. {
  277. // Fetch Frame.
  278. const S32 frame = dAtoi(argv[2]);
  279. // Check Frame.
  280. if ( frame < 0 || frame >= (S32)object->getFrameCount() )
  281. {
  282. // Warn.
  283. Con::warnf("ImageAsset::getFrameSize() - Invalid Frame; Allowed range is 0 to %d", object->getFrameCount()-1 );
  284. // Finish Here.
  285. return NULL;
  286. }
  287. // Fetch Selected Frame Pixel Area.
  288. const ImageAsset::FrameArea::PixelArea& framePixelArea = object->getImageFrameArea( frame ).mPixelArea;
  289. // Create Returnable Buffer.
  290. char* pBuffer = Con::getReturnBuffer(32);
  291. // Format Buffer.
  292. dSprintf(pBuffer, 32, "%d %d", framePixelArea.mPixelWidth, framePixelArea.mPixelHeight );
  293. // Return Velocity.
  294. return pBuffer;
  295. }
  296. //-----------------------------------------------------------------------------
  297. /*! Clears all explicit cells.
  298. The image asset stays in explicit mode however with no explicit cells a single full-frame cell becomes default.
  299. @return Whether the operation was successful or not.
  300. */
  301. ConsoleMethodWithDocs(ImageAsset, clearExplicitCells, ConsoleBool, 2, 2, ())
  302. {
  303. return object->clearExplicitCells();
  304. }
  305. //-----------------------------------------------------------------------------
  306. /*! Add an explicit cell.
  307. @param cellOffsetX The offset in the X axis to the top-left of the cell.
  308. @param cellOffsetY The offset in the Y axis to the top-left of the cell.
  309. @param cellWidth The width of the cell.
  310. @param cellHeight The height of the cell.
  311. @param cellName The name of the cell's region.
  312. The image asset must be in explicit mode for this operation to succeed.
  313. @return Whether the operation was successful or not.
  314. */
  315. ConsoleMethodWithDocs(ImageAsset, addExplicitCell, ConsoleBool, 7, 7, (int cellOffsetX, int cellOffsetY, int cellWidth, int cellHeight, string cellName))
  316. {
  317. // Fetch offsets.
  318. const S32 cellOffsetX = dAtoi( argv[2] );
  319. const S32 cellOffsetY = dAtoi( argv[3] );
  320. // Fetch dimensions.
  321. const S32 cellWidth = dAtoi( argv[4] );
  322. const S32 cellHeight = dAtoi (argv[5] );
  323. return object->addExplicitCell( cellOffsetX, cellOffsetY, cellWidth, cellHeight, argv[6] );
  324. }
  325. //-----------------------------------------------------------------------------
  326. /*! Insert an explicit cell at the specified index.
  327. @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.
  328. @param cellOffsetX The offset in the X axis to the top-left of the cell.
  329. @param cellOffsetY The offset in the Y axis to the top-left of the cell.
  330. @param cellWidth The width of the cell.
  331. @param cellHeight The height of the cell.
  332. @param cellName The name of the cell's region.
  333. The image asset must be in explicit mode for this operation to succeed.
  334. @return Whether the operation was successful or not.
  335. */
  336. ConsoleMethodWithDocs(ImageAsset, insertExplicitCell, ConsoleBool, 8, 8, (int cellIndex, int cellOffsetX, int cellOffsetY, int cellWidth, int cellHeight, string cellName))
  337. {
  338. // Fetch cell index.
  339. const S32 cellIndex = dAtoi( argv[2] );
  340. // Fetch offsets.
  341. const S32 cellOffsetX = dAtoi( argv[3] );
  342. const S32 cellOffsetY = dAtoi( argv[4] );
  343. // Fetch dimensions.
  344. const S32 cellWidth = dAtoi( argv[5] );
  345. const S32 cellHeight = dAtoi (argv[6] );
  346. return object->insertExplicitCell( cellIndex, cellOffsetX, cellOffsetY, cellWidth, cellHeight, argv[7] );
  347. }
  348. //-----------------------------------------------------------------------------
  349. /*! Remove an explicit cell from the specified index.
  350. @param cellIndex The zero-based index to remove the cell from.
  351. @return Whether the operation was successful or not.
  352. */
  353. ConsoleMethodWithDocs(ImageAsset, removeExplicitCell, ConsoleBool, 7, 7, (int cellIndex))
  354. {
  355. // Fetch cell index.
  356. const S32 cellIndex = dAtoi( argv[2] );
  357. return object->removeExplicitCell( cellIndex );
  358. }
  359. //-----------------------------------------------------------------------------
  360. /*! Set an explicit cell at the specified index.
  361. @param cellIndex The zero-based index to set the cell.
  362. @param cellOffsetX The offset in the X axis to the top-left of the cell.
  363. @param cellOffsetY The offset in the Y axis to the top-left of the cell.
  364. @param cellWidth The width of the cell.
  365. @param cellHeight The height of the cell.
  366. @param cellName The name of the cell's region.
  367. The image asset must be in explicit mode for this operation to succeed.
  368. @return Whether the operation was successful or not.
  369. */
  370. ConsoleMethodWithDocs(ImageAsset, setExplicitCell, ConsoleBool, 8, 8, (int cellIndex, int cellOffsetX, int cellOffsetY, int cellWidth, int cellHeight, string cellName))
  371. {
  372. // Fetch cell index.
  373. const S32 cellIndex = dAtoi( argv[2] );
  374. // Fetch offsets.
  375. const S32 cellOffsetX = dAtoi( argv[3] );
  376. const S32 cellOffsetY = dAtoi( argv[4] );
  377. // Fetch dimensions.
  378. const S32 cellWidth = dAtoi( argv[5] );
  379. const S32 cellHeight = dAtoi (argv[6] );
  380. return object->setExplicitCell( cellIndex, cellOffsetX, cellOffsetY, cellWidth, cellHeight, argv[7] );
  381. }
  382. //-----------------------------------------------------------------------------
  383. /*! Gets the explicit cell count.
  384. @return The explicit cell count.
  385. */
  386. ConsoleMethodWithDocs(ImageAsset, getExplicitCellCount, ConsoleInt, 2, 2, ())
  387. {
  388. return object->getExplicitCellCount();
  389. }
  390. //-----------------------------------------------------------------------------
  391. /*! Gets the CELL offset in Explicit Mode.
  392. @param cell The cell index or cell name to use to find the specific offset.
  393. @return The specified CELL width.
  394. */
  395. ConsoleMethodWithDocs(ImageAsset, getExplicitCellOffset, ConsoleString, 3, 3, (cell))
  396. {
  397. // Was it a number or a string?
  398. if (!dIsalpha(*argv[2]))
  399. {
  400. // Using cell index.
  401. const S32 cellIndex = dAtoi(argv[2]);
  402. return object->getExplicitCellOffset(cellIndex).scriptThis();
  403. }
  404. else
  405. {
  406. // Using cell name.
  407. ImageAsset::FrameArea& frameRegion = object->getCellByName(argv[2]);
  408. const Vector2 offset = frameRegion.mPixelArea.mPixelOffset;
  409. return offset.scriptThis();
  410. }
  411. }
  412. //-----------------------------------------------------------------------------
  413. /*! Gets the CELL width in Explicit Mode.
  414. @param cell The cell index or cell name to use to find the specific width.
  415. @return The specified CELL width.
  416. */
  417. ConsoleMethodWithDocs(ImageAsset, getExplicitCellWidth, ConsoleInt, 3, 3, (cell))
  418. {
  419. S32 cellIndex;
  420. // Was it a number or a string?
  421. if (!dIsalpha(*argv[2]))
  422. {
  423. // Using cell index.
  424. cellIndex = dAtoi(argv[2]);
  425. return object->getExplicitCellWidth(cellIndex);
  426. }
  427. else
  428. {
  429. // Using cell name.
  430. ImageAsset::FrameArea& frameRegion = object->getCellByName(argv[2]);
  431. return frameRegion.mPixelArea.mPixelWidth;
  432. }
  433. }
  434. //-----------------------------------------------------------------------------
  435. /*! Gets the CELL height in Explicit Mode.
  436. @param cell The cell index or cell name to use to find the specific height.
  437. @return The specified CELL height.
  438. */
  439. ConsoleMethodWithDocs(ImageAsset, getExplicitCellHeight, ConsoleInt, 3, 3, (cell))
  440. {
  441. S32 cellIndex;
  442. // Was it a number or a string?
  443. if (!dIsalpha(*argv[2]))
  444. {
  445. // Using cell index.
  446. cellIndex = dAtoi(argv[2]);
  447. return object->getExplicitCellHeight(cellIndex);
  448. }
  449. else
  450. {
  451. // Using cell name.
  452. ImageAsset::FrameArea& frameRegion = object->getCellByName(argv[2]);
  453. return frameRegion.mPixelArea.mPixelHeight;
  454. }
  455. }
  456. //-----------------------------------------------------------------------------
  457. /*! Gets the CELL region name in Explicit Mode.
  458. @param cell The cell index to use to find the specific name.
  459. @return The specified CELL region name.
  460. */
  461. ConsoleMethodWithDocs(ImageAsset, getExplicitCellName, ConsoleString, 3, 3, (cell))
  462. {
  463. // Fetch cell index.
  464. const S32 cellIndex = dAtoi(argv[2]);
  465. return object->getExplicitCellName(cellIndex);
  466. }
  467. //-----------------------------------------------------------------------------
  468. /*! Gets the CELL index number in Explicit Mode.
  469. @param cellName The cell name to use to find the specific index.
  470. @return The specified CELL index number.
  471. */
  472. ConsoleMethodWithDocs(ImageAsset, getExplicitCellIndex, ConsoleInt, 3, 3, (cellName))
  473. {
  474. return object->getExplicitCellIndex( argv[2] );
  475. }
  476. /*! Gets the status of Explicit mode
  477. @return Returns true if ExplicitMode is on, false otherwise.
  478. */
  479. ConsoleMethodWithDocs(ImageAsset, getExplicitMode, ConsoleBool, 2, 2, ())
  480. {
  481. return object->getExplicitMode();
  482. }
  483. /*! Sets Explicit Mode
  484. @param explicitMode Whether to set Explicit Mode or disable it
  485. @return No return value.
  486. */
  487. ConsoleMethodWithDocs(ImageAsset, setExplicitMode, ConsoleVoid, 3, 3, (explicitMode))
  488. {
  489. object->setExplicitMode(dAtob(argv[2]));
  490. }
  491. ConsoleMethodGroupEndWithDocs(ImageAsset)