ImageAsset_ScriptBinding.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. ConsoleMethod(ImageAsset, setImageFile, void, 3, 3, "(ImageFile) Sets the image file (bitmap file).\n"
  23. "@return No return value.")
  24. {
  25. object->setImageFile( argv[2] );
  26. }
  27. //-----------------------------------------------------------------------------
  28. ConsoleMethod(ImageAsset, getImageFile, const char*, 2, 2, "() Gets the image file.\n"
  29. "@return Returns the bitmap image file.")
  30. {
  31. return object->getImageFile();
  32. }
  33. //------------------------------------------------------------------------------
  34. ConsoleMethod(ImageAsset, setFilterMode, void, 3, 3, "(mode) Sets the filter mode.\n"
  35. "@return No return value.")
  36. {
  37. // Fetch Texture Filter Mode.
  38. const ImageAsset::TextureFilterMode filterMode = ImageAsset::getFilterModeEnum( argv[2] );
  39. // Valid Filter?
  40. if ( filterMode == ImageAsset::FILTER_INVALID )
  41. {
  42. // Warn.
  43. Con::warnf("ImageAsset::setFilterMode() - Invalid Filter Mode Specified! (%s)", argv[2] );
  44. // Finish Here.
  45. return;
  46. }
  47. // Set Filter Mode.
  48. object->setFilterMode( filterMode );
  49. }
  50. //------------------------------------------------------------------------------
  51. ConsoleMethod(ImageAsset, getFilterMode, const char*, 2, 2, "() Gets the filter mode.\n"
  52. "@return The filter mode.")
  53. {
  54. return ImageAsset::getFilterModeDescription( object->getFilterMode() );
  55. }
  56. //-----------------------------------------------------------------------------
  57. ConsoleMethod(ImageAsset, setForce16Bit, void, 3, 3, "(force16Bit?) Sets whether 16-bit image is forced or not.\n"
  58. "@return No return value.")
  59. {
  60. object->setForce16Bit( dAtob(argv[2]) );
  61. }
  62. //-----------------------------------------------------------------------------
  63. ConsoleMethod(ImageAsset, getForce16Bit, bool, 2, 2, "() Gets whether 16-bit image is forced or not.\n"
  64. "@return Whether 16-bit image is forced or not.")
  65. {
  66. return object->getForce16Bit();
  67. }
  68. //-----------------------------------------------------------------------------
  69. ConsoleMethod(ImageAsset, setCellRowOrder, void, 3, 3, "(rowOrder?) Sets whether CELL row order should be used or not.\n"
  70. "@return No return value.")
  71. {
  72. object->setCellRowOrder( dAtob(argv[2]) );
  73. }
  74. //-----------------------------------------------------------------------------
  75. ConsoleMethod(ImageAsset, getCellRowOrder, bool, 2, 2, "() Gets whether CELL row order should be used or not.\n"
  76. "@return Whether CELL row order should be used or not.")
  77. {
  78. return object->getCellRowOrder();
  79. }
  80. //-----------------------------------------------------------------------------
  81. ConsoleMethod(ImageAsset, setCellOffsetX, void, 3, 3, "(offsetX) Sets the CELL offset X.\n"
  82. "@return No return value.")
  83. {
  84. object->setCellOffsetX( dAtoi(argv[2]) );
  85. }
  86. //-----------------------------------------------------------------------------
  87. ConsoleMethod(ImageAsset, getCellOffsetX, S32, 2, 2, "() Gets the CELL offset X.\n"
  88. "@return The CELL offset X.")
  89. {
  90. return object->getCellOffsetX();
  91. }
  92. //-----------------------------------------------------------------------------
  93. ConsoleMethod(ImageAsset, setCellOffsetY, void, 3, 3, "(offsetY) Sets the CELL offset Y.\n"
  94. "@return No return value.")
  95. {
  96. object->setCellOffsetY( dAtoi(argv[2]) );
  97. }
  98. //-----------------------------------------------------------------------------
  99. ConsoleMethod(ImageAsset, getCellOffsetY, S32, 2, 2, "() Gets the CELL offset Y.\n"
  100. "@return The CELL offset Y.")
  101. {
  102. return object->getCellOffsetY();
  103. }
  104. //-----------------------------------------------------------------------------
  105. ConsoleMethod(ImageAsset, setCellStrideX, void, 3, 3, "(strideX) Sets the CELL stride X.\n"
  106. "@return No return value.")
  107. {
  108. object->setCellStrideX( dAtoi(argv[2]) );
  109. }
  110. //-----------------------------------------------------------------------------
  111. ConsoleMethod(ImageAsset, getCellStrideX, S32, 2, 2, "() Gets the CELL stride X.\n"
  112. "@return The CELL stride X.")
  113. {
  114. return object->getCellStrideX();
  115. }
  116. //-----------------------------------------------------------------------------
  117. ConsoleMethod(ImageAsset, setCellStrideY, void, 3, 3, "(strideY) Sets the CELL stride Y.\n"
  118. "@return No return value.")
  119. {
  120. object->setCellStrideY( dAtoi(argv[2]) );
  121. }
  122. //-----------------------------------------------------------------------------
  123. ConsoleMethod(ImageAsset, getCellStrideY, S32, 2, 2, "() Gets the CELL stride Y.\n"
  124. "@return The CELL stride Y.")
  125. {
  126. return object->getCellStrideY();
  127. }
  128. //-----------------------------------------------------------------------------
  129. ConsoleMethod(ImageAsset, setCellCountX, void, 3, 3, "(countX) Sets the CELL count X.\n"
  130. "@return No return value.")
  131. {
  132. object->setCellCountX( dAtoi(argv[2]) );
  133. }
  134. //-----------------------------------------------------------------------------
  135. ConsoleMethod(ImageAsset, getCellCountX, S32, 2, 2, "() Gets the CELL count X.\n"
  136. "@return The CELL count X.")
  137. {
  138. return object->getCellCountX();
  139. }
  140. //-----------------------------------------------------------------------------
  141. ConsoleMethod(ImageAsset, setCellCountY, void, 3, 3, "(countY) Sets the CELL count Y.\n"
  142. "@return No return value.")
  143. {
  144. object->setCellCountY( dAtoi(argv[2]) );
  145. }
  146. //-----------------------------------------------------------------------------
  147. ConsoleMethod(ImageAsset, getCellCountY, S32, 2, 2, "() Gets the CELL count Y.\n"
  148. "@return The CELL count Y.")
  149. {
  150. return object->getCellCountY();
  151. }
  152. //-----------------------------------------------------------------------------
  153. ConsoleMethod(ImageAsset, setCellWidth, void, 3, 3, "(Width) Sets the CELL width.\n"
  154. "@return No return value.")
  155. {
  156. object->setCellWidth( dAtoi(argv[2]) );
  157. }
  158. //-----------------------------------------------------------------------------
  159. ConsoleMethod(ImageAsset, getCellWidth, S32, 2, 2, "() Gets the CELL width.\n"
  160. "@return The CELL width.")
  161. {
  162. return object->getCellWidth();
  163. }
  164. //-----------------------------------------------------------------------------
  165. ConsoleMethod(ImageAsset, setCellHeight, void, 3, 3, "(Height) Sets the CELL height.\n"
  166. "@return No return value.")
  167. {
  168. object->setCellHeight( dAtoi(argv[2]) );
  169. }
  170. //-----------------------------------------------------------------------------
  171. ConsoleMethod(ImageAsset, getCellHeight, S32, 2, 2, "() Gets the CELL height.\n"
  172. "@return The CELL height.")
  173. {
  174. return object->getCellHeight();
  175. }
  176. //-----------------------------------------------------------------------------
  177. ConsoleMethod(ImageAsset, getImageWidth, S32, 2, 2, "() Gets the image width.\n"
  178. "@return The image width.")
  179. {
  180. return object->getImageWidth();
  181. }
  182. //-----------------------------------------------------------------------------
  183. ConsoleMethod(ImageAsset, getImageHeight, S32, 2, 2, "() Gets the image height.\n"
  184. "@return The image width.")
  185. {
  186. return object->getImageHeight();
  187. }
  188. //-----------------------------------------------------------------------------
  189. ConsoleMethod(ImageAsset, getImageSize, const char*, 2, 2, "() Gets the image size.\n"
  190. "@return The image size.")
  191. {
  192. // Create Returnable Buffer.
  193. char* pBuffer = Con::getReturnBuffer(32);
  194. // Format Buffer.
  195. dSprintf(pBuffer, 32, "%d %d", object->getImageWidth(), object->getImageHeight());
  196. // Return Buffer.
  197. return pBuffer;
  198. }
  199. //-----------------------------------------------------------------------------
  200. ConsoleMethod(ImageAsset, getIsImagePOT, bool, 2, 2, "() Gets whether the image has a power-of-two dimensions or not.\n"
  201. "@return Whether the image has a power-of-two dimensions or not." )
  202. {
  203. return isPow2( object->getImageWidth() ) && isPow2( object->getImageHeight() );
  204. }
  205. //-----------------------------------------------------------------------------
  206. ConsoleMethod(ImageAsset, getFrameCount, S32, 2, 2, "() Gets the frame count.\n"
  207. "@return The frame count.")
  208. {
  209. return object->getFrameCount();
  210. }
  211. //-----------------------------------------------------------------------------
  212. ConsoleMethod(ImageAsset, getFrameSize, const char*, 3, 3, "(int frame) - Gets the specified frames size.\n"
  213. "@param frame The frame number to use.\n"
  214. "@return The specified frames size.")
  215. {
  216. // Fetch Frame.
  217. const S32 frame = dAtoi(argv[2]);
  218. // Check Frame.
  219. if ( frame < 0 || frame >= (S32)object->getFrameCount() )
  220. {
  221. // Warn.
  222. Con::warnf("ImageAsset::getFrameSize() - Invalid Frame; Allowed range is 0 to %d", object->getFrameCount()-1 );
  223. // Finish Here.
  224. return NULL;
  225. }
  226. // Fetch Selected Frame Pixel Area.
  227. const ImageAsset::FrameArea::PixelArea& framePixelArea = object->getImageFrameArea( frame ).mPixelArea;
  228. // Create Returnable Buffer.
  229. char* pBuffer = Con::getReturnBuffer(32);
  230. // Format Buffer.
  231. dSprintf(pBuffer, 32, "%d %d", framePixelArea.mPixelWidth, framePixelArea.mPixelHeight );
  232. // Return Velocity.
  233. return pBuffer;
  234. }
  235. //-----------------------------------------------------------------------------
  236. ConsoleMethod(ImageAsset, clearExplicitCells, bool, 2, 2, "() Clears all explicit cells.\n"
  237. "The image asset stays in explicit mode however with no explicit cells a single full-frame cell becomes default.\n"
  238. "@return Whether the operation was successful or not.")
  239. {
  240. return object->clearExplicitCells();
  241. }
  242. //-----------------------------------------------------------------------------
  243. ConsoleMethod(ImageAsset, addExplicitCell, bool, 6, 6, "(int cellOffsetX, int cellOffsetY, int cellWidth, int cellHeight) Add an explicit cell.\n"
  244. "@param cellOffsetX The offset in the X axis to the top-left of the cell.\n"
  245. "@param cellOffsetY The offset in the Y axis to the top-left of the cell.\n"
  246. "@param cellWidth The width of the cell.\n"
  247. "@param cellHeight The height of the cell.\n"
  248. "The image asset must be in explicit mode for this operation to succeed.\n"
  249. "@return Whether the operation was successful or not.")
  250. {
  251. // Fetch offsets.
  252. const S32 cellOffsetX = dAtoi( argv[2] );
  253. const S32 cellOffsetY = dAtoi( argv[3] );
  254. // Fetch dimensions.
  255. const S32 cellWidth = dAtoi( argv[4] );
  256. const S32 cellHeight = dAtoi (argv[5] );
  257. return object->addExplicitCell( cellOffsetX, cellOffsetY, cellWidth, cellHeight );
  258. }
  259. //-----------------------------------------------------------------------------
  260. ConsoleMethod(ImageAsset, insertExplicitCell, bool, 7, 7, "(int cellIndex, int cellOffsetX, int cellOffsetY, int cellWidth, int cellHeight) Insert an explicit cell at the specified index.\n"
  261. "@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.\n"
  262. "@param cellOffsetX The offset in the X axis to the top-left of the cell.\n"
  263. "@param cellOffsetY The offset in the Y axis to the top-left of the cell.\n"
  264. "@param cellWidth The width of the cell.\n"
  265. "@param cellHeight The height of the cell.\n"
  266. "The image asset must be in explicit mode for this operation to succeed.\n"
  267. "@return Whether the operation was successful or not.")
  268. {
  269. // Fetch cell index.
  270. const S32 cellIndex = dAtoi( argv[2] );
  271. // Fetch offsets.
  272. const S32 cellOffsetX = dAtoi( argv[3] );
  273. const S32 cellOffsetY = dAtoi( argv[4] );
  274. // Fetch dimensions.
  275. const S32 cellWidth = dAtoi( argv[5] );
  276. const S32 cellHeight = dAtoi (argv[6] );
  277. return object->insertExplicitCell( cellIndex, cellOffsetX, cellOffsetY, cellWidth, cellHeight );
  278. }
  279. //-----------------------------------------------------------------------------
  280. ConsoleMethod(ImageAsset, removeExplicitCell, bool, 7, 7, "(int cellIndex) Remove an explicit cell from the specified index.\n"
  281. "@param cellIndex The zero-based index to remove the cell from.\n"
  282. "@return Whether the operation was successful or not.")
  283. {
  284. // Fetch cell index.
  285. const S32 cellIndex = dAtoi( argv[2] );
  286. return object->removeExplicitCell( cellIndex );
  287. }
  288. //-----------------------------------------------------------------------------
  289. ConsoleMethod(ImageAsset, setExplicitCell, bool, 7, 7, "(int cellIndex, int cellOffsetX, int cellOffsetY, int cellWidth, int cellHeight) Set an explicit cell at the specified index.\n"
  290. "@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.\n"
  291. "@param cellOffsetX The offset in the X axis to the top-left of the cell.\n"
  292. "@param cellOffsetY The offset in the Y axis to the top-left of the cell.\n"
  293. "@param cellWidth The width of the cell.\n"
  294. "@param cellHeight The height of the cell.\n"
  295. "The image asset must be in explicit mode for this operation to succeed.\n"
  296. "@return Whether the operation was successful or not.")
  297. {
  298. // Fetch cell index.
  299. const S32 cellIndex = dAtoi( argv[2] );
  300. // Fetch offsets.
  301. const S32 cellOffsetX = dAtoi( argv[3] );
  302. const S32 cellOffsetY = dAtoi( argv[4] );
  303. // Fetch dimensions.
  304. const S32 cellWidth = dAtoi( argv[5] );
  305. const S32 cellHeight = dAtoi (argv[6] );
  306. return object->setExplicitCell( cellIndex, cellOffsetX, cellOffsetY, cellWidth, cellHeight );
  307. }
  308. //-----------------------------------------------------------------------------
  309. ConsoleMethod(ImageAsset, getExplicitCellCount, S32, 2, 2, "() Gets the explicit cell count.\n"
  310. "@return The explicit cell count.")
  311. {
  312. return object->getExplicitCellCount();
  313. }