ImageFont_ScriptBinding.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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(ImageFont, SceneObject)
  23. /*! Sets the image asset to use..
  24. @param imageName The image asset to use.
  25. @return Returns true on success.
  26. */
  27. ConsoleMethodWithDocs(ImageFont, setImage, ConsoleBool, 3, 3, (imageAssetId))
  28. {
  29. // Set Image.
  30. return object->setImage( argv[2] );
  31. }
  32. //-----------------------------------------------------------------------------
  33. /*! Gets current image asset..
  34. @return The current image asset.
  35. */
  36. ConsoleMethodWithDocs(ImageFont, getImage, ConsoleString, 2, 2, ())
  37. {
  38. // Get Image.
  39. return object->getImage();
  40. }
  41. //-----------------------------------------------------------------------------
  42. /*! Set the text to render.
  43. */
  44. ConsoleMethodWithDocs(ImageFont, setText, ConsoleVoid, 3, 3, (text))
  45. {
  46. object->setText(argv[2]);
  47. }
  48. //-----------------------------------------------------------------------------
  49. /*! Gets the text being rendered.
  50. */
  51. ConsoleMethodWithDocs(ImageFont, getText, ConsoleString, 2, 2, ())
  52. {
  53. return object->getText().getPtr8();
  54. }
  55. //-----------------------------------------------------------------------------
  56. /*! Set the text alignment to 'left', 'center' or 'right'.
  57. @param alignment The text alignment of 'left', 'center' or 'right'.
  58. @return No return value.
  59. */
  60. ConsoleMethodWithDocs(ImageFont, setTextAlignment, ConsoleVoid, 3, 3, (alignment))
  61. {
  62. object->setTextAlignment( ImageFont::getTextAlignmentEnum(argv[2]) );
  63. }
  64. //-----------------------------------------------------------------------------
  65. /*! Gets the text alignment.
  66. @return The text alignment of 'left', 'center' or 'right'.
  67. */
  68. ConsoleMethodWithDocs(ImageFont, getTextAlignment, ConsoleString, 2, 2, ())
  69. {
  70. return ImageFont::getTextAlignmentDescription(object->getTextAlignment());
  71. }
  72. //-----------------------------------------------------------------------------
  73. /*! Set the size of the font characters.
  74. @param width The width of a font character.
  75. @param height The height of a font character.
  76. @return No return value.
  77. */
  78. ConsoleMethodWithDocs(ImageFont, setFontSize, ConsoleVoid, 3, 4, (width, height))
  79. {
  80. F32 width, height;
  81. U32 elementCount = Utility::mGetStringElementCount(argv[2]);
  82. // ("width height")
  83. if ((elementCount == 2) && (argc == 3))
  84. {
  85. width = dAtof(Utility::mGetStringElement(argv[2], 0));
  86. height = dAtof(Utility::mGetStringElement(argv[2], 1));
  87. }
  88. // (width, [height])
  89. else if (elementCount == 1)
  90. {
  91. width = dAtof(argv[2]);
  92. if (argc > 3)
  93. height = dAtof(argv[3]);
  94. else
  95. height = width;
  96. }
  97. // Invalid
  98. else
  99. {
  100. Con::warnf("ImageFont::setFontSize() - Invalid number of parameters!");
  101. return;
  102. }
  103. // Set character size.
  104. object->setFontSize(Vector2(width, height));
  105. }
  106. //-----------------------------------------------------------------------------
  107. /*! Gets the size of the font characters.
  108. @return The size of the font characters.
  109. */
  110. ConsoleMethodWithDocs(ImageFont, getFontSize, ConsoleString, 2, 2, ())
  111. {
  112. return object->getFontSize().scriptThis();
  113. }
  114. //-----------------------------------------------------------------------------
  115. /*! Set the font padding.
  116. @param padding The space added in-between font characters.
  117. @return No return value.
  118. */
  119. ConsoleMethodWithDocs(ImageFont, setFontPadding, ConsoleVoid, 3, 3, (padding))
  120. {
  121. // Set character padding.
  122. object->setFontPadding( dAtof(argv[2]) );
  123. }
  124. //-----------------------------------------------------------------------------
  125. /*! Gets the font padding.
  126. @return The font padding.
  127. */
  128. ConsoleMethodWithDocs(ImageFont, getFontPadding, ConsoleFloat, 2, 2, ())
  129. {
  130. return object->getFontPadding();
  131. }
  132. ConsoleMethodGroupEndWithDocs(ImageFont)