SceneWindow_ScriptBinding.h 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560
  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(SceneWindow, GuiControl)
  23. /*! Fetch Window Extents (Position/Size).
  24. @return Returns the window dimensions as a string formatted as follows: <position.x> <position.y> <width> <height>
  25. */
  26. ConsoleMethodWithDocs(SceneWindow, getWindowExtents, ConsoleString, 2, 2, ())
  27. {
  28. // Get Size Argument Buffer.
  29. char* pExtentsBuffer = Con::getReturnBuffer(64);
  30. // Format Buffer.
  31. dSprintf( pExtentsBuffer, 64, "%d %d %d %d", object->getPosition().x, object->getPosition().y, object->getExtent().x, object->getExtent().y );
  32. // Return Buffer.
  33. return pExtentsBuffer;
  34. }
  35. //-----------------------------------------------------------------------------
  36. /*! Returns the Scene associated with this window.
  37. @return Returns the scene ID as a string
  38. */
  39. ConsoleMethodWithDocs(SceneWindow, getScene, ConsoleString, 2, 2, ())
  40. {
  41. Scene* pScene = object->getScene();
  42. char* id = Con::getReturnBuffer(8);
  43. if (pScene)
  44. {
  45. dItoa(pScene->getId(), id );
  46. }
  47. else
  48. {
  49. id[0] = '\0';
  50. }
  51. return id;
  52. }
  53. //-----------------------------------------------------------------------------
  54. /*! Associates Scene Object.
  55. @param Scene The scene ID or name.
  56. @return No return value.
  57. */
  58. ConsoleMethodWithDocs(SceneWindow, setScene, ConsoleVoid, 2, 3, (Scene))
  59. {
  60. // No scene specified?
  61. if ( argc < 3 )
  62. {
  63. // No, so reset the scene.
  64. object->resetScene();
  65. // Finish here.
  66. return;
  67. }
  68. // Find Scene Object.
  69. Scene* pScene = (Scene*)(Sim::findObject(argv[2]));
  70. // Validate Object.
  71. if ( !pScene )
  72. {
  73. Con::warnf("SceneWindow::setScene() - Couldn't find object '%s'.", argv[2]);
  74. return;
  75. }
  76. // Set Scene.
  77. object->setScene( pScene );
  78. }
  79. //-----------------------------------------------------------------------------
  80. /*! Detaches the window from any Scene Object.
  81. @return No return value
  82. */
  83. ConsoleMethodWithDocs(SceneWindow, resetScene, ConsoleVoid, 2, 2, ())
  84. {
  85. // Reset Scene.
  86. object->resetScene();
  87. }
  88. //-----------------------------------------------------------------------------
  89. /*! Set the current camera position.
  90. @param X Position along the X axis.
  91. @param Y Position along the Y axis.
  92. @return No return value.
  93. */
  94. ConsoleMethodWithDocs(SceneWindow, setCameraPosition, ConsoleVoid, 3, 4, (x , y))
  95. {
  96. if ( argc == 3 )
  97. {
  98. object->setCameraPosition( Vector2(argv[2]) );
  99. return;
  100. }
  101. object->setCameraPosition( Vector2(dAtof(argv[2]), dAtof(argv[3])) );
  102. }
  103. //-----------------------------------------------------------------------------
  104. /*! Get the current camera position.
  105. @return The current camera position.
  106. */
  107. ConsoleMethodWithDocs(SceneWindow, getCameraPosition, ConsoleString, 2, 2, ())
  108. {
  109. return object->getCameraPosition().scriptThis();
  110. }
  111. //-----------------------------------------------------------------------------
  112. /*! Set the current camera position.
  113. @param width Size along the X axis.
  114. @param height Size along the Y axis.
  115. @return No return value.
  116. */
  117. ConsoleMethodWithDocs(SceneWindow, setCameraSize, ConsoleVoid, 3, 4, (width , height))
  118. {
  119. if ( argc == 3 )
  120. {
  121. object->setCameraSize( Vector2(argv[2]) );
  122. return;
  123. }
  124. object->setCameraSize( Vector2(dAtof(argv[2]), dAtof(argv[3])) );
  125. }
  126. //-----------------------------------------------------------------------------
  127. /*! Get the current camera size.
  128. @return The current camera width and height.
  129. */
  130. ConsoleMethodWithDocs(SceneWindow, getCameraSize, ConsoleString, 2, 2, ())
  131. {
  132. return object->getCameraSize().scriptThis();
  133. }
  134. //-----------------------------------------------------------------------------
  135. /*! Set the current camera area.
  136. @param x1,y1,x2,y2 The coordinates of the minimum and maximum points (top left, bottom right)
  137. The input can be formatted as either \x1 y1 x2 y2\, \x1 y1, x2 y2\, \x1, y1, x2, y2\
  138. @return No return value.
  139. */
  140. ConsoleMethodWithDocs(SceneWindow, setCameraArea, ConsoleVoid, 3, 6, (x1 / y1 / x2 / y2))
  141. {
  142. // Upper left bound.
  143. Vector2 v1;
  144. // Lower right bound.
  145. Vector2 v2;
  146. // Grab the number of elements in the first two parameters.
  147. U32 elementCount1 = Utility::mGetStringElementCount(argv[2]);
  148. U32 elementCount2 = 1;
  149. if (argc > 3)
  150. elementCount2 = Utility::mGetStringElementCount(argv[3]);
  151. // ("x1 y1 x2 y2")
  152. if ((elementCount1 == 4) && (argc == 3))
  153. {
  154. v1 = Utility::mGetStringElementVector(argv[2]);
  155. v2 = Utility::mGetStringElementVector(argv[2], 2);
  156. }
  157. // ("x1 y1", "x2 y2")
  158. else if ((elementCount1 == 2) && (elementCount2 == 2) && (argc == 4))
  159. {
  160. v1 = Utility::mGetStringElementVector(argv[2]);
  161. v2 = Utility::mGetStringElementVector(argv[3]);
  162. }
  163. // (x1, y1, x2, y2)
  164. else if (argc == 6)
  165. {
  166. v1 = Vector2(dAtof(argv[2]), dAtof(argv[3]));
  167. v2 = Vector2(dAtof(argv[4]), dAtof(argv[5]));
  168. }
  169. // Invalid
  170. else
  171. {
  172. Con::warnf("SceneWindow::setCameraArea() - Invalid number of parameters!");
  173. return;
  174. }
  175. // Calculate Normalised Rectangle.
  176. Vector2 topLeft( (v1.x <= v2.x) ? v1.x : v2.x, (v1.y <= v2.y) ? v1.y : v2.y );
  177. Vector2 bottomRight( (v1.x > v2.x) ? v1.x : v2.x, (v1.y > v2.y) ? v1.y : v2.y );
  178. // Set Current Camera Area.
  179. object->setCameraArea( RectF(topLeft.x, topLeft.y, bottomRight.x-topLeft.x, bottomRight.y-topLeft.y) );
  180. }
  181. //-----------------------------------------------------------------------------
  182. /*! Get the current camera Area.
  183. @return The camera area formatted as \x1 y1 x2 y2\
  184. */
  185. ConsoleMethodWithDocs(SceneWindow, getCameraArea, ConsoleString, 2, 2, ())
  186. {
  187. // Fetch Camera Window.
  188. const RectF cameraWindow = object->getCameraArea();
  189. // Create Returnable Buffer.
  190. char* pBuffer = Con::getReturnBuffer(64);
  191. // Format Buffer.
  192. dSprintf(pBuffer, 64, "%.5g %.5g %.5g %.5g", cameraWindow.point.x, cameraWindow.point.y, cameraWindow.point.x+cameraWindow.extent.x, cameraWindow.point.y+cameraWindow.extent.y);
  193. // Return Buffer.
  194. return pBuffer;
  195. }
  196. //-----------------------------------------------------------------------------
  197. /*! Set the current camera Zoom Factor.
  198. @param zoomFactor A float value representing the zoom factor
  199. @return No return value.
  200. */
  201. ConsoleMethodWithDocs(SceneWindow, setCameraZoom, ConsoleVoid, 3, 3, (zoomFactor))
  202. {
  203. object->setCameraZoom( dAtof(argv[2]) );
  204. }
  205. //-----------------------------------------------------------------------------
  206. /*! Get the current camera Zoom.
  207. @return The current camera zoom.
  208. */
  209. ConsoleMethodWithDocs(SceneWindow, getCameraZoom, ConsoleFloat, 2, 2, ())
  210. {
  211. return object->getCameraZoom();
  212. }
  213. //-----------------------------------------------------------------------------
  214. /*! Sets the current camera angle.
  215. @param angle The current camera angle in degrees.
  216. @return No return value.
  217. */
  218. ConsoleMethodWithDocs(SceneWindow, setCameraAngle, ConsoleVoid, 3, 3, (angle))
  219. {
  220. object->setCameraAngle( mDegToRad(dAtof(argv[2])) );
  221. }
  222. //-----------------------------------------------------------------------------
  223. /*! Gets the current camera angle.
  224. @return The current camera angle in degrees.
  225. */
  226. ConsoleMethodWithDocs(SceneWindow, getCameraAngle, ConsoleFloat, 2, 2, ())
  227. {
  228. return object->getCameraAngle();
  229. }
  230. //-----------------------------------------------------------------------------
  231. /*! Get current camera scale to world.
  232. @return Returns the cameras window width/height scale to world as a string formatted as \widthScale heightScale\
  233. */
  234. ConsoleMethodWithDocs(SceneWindow, getCameraWorldScale, ConsoleString, 2, 2, ())
  235. {
  236. // Fetch camera window
  237. const Vector2 cameraWindowScale = object->getCameraWindowScale();
  238. return cameraWindowScale.scriptThis();
  239. }
  240. //-----------------------------------------------------------------------------
  241. /*! Get current camera position post-view-limit clamping.
  242. @return The current camera render position.
  243. */
  244. ConsoleMethodWithDocs(SceneWindow, getCameraRenderPosition, ConsoleString, 2, 2, ())
  245. {
  246. return object->getCameraRenderPosition().scriptThis();
  247. }
  248. //-----------------------------------------------------------------------------
  249. /*! Get current camera scale to render.
  250. @return Returns the cameras window width/height scale to render as a string formatted as \widthScale heightScale\
  251. */
  252. ConsoleMethodWithDocs(SceneWindow, getCameraRenderScale, ConsoleString, 2, 2, ())
  253. {
  254. // Fetch camera window scale.
  255. Vector2 cameraWindowScale = object->getCameraWindowScale();
  256. // Inverse scale.
  257. cameraWindowScale.receiprocate();
  258. return cameraWindowScale.scriptThis();
  259. }
  260. //-----------------------------------------------------------------------------
  261. /*! Set the target camera position.
  262. @param X Position along the X axis.
  263. @param Y Position along the Y axis.
  264. @return No return value.
  265. */
  266. ConsoleMethodWithDocs(SceneWindow, setTargetCameraPosition, ConsoleVoid, 3, 4, (x , y))
  267. {
  268. if ( argc == 3 )
  269. {
  270. object->setTargetCameraPosition( Vector2(argv[2]) );
  271. return;
  272. }
  273. object->setTargetCameraPosition( Vector2(dAtof(argv[2]), dAtof(argv[3])) );
  274. }
  275. //-----------------------------------------------------------------------------
  276. /*! Get the target camera position.
  277. @return The target camera position.
  278. */
  279. ConsoleMethodWithDocs(SceneWindow, getTargetCameraPosition, ConsoleString, 2, 2, ())
  280. {
  281. return object->getTargetCameraPosition().scriptThis();
  282. }
  283. //-----------------------------------------------------------------------------
  284. /*! Set the target camera position.
  285. @param width Size along the X axis.
  286. @param height Size along the Y axis.
  287. @return No return value.
  288. */
  289. ConsoleMethodWithDocs(SceneWindow, setTargetCameraSize, ConsoleVoid, 3, 4, (width , height))
  290. {
  291. if ( argc == 3 )
  292. {
  293. object->setTargetCameraSize( Vector2(argv[2]) );
  294. return;
  295. }
  296. object->setTargetCameraSize( Vector2(dAtof(argv[2]), dAtof(argv[3])) );
  297. }
  298. //-----------------------------------------------------------------------------
  299. /*! Get the target camera size.
  300. @return The target camera width and height.
  301. */
  302. ConsoleMethodWithDocs(SceneWindow, getTargetCameraSize, ConsoleString, 2, 2, ())
  303. {
  304. return object->getTargetCameraSize().scriptThis();
  305. }
  306. //-----------------------------------------------------------------------------
  307. /*! Set the target camera area.
  308. @param x1 / y1 Coordinates of the upper left corner of the target area.
  309. @param x2 / y2 Coordinates of the lower right corner of the target area.
  310. @return No return value.
  311. */
  312. ConsoleMethodWithDocs(SceneWindow, setTargetCameraArea, ConsoleVoid, 3, 6, (x1 / y1 / x2 / y2))
  313. {
  314. // Upper left bound.
  315. Vector2 v1;
  316. // Lower right bound.
  317. Vector2 v2;
  318. // Grab the number of elements in the first two parameters.
  319. U32 elementCount1 = Utility::mGetStringElementCount(argv[2]);
  320. U32 elementCount2 = 1;
  321. if (argc > 3)
  322. elementCount2 = Utility::mGetStringElementCount(argv[3]);
  323. // ("x1 y1 x2 y2")
  324. if ((elementCount1 == 4) && (argc == 3))
  325. {
  326. v1 = Utility::mGetStringElementVector(argv[2]);
  327. v2 = Utility::mGetStringElementVector(argv[2], 2);
  328. }
  329. // ("x1 y1", "x2 y2")
  330. else if ((elementCount1 == 2) && (elementCount2 == 2) && (argc == 4))
  331. {
  332. v1 = Utility::mGetStringElementVector(argv[2]);
  333. v2 = Utility::mGetStringElementVector(argv[3]);
  334. }
  335. // (x1, y1, x2, y2)
  336. else if (argc == 6)
  337. {
  338. v1 = Vector2(dAtof(argv[2]), dAtof(argv[3]));
  339. v2 = Vector2(dAtof(argv[4]), dAtof(argv[5]));
  340. }
  341. // Invalid
  342. else
  343. {
  344. Con::warnf("SceneWindow::setTargetCameraArea() - Invalid number of parameters!");
  345. return;
  346. }
  347. // Calculate Normalised Rectangle.
  348. Vector2 topLeft( (v1.x <= v2.x) ? v1.x : v2.x, (v1.y <= v2.y) ? v1.y : v2.y );
  349. Vector2 bottomRight( (v1.x > v2.x) ? v1.x : v2.x, (v1.y > v2.y) ? v1.y : v2.y );
  350. // Set Target Camera Area.
  351. object->setTargetCameraArea( RectF(topLeft.x, topLeft.y, bottomRight.x-topLeft.x+1, bottomRight.y-topLeft.y+1) );
  352. }
  353. //-----------------------------------------------------------------------------
  354. /*! Get the target camera Area.
  355. @return The camera area formatted as \x1 y1 x2 y2\
  356. */
  357. ConsoleMethodWithDocs(SceneWindow, getTargetCameraArea, ConsoleString, 2, 2, ())
  358. {
  359. // Fetch Camera Window.
  360. const RectF cameraWindow = object->getTargetCameraArea();
  361. // Create Returnable Buffer.
  362. char* pBuffer = Con::getReturnBuffer(64);
  363. // Format Buffer.
  364. dSprintf(pBuffer, 64, "%.5g %.5g %.5g %.5g", cameraWindow.point.x, cameraWindow.point.y, cameraWindow.point.x+cameraWindow.extent.x, cameraWindow.point.y+cameraWindow.extent.y);
  365. // Return Buffer.
  366. return pBuffer;
  367. }
  368. //-----------------------------------------------------------------------------
  369. /*! Set the target camera Zoom Factor.
  370. @return No return value.
  371. */
  372. ConsoleMethodWithDocs(SceneWindow, setTargetCameraZoom, ConsoleVoid, 3, 3, (zoomFactor))
  373. {
  374. object->setTargetCameraZoom( dAtof(argv[2]) );
  375. }
  376. //-----------------------------------------------------------------------------
  377. /*! Get the target camera Zoom.
  378. @return The current camera zoom.
  379. */
  380. ConsoleMethodWithDocs(SceneWindow, getTargetCameraZoom, ConsoleFloat, 2, 2, ())
  381. {
  382. return object->getTargetCameraZoom();
  383. }
  384. //-----------------------------------------------------------------------------
  385. /*! Sets the target camera angle.
  386. @param angle The target camera angle in degrees.
  387. @return No return value.
  388. */
  389. ConsoleMethodWithDocs(SceneWindow, setTargetCameraAngle, ConsoleVoid, 3, 3, (angle))
  390. {
  391. object->setTargetCameraAngle( mDegToRad(dAtof(argv[2])) );
  392. }
  393. //-----------------------------------------------------------------------------
  394. /*! Gets the target camera angle.
  395. @return The target camera angle in degrees.
  396. */
  397. ConsoleMethodWithDocs(SceneWindow, getTargetCameraAngle, ConsoleFloat, 2, 2, ())
  398. {
  399. return object->getTargetCameraAngle();
  400. }
  401. //-----------------------------------------------------------------------------
  402. /*! Set camera interpolation time.
  403. @return No return value
  404. */
  405. ConsoleMethodWithDocs(SceneWindow, setCameraInterpolationTime, ConsoleVoid, 3, 3, (interpolationTime))
  406. {
  407. // Set Camera Interpolation Time.
  408. object->setCameraInterpolationTime( dAtof(argv[2]) );
  409. }
  410. //-----------------------------------------------------------------------------
  411. /*! Set camera interpolation mode.
  412. @return No return value.
  413. */
  414. ConsoleMethodWithDocs(SceneWindow, setCameraInterpolationMode, ConsoleVoid, 3, 3, (interpolationMode))
  415. {
  416. // Set Camera Interpolation Mode.
  417. object->setCameraInterpolationMode( SceneWindow::getInterpolationModeEnum(argv[2]) );
  418. }
  419. //-----------------------------------------------------------------------------
  420. /*! Start Camera Move.
  421. @return No return value.
  422. */
  423. ConsoleMethodWithDocs(SceneWindow, startCameraMove, ConsoleVoid, 2, 3, ([interpolationTime]))
  424. {
  425. F32 interpolationTime;
  426. // Interpolation Time?
  427. if ( argc >= 3 )
  428. interpolationTime = dAtof(argv[2]);
  429. else
  430. interpolationTime = object->getCameraInterpolationTime();
  431. // Start Camera Move.
  432. object->startCameraMove( interpolationTime );
  433. }
  434. //-----------------------------------------------------------------------------
  435. /*! Stops current camera movement
  436. @return No return value.
  437. */
  438. ConsoleMethodWithDocs(SceneWindow, stopCameraMove, ConsoleVoid, 2, 2, ())
  439. {
  440. // Stop Camera Move.
  441. object->stopCameraMove();
  442. }
  443. //-----------------------------------------------------------------------------
  444. /*! Moves camera directly to target.
  445. @return No return value.
  446. */
  447. ConsoleMethodWithDocs(SceneWindow, completeCameraMove, ConsoleVoid, 2, 2, ())
  448. {
  449. // Complete Camera Move.
  450. object->completeCameraMove();
  451. }
  452. //-----------------------------------------------------------------------------
  453. /*! Reverses previous camera movement.
  454. @return No return value.
  455. */
  456. ConsoleMethodWithDocs(SceneWindow, undoCameraMove, ConsoleVoid, 2, 3, ([interpolationTime]))
  457. {
  458. F32 interpolationTime;
  459. // Interpolation Time?
  460. if ( argc >= 3 )
  461. interpolationTime = dAtof(argv[2]);
  462. else
  463. interpolationTime = object->getCameraInterpolationTime();
  464. // Undo Camera Move.
  465. object->undoCameraMove( interpolationTime );
  466. }
  467. //-----------------------------------------------------------------------------
  468. /*! Check the camera moving status.
  469. @return Returns a boolean value as to whether or not the camera is moving.
  470. */
  471. ConsoleMethodWithDocs(SceneWindow, getIsCameraMoving, ConsoleBool, 2, 2, ())
  472. {
  473. // Is Camera Moving?
  474. return object->isCameraMoving();
  475. }
  476. //-----------------------------------------------------------------------------
  477. /*! Check the camera mounted status.
  478. @return Returns a boolean value as to whether or not the camera is mounted.
  479. */
  480. ConsoleMethodWithDocs(SceneWindow, getIsCameraMounted, ConsoleBool, 2, 2, ())
  481. {
  482. // Is Camera Mounted.
  483. return object->isCameraMounted();
  484. }
  485. //-----------------------------------------------------------------------------
  486. /*! Starts the camera shaking.
  487. @param shakeMagnitude The intensity of the shaking
  488. @param time The length of the shake
  489. @return No return value
  490. */
  491. ConsoleMethodWithDocs(SceneWindow, startCameraShake, ConsoleVoid, 4, 4, (shakeMagnitude, time))
  492. {
  493. // Start Camera Shake.
  494. object->startCameraShake( dAtof(argv[2]), dAtof(argv[3]) );
  495. }
  496. //-----------------------------------------------------------------------------
  497. /*! Stops the camera shaking.
  498. @return No return value
  499. */
  500. ConsoleMethodWithDocs(SceneWindow, stopCameraShake, ConsoleVoid, 2, 2, ())
  501. {
  502. // Stop Camera Shake.
  503. object->stopCameraShake();
  504. }
  505. //-----------------------------------------------------------------------------
  506. /*! Mounts the camera onto the specified object.
  507. @param sceneObject The scene object to mount the camera to.
  508. @param offsetX / offsetY The offset from the objects position to mount the camera to. Optional: Defaults to no offset.
  509. @param mountForce The force to use to keep the camera mounted to the object. Zero is a rigid mount. Optional: Defaults to zero.
  510. @param sendToMount Whether to immediately move the camera to the objects position or not. Optional: Defaults to true.
  511. @param mountAngle Whether to mount the cameras angle to the objects angle or not. Optional: Defaults to false.
  512. @return No return value
  513. */
  514. ConsoleMethodWithDocs(SceneWindow, mount, ConsoleVoid, 3, 8, (sceneObject, [offsetX / offsetY], [mountForce], [sendToMount?], [mountAngle?]))
  515. {
  516. // Grab the object. Always specified.
  517. SceneObject* pSceneObject = dynamic_cast<SceneObject*>(Sim::findObject(argv[2]));
  518. // Validate Object.
  519. if (!pSceneObject)
  520. {
  521. Con::warnf("SceneWindow::mount() - Couldn't find/Invalid object '%s'.", argv[2]);
  522. return;
  523. }
  524. // Set defaults.
  525. Vector2 mountOffset(0.0f, 0.0f);
  526. F32 mountForce = 0.0f;
  527. bool sendToMount = true;
  528. bool mountAngle = false;
  529. U32 nextArg = 3;
  530. if ( (U32)argc > nextArg )
  531. {
  532. // Fetch Element Count.
  533. const U32 elementCount = Utility::mGetStringElementCount(argv[nextArg]);
  534. // (object, "offsetX offsetY", ...)
  535. if ( elementCount == 2 )
  536. {
  537. mountOffset = Utility::mGetStringElementVector(argv[nextArg++]);
  538. }
  539. // (object, offsetX, offsetY, ...)
  540. else if ( elementCount == 1 && (U32)argc >= nextArg+1 )
  541. {
  542. mountOffset = Vector2(dAtof(argv[nextArg]), dAtof(argv[nextArg+1]));
  543. nextArg += 2;
  544. }
  545. // Invalid.
  546. else
  547. {
  548. Con::warnf("SceneWindow::mount() - Invalid number of parameters!");
  549. return;
  550. }
  551. }
  552. // Grab the mount force - if it's specified.
  553. if ( (U32)argc > nextArg )
  554. mountForce = dAtof(argv[nextArg++]);
  555. // Grab the send to mount flag.
  556. if ( (U32)argc > nextArg )
  557. sendToMount = dAtob(argv[nextArg++]);
  558. if ( (U32)argc > nextArg )
  559. mountAngle = dAtob(argv[nextArg++]);
  560. // Mount Object.
  561. object->mount( pSceneObject, mountOffset, mountForce, sendToMount, mountAngle );
  562. }
  563. //-----------------------------------------------------------------------------
  564. /*! Dismounts Camera from object.
  565. @return No return value
  566. */
  567. ConsoleMethodWithDocs(SceneWindow, dismount, ConsoleVoid, 2, 2, ())
  568. {
  569. // Dismount Object.
  570. object->dismount();
  571. }
  572. //-----------------------------------------------------------------------------
  573. void SceneWindow::dismountMe( SceneObject* pSceneObject )
  574. {
  575. // Are we mounted to the specified object?
  576. if ( isCameraMounted() && pSceneObject != mpMountedTo )
  577. {
  578. // No, so warn.
  579. Con::warnf("SceneWindow::dismountMe() - Object is not mounted by the camera!");
  580. return;
  581. }
  582. // Dismount Object.
  583. dismount();
  584. }
  585. //-----------------------------------------------------------------------------
  586. /*! Set View Limit On.
  587. @return No return value
  588. */
  589. ConsoleMethodWithDocs(SceneWindow, setViewLimitOn, ConsoleVoid, 3, 6, ([minX / minY / maxX / maxY]))
  590. {
  591. // Upper left bound.
  592. Vector2 v1;
  593. // Lower right bound.
  594. Vector2 v2;
  595. // Grab the number of elements in the first two parameters.
  596. U32 elementCount1 = Utility::mGetStringElementCount(argv[2]);
  597. U32 elementCount2 = 1;
  598. if (argc > 3)
  599. elementCount2 = Utility::mGetStringElementCount(argv[3]);
  600. // ("x1 y1 x2 y2")
  601. if ((elementCount1 == 4) && (argc == 3))
  602. {
  603. v1 = Utility::mGetStringElementVector(argv[2]);
  604. v2 = Utility::mGetStringElementVector(argv[2], 2);
  605. }
  606. // ("x1 y1", "x2 y2")
  607. else if ((elementCount1 == 2) && (elementCount2 == 2) && (argc == 4))
  608. {
  609. v1 = Utility::mGetStringElementVector(argv[2]);
  610. v2 = Utility::mGetStringElementVector(argv[3]);
  611. }
  612. // (x1, y1, x2, y2)
  613. else if (argc == 6)
  614. {
  615. v1 = Vector2(dAtof(argv[2]), dAtof(argv[3]));
  616. v2 = Vector2(dAtof(argv[4]), dAtof(argv[5]));
  617. }
  618. // Invalid
  619. else
  620. {
  621. Con::warnf("SceneWindow::setViewLimitOn() - Invalid number of parameters!");
  622. return;
  623. }
  624. // Calculate Normalised Rectangle.
  625. Vector2 topLeft((v1.x <= v2.x) ? v1.x : v2.x, (v1.y <= v2.y) ? v1.y : v2.y);
  626. Vector2 bottomRight((v1.x > v2.x) ? v1.x : v2.x, (v1.y > v2.y) ? v1.y : v2.y);
  627. // Set the View Limit On.
  628. object->setViewLimitOn(topLeft, bottomRight);
  629. }
  630. //-----------------------------------------------------------------------------
  631. /*! Set View Limit Off.
  632. @return No return value
  633. */
  634. ConsoleMethodWithDocs(SceneWindow, setViewLimitOff, ConsoleVoid, 2, 2, ())
  635. {
  636. // Set View Limit Off.
  637. object->setViewLimitOff();
  638. }
  639. //-----------------------------------------------------------------------------
  640. /*! Clamps the current camera to the current view limit.
  641. Nothing will happen if the view-limit is not active or the camera is moving.
  642. @return No return value
  643. */
  644. ConsoleMethodWithDocs(SceneWindow, clampCameraViewLimit, ConsoleVoid, 2, 2, ())
  645. {
  646. object->clampCameraViewLimit();
  647. }
  648. //-----------------------------------------------------------------------------
  649. /*! Sets the render group(s).
  650. @param groups The list of groups you wish to set.
  651. @return No return value.
  652. */
  653. ConsoleMethodWithDocs(SceneWindow, setRenderGroups, ConsoleVoid, 3, 2 + MASK_BITCOUNT, (groups$))
  654. {
  655. // The mask.
  656. U32 mask = 0;
  657. // Grab the element count of the first parameter.
  658. U32 elementCount = Utility::mGetStringElementCount(argv[2]);
  659. // Make sure we get at least one number.
  660. if (elementCount < 1)
  661. {
  662. Con::warnf("SceneWindow::setRenderGroups() - Invalid number of parameters!");
  663. return;
  664. }
  665. // Space separated list.
  666. if (argc == 3)
  667. {
  668. // Convert the string to a mask.
  669. for (U32 i = 0; i < elementCount; i++)
  670. {
  671. S32 bit = dAtoi(Utility::mGetStringElement(argv[2], i));
  672. // Make sure the group is valid.
  673. if ((bit < 0) || (bit >= MASK_BITCOUNT))
  674. {
  675. Con::warnf("SceneWindow::setRenderGroups() - Invalid group specified (%d); skipped!", bit);
  676. continue;
  677. }
  678. mask |= (1 << bit);
  679. }
  680. }
  681. // Comma separated list.
  682. else
  683. {
  684. // Convert the list to a mask.
  685. for ( U32 i = 2; i < (U32)argc; i++ )
  686. {
  687. S32 bit = dAtoi(argv[i]);
  688. // Make sure the group is valid.
  689. if ((bit < 0) || (bit >= MASK_BITCOUNT))
  690. {
  691. Con::warnf("SceneWindow::setRenderGroups() - Invalid group specified (%d); skipped!", bit);
  692. continue;
  693. }
  694. mask |= (1 << bit);
  695. }
  696. }
  697. // Set Collision Groups.
  698. object->setRenderGroups(mask);
  699. }
  700. //-----------------------------------------------------------------------------
  701. /*! Sets the render layers(s).
  702. @param The layer numbers you wish to set.
  703. @return No return value.
  704. */
  705. ConsoleMethodWithDocs(SceneWindow, setRenderLayers, ConsoleVoid, 3, 2 + MASK_BITCOUNT, (layers$))
  706. {
  707. // The mask.
  708. U32 mask = 0;
  709. // Grab the element count of the first parameter.
  710. U32 elementCount = Utility::mGetStringElementCount(argv[2]);
  711. // Make sure we get at least one number.
  712. if (elementCount < 1)
  713. {
  714. Con::warnf("SceneWindow::setRenderLayers() - Invalid number of parameters!");
  715. return;
  716. }
  717. // Space separated list.
  718. if (argc == 3)
  719. {
  720. // Convert the string to a mask.
  721. for (U32 i = 0; i < elementCount; i++)
  722. {
  723. S32 bit = dAtoi(Utility::mGetStringElement(argv[2], i));
  724. // Make sure the group is valid.
  725. if ((bit < 0) || (bit >= MASK_BITCOUNT))
  726. {
  727. Con::warnf("SceneWindow::setRenderLayers() - Invalid layer specified (%d); skipped!", bit);
  728. continue;
  729. }
  730. mask |= (1 << bit);
  731. }
  732. }
  733. // Comma separated list.
  734. else
  735. {
  736. // Convert the list to a mask.
  737. for ( U32 i = 2; i < (U32)argc; i++ )
  738. {
  739. S32 bit = dAtoi(argv[i]);
  740. // Make sure the group is valid.
  741. if ((bit < 0) || (bit >= MASK_BITCOUNT))
  742. {
  743. Con::warnf("SceneWindow::setRenderLayers() - Invalid layer specified (%d); skipped!", bit);
  744. continue;
  745. }
  746. mask |= (1 << bit);
  747. }
  748. }
  749. // Set Collision Groups.
  750. object->setRenderLayers(mask);
  751. }
  752. //-----------------------------------------------------------------------------
  753. /*! Sets the layer/group mask which control what is rendered.
  754. @param layermask The bitmask for setting the layers to render
  755. @param groupmask The bitmask for setting the groups to render
  756. @return No return value.
  757. */
  758. ConsoleMethodWithDocs(SceneWindow, setRenderMasks, ConsoleVoid, 3, 4, (layerMask, groupMask))
  759. {
  760. // Set Render Masks.
  761. if( argc < 4 )
  762. object->setRenderLayers( dAtoi( argv[2] ) );
  763. else
  764. object->setRenderMasks( dAtoi(argv[2]), dAtoi(argv[3]) );
  765. }
  766. //-----------------------------------------------------------------------------
  767. /*! Gets the layer mask which controls what is rendered.
  768. @returns The bit mask corresponding to the layers which are to be rendered
  769. */
  770. ConsoleMethodWithDocs(SceneWindow, getRenderLayerMask, ConsoleInt, 2, 2, ())
  771. {
  772. return object->getRenderLayerMask();
  773. }
  774. //-----------------------------------------------------------------------------
  775. /*! Gets the group mask which controls what is rendered.
  776. @returns The bit mask corresponding to the groups which are to be rendered
  777. */
  778. ConsoleMethodWithDocs(SceneWindow, getRenderGroupMask, ConsoleInt, 2, 2, ())
  779. {
  780. return object->getRenderGroupMask();
  781. }
  782. //-----------------------------------------------------------------------------
  783. /*! or ( stockColorName ) - Sets the background color for the scene.
  784. @param red The red value.
  785. @param green The green value.
  786. @param blue The blue value.
  787. @param alpha The alpha value.
  788. @return No return Value.
  789. */
  790. ConsoleMethodWithDocs(SceneWindow, setBackgroundColor, ConsoleVoid, 3, 6, (float red, float green, float blue, [float alpha = 1.0]))
  791. {
  792. // The colors.
  793. F32 red;
  794. F32 green;
  795. F32 blue;
  796. F32 alpha = 1.0f;
  797. // Space separated.
  798. if (argc == 3)
  799. {
  800. // Grab the element count.
  801. const U32 elementCount = Utility::mGetStringElementCount(argv[2]);
  802. // Has a single argument been specified?
  803. if ( elementCount == 1 )
  804. {
  805. object->setDataField( StringTable->insert("BackgroundColor"), NULL, argv[2] );
  806. return;
  807. }
  808. // ("R G B [A]")
  809. if ((elementCount == 3) || (elementCount == 4))
  810. {
  811. // Extract the color.
  812. red = dAtof(Utility::mGetStringElement(argv[2], 0));
  813. green = dAtof(Utility::mGetStringElement(argv[2], 1));
  814. blue = dAtof(Utility::mGetStringElement(argv[2], 2));
  815. // Grab the alpha if it's there.
  816. if (elementCount > 3)
  817. alpha = dAtof(Utility::mGetStringElement(argv[2], 3));
  818. }
  819. // Invalid.
  820. else
  821. {
  822. Con::warnf("SceneWindow::setBackgroundColor() - Invalid Number of parameters!");
  823. return;
  824. }
  825. }
  826. // (R, G, B)
  827. else if (argc >= 5)
  828. {
  829. red = dAtof(argv[2]);
  830. green = dAtof(argv[3]);
  831. blue = dAtof(argv[4]);
  832. // Grab the alpha if it's there.
  833. if (argc > 5)
  834. alpha = dAtof(argv[5]);
  835. }
  836. // Invalid.
  837. else
  838. {
  839. Con::warnf("SceneWindow::setBackgroundColor() - Invalid Number of parameters!");
  840. return;
  841. }
  842. // Set background color.
  843. object->setBackgroundColor(ColorF(red, green, blue, alpha) );
  844. }
  845. //-----------------------------------------------------------------------------
  846. /*! Gets the background color for the scene.
  847. @return (float red / float green / float blue / float alpha) The background color for the scene.
  848. */
  849. ConsoleMethodWithDocs(SceneWindow, getBackgroundColor, ConsoleString, 2, 2, (...))
  850. {
  851. // Get the background color.
  852. const ColorF& color = object->getBackgroundColor();
  853. // Fetch color name.
  854. StringTableEntry colorName = StockColor::name( color );
  855. // Return the color name if it's valid.
  856. if ( colorName != StringTable->EmptyString )
  857. return colorName;
  858. // Create Returnable Buffer.
  859. char* pBuffer = Con::getReturnBuffer(64);
  860. // Format Buffer.
  861. dSprintf(pBuffer, 64, "%g %g %g %g", color.red, color.green, color.blue, color.alpha );
  862. // Return buffer.
  863. return pBuffer;
  864. }
  865. //-----------------------------------------------------------------------------
  866. /*! Sets whether to use the scene background color or not.
  867. @param useBackgroundColor Whether to use the scene background color or not.
  868. @return No return value.
  869. */
  870. ConsoleMethodWithDocs(SceneWindow, setUseBackgroundColor, ConsoleVoid, 3, 3, (...))
  871. {
  872. // Fetch flag.
  873. const bool useBackgroundColor = dAtob(argv[2]);
  874. // Set the flag.
  875. object->setUseBackgroundColor( useBackgroundColor );
  876. }
  877. //-----------------------------------------------------------------------------
  878. /*! Gets whether the scene background color is in use or not.
  879. @return Whether the scene background color is in use or not.
  880. */
  881. ConsoleMethodWithDocs(SceneWindow, getUseBackgroundColor, ConsoleBool, 2, 2, (...))
  882. {
  883. // Get the flag.
  884. return object->getUseBackgroundColor();
  885. }
  886. //-----------------------------------------------------------------------------
  887. /*! Sets whether input events are monitored by the window or not.
  888. @param inputStatus Whether input events are processed by the window or not.
  889. @return No return value.
  890. */
  891. ConsoleMethodWithDocs(SceneWindow, setUseWindowInputEvents, ConsoleVoid, 3, 3, (inputStatus))
  892. {
  893. object->setUseWindowInputEvents( dAtob(argv[2]) );
  894. }
  895. //-----------------------------------------------------------------------------
  896. /*! Gets whether input events are monitored by the window or not.
  897. @return Whether input events are monitored by the window or not.
  898. */
  899. ConsoleMethodWithDocs(SceneWindow, getUseWindowInputEvents, ConsoleBool, 2, 2, ())
  900. {
  901. return object->getUseWindowInputEvents();
  902. }
  903. //-----------------------------------------------------------------------------
  904. /*! Sets whether input events are passed onto scene objects or not.
  905. @param mouseStatus Whether input events are passed onto scene objects or not.
  906. */
  907. ConsoleMethodWithDocs(SceneWindow, setUseObjectInputEvents, ConsoleVoid, 3, 3, (inputStatus))
  908. {
  909. object->setUseObjectInputEvents( dAtob(argv[2]) );
  910. }
  911. //-----------------------------------------------------------------------------
  912. /*! Gets whether input events are passed onto scene objects or not.
  913. @return Whether input events are passed onto scene objects or not..
  914. */
  915. ConsoleMethodWithDocs(SceneWindow, getUseObjectInputEvents, ConsoleBool, 2, 2, ())
  916. {
  917. return object->getUseObjectInputEvents();
  918. }
  919. //-----------------------------------------------------------------------------
  920. /*! Sets the input events group filter.
  921. @param List of groups to filter input events with.
  922. @return No return value.
  923. */
  924. ConsoleMethodWithDocs(SceneWindow, setObjectInputEventGroupFilter, ConsoleVoid, 3, 2 + MASK_BITCOUNT, (groups$))
  925. {
  926. // The mask.
  927. U32 mask = 0;
  928. // Grab the element count of the first parameter.
  929. U32 elementCount = Utility::mGetStringElementCount(argv[2]);
  930. // Make sure we get at least one number.
  931. if (elementCount < 1)
  932. {
  933. Con::warnf("SceneWindow::setObjectInputEventGroupFilter() - Invalid number of parameters!");
  934. return;
  935. }
  936. // Space separated list.
  937. if (argc == 3)
  938. {
  939. // Convert the string to a mask.
  940. for (U32 i = 0; i < elementCount; i++)
  941. {
  942. S32 bit = dAtoi(Utility::mGetStringElement(argv[2], i));
  943. // Make sure the group is valid.
  944. if ((bit < 0) || (bit >= MASK_BITCOUNT))
  945. {
  946. Con::warnf("SceneWindow::setObjectInputEventGroupFilter() - Invalid group specified (%d); skipped!", bit);
  947. continue;
  948. }
  949. mask |= (1 << bit);
  950. }
  951. }
  952. // Comma separated list.
  953. else
  954. {
  955. // Convert the list to a mask.
  956. for ( U32 i = 2; i < (U32)argc; i++ )
  957. {
  958. S32 bit = dAtoi(argv[i]);
  959. // Make sure the group is valid.
  960. if ((bit < 0) || (bit >= MASK_BITCOUNT))
  961. {
  962. Con::warnf("SceneWindow::setObjectInputEventGroupFilter() - Invalid group specified (%d); skipped!", bit);
  963. continue;
  964. }
  965. mask |= (1 << bit);
  966. }
  967. }
  968. // Set group filter.
  969. object->setObjectInputEventGroupFilter(mask);
  970. }
  971. //-----------------------------------------------------------------------------
  972. /*! Sets the input events layer filter.
  973. @param The list of layers to filter input events with.
  974. @return No return value.
  975. */
  976. ConsoleMethodWithDocs(SceneWindow, setObjectInputEventLayerFilter, ConsoleVoid, 3, 2 + MASK_BITCOUNT, (layers$))
  977. {
  978. // The mask.
  979. U32 mask = 0;
  980. // Grab the element count of the first parameter.
  981. U32 elementCount = Utility::mGetStringElementCount(argv[2]);
  982. // Make sure we get at least one number.
  983. if (elementCount < 1)
  984. {
  985. Con::warnf("SceneWindow::setObjectInputEventLayerFilter() - Invalid number of parameters!");
  986. return;
  987. }
  988. // Space separated list.
  989. if (argc == 3)
  990. {
  991. // Convert the string to a mask.
  992. for (U32 i = 0; i < elementCount; i++)
  993. {
  994. S32 bit = dAtoi(Utility::mGetStringElement(argv[2], i));
  995. // Make sure the group is valid.
  996. if ((bit < 0) || (bit >= MASK_BITCOUNT))
  997. {
  998. Con::warnf("SceneWindow::setObjectInputEventLayerFilter() - Invalid layer specified (%d); skipped!", bit);
  999. continue;
  1000. }
  1001. mask |= (1 << bit);
  1002. }
  1003. }
  1004. // Comma separated list.
  1005. else
  1006. {
  1007. // Convert the list to a mask.
  1008. for ( U32 i = 2; i < (U32)argc; i++ )
  1009. {
  1010. S32 bit = dAtoi(argv[i]);
  1011. // Make sure the group is valid.
  1012. if ((bit < 0) || (bit >= MASK_BITCOUNT))
  1013. {
  1014. Con::warnf("SceneWindow::setObjectInputEventLayerFilter() - Invalid layer specified (%d); skipped!", bit);
  1015. continue;
  1016. }
  1017. mask |= (1 << bit);
  1018. }
  1019. }
  1020. // Set layer filter.
  1021. object->setObjectInputEventLayerFilter(mask);
  1022. }
  1023. //-----------------------------------------------------------------------------
  1024. /*! Sets input filter for input events.
  1025. */
  1026. ConsoleMethodWithDocs(SceneWindow, setObjectInputEventFilter, ConsoleVoid, 4, 5, (groupMask, layerMask, [useInvisibleFilter?]))
  1027. {
  1028. // Calculate Use Invisible Flag.
  1029. bool useInvisible = argc >= 5 ? dAtob(argv[4]) : true;
  1030. // Set input event filter.
  1031. object->setObjectInputEventFilter( dAtoi(argv[2]), dAtoi(argv[3]), useInvisible );
  1032. }
  1033. //-----------------------------------------------------------------------------
  1034. /*! Sets whether invisible objects should be filtered for input events or not.
  1035. */
  1036. ConsoleMethodWithDocs(SceneWindow, setObjectInputEventInvisibleFilter, ConsoleVoid, 3, 3, (bool useInvisibleFilter))
  1037. {
  1038. object->setObjectInputEventInvisibleFilter(dAtob(argv[2]));
  1039. }
  1040. //-----------------------------------------------------------------------------
  1041. /*! Adds an object as an input listener.
  1042. @param inputListener The object to add as an input listener.
  1043. @return Whether the object was added as an input event listener or not.
  1044. */
  1045. ConsoleMethodWithDocs(SceneWindow, addInputListener, ConsoleBool, 3, 3, (inputListener))
  1046. {
  1047. // Find the SimObject
  1048. SimObject* pSimObject = Sim::findObject( argv[2] );
  1049. // Did we find the SimObject?
  1050. if ( pSimObject == NULL )
  1051. {
  1052. // No, so warn.
  1053. Con::warnf( "SceneWindow::addInputListener() - Could not find the object '%s' to add as an input event listener.", argv[2] );
  1054. return false;
  1055. }
  1056. // Add input listener.
  1057. object->addInputListener( pSimObject );
  1058. return true;
  1059. }
  1060. //-----------------------------------------------------------------------------
  1061. /*! Removes an object from being an input listener.
  1062. @param inputListener The object to remove as an input listener.
  1063. @return Whether the object was removed as an input event listener or not.
  1064. */
  1065. ConsoleMethodWithDocs(SceneWindow, removeInputListener, ConsoleBool, 3, 3, (inputListener))
  1066. {
  1067. // Find the SimObject
  1068. SimObject* pSimObject = Sim::findObject( argv[2] );
  1069. // Did we find the SimObject?
  1070. if ( pSimObject == NULL )
  1071. {
  1072. // No, so warn.
  1073. Con::warnf( "SceneWindow::removeInputListener() - Could not find the object '%s' to remove from being an input event listener.", argv[2] );
  1074. return false;
  1075. }
  1076. // Remove input listener.
  1077. object->removeInputListener( pSimObject );
  1078. return true;
  1079. }
  1080. //-----------------------------------------------------------------------------
  1081. /*! Sets the window mouse-lock status.
  1082. @return No return value.
  1083. */
  1084. ConsoleMethodWithDocs(SceneWindow, setLockMouse, ConsoleVoid, 3, 3, (bool lockSet))
  1085. {
  1086. // Set Lock Mouse.
  1087. object->setLockMouse( dAtob(argv[2]) );
  1088. }
  1089. //-----------------------------------------------------------------------------
  1090. /*! Gets the window mouse-lock status.
  1091. */
  1092. ConsoleMethodWithDocs(SceneWindow, getLockMouse, ConsoleBool, 2, 2, ())
  1093. {
  1094. // Get Lock Mouse.
  1095. return object->getLockMouse();
  1096. }
  1097. //-----------------------------------------------------------------------------
  1098. /*! Sets Current Mouse Position.
  1099. @param x,y The coordinates to set the mouse cursor. Accepts either (x,y) or (\x y\
  1100. */
  1101. ConsoleMethodWithDocs(SceneWindow, setMousePosition, ConsoleVoid, 3, 4, (x/y))
  1102. {
  1103. // The new position.
  1104. Vector2 position;
  1105. // Elements in the first argument.
  1106. U32 elementCount = Utility::mGetStringElementCount(argv[2]);
  1107. // ("x y")
  1108. if ((elementCount == 2) && (argc == 3))
  1109. position = Utility::mGetStringElementVector(argv[2]);
  1110. // (x, y)
  1111. else if ((elementCount == 1) && (argc == 4))
  1112. position = Vector2(dAtof(argv[2]), dAtof(argv[3]));
  1113. // Invalid
  1114. else
  1115. {
  1116. Con::warnf("SceneWindow::setMousePosition() - Invalid number of parameters!");
  1117. return;
  1118. }
  1119. // Set Mouse Position.
  1120. object->setMousePosition( position );
  1121. }
  1122. //-----------------------------------------------------------------------------
  1123. /*! Gets Current Mouse Position.
  1124. @return Returns a string with the current mouse cursor coordinates formatted as \x y\
  1125. */
  1126. ConsoleMethodWithDocs(SceneWindow, getMousePosition, ConsoleString, 2, 2, ())
  1127. {
  1128. // Fetch Mouse Position.
  1129. Vector2 worldMousePoint = object->getMousePosition();
  1130. // Create Returnable Buffer.
  1131. char* pBuffer = Con::getReturnBuffer(32);
  1132. // Generate Script Parameters.
  1133. dSprintf(pBuffer, 32, "%g %g", worldMousePoint.x, worldMousePoint.y);
  1134. // Return Buffer.
  1135. return pBuffer;
  1136. }
  1137. //-----------------------------------------------------------------------------
  1138. /*! Returns World coordinate of Window coordinate.
  1139. @param x,y The coordinates in window coordinates you wish to convert to world coordinates. Accepts either (x,y) or (\x y\
  1140. @return Returns the desired world coordinates as a string formatted as \x y\
  1141. */
  1142. ConsoleMethodWithDocs(SceneWindow, getWorldPoint, ConsoleString, 3, 4, (X / Y))
  1143. {
  1144. // The new position.
  1145. Vector2 srcPoint;
  1146. // Elements in the first argument.
  1147. U32 elementCount = Utility::mGetStringElementCount(argv[2]);
  1148. // ("x y")
  1149. if ((elementCount == 2) && (argc == 3))
  1150. srcPoint = Utility::mGetStringElementVector(argv[2]);
  1151. // (x, y)
  1152. else if ((elementCount == 1) && (argc == 4))
  1153. srcPoint = Vector2(dAtof(argv[2]), dAtof(argv[3]));
  1154. // Invalid
  1155. else
  1156. {
  1157. Con::warnf("SceneWindow::getWorldPoint() - Invalid number of parameters!");
  1158. return NULL;
  1159. }
  1160. // Destination Point.
  1161. Vector2 dstPoint;
  1162. // Do Conversion.
  1163. object->windowToScenePoint( srcPoint, dstPoint );
  1164. return dstPoint.scriptThis();
  1165. }
  1166. //-----------------------------------------------------------------------------
  1167. /*! Returns Window coordinate of World coordinate.
  1168. @param x,y The coordinates in world coordinates you wish to convert to window coordinates. Accepts either (x,y) or (\x y\
  1169. @return Returns the desired window coordinates as a string formatted as \x y\
  1170. */
  1171. ConsoleMethodWithDocs(SceneWindow, getWindowPoint, ConsoleString, 3, 4, (X / Y))
  1172. {
  1173. // The new position.
  1174. Vector2 srcPoint;
  1175. // Elements in the first argument.
  1176. U32 elementCount = Utility::mGetStringElementCount(argv[2]);
  1177. // ("x y")
  1178. if ((elementCount == 2) && (argc == 3))
  1179. srcPoint = Utility::mGetStringElementVector(argv[2]);
  1180. // (x, y)
  1181. else if ((elementCount == 1) && (argc == 4))
  1182. srcPoint = Vector2(dAtof(argv[2]), dAtof(argv[3]));
  1183. // Invalid
  1184. else
  1185. {
  1186. Con::warnf("SceneWindow::getWindowPoint() - Invalid number of parameters!");
  1187. return NULL;
  1188. }
  1189. // Destination Point.
  1190. Vector2 dstPoint;
  1191. // Do Conversion.
  1192. object->sceneToWindowPoint( srcPoint, dstPoint );
  1193. return dstPoint.scriptThis();
  1194. }
  1195. //-----------------------------------------------------------------------------
  1196. /*! Returns Canvas coordinate of Window coordinate.
  1197. @param x,y The coordinates in world coordinates you wish to convert to window coordinates. Accepts either (x,y) or (\x y\
  1198. @return Returns the desired canvas coordinates as a string formatted as \x y\
  1199. */
  1200. ConsoleMethodWithDocs(SceneWindow, getCanvasPoint, ConsoleString, 3, 4, (X / Y))
  1201. {
  1202. // The new position.
  1203. Point2I srcPoint;
  1204. // Elements in the first argument.
  1205. U32 elementCount = Utility::mGetStringElementCount(argv[2]);
  1206. // ("x y")
  1207. if ((elementCount == 2) && (argc == 3))
  1208. {
  1209. srcPoint.x = dAtoi(Utility::mGetStringElement(argv[2], 0));
  1210. srcPoint.y = dAtoi(Utility::mGetStringElement(argv[2], 1));
  1211. }
  1212. // (x, y)
  1213. else if ((elementCount == 1) && (argc == 4))
  1214. srcPoint = Point2I(dAtoi(argv[2]), dAtoi(argv[3]));
  1215. // Invalid
  1216. else
  1217. {
  1218. Con::warnf("SceneWindow::getCanvasPoint() - Invalid number of parameters!");
  1219. return NULL;
  1220. }
  1221. // Do Conversion.
  1222. Point2I dstPoint = object->localToGlobalCoord( srcPoint );
  1223. // Create Returnable Buffer.
  1224. char* pBuffer = Con::getReturnBuffer(32);
  1225. // Format Buffer.
  1226. dSprintf(pBuffer, 32, "%d %d", dstPoint.x, dstPoint.y);
  1227. // Return buffer.
  1228. return pBuffer;
  1229. }
  1230. //-----------------------------------------------------------------------------
  1231. /*! Checks if World coordinate is inside Window.
  1232. @param x,y The coordinates in world coordinates you wish to check. Accepts either (x,y) or (\x y\
  1233. @return Returns true if the coordinates are within the window, and false otherwise.
  1234. */
  1235. ConsoleMethodWithDocs(SceneWindow, getIsWindowPoint, ConsoleBool, 3, 4, (X / Y))
  1236. {
  1237. // The new position.
  1238. Vector2 srcPoint;
  1239. // Elements in the first argument.
  1240. U32 elementCount = Utility::mGetStringElementCount(argv[2]);
  1241. // ("x y")
  1242. if ((elementCount == 2) && (argc == 3))
  1243. srcPoint = Utility::mGetStringElementVector(argv[2]);
  1244. // (x, y)
  1245. else if ((elementCount == 1) && (argc == 4))
  1246. srcPoint = Vector2(dAtof(argv[2]), dAtof(argv[3]));
  1247. // Invalid
  1248. else
  1249. {
  1250. Con::warnf("SceneWindow::getIsWindowPoint() - Invalid number of parameters!");
  1251. return false;
  1252. }
  1253. // Destination Point.
  1254. Vector2 dstPoint;
  1255. // Do Conversion.
  1256. object->sceneToWindowPoint( srcPoint, dstPoint );
  1257. // Check if point is in window bounds.
  1258. return object->mBounds.pointInRect( Point2I( S32(mFloor(dstPoint.x)+object->mBounds.point.x), S32(mFloor(dstPoint.y)+object->mBounds.point.y )) );
  1259. }
  1260. /*! Sets this Scenewindow to process the AudioListener's position and velocity
  1261. WARNING : The code does not verify if multiple SceneWindows have this function enabled.
  1262. User must make sure to manage this manually. Multiple listeners may lead to crashes/bugs/unexpected behaviors.
  1263. @param status - Whether to enable or disable AudioListener processing (optional, default to true)
  1264. */
  1265. ConsoleMethodWithDocs(SceneWindow, setAudioListener, ConsoleVoid, 2, 3, ())
  1266. {
  1267. bool onoff = true;
  1268. if ((argc > 2) && !dAtob(argv[2])) onoff = false;
  1269. object->setProcessAudioListener(onoff);
  1270. }
  1271. ConsoleMethodGroupEndWithDocs(SceneWindow)