Scroller_ScriptBinding.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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(Scroller, setRepeatX, void, 3, 3, "(repeatX) Sets the number of times to repeat the texture over x direction\n"
  23. "@return No return value.")
  24. {
  25. object->setRepeatX( dAtof(argv[2]) );
  26. }
  27. //------------------------------------------------------------------------------
  28. ConsoleMethod(Scroller, setRepeatY, void, 3, 3, "(repeatY) Sets the number of times to repeat the texture in y direction.\n"
  29. "@return No return value.")
  30. {
  31. object->setRepeatY( dAtof(argv[2]) );
  32. }
  33. //------------------------------------------------------------------------------
  34. ConsoleMethod(Scroller, getRepeatX, F32, 2, 2, "() \n @return Returns repeat X value")
  35. {
  36. return object->getRepeatX();
  37. }
  38. //------------------------------------------------------------------------------
  39. ConsoleMethod(Scroller, getRepeatY, F32, 2, 2, "() \n @return Returns repeat Y value")
  40. {
  41. return object->getRepeatY();
  42. }
  43. //------------------------------------------------------------------------------
  44. ConsoleMethod(Scroller, setScrollX, void, 3, 3, "(ScrollX) Sets the scroll speed in x direction\n"
  45. "@return No return value.")
  46. {
  47. object->setScroll(dAtof(argv[2]), object->getScrollY());
  48. }
  49. //------------------------------------------------------------------------------
  50. ConsoleMethod(Scroller, setScrollY, void, 3, 3, "(ScrollY) Sets the scroll speed in the Y direction\n"
  51. "@return No return value.")
  52. {
  53. object->setScroll(object->getScrollX(), dAtof(argv[2]));
  54. }
  55. //------------------------------------------------------------------------------
  56. ConsoleMethod(Scroller, getScrollX, F32, 2, 2, "() \n @return Returns Scroll speed in x direction.")
  57. {
  58. return object->getScrollX();
  59. }
  60. //------------------------------------------------------------------------------
  61. ConsoleMethod(Scroller, getScrollY, F32, 2, 2, "() \n @return Returns Scroll speed in y direction.")
  62. {
  63. return object->getScrollY();
  64. }
  65. //------------------------------------------------------------------------------
  66. ConsoleMethod(Scroller, setScrollPositionX, void, 3, 3, "(ScrollPositionX) Set the texture's position in x direction\n"
  67. "@return No return value.")
  68. {
  69. object->setScrollPosition(dAtof(argv[2]), object->getScrollPositionY());
  70. }
  71. //------------------------------------------------------------------------------
  72. ConsoleMethod(Scroller, setScrollPositionY, void, 3, 3, "(ScrollPositionY) Set the texture's position in y direction\n"
  73. "@return No return value.")
  74. {
  75. object->setScrollPosition(object->getScrollPositionX(), dAtof(argv[2]));
  76. }
  77. //------------------------------------------------------------------------------
  78. ConsoleMethod(Scroller, getScrollPositionX, F32, 2, 2, "() \nReturns texture's position in x direction")
  79. {
  80. return object->getScrollPositionX();
  81. }
  82. //------------------------------------------------------------------------------
  83. ConsoleMethod(Scroller, getScrollPositionY, F32, 2, 2, "() \nReturns texture's position in y direction")
  84. {
  85. return object->getScrollPositionY();
  86. }
  87. //------------------------------------------------------------------------------
  88. ConsoleMethod(Scroller, setRepeat, void, 3, 4, "(float repeatX / float repeatY) Sets the Repeat X/Y repetition in each direction.\n"
  89. "@param repeatX/Y The number of times to repeat in each direction as either (\"x y\") or (x, y)\n"
  90. "@return No return value.")
  91. {
  92. // The new position.
  93. F32 repeatX;
  94. F32 repeatY;
  95. // Elements in the first argument.
  96. U32 elementCount = Utility::mGetStringElementCount(argv[2]);
  97. // ("repeatX repeatY")
  98. if ((elementCount == 2) && (argc == 3))
  99. {
  100. repeatX = dAtof(Utility::mGetStringElement(argv[2], 0));
  101. repeatY = dAtof(Utility::mGetStringElement(argv[2], 1));
  102. }
  103. // (repeatX, repeatY)
  104. else if ((elementCount == 1) && (argc == 4))
  105. {
  106. repeatX = dAtof(argv[2]);
  107. repeatY = dAtof(argv[3]);
  108. }
  109. // Invalid
  110. else
  111. {
  112. Con::warnf("Scroller::setRepeat() - Invalid number of parameters!");
  113. return;
  114. }
  115. // Set Repeat.
  116. object->setRepeat(repeatX, repeatY);
  117. }
  118. //------------------------------------------------------------------------------
  119. ConsoleMethod(Scroller, setScroll, void, 3, 4, "(offsetX / offsetY) Sets the Scroll speed."
  120. "@param offsetX/Y The scroll speed in each direction as either (\"x y\") or (x, y)\n"
  121. "@return No return value.")
  122. {
  123. // The new position.
  124. F32 scrollX;
  125. F32 scrollY;
  126. // Elements in the first argument.
  127. U32 elementCount = Utility::mGetStringElementCount(argv[2]);
  128. // ("scrollX scrollY")
  129. if ((elementCount == 2) && (argc == 3))
  130. {
  131. scrollX = dAtof(Utility::mGetStringElement(argv[2], 0));
  132. scrollY = dAtof(Utility::mGetStringElement(argv[2], 1));
  133. }
  134. // (scrollX, scrollY)
  135. else if ((elementCount == 1) && (argc == 4))
  136. {
  137. scrollX = dAtof(argv[2]);
  138. scrollY = dAtof(argv[3]);
  139. }
  140. // Invalid
  141. else
  142. {
  143. Con::warnf("Scroller::setScroll() - Invalid number of parameters!");
  144. return;
  145. }
  146. // Set Scroll.
  147. object->setScroll(scrollX, scrollY);
  148. }
  149. //------------------------------------------------------------------------------
  150. ConsoleMethod(Scroller, setScrollPolar, void, 4, 4, "(angle, scrollSpeed) Sets Auto-Pan Polarwise.\n"
  151. "@param angle Polar angle.\n"
  152. "@param scrollSpeed Speed as polar magnitude\n"
  153. "@return No return value.")
  154. {
  155. // Renormalise Angle.
  156. F32 angle = mFmod(dAtof(argv[2]), 360.0f);
  157. // Fetch Speed.
  158. F32 scrollSpeed = dAtof(argv[3]);
  159. // Set Scroll.
  160. object->setScroll( mSin(mDegToRad(angle))*scrollSpeed, -mCos(mDegToRad(angle))*scrollSpeed );
  161. }
  162. //------------------------------------------------------------------------------
  163. ConsoleMethod(Scroller, setScrollPosition, void, 3, 4, "(positionX / positionY) Sets the Scroll position X/Y."
  164. "@param positionX/Y The scroll texture position as either (\"x y\") or (x, y)\n"
  165. "@return No return value.")
  166. {
  167. // The new position.
  168. F32 scrollX;
  169. F32 scrollY;
  170. // Elements in the first argument.
  171. U32 elementCount = Utility::mGetStringElementCount(argv[2]);
  172. // ("positionX positionY")
  173. if ((elementCount == 2) && (argc == 3))
  174. {
  175. scrollX = dAtof(Utility::mGetStringElement(argv[2], 0));
  176. scrollY = dAtof(Utility::mGetStringElement(argv[2], 1));
  177. }
  178. // (positionX, positionY)
  179. else if ((elementCount == 1) && (argc == 4))
  180. {
  181. scrollX = dAtof(argv[2]);
  182. scrollY = dAtof(argv[3]);
  183. }
  184. // Invalid
  185. else
  186. {
  187. Con::warnf("Scroller::setScrollPosition() - Invalid number of parameters!");
  188. return;
  189. }
  190. // Set Scroll Position.
  191. object->setScrollPosition(scrollX, scrollY);
  192. }