VEditorWindow.cpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. //-----------------------------------------------------------------------------
  2. // Verve
  3. // Copyright (C) 2014 - Violent Tulip
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to
  7. // deal in the Software without restriction, including without limitation the
  8. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9. // sell copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. // IN THE SOFTWARE.
  22. //-----------------------------------------------------------------------------
  23. #include "Verve/GUI/VEditorWindow.h"
  24. #include "gfx/gfxInit.h"
  25. //-----------------------------------------------------------------------------
  26. IMPLEMENT_CONOBJECT( VEditorWindow );
  27. //-----------------------------------------------------------------------------
  28. bool VEditorWindow::onAdd( void )
  29. {
  30. if ( !Parent::onAdd() )
  31. {
  32. return false;
  33. }
  34. GFXAdapter *adapter = GFXInit::getBestAdapterChoice();
  35. if ( adapter && adapter->mType != NullDevice )
  36. {
  37. mPlatformWindow->setMinimumWindowSize( Point2I( 904, 287 ) );
  38. }
  39. return true;
  40. }
  41. //-----------------------------------------------------------------------------
  42. ConsoleMethod( VEditorWindow, resetCursor, void, 2, 2, "( )" )
  43. {
  44. S32 currCursor = PlatformCursorController::curArrow;
  45. if ( object->mCursorChanged == currCursor )
  46. {
  47. return;
  48. }
  49. PlatformWindow *window = object->getPlatformWindow();
  50. PlatformCursorController *controller = window->getCursorController();
  51. if( object->mCursorChanged != -1)
  52. {
  53. controller->popCursor();
  54. }
  55. controller->pushCursor(currCursor);
  56. object->mCursorChanged = currCursor;
  57. Platform::setWindowLocked( false );
  58. }
  59. ConsoleMethod( VEditorWindow, setVideoMode, void, 5, 8,
  60. "(int width, int height, bool fullscreen, [int bitDepth], [int refreshRate])\n"
  61. "Change the video mode of this canvas. This method has the side effect of setting the $pref::Video::mode to the new values.\n\n"
  62. "\\param width The screen width to set.\n"
  63. "\\param height The screen height to set.\n"
  64. "\\param fullscreen Specify true to run fullscreen or false to run in a window\n"
  65. "\\param bitDepth [optional] The desired bit-depth. Defaults to the current setting. This parameter is ignored if you are running in a window.\n"
  66. "\\param refreshRate [optional] The desired refresh rate. Defaults to the current setting. This parameter is ignored if you are running in a window"
  67. "\\param antialiasLevel [optional] The level of anti-aliasing to apply 0 = none" )
  68. {
  69. if (!object->getPlatformWindow())
  70. return;
  71. // Update the video mode and tell the window to reset.
  72. GFXVideoMode vm = object->getPlatformWindow()->getVideoMode();
  73. U32 width = dAtoi(argv[2]);
  74. U32 height = dAtoi(argv[3]);
  75. bool changed = false;
  76. if (width == 0 && height > 0)
  77. {
  78. // Our width is 0 but our height isn't...
  79. // Try to find a matching width
  80. for(S32 i=0; i<object->getPlatformWindow()->getGFXDevice()->getVideoModeList()->size(); i++)
  81. {
  82. const GFXVideoMode &newVm = (*(object->getPlatformWindow()->getGFXDevice()->getVideoModeList()))[i];
  83. if(newVm.resolution.y == height)
  84. {
  85. width = newVm.resolution.x;
  86. changed = true;
  87. break;
  88. }
  89. }
  90. }
  91. else if (height == 0 && width > 0)
  92. {
  93. // Our height is 0 but our width isn't...
  94. // Try to find a matching height
  95. for(S32 i=0; i<object->getPlatformWindow()->getGFXDevice()->getVideoModeList()->size(); i++)
  96. {
  97. const GFXVideoMode &newVm = (*(object->getPlatformWindow()->getGFXDevice()->getVideoModeList()))[i];
  98. if(newVm.resolution.x == width)
  99. {
  100. height = newVm.resolution.y;
  101. changed = true;
  102. break;
  103. }
  104. }
  105. }
  106. if (width == 0 || height == 0)
  107. {
  108. // Got a bad size for both of our dimensions or one of our dimensions and
  109. // didn't get a match for the other default back to our current resolution
  110. width = vm.resolution.x;
  111. height = vm.resolution.y;
  112. changed = true;
  113. }
  114. if (changed)
  115. Con::errorf("GuiCanvas::setVideoMode(): Error - Invalid resolution of (%d, %d) - attempting (%d, %d)", dAtoi(argv[2]), dAtoi(argv[3]), width, height);
  116. vm.resolution = Point2I(width, height);
  117. vm.fullScreen = dAtob(argv[4]);
  118. // These optional params are set to default at construction of vm. If they
  119. // aren't specified, just leave them at whatever they were set to.
  120. if ((argc > 5) && (dStrlen(argv[5]) > 0))
  121. {
  122. vm.bitDepth = dAtoi(argv[5]);
  123. }
  124. if ((argc > 6) && (dStrlen(argv[6]) > 0))
  125. {
  126. vm.refreshRate = dAtoi(argv[6]);
  127. }
  128. if ((argc > 7) && (dStrlen(argv[7]) > 0))
  129. {
  130. vm.antialiasLevel = dAtoi(argv[7]);
  131. }
  132. #ifndef TORQUE_OS_XENON
  133. object->getPlatformWindow()->setVideoMode(vm);
  134. #endif
  135. }