guiRenderTargetVizCtrl.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 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. #include "platform/platform.h"
  23. #include "gui/utility/guiRenderTargetVizCtrl.h"
  24. #include "console/console.h"
  25. #include "console/consoleTypes.h"
  26. #include "gfx/gfxDevice.h"
  27. #include "gfx/gfxDrawUtil.h"
  28. #include "gui/core/guiCanvas.h"
  29. #include "gui/core/guiDefaultControlRender.h"
  30. #include "T3D/camera.h"
  31. IMPLEMENT_CONOBJECT(GuiRenderTargetVizCtrl);
  32. ConsoleDocClass(GuiRenderTargetVizCtrl,
  33. "@brief The most widely used button class.\n\n"
  34. "GuiRenderTargetVizCtrl renders seperately of, but utilizes all of the functionality of GuiBaseButtonCtrl.\n"
  35. "This grants GuiRenderTargetVizCtrl the versatility to be either of the 3 button types.\n\n"
  36. "@tsexample\n"
  37. "// Create a PushButton GuiRenderTargetVizCtrl that calls randomFunction when clicked\n"
  38. "%button = new GuiRenderTargetVizCtrl()\n"
  39. "{\n"
  40. " profile = \"GuiButtonProfile\";\n"
  41. " buttonType = \"PushButton\";\n"
  42. " command = \"randomFunction();\";\n"
  43. "};\n"
  44. "@endtsexample\n\n"
  45. "@ingroup GuiButtons"
  46. );
  47. //-----------------------------------------------------------------------------
  48. GuiRenderTargetVizCtrl::GuiRenderTargetVizCtrl()
  49. {
  50. mTargetName = StringTable->EmptyString();
  51. mTarget = nullptr;
  52. mTargetTexture = nullptr;
  53. mCameraObject = nullptr;
  54. }
  55. //-----------------------------------------------------------------------------
  56. bool GuiRenderTargetVizCtrl::onWake()
  57. {
  58. if (!Parent::onWake())
  59. return false;
  60. return true;
  61. }
  62. void GuiRenderTargetVizCtrl::initPersistFields()
  63. {
  64. Parent::initPersistFields();
  65. addField("RenderTargetName", TypeString, Offset(mTargetName, GuiRenderTargetVizCtrl), "");
  66. addField("cameraObject", TypeSimObjectPtr, Offset(mCameraObject, GuiRenderTargetVizCtrl), "");
  67. }
  68. //-----------------------------------------------------------------------------
  69. void GuiRenderTargetVizCtrl::onRender(Point2I offset,
  70. const RectI& updateRect)
  71. {
  72. GFXDrawUtil* drawer = GFX->getDrawUtil();
  73. RectI boundsRect(offset, getExtent());
  74. //Draw backdrop
  75. GFX->getDrawUtil()->drawRectFill(boundsRect, ColorI::BLACK);
  76. if (mCameraObject != nullptr)
  77. {
  78. Camera* camObject = dynamic_cast<Camera*>(mCameraObject);
  79. camObject = dynamic_cast<Camera*>(camObject->getClientObject());
  80. if (camObject)
  81. {
  82. GFXTexHandle targ = camObject->getCameraRenderTarget();
  83. if (targ)
  84. {
  85. Point2I size = Point2I(targ->getWidth(), targ->getHeight());
  86. drawer->drawBitmapStretchSR(targ, boundsRect, RectI(Point2I::Zero, size));
  87. }
  88. return;
  89. }
  90. }
  91. else if (mTargetName == StringTable->EmptyString())
  92. return;
  93. NamedTexTarget* namedTarget = NamedTexTarget::find(mTargetName);
  94. if (namedTarget)
  95. {
  96. GFXTextureObject* theTex = namedTarget->getTexture(0);
  97. RectI viewport = namedTarget->getViewport();
  98. drawer->drawBitmapStretchSR(theTex, boundsRect, viewport);
  99. }
  100. }