ShapeVector_ScriptBinding.h 15 KB

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