ShapeVector_ScriptBinding.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  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(ShapeVector, SceneObject)
  23. /*! Sets a regular polygon primitive.
  24. @return No return value.
  25. */
  26. ConsoleMethodWithDocs(ShapeVector, setPolyPrimitive, ConsoleVoid, 3, 3, (vertexCount))
  27. {
  28. // Set Polygon Primitive.
  29. object->setPolyPrimitive( dAtoi(argv[2]) );
  30. }
  31. //----------------------------------------------------------------------------
  32. /*! Sets Custom Polygon.
  33. @return No return value.
  34. */
  35. ConsoleMethodWithDocs(ShapeVector, setPolyCustom, ConsoleVoid, 4, 4, (poly-count, poly-Definition$))
  36. {
  37. // Set Collision Poly Custom.
  38. object->setPolyCustom( dAtoi(argv[2]), argv[3] );
  39. }
  40. //----------------------------------------------------------------------------
  41. /*! Gets Polygon.
  42. @return (poly-Definition) The vertices of the polygon in object space.
  43. */
  44. ConsoleMethodWithDocs(ShapeVector, getPoly, ConsoleString, 2, 2, ())
  45. {
  46. // Get Collision Poly Count.
  47. return object->getPoly();
  48. }
  49. //----------------------------------------------------------------------------
  50. /*! Gets Polygon points in world space.
  51. @return (poly-Definition) The vertices of the polygon in world space.
  52. */
  53. ConsoleMethodWithDocs(ShapeVector, getWorldPoly, ConsoleString, 2, 2, ())
  54. {
  55. // Get Collision Poly Count.
  56. return object->getWorldPoly();
  57. }
  58. //----------------------------------------------------------------------------
  59. /*! RGBA value or ( stockColorName ) - Sets the line color.
  60. @param red The red value.
  61. @param green The green value.
  62. @param blue The blue value.
  63. @param alpha The alpha value.
  64. @return No return Value.
  65. */
  66. ConsoleMethodWithDocs(ShapeVector, setLineColor, ConsoleVoid, 3, 6, (float red, float green, float blue, [float alpha = 1.0]))
  67. {
  68. // The colors.
  69. F32 red;
  70. F32 green;
  71. F32 blue;
  72. F32 alpha = 1.0f;
  73. // Space separated.
  74. if (argc == 3 )
  75. {
  76. // Grab the element count.
  77. const U32 elementCount = Utility::mGetStringElementCount(argv[2]);
  78. // Has a single argument been specified?
  79. if ( elementCount == 1 )
  80. {
  81. // Set color.
  82. Con::setData( TypeColorF, &const_cast<ColorF&>(object->getLineColor()), 0, 1, &(argv[2]) );
  83. return;
  84. }
  85. // ("R G B [A]")
  86. if ((elementCount == 3) || (elementCount == 4))
  87. {
  88. // Extract the color.
  89. red = dAtof(Utility::mGetStringElement(argv[2], 0));
  90. green = dAtof(Utility::mGetStringElement(argv[2], 1));
  91. blue = dAtof(Utility::mGetStringElement(argv[2], 2));
  92. // Grab the alpha if it's there.
  93. if (elementCount > 3)
  94. alpha = dAtof(Utility::mGetStringElement(argv[2], 3));
  95. }
  96. // Invalid.
  97. else
  98. {
  99. Con::warnf("ShapeVector::setLineColor() - Invalid Number of parameters!");
  100. return;
  101. }
  102. }
  103. // (R, G, B)
  104. else if (argc >= 5)
  105. {
  106. red = dAtof(argv[2]);
  107. green = dAtof(argv[3]);
  108. blue = dAtof(argv[4]);
  109. // Grab the alpha if it's there.
  110. if (argc > 5)
  111. alpha = dAtof(argv[5]);
  112. }
  113. // Invalid.
  114. else
  115. {
  116. Con::warnf("ShapeVector::setLineColor() - Invalid Number of parameters!");
  117. return;
  118. }
  119. object->setLineColor( ColorF(red, green, blue, alpha) );
  120. }
  121. //----------------------------------------------------------------------------
  122. /*! Gets the fill color.
  123. @param allowColorNames Whether to allow stock color names to be returned or not. Optional: Defaults to false.
  124. @return (float red / float green / float blue / float alpha) The sprite blend color.
  125. */
  126. ConsoleMethodWithDocs(ShapeVector, getLineColor, ConsoleString, 2, 3, (allowColorNames))
  127. {
  128. // Get line color.
  129. ColorF color = object->getLineColor();
  130. // Fetch allow color names flag.
  131. const bool allowColorNames = (argc > 2) ? dAtob(argv[2] ) : false;
  132. // Are color names allowed?
  133. if ( allowColorNames )
  134. {
  135. // Yes, so fetch the field value.
  136. return Con::getData( TypeColorF, &color, 0 );
  137. }
  138. // No, so fetch the raw color values.
  139. return color.scriptThis();
  140. }
  141. //----------------------------------------------------------------------------
  142. /*! Sets the Rendering Line Alpha (transparency).
  143. @param alpha The alpha value.
  144. @return No return value.
  145. */
  146. ConsoleMethodWithDocs(ShapeVector, setLineAlpha, ConsoleVoid, 3, 3, (alpha))
  147. {
  148. // Set Line Alpha.
  149. object->setLineAlpha( dAtof(argv[2]) );
  150. }
  151. //----------------------------------------------------------------------------
  152. /*! RGBA value or ( stockColorName ) - Sets the fill color.
  153. @param red The red value.
  154. @param green The green value.
  155. @param blue The blue value.
  156. @param alpha The alpha value.
  157. @return No return Value.
  158. */
  159. ConsoleMethodWithDocs(ShapeVector, setFillColor, ConsoleVoid, 3, 3, (float red, float green, float blue, [float alpha = 1.0]))
  160. {
  161. // The colors.
  162. F32 red;
  163. F32 green;
  164. F32 blue;
  165. F32 alpha = 1.0f;
  166. // Space separated.
  167. if (argc == 3 )
  168. {
  169. // Grab the element count.
  170. const U32 elementCount = Utility::mGetStringElementCount(argv[2]);
  171. // Has a single argument been specified?
  172. if ( elementCount == 1 )
  173. {
  174. // Set color.
  175. Con::setData( TypeColorF, &const_cast<ColorF&>(object->getFillColor()), 0, 1, &(argv[2]) );
  176. return;
  177. }
  178. // ("R G B [A]")
  179. if ((elementCount == 3) || (elementCount == 4))
  180. {
  181. // Extract the color.
  182. red = dAtof(Utility::mGetStringElement(argv[2], 0));
  183. green = dAtof(Utility::mGetStringElement(argv[2], 1));
  184. blue = dAtof(Utility::mGetStringElement(argv[2], 2));
  185. // Grab the alpha if it's there.
  186. if (elementCount > 3)
  187. alpha = dAtof(Utility::mGetStringElement(argv[2], 3));
  188. }
  189. // Invalid.
  190. else
  191. {
  192. Con::warnf("ShapeVector::setFillColor() - Invalid Number of parameters!");
  193. return;
  194. }
  195. }
  196. // (R, G, B)
  197. else if (argc >= 5)
  198. {
  199. red = dAtof(argv[2]);
  200. green = dAtof(argv[3]);
  201. blue = dAtof(argv[4]);
  202. // Grab the alpha if it's there.
  203. if (argc > 5)
  204. alpha = dAtof(argv[5]);
  205. }
  206. // Invalid.
  207. else
  208. {
  209. Con::warnf("ShapeVector::setFillColor() - Invalid Number of parameters!");
  210. return;
  211. }
  212. object->setFillColor( ColorF(red, green, blue, alpha) );
  213. }
  214. //----------------------------------------------------------------------------
  215. /*! Gets the fill color.
  216. @param allowColorNames Whether to allow stock color names to be returned or not. Optional: Defaults to false.
  217. @return (float red / float green / float blue / float alpha) The sprite blend color.
  218. */
  219. ConsoleMethodWithDocs(ShapeVector, getFillColor, ConsoleString, 2, 3, (allowColorNames))
  220. {
  221. // Get line color.
  222. ColorF color = object->getFillColor();
  223. // Fetch allow color names flag.
  224. const bool allowColorNames = (argc > 2) ? dAtob(argv[2] ) : false;
  225. // Are color names allowed?
  226. if ( allowColorNames )
  227. {
  228. // Yes, so fetch the field value.
  229. return Con::getData( TypeColorF, &color, 0 );
  230. }
  231. // No, so fetch the raw color values.
  232. return color.scriptThis();
  233. }
  234. //----------------------------------------------------------------------------
  235. /*! Sets the Rendering Fill Alpha (transparency).
  236. @param alpha The alpha value.
  237. @return No return value.
  238. */
  239. ConsoleMethodWithDocs(ShapeVector, setFillAlpha, ConsoleVoid, 3, 3, (alpha))
  240. {
  241. // Set Fill Alpha.
  242. object->setFillAlpha( dAtof(argv[2]) );
  243. }
  244. //----------------------------------------------------------------------------
  245. /*! Sets the Rendering Fill Mode.
  246. @return No return value.
  247. */
  248. ConsoleMethodWithDocs(ShapeVector, setFillMode, ConsoleVoid, 3, 3, (fillMode?))
  249. {
  250. // Set Fill Mode.
  251. object->setFillMode( dAtob(argv[2]) );
  252. }
  253. //----------------------------------------------------------------------------
  254. /*! Gets the Rendering Fill Mode.
  255. @return The fill mode as a boolean value.
  256. */
  257. ConsoleMethodWithDocs(ShapeVector, getFillMode, ConsoleBool, 2, 2, ())
  258. {
  259. return object->getFillMode();
  260. }
  261. //----------------------------------------------------------------------------
  262. /*! Sets whether this shape is a circle or not.
  263. @return The fill mode as a boolean value.
  264. */
  265. ConsoleMethodWithDocs(ShapeVector, setIsCircle, ConsoleVoid, 3, 3, (isCircle?))
  266. {
  267. object->setIsCircle(dAtob(argv[2]));
  268. }
  269. //----------------------------------------------------------------------------
  270. /*! Returns whether this shape is a circle or not.
  271. @return The fill mode as a boolean value.
  272. */
  273. ConsoleMethodWithDocs(ShapeVector, getIsCircle, ConsoleBool, 2, 2, ())
  274. {
  275. return object->getIsCircle();
  276. }
  277. //----------------------------------------------------------------------------
  278. /*! Returns the radius of the shape if it is a circle.
  279. @return The fill mode as a boolean value.
  280. */
  281. ConsoleMethodWithDocs(ShapeVector, getCircleRadius, ConsoleBool, 2, 2, ())
  282. {
  283. return object->getCircleRadius();
  284. }
  285. //----------------------------------------------------------------------------
  286. /*! Changes the radius of the shape if it is a circle.
  287. @return The fill mode as a boolean value.
  288. */
  289. ConsoleMethodWithDocs(ShapeVector, setCircleRadius, ConsoleVoid, 3, 3, (radius))
  290. {
  291. object->setCircleRadius(dAtof(argv[2]));
  292. }
  293. //-----------------------------------------------------------------------------
  294. /*! Get the number of vertices on a polygon shape.
  295. */
  296. ConsoleMethodWithDocs(ShapeVector, getVertexCount, ConsoleInt, 2, 2, ())
  297. {
  298. return object->getPolyVertexCount();
  299. }
  300. //-----------------------------------------------------------------------------
  301. /*! Get a box (\width height\ that wraps around the poly vertices
  302. */
  303. ConsoleMethodWithDocs(ShapeVector, getBoxFromPoints, ConsoleString, 2, 2, ())
  304. {
  305. Vector2 box = object->getBoxFromPoints();
  306. // Create Returnable Buffer.
  307. char* pBuffer = Con::getReturnBuffer(32);
  308. // Format Buffer.
  309. dSprintf(pBuffer, 32, "%g %g", box.x, box.y);
  310. // Return box width and height.
  311. return pBuffer;
  312. }
  313. //-----------------------------------------------------------------------------
  314. /*! Sets shape flipping for each axis.
  315. @param flipX Whether or not to flip the shape along the x (horizontal) axis.
  316. @param flipY Whether or not to flip the shape along the y (vertical) axis.
  317. @return No return value.
  318. */
  319. ConsoleMethodWithDocs(ShapeVector, setFlip, ConsoleVoid, 4, 4, (bool flipX, bool flipY))
  320. {
  321. // Set Flip.
  322. object->setFlip( dAtob(argv[2]), dAtob(argv[3]) );
  323. }
  324. //-----------------------------------------------------------------------------
  325. /*! Gets the flip for each axis.
  326. @return (bool flipX/bool flipY) Whether or not the shape is flipped along the x and y axis.
  327. */
  328. ConsoleMethodWithDocs(ShapeVector, getFlip, ConsoleString, 2, 2, ())
  329. {
  330. // Create Returnable Buffer.
  331. char* pBuffer = Con::getReturnBuffer(32);
  332. // Format Buffer.
  333. dSprintf(pBuffer, 32, "%d %d", object->getFlipX(), object->getFlipY());
  334. // Return Buffer.
  335. return pBuffer;
  336. }
  337. //-----------------------------------------------------------------------------
  338. /*! Sets whether or not the shape is flipped horizontally.
  339. @param flipX Whether or not to flip the shape along the x (horizontal) axis.
  340. @return No return value.
  341. */
  342. ConsoleMethodWithDocs(ShapeVector, setFlipX, ConsoleVoid, 3, 3, (bool flipX))
  343. {
  344. // Set Flip.
  345. object->setFlipX( dAtob(argv[2]) );
  346. }
  347. //-----------------------------------------------------------------------------
  348. /*! Sets whether or not the shape is flipped vertically.
  349. @param flipY Whether or not to flip the shape along the y (vertical) axis.
  350. @return No return value.
  351. */
  352. ConsoleMethodWithDocs(ShapeVector, setFlipY, ConsoleVoid, 3, 3, (bool flipY))
  353. {
  354. // Set Flip.
  355. object->setFlipY( dAtob(argv[2]) );
  356. }
  357. //-----------------------------------------------------------------------------
  358. /*! Gets whether or not the shape is flipped horizontally.
  359. @return (bool flipX) Whether or not the shape is flipped along the x axis.
  360. */
  361. ConsoleMethodWithDocs(ShapeVector, getFlipX, ConsoleBool, 2, 2, ())
  362. {
  363. return object->getFlipX();
  364. }
  365. //-----------------------------------------------------------------------------
  366. /*! Gets whether or not the shape is flipped vertically.
  367. @return (bool flipY) Whether or not the shape is flipped along the y axis.
  368. */
  369. ConsoleMethodWithDocs(ShapeVector, getFlipY, ConsoleBool, 2, 2, ())
  370. {
  371. return object->getFlipY();
  372. }
  373. ConsoleMethodGroupEndWithDocs(ShapeVector)