TextSprite_ScriptBinding.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  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(TextSprite, SceneObject)
  23. /*! Sets the image asset to use..
  24. @param fontName The font asset to use.
  25. @return Returns true on success.
  26. */
  27. ConsoleMethodWithDocs(TextSprite, setFont, ConsoleBool, 3, 3, (fontAssetId))
  28. {
  29. return object->setFont( argv[2] );
  30. }
  31. //-----------------------------------------------------------------------------
  32. /*! Gets current font asset..
  33. @return The current font asset.
  34. */
  35. ConsoleMethodWithDocs(TextSprite, getFont, ConsoleString, 2, 2, ())
  36. {
  37. return object->getFont();
  38. }
  39. //-----------------------------------------------------------------------------
  40. /*! Sets the text to render.
  41. */
  42. ConsoleMethodWithDocs(TextSprite, setText, ConsoleVoid, 3, 3, (text))
  43. {
  44. object->setText(argv[2]);
  45. }
  46. //-----------------------------------------------------------------------------
  47. /*! Gets the text being rendered.
  48. */
  49. ConsoleMethodWithDocs(TextSprite, getText, ConsoleString, 2, 2, ())
  50. {
  51. return object->getText().getPtr8();
  52. }
  53. //-----------------------------------------------------------------------------
  54. /*! Sets the size of the font.
  55. @param size The distance between the top of a line of text and the bottom.
  56. @return No return value.
  57. */
  58. ConsoleMethodWithDocs(TextSprite, setFontSize, ConsoleVoid, 3, 3, (size))
  59. {
  60. object->setFontSize(dAtof(argv[2]));
  61. }
  62. //-----------------------------------------------------------------------------
  63. /*! Gets the size of the font.
  64. @return The size of the font.
  65. */
  66. ConsoleMethodWithDocs(TextSprite, getFontSize, ConsoleFloat, 2, 2, ())
  67. {
  68. return object->getFontSize();
  69. }
  70. //-----------------------------------------------------------------------------
  71. /*! Sets the scale of the font in the X direction.
  72. @param scale The amount to multiply the width of the text by.
  73. @return No return value.
  74. */
  75. ConsoleMethodWithDocs(TextSprite, setFontScaleX, ConsoleVoid, 3, 3, (scale))
  76. {
  77. object->setFontScaleX(dAtof(argv[2]));
  78. }
  79. //-----------------------------------------------------------------------------
  80. /*! Gets the scale of the font in the X direction.
  81. @return The scale of the of the font in the X direction.
  82. */
  83. ConsoleMethodWithDocs(TextSprite, getFontScaleX, ConsoleFloat, 2, 2, ())
  84. {
  85. return object->getFontScaleX();
  86. }
  87. //-----------------------------------------------------------------------------
  88. /*! Sets the scale of the font in the Y direction.
  89. @param scale The amount to multiply the height of the text by.
  90. @return No return value.
  91. */
  92. ConsoleMethodWithDocs(TextSprite, setFontScaleY, ConsoleVoid, 3, 3, (scale))
  93. {
  94. object->setFontScaleY(dAtof(argv[2]));
  95. }
  96. //-----------------------------------------------------------------------------
  97. /*! Gets the scale of the font in the Y direction.
  98. @return The scale of the of the font in the Y direction.
  99. */
  100. ConsoleMethodWithDocs(TextSprite, getFontScaleY, ConsoleFloat, 2, 2, ())
  101. {
  102. return object->getFontScaleY();
  103. }
  104. //-----------------------------------------------------------------------------
  105. /*! Sets the horizontal text alignment to 'left', 'center', 'right', or 'justify'.
  106. @param alignment The text alignment of 'left', 'center', 'right', or 'justify'.
  107. @return No return value.
  108. */
  109. ConsoleMethodWithDocs(TextSprite, setTextAlignment, ConsoleVoid, 3, 3, (alignment))
  110. {
  111. object->setTextAlignment( TextSprite::getTextAlignmentEnum(argv[2]) );
  112. }
  113. //-----------------------------------------------------------------------------
  114. /*! Gets the horizontal text alignment.
  115. @return The text alignment of 'left', 'center', 'right', or 'justify'.
  116. */
  117. ConsoleMethodWithDocs(TextSprite, getTextAlignment, ConsoleString, 2, 2, ())
  118. {
  119. return TextSprite::getTextAlignmentDescription(object->getTextAlignment());
  120. }
  121. //-----------------------------------------------------------------------------
  122. /*! Sets the vertical text alignment to 'top', 'middle', or 'bottom'.
  123. @param alignment The vertical text alignment of 'top', 'middle', or 'bottom'.
  124. @return No return value.
  125. */
  126. ConsoleMethodWithDocs(TextSprite, setTextVAlignment, ConsoleVoid, 3, 3, (alignment))
  127. {
  128. object->setTextVAlignment(TextSprite::getTextVAlignmentEnum(argv[2]));
  129. }
  130. //-----------------------------------------------------------------------------
  131. /*! Gets the vertical text alignment.
  132. @return The vertical text alignment of 'top', 'middle', or 'bottom'.
  133. */
  134. ConsoleMethodWithDocs(TextSprite, getTextVAlignment, ConsoleString, 2, 2, ())
  135. {
  136. return TextSprite::getTextVAlignmentDescription(object->getTextVAlignment());
  137. }
  138. //-----------------------------------------------------------------------------
  139. /*! Sets the overflow mode X to 'wrap', 'visible', 'hidden', or 'shrink'.
  140. @param mode The overflow mode X of 'wrap', 'visible', 'hidden', or 'shrink'.
  141. @return No return value.
  142. */
  143. ConsoleMethodWithDocs(TextSprite, setOverflowModeX, ConsoleVoid, 3, 3, (mode))
  144. {
  145. object->setOverflowModeX(TextSprite::getOverflowModeXEnum(argv[2]));
  146. }
  147. //-----------------------------------------------------------------------------
  148. /*! Gets the overflow mode X.
  149. @return The overflow mode X of 'wrap', 'visible', 'hidden', or 'shrink'.
  150. */
  151. ConsoleMethodWithDocs(TextSprite, getOverflowModeX, ConsoleString, 2, 2, ())
  152. {
  153. return TextSprite::getOverflowModeXDescription(object->getOverflowModeX());
  154. }
  155. //-----------------------------------------------------------------------------
  156. /*! Sets the overflow mode Y to 'visible', 'hidden', or 'shrink'.
  157. @param mode The overflow mode Y of 'visible', 'hidden', or 'shrink'.
  158. @return No return value.
  159. */
  160. ConsoleMethodWithDocs(TextSprite, setOverflowModeY, ConsoleVoid, 3, 3, (mode))
  161. {
  162. object->setOverflowModeY(TextSprite::getOverflowModeYEnum(argv[2]));
  163. }
  164. //-----------------------------------------------------------------------------
  165. /*! Gets the overflow mode Y.
  166. @return The overflow mode Y of 'visible', 'hidden', or 'shrink'.
  167. */
  168. ConsoleMethodWithDocs(TextSprite, getOverflowModeY, ConsoleString, 2, 2, ())
  169. {
  170. return TextSprite::getOverflowModeYDescription(object->getOverflowModeY());
  171. }
  172. //-----------------------------------------------------------------------------
  173. /*! Sets if the line height should be automatically calculated.
  174. @param isAuto True if the line height automatically calculated or false to use the custom line height.
  175. @return No return value.
  176. */
  177. ConsoleMethodWithDocs(TextSprite, setAutoLineHeight, ConsoleVoid, 3, 3, (isAuto))
  178. {
  179. object->setAutoLineHeight(dAtob(argv[2]));
  180. }
  181. //-----------------------------------------------------------------------------
  182. /*! Gets whether the line height is automatically calculated.
  183. @return True if the line height is automatically calculated or false if the custom line height is used.
  184. */
  185. ConsoleMethodWithDocs(TextSprite, getAutoLineHeight, ConsoleBool, 2, 2, ())
  186. {
  187. return object->getAutoLineHeight();
  188. }
  189. //-----------------------------------------------------------------------------
  190. /*! Sets the custom line height and disables the auto line height.
  191. @param lineHeight The distance between the top and the bottom of a line before adjusting by the fontScaleY.
  192. @return No return value.
  193. */
  194. ConsoleMethodWithDocs(TextSprite, setCustomLineHeight, ConsoleVoid, 3, 3, (lineHeight))
  195. {
  196. object->setCustomLineHeight(dAtof(argv[2]));
  197. object->setAutoLineHeight(false);
  198. }
  199. //-----------------------------------------------------------------------------
  200. /*! Gets the custom line height.
  201. @return The distance between the top and the bottom of a line.
  202. */
  203. ConsoleMethodWithDocs(TextSprite, getCustomLineHeight, ConsoleFloat, 2, 2, ())
  204. {
  205. return object->getCustomLineHeight();
  206. }
  207. //-----------------------------------------------------------------------------
  208. /*! Sets kerning to be used between each character. Kerning is ignored when using alignment of 'justify'.
  209. @param kerning The amount to decrease the distance by between each character. Positive valus move the characters closer together and negative values move them apart.
  210. @return No return value.
  211. */
  212. ConsoleMethodWithDocs(TextSprite, setKerning, ConsoleVoid, 3, 3, (kerning))
  213. {
  214. object->setKerning(dAtof(argv[2]));
  215. }
  216. //-----------------------------------------------------------------------------
  217. /*! Gets the kerning amount.
  218. @return The amount each character is moved closer together.
  219. */
  220. ConsoleMethodWithDocs(TextSprite, getKerning, ConsoleFloat, 2, 2, ())
  221. {
  222. return object->getKerning();
  223. }
  224. //-----------------------------------------------------------------------------
  225. /*! Resets the blend color, scale, and offset for all characters'.
  226. @return No return value.
  227. */
  228. ConsoleMethodWithDocs(TextSprite, resetCharacterSettings, ConsoleVoid, 2, 2, ())
  229. {
  230. object->resetCharacterSettings();
  231. }
  232. //-----------------------------------------------------------------------------
  233. /*! Sets the blend color for an individual character.
  234. @param index The zero based index for the character.
  235. @param color The blend color to use for character.
  236. @return No return value.
  237. */
  238. ConsoleMethodWithDocs(TextSprite, setCharacterBlendColor, ConsoleVoid, 4, 4, (index, color))
  239. {
  240. if (argc < 3)
  241. {
  242. Con::warnf("TextSprite::setCharacterBlendColor() - Invalid number of parameters!");
  243. return;
  244. }
  245. const U32 colorCount = Utility::mGetStringElementCount(argv[3]);
  246. if (colorCount != 4)
  247. {
  248. Con::warnf("TextSprite::setCharacterBlendColor() - Invalid color! Colors require four values (red / green / blue / alpha)!");
  249. return;
  250. }
  251. object->setCharacterBlendColor(dAtoi(argv[2]), ColorF(dAtof(Utility::mGetStringElement(argv[3], 0)),
  252. dAtof(Utility::mGetStringElement(argv[3], 1)),
  253. dAtof(Utility::mGetStringElement(argv[3], 2)),
  254. dAtof(Utility::mGetStringElement(argv[3], 3))));
  255. }
  256. //-----------------------------------------------------------------------------
  257. /*! Gets the blend color for an individual character if set or the blend color for the sprite.
  258. @param index The zero based index for the character.
  259. @return The blend color for the character or the sprite.
  260. */
  261. ConsoleMethodWithDocs(TextSprite, getCharacterBlendColor, ConsoleString, 3, 3, (index))
  262. {
  263. U32 charNum = dAtoi(argv[2]);
  264. if (object->getCharacterHasBlendColor(charNum))
  265. {
  266. return object->getCharacterBlendColor(charNum).scriptThis();
  267. }
  268. else
  269. {
  270. return object->getBlendColor().scriptThis();
  271. }
  272. }
  273. //-----------------------------------------------------------------------------
  274. /*! Gets if the character is using a custom blend color.
  275. @param index The zero based index for the character.
  276. @return True if the character is using a custom blend color or false if the character uses the sprite's blend color.
  277. */
  278. ConsoleMethodWithDocs(TextSprite, getCharacterHasBlendColor, ConsoleBool, 3, 3, (index))
  279. {
  280. return object->getCharacterHasBlendColor(dAtoi(argv[2]));
  281. }
  282. //-----------------------------------------------------------------------------
  283. /*! Resets the blend color for a character so that it uses the sprite's blend color.
  284. @param index The zero based index for the character.
  285. @return No return value.
  286. */
  287. ConsoleMethodWithDocs(TextSprite, resetCharacterBlendColor, ConsoleVoid, 3, 3, (index))
  288. {
  289. object->resetCharacterBlendColor(dAtoi(argv[2]));
  290. }
  291. //-----------------------------------------------------------------------------
  292. /*! Sets the scale of a given character. This is multiplied by the scale of the font to get the total scale.
  293. @param index The zero based index for the character.
  294. @param (scaleX / scaleY) The amount to multiply the size of the character by. Default value is 1.
  295. @return No return value.
  296. */
  297. ConsoleMethodWithDocs(TextSprite, setCharacterScale, ConsoleVoid, 4, 4, (index, scale scaleX / scaleY))
  298. {
  299. U32 charNum = dAtoi(argv[2]);
  300. const U32 count = Utility::mGetStringElementCount(argv[3]);
  301. if (count != 2)
  302. {
  303. Con::warnf("TextSprite::setCharacterScale() - Invalid number of values (scaleX / scaleY)!");
  304. return;
  305. }
  306. object->setCharacterScale(charNum, dAtof(Utility::mGetStringElement(argv[3], 0)), dAtof(Utility::mGetStringElement(argv[3], 1)));
  307. }
  308. //-----------------------------------------------------------------------------
  309. /*! Gets scale of a given character.
  310. @param index The zero based index for the character.
  311. @return (scaleX / scaleY) The scale of the character.
  312. */
  313. ConsoleMethodWithDocs(TextSprite, getCharacterScale, ConsoleString, 3, 3, (index))
  314. {
  315. return object->getCharacterScale(dAtoi(argv[2])).scriptThis();
  316. }
  317. //-----------------------------------------------------------------------------
  318. /*! Resets the scale of a given character.
  319. @param index The zero based index for the character.
  320. @return No return value.
  321. */
  322. ConsoleMethodWithDocs(TextSprite, resetCharacterScale, ConsoleVoid, 3, 3, (index))
  323. {
  324. object->resetCharacterScale(dAtoi(argv[2]));
  325. }
  326. //-----------------------------------------------------------------------------
  327. /*! Sets the offset of a given character.
  328. @param index The zero based index for the character.
  329. @param (offsetX / offsetY) The amount to move a character from it's calculated position.
  330. @return No return value.
  331. */
  332. ConsoleMethodWithDocs(TextSprite, setCharacterOffset, ConsoleVoid, 4, 4, (index, offset offsetX / offsetY))
  333. {
  334. U32 charNum = dAtoi(argv[2]);
  335. const U32 count = Utility::mGetStringElementCount(argv[3]);
  336. if (count != 2)
  337. {
  338. Con::warnf("TextSprite::setCharacterOffset() - Invalid number of values (offsetX / offsetY)!");
  339. return;
  340. }
  341. object->setCharacterOffset(charNum, dAtof(Utility::mGetStringElement(argv[3], 0)), dAtof(Utility::mGetStringElement(argv[3], 1)));
  342. }
  343. //-----------------------------------------------------------------------------
  344. /*! Gets offset of a given character.
  345. @param index The zero based index for the character.
  346. @return (offsetX / offsetY) The offset of the character.
  347. */
  348. ConsoleMethodWithDocs(TextSprite, getCharacterOffset, ConsoleString, 3, 3, (index))
  349. {
  350. return object->getCharacterOffset(dAtoi(argv[2])).scriptThis();
  351. }
  352. //-----------------------------------------------------------------------------
  353. /*! Resets the offset of a given character.
  354. @param index The zero based index for the character.
  355. @return No return value.
  356. */
  357. ConsoleMethodWithDocs(TextSprite, resetCharacterOffset, ConsoleVoid, 3, 3, (index))
  358. {
  359. object->resetCharacterOffset(dAtoi(argv[2]));
  360. }
  361. ConsoleMethodGroupEndWithDocs(TextSprite)