Scroller_ScriptBinding.h 8.3 KB

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