From 01e3cb53de1ccb9dd173e815c117c74f418e3699 Mon Sep 17 00:00:00 2001 From: irei1as Date: Wed, 11 May 2016 17:47:05 +0200 Subject: [PATCH] Set textures as bitmapctrl in script A new method to GuiBitmapCtrl in order to set "named textures" as the image displayed in script. Those "named textures" are created in two places from script (not c++) that I know: as part of GuiOffscreenCanvas (targetName field) and, more useful, as the target of a PostEffect using target = "#name" (the '#' is not used for this method). --- Engine/source/gui/controls/guiBitmapCtrl.cpp | 23 ++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Engine/source/gui/controls/guiBitmapCtrl.cpp b/Engine/source/gui/controls/guiBitmapCtrl.cpp index 1d0cd21c7..c1d77c4c1 100644 --- a/Engine/source/gui/controls/guiBitmapCtrl.cpp +++ b/Engine/source/gui/controls/guiBitmapCtrl.cpp @@ -29,6 +29,8 @@ #include "gfx/gfxDevice.h" #include "gfx/gfxDrawUtil.h" +#include "materials/matTextureTarget.h" + IMPLEMENT_CONOBJECT(GuiBitmapCtrl); @@ -264,3 +266,24 @@ DefineConsoleMethod( GuiBitmapCtrl, setBitmap, void, ( const char * fileRoot, bo Con::expandScriptFilename(filename, sizeof(filename), fileRoot); object->setBitmap(filename, resize ); } + +DefineEngineMethod( GuiBitmapCtrl, setNamedTexture, bool, (String namedtexture),, + "@brief Set a texture as the image.\n\n" + "@param namedtexture The name of the texture (NamedTexTarget).\n" + "@return true if the texture exists." ) +{ + GFXTexHandle theTex; + NamedTexTarget *namedTarget = NULL; + namedTarget = NamedTexTarget::find(namedtexture.c_str()); + if ( namedTarget ) + { + theTex = namedTarget->getTexture( 0 ); + } + + if ( theTex.isValid() ) + { + object->setBitmapHandle( theTex , false ); + return true; //a new texture was set correctly + } + return false; //we couldn't change the texture +}