ShapeVector_ScriptBinding.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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(ShapeVector, setPolyScale, void, 3, 3, "(widthScale / [heightScale]) - Sets the polygon scale.\n"
  23. "@param width/heightScale The scale values of the given polygon. If no height is specified, the widthScale value is repeated.\n"
  24. "@return No return value.")
  25. {
  26. // Calculate Element Count.
  27. const U32 elementCount = Utility::mGetStringElementCount( argv[2] );
  28. // Check Parameters.
  29. if ( elementCount < 1 )
  30. {
  31. Con::warnf("ShapeVector::setPolyScale() - Invalid number of parameters!");
  32. return;
  33. }
  34. // Fetch Width Scale.
  35. Vector2 scale;
  36. scale.x = dAtof(Utility::mGetStringElement(argv[2],0));
  37. // Use Fixed-Aspect for Scale if Height-Scale not specified.
  38. if ( elementCount == 2 )
  39. {
  40. // Specified Height Scale.
  41. scale.y = dAtof(Utility::mGetStringElement(argv[2],1));
  42. }
  43. else
  44. {
  45. // Fixed-Aspect Scale.
  46. scale.y = scale.x;
  47. }
  48. // Set Polygon Scale.
  49. object->setPolyScale( scale );
  50. }
  51. //----------------------------------------------------------------------------
  52. ConsoleMethod(ShapeVector, setPolyPrimitive, void, 3, 3, "(vertexCount) Sets a regular polygon primitive.\n"
  53. "@return No return value.")
  54. {
  55. // Set Polygon Primitive.
  56. object->setPolyPrimitive( dAtoi(argv[2]) );
  57. }
  58. //----------------------------------------------------------------------------
  59. ConsoleMethod(ShapeVector, setPolyCustom, void, 4, 4, "(poly-count, poly-Definition$) Sets Custom Polygon.\n"
  60. "@return No return value.")
  61. {
  62. // Set Collision Poly Custom.
  63. object->setPolyCustom( dAtoi(argv[2]), argv[3] );
  64. }
  65. //----------------------------------------------------------------------------
  66. ConsoleMethod(ShapeVector, getPoly, const char*, 2, 2, "() Gets Polygon.\n"
  67. "@return (poly-Definition) The vertices of the polygon in object space.")
  68. {
  69. // Get Collision Poly Count.
  70. return object->getPoly();
  71. }
  72. //----------------------------------------------------------------------------
  73. ConsoleMethod(ShapeVector, getWorldPoly, const char*, 2, 2, "() Gets Polygon points in world space.\n"
  74. "@return (poly-Definition) The vertices of the polygon in world space.")
  75. {
  76. // Get Collision Poly Count.
  77. return object->getWorldPoly();
  78. }
  79. //----------------------------------------------------------------------------
  80. ConsoleMethod(ShapeVector, setLineColour, void, 3, 3, "(R / G / B / [A]) Sets the Rendering Line Color (identical to setLineColor).\n"
  81. "@param R/G/B/[A] Color values (0.0f - 1.0f) formatted as (\"Red Green Blue [Alpha]\"). Alpha is optional.\n"
  82. "@return No return value.")
  83. {
  84. // Set Line Color.
  85. object->setLineColorString( argv[2] );
  86. }
  87. //----------------------------------------------------------------------------
  88. ConsoleMethod(ShapeVector, setLineColor, void, 3, 3, "(R / G / B / [A]) - Sets the Rendering Line Color(identical to setLineColor).\n"
  89. "@param R/G/B/[A] Color values (0.0f - 1.0f) formatted as (\"Red Green Blue [Alpha]\"). Alpha is optional.\n"
  90. "@return No return value.")
  91. {
  92. // Set Line Color.
  93. object->setLineColorString( argv[2] );
  94. }
  95. //----------------------------------------------------------------------------
  96. ConsoleMethod(ShapeVector, getLineColor, const char*, 2, 2, "() Gets the Rendering Line Color.\n"
  97. "@return Returns the fill color as a string formatted with \"Red Green Blue Alpha\"")
  98. {
  99. return object->getLineColor();
  100. }
  101. //----------------------------------------------------------------------------
  102. ConsoleMethod(ShapeVector, setLineAlpha, void, 3, 3, "(alpha) Sets the Rendering Line Alpha (transparency).\n"
  103. "@param alpha The alpha value.\n"
  104. "@return No return value.")
  105. {
  106. // Set Line Alpha.
  107. object->setLineAlpha( dAtof(argv[2]) );
  108. }
  109. //----------------------------------------------------------------------------
  110. ConsoleMethod(ShapeVector, setFillColour, void, 3, 3, "(R / G / B / [A]) Sets the Rendering Fill Color (identical to setFillColor).\n"
  111. "@param R/G/B/[A] Color values (0.0f - 1.0f) formatted as (\"Red Green Blue [Alpha]\"). Alpha is optional.\n"
  112. "@return No return value."
  113. )
  114. {
  115. // Set Fill Color.
  116. object->setLineColorString( argv[2] );
  117. }
  118. //----------------------------------------------------------------------------
  119. ConsoleMethod(ShapeVector, setFillColor, void, 3, 3, "(R / G / B / [A]) - Sets the Rendering Fill Color (identical to setFillColour).\n"
  120. "@param R/G/B/[A] Color values (0.0f - 1.0f) formatted as (\"Red Green Blue [Alpha]\"). Alpha is optional.\n"
  121. "@return No return value.")
  122. {
  123. // Set Fill Color.
  124. object->setFillColorString( argv[2] );
  125. }
  126. //----------------------------------------------------------------------------
  127. ConsoleMethod(ShapeVector, getFillColor, const char*, 2, 2, "() Gets the Rendering Fill Color.\n"
  128. "@return Returns the fill color as a string formatted with \"Red Green Blue Alpha\"")
  129. {
  130. return object->getFillColor();
  131. }
  132. //----------------------------------------------------------------------------
  133. ConsoleMethod(ShapeVector, setFillAlpha, void, 3, 3, "(alpha) Sets the Rendering Fill Alpha (transparency).\n"
  134. "@param alpha The alpha value.\n"
  135. "@return No return value.")
  136. {
  137. // Set Fill Alpha.
  138. object->setFillAlpha( dAtof(argv[2]) );
  139. }
  140. //----------------------------------------------------------------------------
  141. ConsoleMethod(ShapeVector, setFillMode, void, 3, 3, "(fillMode?) Sets the Rendering Fill Mode.\n"
  142. "@return No return value.")
  143. {
  144. // Set Fill Mode.
  145. object->setFillMode( dAtob(argv[2]) );
  146. }
  147. //----------------------------------------------------------------------------
  148. ConsoleMethod(ShapeVector, getFillMode, bool, 2, 2, "() Gets the Rendering Fill Mode.\n"
  149. "@return The fill mode as a boolean value.")
  150. {
  151. return object->getFillMode();
  152. }
  153. //----------------------------------------------------------------------------
  154. ConsoleMethod(ShapeVector, setIsCircle, void, 3, 3, "(isCircle?) Sets whether this shape is a circle or not.\n"
  155. "@return The fill mode as a boolean value.")
  156. {
  157. object->setIsCircle(dAtob(argv[2]));
  158. }
  159. //----------------------------------------------------------------------------
  160. ConsoleMethod(ShapeVector, getIsCircle, bool, 2, 2, "() Returns whether this shape is a circle or not.\n"
  161. "@return The fill mode as a boolean value.")
  162. {
  163. return object->getIsCircle();
  164. }
  165. //----------------------------------------------------------------------------
  166. ConsoleMethod(ShapeVector, getCircleRadius, bool, 2, 2, "() Returns the radius of the shape if it is a circle.\n"
  167. "@return The fill mode as a boolean value.")
  168. {
  169. return object->getCircleRadius();
  170. }
  171. //----------------------------------------------------------------------------
  172. ConsoleMethod(ShapeVector, setCircleRadius, void, 3, 3, "(radius) Changes the radius of the shape if it is a circle.\n"
  173. "@return The fill mode as a boolean value.")
  174. {
  175. object->setCircleRadius(dAtof(argv[2]));
  176. }
  177. //-----------------------------------------------------------------------------
  178. ConsoleMethod(ShapeVector, getVertexCount, S32, 2, 2, "() Get the number of vertices on a polygon shape.\n")
  179. {
  180. return object->getPolyVertexCount();
  181. }
  182. //-----------------------------------------------------------------------------
  183. ConsoleMethod(ShapeVector, getBoxFromPoints, const char*, 2, 2, "() Get a box (\"width height\") that wraps around the poly vertices")
  184. {
  185. Vector2 box = object->getBoxFromPoints();
  186. // Create Returnable Buffer.
  187. char* pBuffer = Con::getReturnBuffer(32);
  188. // Format Buffer.
  189. dSprintf(pBuffer, 32, "%g %g", box.x, box.y);
  190. // Return box width and height.
  191. return pBuffer;
  192. }
  193. //-----------------------------------------------------------------------------
  194. ConsoleMethod(ShapeVector, setFlip, void, 4, 4, "(bool flipX, bool flipY) Sets shape flipping for each axis.\n"
  195. "@param flipX Whether or not to flip the shape along the x (horizontal) axis.\n"
  196. "@param flipY Whether or not to flip the shape along the y (vertical) axis.\n"
  197. "@return No return value.")
  198. {
  199. // Set Flip.
  200. object->setFlip( dAtob(argv[2]), dAtob(argv[3]) );
  201. }
  202. //-----------------------------------------------------------------------------
  203. ConsoleMethod(ShapeVector, getFlip, const char*, 2, 2, "() Gets the flip for each axis.\n"
  204. "@return (bool flipX/bool flipY) Whether or not the shape is flipped along the x and y axis.")
  205. {
  206. // Create Returnable Buffer.
  207. char* pBuffer = Con::getReturnBuffer(32);
  208. // Format Buffer.
  209. dSprintf(pBuffer, 32, "%d %d", object->getFlipX(), object->getFlipY());
  210. // Return Buffer.
  211. return pBuffer;
  212. }
  213. //-----------------------------------------------------------------------------
  214. ConsoleMethod(ShapeVector, setFlipX, void, 3, 3, "(bool flipX) Sets whether or not the shape is flipped horizontally.\n"
  215. "@param flipX Whether or not to flip the shape along the x (horizontal) axis."
  216. "@return No return value.")
  217. {
  218. // Set Flip.
  219. object->setFlipX( dAtob(argv[2]) );
  220. }
  221. //-----------------------------------------------------------------------------
  222. ConsoleMethod(ShapeVector, setFlipY, void, 3, 3, "(bool flipY) Sets whether or not the shape is flipped vertically.\n"
  223. "@param flipY Whether or not to flip the shape along the y (vertical) axis."
  224. "@return No return value.")
  225. {
  226. // Set Flip.
  227. object->setFlipY( dAtob(argv[2]) );
  228. }
  229. //-----------------------------------------------------------------------------
  230. ConsoleMethod(ShapeVector, getFlipX, bool, 2, 2, "() Gets whether or not the shape is flipped horizontally.\n"
  231. "@return (bool flipX) Whether or not the shape is flipped along the x axis.")
  232. {
  233. return object->getFlipX();
  234. }
  235. //-----------------------------------------------------------------------------
  236. ConsoleMethod(ShapeVector, getFlipY, bool, 2, 2, "() Gets whether or not the shape is flipped vertically."
  237. "@return (bool flipY) Whether or not the shape is flipped along the y axis.")
  238. {
  239. return object->getFlipY();
  240. }