ImageAsset_ScriptBinding.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  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. /*! Gets the CELL width in Explicit Mode.
  211. @return the specified CELL width.
  212. */
  213. ConsoleMethodWithDocs(ImageAsset, getExplicitCellWidth, ConsoleInt, 3,3, (CellIndex))
  214. {
  215. // Fetch cell index.
  216. const S32 cellIndex = dAtoi( argv[2] );
  217. return(object->getExplicitCellWidth(cellIndex));
  218. }
  219. //-----------------------------------------------------------------------------
  220. /*! Gets the CELL height in Explicit Mode.
  221. @return the specified CELL height.
  222. */
  223. ConsoleMethodWithDocs(ImageAsset, getExplicitCellHeight, ConsoleInt, 3,3, (CellIndex))
  224. {
  225. // Fetch cell index.
  226. const S32 cellIndex = dAtoi( argv[2] );
  227. return(object->getExplicitCellHeight(cellIndex));
  228. }
  229. //-----------------------------------------------------------------------------
  230. /*! Sets the CELL height.
  231. @return No return value.
  232. */
  233. ConsoleMethodWithDocs(ImageAsset, setCellHeight, ConsoleVoid, 3, 3, (Height))
  234. {
  235. object->setCellHeight( dAtoi(argv[2]) );
  236. }
  237. //-----------------------------------------------------------------------------
  238. /*! Gets the CELL height.
  239. @return The CELL height.
  240. */
  241. ConsoleMethodWithDocs(ImageAsset, getCellHeight, ConsoleInt, 2, 2, ())
  242. {
  243. return object->getCellHeight();
  244. }
  245. //-----------------------------------------------------------------------------
  246. /*! Gets the image width.
  247. @return The image width.
  248. */
  249. ConsoleMethodWithDocs(ImageAsset, getImageWidth, ConsoleInt, 2, 2, ())
  250. {
  251. return object->getImageWidth();
  252. }
  253. //-----------------------------------------------------------------------------
  254. /*! Gets the image height.
  255. @return The image width.
  256. */
  257. ConsoleMethodWithDocs(ImageAsset, getImageHeight, ConsoleInt, 2, 2, ())
  258. {
  259. return object->getImageHeight();
  260. }
  261. //-----------------------------------------------------------------------------
  262. /*! Gets the image size.
  263. @return The image size.
  264. */
  265. ConsoleMethodWithDocs(ImageAsset, getImageSize, ConsoleString, 2, 2, ())
  266. {
  267. // Create Returnable Buffer.
  268. char* pBuffer = Con::getReturnBuffer(32);
  269. // Format Buffer.
  270. dSprintf(pBuffer, 32, "%d %d", object->getImageWidth(), object->getImageHeight());
  271. // Return Buffer.
  272. return pBuffer;
  273. }
  274. //-----------------------------------------------------------------------------
  275. /*! Gets whether the image has a power-of-two dimensions or not.
  276. @return Whether the image has a power-of-two dimensions or not.
  277. */
  278. ConsoleMethodWithDocs(ImageAsset, getIsImagePOT, ConsoleBool, 2, 2, ())
  279. {
  280. return isPow2( object->getImageWidth() ) && isPow2( object->getImageHeight() );
  281. }
  282. //-----------------------------------------------------------------------------
  283. /*! Gets the frame count.
  284. @return The frame count.
  285. */
  286. ConsoleMethodWithDocs(ImageAsset, getFrameCount, ConsoleInt, 2, 2, ())
  287. {
  288. return object->getFrameCount();
  289. }
  290. //-----------------------------------------------------------------------------
  291. /*! Gets the specified frames size.
  292. @param frame The frame number to use.
  293. @return The specified frames size.
  294. */
  295. ConsoleMethodWithDocs(ImageAsset, getFrameSize, ConsoleString, 3, 3, (int frame))
  296. {
  297. // Fetch Frame.
  298. const S32 frame = dAtoi(argv[2]);
  299. // Check Frame.
  300. if ( frame < 0 || frame >= (S32)object->getFrameCount() )
  301. {
  302. // Warn.
  303. Con::warnf("ImageAsset::getFrameSize() - Invalid Frame; Allowed range is 0 to %d", object->getFrameCount()-1 );
  304. // Finish Here.
  305. return NULL;
  306. }
  307. // Fetch Selected Frame Pixel Area.
  308. const ImageAsset::FrameArea::PixelArea& framePixelArea = object->getImageFrameArea( frame ).mPixelArea;
  309. // Create Returnable Buffer.
  310. char* pBuffer = Con::getReturnBuffer(32);
  311. // Format Buffer.
  312. dSprintf(pBuffer, 32, "%d %d", framePixelArea.mPixelWidth, framePixelArea.mPixelHeight );
  313. // Return Velocity.
  314. return pBuffer;
  315. }
  316. //-----------------------------------------------------------------------------
  317. /*! Clears all explicit cells.
  318. The image asset stays in explicit mode however with no explicit cells a single full-frame cell becomes default.
  319. @return Whether the operation was successful or not.
  320. */
  321. ConsoleMethodWithDocs(ImageAsset, clearExplicitCells, ConsoleBool, 2, 2, ())
  322. {
  323. return object->clearExplicitCells();
  324. }
  325. //-----------------------------------------------------------------------------
  326. /*! Add an explicit cell.
  327. @param cellOffsetX The offset in the X axis to the top-left of the cell.
  328. @param cellOffsetY The offset in the Y axis to the top-left of the cell.
  329. @param cellWidth The width of the cell.
  330. @param cellHeight The height of the cell.
  331. @param cellName The name of the cell's region.
  332. The image asset must be in explicit mode for this operation to succeed.
  333. @return Whether the operation was successful or not.
  334. */
  335. ConsoleMethodWithDocs(ImageAsset, addExplicitCell, ConsoleBool, 7, 7, (int cellOffsetX, int cellOffsetY, int cellWidth, int cellHeight, string cellName))
  336. {
  337. // Fetch offsets.
  338. const S32 cellOffsetX = dAtoi( argv[2] );
  339. const S32 cellOffsetY = dAtoi( argv[3] );
  340. // Fetch dimensions.
  341. const S32 cellWidth = dAtoi( argv[4] );
  342. const S32 cellHeight = dAtoi (argv[5] );
  343. return object->addExplicitCell( cellOffsetX, cellOffsetY, cellWidth, cellHeight, argv[6] );
  344. }
  345. //-----------------------------------------------------------------------------
  346. /*! Insert an explicit cell at the specified index.
  347. @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.
  348. @param cellOffsetX The offset in the X axis to the top-left of the cell.
  349. @param cellOffsetY The offset in the Y axis to the top-left of the cell.
  350. @param cellWidth The width of the cell.
  351. @param cellHeight The height of the cell.
  352. @param cellName The name of the cell's region.
  353. The image asset must be in explicit mode for this operation to succeed.
  354. @return Whether the operation was successful or not.
  355. */
  356. ConsoleMethodWithDocs(ImageAsset, insertExplicitCell, ConsoleBool, 8, 8, (int cellIndex, int cellOffsetX, int cellOffsetY, int cellWidth, int cellHeight, string cellName))
  357. {
  358. // Fetch cell index.
  359. const S32 cellIndex = dAtoi( argv[2] );
  360. // Fetch offsets.
  361. const S32 cellOffsetX = dAtoi( argv[3] );
  362. const S32 cellOffsetY = dAtoi( argv[4] );
  363. // Fetch dimensions.
  364. const S32 cellWidth = dAtoi( argv[5] );
  365. const S32 cellHeight = dAtoi (argv[6] );
  366. return object->insertExplicitCell( cellIndex, cellOffsetX, cellOffsetY, cellWidth, cellHeight, argv[7] );
  367. }
  368. //-----------------------------------------------------------------------------
  369. /*! Remove an explicit cell from the specified index.
  370. @param cellIndex The zero-based index to remove the cell from.
  371. @return Whether the operation was successful or not.
  372. */
  373. ConsoleMethodWithDocs(ImageAsset, removeExplicitCell, ConsoleBool, 7, 7, (int cellIndex))
  374. {
  375. // Fetch cell index.
  376. const S32 cellIndex = dAtoi( argv[2] );
  377. return object->removeExplicitCell( cellIndex );
  378. }
  379. //-----------------------------------------------------------------------------
  380. /*! Set an explicit cell at the specified index.
  381. @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.
  382. @param cellOffsetX The offset in the X axis to the top-left of the cell.
  383. @param cellOffsetY The offset in the Y axis to the top-left of the cell.
  384. @param cellWidth The width of the cell.
  385. @param cellHeight The height of the cell.
  386. @param cellName The name of the cell's region.
  387. The image asset must be in explicit mode for this operation to succeed.
  388. @return Whether the operation was successful or not.
  389. */
  390. ConsoleMethodWithDocs(ImageAsset, setExplicitCell, ConsoleBool, 8, 8, (int cellIndex, int cellOffsetX, int cellOffsetY, int cellWidth, int cellHeight, string cellName))
  391. {
  392. // Fetch cell index.
  393. const S32 cellIndex = dAtoi( argv[2] );
  394. // Fetch offsets.
  395. const S32 cellOffsetX = dAtoi( argv[3] );
  396. const S32 cellOffsetY = dAtoi( argv[4] );
  397. // Fetch dimensions.
  398. const S32 cellWidth = dAtoi( argv[5] );
  399. const S32 cellHeight = dAtoi (argv[6] );
  400. return object->setExplicitCell( cellIndex, cellOffsetX, cellOffsetY, cellWidth, cellHeight, argv[7] );
  401. }
  402. //-----------------------------------------------------------------------------
  403. /*! Gets the explicit cell count.
  404. @return The explicit cell count.
  405. */
  406. ConsoleMethodWithDocs(ImageAsset, getExplicitCellCount, ConsoleInt, 2, 2, ())
  407. {
  408. return object->getExplicitCellCount();
  409. }
  410. ConsoleMethodGroupEndWithDocs(ImageAsset)