VEditorWindow.cpp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. DefineEngineMethod( VEditorWindow, resetCursor, void, (),, "( )" )
  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. DefineEngineMethod( VEditorWindow, setVideoMode, void, (S32 width, S32 height, bool fullscreen, S32 bitDepth, S32 refreshRate, S32 antiAliasLevel),
  60. (800,600,false,32,60, 0),
  61. "(int width, int height, bool fullscreen, [int bitDepth], [int refreshRate])\n"
  62. "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"
  63. "\\param width The screen width to set.\n"
  64. "\\param height The screen height to set.\n"
  65. "\\param fullscreen Specify true to run fullscreen or false to run in a window\n"
  66. "\\param bitDepth [optional] The desired bit-depth. Defaults to the current setting. This parameter is ignored if you are running in a window.\n"
  67. "\\param refreshRate [optional] The desired refresh rate. Defaults to the current setting. This parameter is ignored if you are running in a window"
  68. "\\param antialiasLevel [optional] The level of anti-aliasing to apply 0 = none" )
  69. {
  70. if (!object->getPlatformWindow())
  71. return;
  72. // Update the video mode and tell the window to reset.
  73. GFXVideoMode vm = object->getPlatformWindow()->getVideoMode();
  74. bool changed = false;
  75. if (width == 0 && height > 0)
  76. {
  77. // Our width is 0 but our height isn't...
  78. // Try to find a matching width
  79. for(S32 i=0; i<object->getPlatformWindow()->getGFXDevice()->getVideoModeList()->size(); i++)
  80. {
  81. const GFXVideoMode &newVm = (*(object->getPlatformWindow()->getGFXDevice()->getVideoModeList()))[i];
  82. if(newVm.resolution.y == height)
  83. {
  84. width = newVm.resolution.x;
  85. changed = true;
  86. break;
  87. }
  88. }
  89. }
  90. else if (height == 0 && width > 0)
  91. {
  92. // Our height is 0 but our width isn't...
  93. // Try to find a matching height
  94. for(S32 i=0; i<object->getPlatformWindow()->getGFXDevice()->getVideoModeList()->size(); i++)
  95. {
  96. const GFXVideoMode &newVm = (*(object->getPlatformWindow()->getGFXDevice()->getVideoModeList()))[i];
  97. if(newVm.resolution.x == width)
  98. {
  99. height = newVm.resolution.y;
  100. changed = true;
  101. break;
  102. }
  103. }
  104. }
  105. if (width == 0 || height == 0)
  106. {
  107. // Got a bad size for both of our dimensions or one of our dimensions and
  108. // didn't get a match for the other default back to our current resolution
  109. width = vm.resolution.x;
  110. height = vm.resolution.y;
  111. changed = true;
  112. }
  113. if (changed)
  114. Con::errorf("GuiCanvas::setVideoMode(): Error - Invalid resolution of (%d, %d) - attempting (%d, %d)", width, height, width, height);
  115. vm.resolution = Point2I(width, height);
  116. vm.fullScreen = fullscreen;
  117. vm.bitDepth = bitDepth;
  118. vm.refreshRate = refreshRate;
  119. vm.antialiasLevel = antiAliasLevel;
  120. #ifndef TORQUE_OS_XENON
  121. object->getPlatformWindow()->setVideoMode(vm);
  122. #endif
  123. }