BsGUIRenderTexture.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include "BsGUIRenderTexture.h"
  2. #include "BsGUIWidget.h"
  3. #include "BsGUISkin.h"
  4. #include "BsGUIManager.h"
  5. #include "CmRenderTexture.h"
  6. #include "BsSpriteTexture.h"
  7. using namespace CamelotFramework;
  8. namespace BansheeEngine
  9. {
  10. const String& GUIRenderTexture::getGUITypeName()
  11. {
  12. static String name = "RenderTexture";
  13. return name;
  14. }
  15. GUIRenderTexture::GUIRenderTexture(const CM::String& styleName, const RenderTexturePtr& texture, const GUILayoutOptions& layoutOptions)
  16. :GUITexture(styleName, HSpriteTexture(), GUIImageScaleMode::StretchToFit, layoutOptions), mSourceTexture(texture.get())
  17. {
  18. if(mSourceTexture->requiresTextureFlipping())
  19. {
  20. mDesc.uvOffset = Vector2(0.0f, 1.0f);
  21. mDesc.uvScale = Vector2(1.0f, -1.0f);
  22. }
  23. setTexture(SpriteTexture::create(texture->getBindableColorTexture()));
  24. GUIManager::instance().setInputBridge(mSourceTexture, this);
  25. }
  26. GUIRenderTexture::~GUIRenderTexture()
  27. {
  28. GUIManager::instance().setInputBridge(mSourceTexture, nullptr);
  29. }
  30. GUIRenderTexture* GUIRenderTexture::create(const RenderTexturePtr& texture, const CM::String& styleName)
  31. {
  32. return new (cm_alloc<GUIRenderTexture, PoolAlloc>()) GUIRenderTexture(getStyleName<GUIRenderTexture>(styleName), texture, GUILayoutOptions::create());
  33. }
  34. GUIRenderTexture* GUIRenderTexture::create(const RenderTexturePtr& texture, const GUIOptions& layoutOptions, const CM::String& styleName)
  35. {
  36. return new (cm_alloc<GUIRenderTexture, PoolAlloc>()) GUIRenderTexture(getStyleName<GUIRenderTexture>(styleName), texture, GUILayoutOptions::create(layoutOptions));
  37. }
  38. void GUIRenderTexture::updateRenderElementsInternal()
  39. {
  40. if(mActiveTexture != nullptr && mActiveTexture.isLoaded())
  41. {
  42. mDesc.texture = mActiveTexture.getInternalPtr();
  43. }
  44. mDesc.width = mWidth;
  45. mDesc.height = mHeight;
  46. mImageSprite->update(mDesc);
  47. GUIElement::updateRenderElementsInternal();
  48. }
  49. }