ImageFont_ScriptBinding.h 5.4 KB

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