scene.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. function createSandboxWindow()
  23. {
  24. // Sanity!
  25. if ( !isObject(SandboxWindow) )
  26. {
  27. // Create the scene window.
  28. new SceneWindow(SandboxWindow);
  29. // Set profile.
  30. SandboxWindow.Profile = SandboxWindowProfile;
  31. // Push the window.
  32. Canvas.setContent( SandboxWindow );
  33. }
  34. // Set camera to a canonical state.
  35. %allBits = "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31";
  36. SandboxWindow.stopCameraMove();
  37. SandboxWindow.dismount();
  38. SandboxWindow.setViewLimitOff();
  39. SandboxWindow.setRenderGroups( %allBits );
  40. SandboxWindow.setRenderLayers( %allBits );
  41. SandboxWindow.setObjectInputEventGroupFilter( %allBits );
  42. SandboxWindow.setObjectInputEventLayerFilter( %allBits );
  43. SandboxWindow.setLockMouse( true );
  44. SandboxWindow.setCameraPosition( 0, 0 );
  45. SandboxWindow.setCameraSize( 100, 75 );
  46. SandboxWindow.setCameraZoom( 1 );
  47. SandboxWindow.setCameraAngle( 0 );
  48. }
  49. //-----------------------------------------------------------------------------
  50. function destroySandboxWindow()
  51. {
  52. // Finish if no window available.
  53. if ( !isObject(SandboxWindow) )
  54. return;
  55. // Delete the window.
  56. SandboxWindow.delete();
  57. }
  58. //-----------------------------------------------------------------------------
  59. function createSandboxScene()
  60. {
  61. // Destroy the scene if it already exists.
  62. if ( isObject(SandboxScene) )
  63. destroySandboxScene();
  64. // Create the scene.
  65. new Scene(SandboxScene);
  66. // Sanity!
  67. if ( !isObject(SandboxWindow) )
  68. {
  69. error( "Sandbox: Created scene but no window available." );
  70. return;
  71. }
  72. // Set window to scene.
  73. setSceneToWindow();
  74. }
  75. //-----------------------------------------------------------------------------
  76. function destroySandboxScene()
  77. {
  78. // Finish if no scene available.
  79. if ( !isObject(SandboxScene) )
  80. return;
  81. // Delete the scene.
  82. SandboxScene.delete();
  83. }
  84. //-----------------------------------------------------------------------------
  85. function setSceneToWindow()
  86. {
  87. // Sanity!
  88. if ( !isObject(SandboxScene) )
  89. {
  90. error( "Cannot set Sandbox Scene to Window as the Scene is invalid." );
  91. return;
  92. }
  93. // Set scene to window.
  94. SandboxWindow.setScene( SandboxScene );
  95. // Set camera to a canonical state.
  96. %allBits = "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31";
  97. SandboxWindow.stopCameraMove();
  98. SandboxWindow.dismount();
  99. SandboxWindow.setViewLimitOff();
  100. SandboxWindow.setRenderGroups( %allBits );
  101. SandboxWindow.setRenderLayers( %allBits );
  102. SandboxWindow.setObjectInputEventGroupFilter( %allBits );
  103. SandboxWindow.setObjectInputEventLayerFilter( %allBits );
  104. SandboxWindow.setLockMouse( true );
  105. SandboxWindow.setCameraPosition( 0, 0 );
  106. SandboxWindow.setCameraSize( 100, 75 );
  107. SandboxWindow.setCameraZoom( 1 );
  108. SandboxWindow.setCameraAngle( 0 );
  109. // Update the toolbox options.
  110. updateToolboxOptions();
  111. // reset the sandbox manipulation modes.
  112. Sandbox.resetManipulationModes();
  113. }
  114. //-----------------------------------------------------------------------------
  115. function setCustomScene( %scene )
  116. {
  117. // Sanity!
  118. if ( !isObject(%scene) )
  119. {
  120. error( "Cannot set Sandbox to use an invalid Scene." );
  121. return;
  122. }
  123. // Destroy the existing scene.
  124. destroySandboxScene();
  125. // The Sandbox needs the scene to be named this.
  126. %scene.setName( "SandboxScene" );
  127. // Set the scene to the window.
  128. setSceneToWindow();
  129. }
  130. function SceneWindow::onExtentChange(%this)
  131. {
  132. %extent = Canvas.extent;
  133. %aspect = %extent.x / %extent.y;
  134. %cam = SandboxWindow.getCameraSize();
  135. %cam.x = %cam.y * %aspect;
  136. %this.setCameraSize(%cam);
  137. }