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