1 | //************************************ bs::framework - Copyright 2018 Marko Pintera **************************************// |
2 | //*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********// |
3 | #include "GUI/BsGUIRenderTexture.h" |
4 | #include "GUI/BsGUIManager.h" |
5 | #include "RenderAPI/BsRenderTexture.h" |
6 | #include "Image/BsSpriteTexture.h" |
7 | |
8 | namespace bs |
9 | { |
10 | const String& GUIRenderTexture::getGUITypeName() |
11 | { |
12 | static String name = "RenderTexture" ; |
13 | return name; |
14 | } |
15 | |
16 | GUIRenderTexture::GUIRenderTexture(const String& styleName, const SPtr<RenderTexture>& texture, bool transparent, |
17 | const GUIDimensions& dimensions) |
18 | :GUITexture(styleName, HSpriteTexture(), TextureScaleMode::StretchToFit, false, dimensions), mTransparent(transparent) |
19 | { |
20 | setRenderTexture(texture); |
21 | } |
22 | |
23 | GUIRenderTexture::~GUIRenderTexture() |
24 | { |
25 | if (mSourceTexture != nullptr) |
26 | GUIManager::instance().setInputBridge(mSourceTexture.get(), nullptr); |
27 | } |
28 | |
29 | GUIRenderTexture* GUIRenderTexture::create(const SPtr<RenderTexture>& texture, bool transparent, const String& styleName) |
30 | { |
31 | return new (bs_alloc<GUIRenderTexture>()) GUIRenderTexture(styleName, texture, transparent, GUIDimensions::create()); |
32 | } |
33 | |
34 | GUIRenderTexture* GUIRenderTexture::create(const SPtr<RenderTexture>& texture, bool transparent, const GUIOptions& options, |
35 | const String& styleName) |
36 | { |
37 | return new (bs_alloc<GUIRenderTexture>()) GUIRenderTexture(styleName, texture, transparent, GUIDimensions::create(options)); |
38 | } |
39 | |
40 | GUIRenderTexture* GUIRenderTexture::create(const SPtr<RenderTexture>& texture, const String& styleName) |
41 | { |
42 | return new (bs_alloc<GUIRenderTexture>()) GUIRenderTexture(styleName, texture, false, GUIDimensions::create()); |
43 | } |
44 | |
45 | GUIRenderTexture* GUIRenderTexture::create(const SPtr<RenderTexture>& texture, const GUIOptions& options, const String& styleName) |
46 | { |
47 | return new (bs_alloc<GUIRenderTexture>()) GUIRenderTexture(styleName, texture, false, GUIDimensions::create(options)); |
48 | } |
49 | |
50 | void GUIRenderTexture::setRenderTexture(const SPtr<RenderTexture>& texture) |
51 | { |
52 | if (mSourceTexture != nullptr) |
53 | GUIManager::instance().setInputBridge(mSourceTexture.get(), nullptr); |
54 | |
55 | mSourceTexture = texture; |
56 | |
57 | if (mSourceTexture != nullptr) |
58 | { |
59 | if (mSourceTexture->getProperties().requiresTextureFlipping) |
60 | { |
61 | mDesc.uvOffset = Vector2(0.0f, 1.0f); |
62 | mDesc.uvScale = Vector2(1.0f, -1.0f); |
63 | } |
64 | |
65 | setTexture(SpriteTexture::create(texture->getColorTexture(0))); |
66 | |
67 | GUIManager::instance().setInputBridge(mSourceTexture.get(), this); |
68 | } |
69 | else |
70 | { |
71 | setTexture(SpriteTexture::create(HTexture())); |
72 | } |
73 | |
74 | _markLayoutAsDirty(); |
75 | } |
76 | |
77 | void GUIRenderTexture::updateRenderElementsInternal() |
78 | { |
79 | if(mActiveTexture != nullptr && mActiveTexture.isLoaded()) |
80 | mDesc.texture = mActiveTexture; |
81 | |
82 | mDesc.width = mLayoutData.area.width; |
83 | mDesc.height = mLayoutData.area.height; |
84 | mDesc.transparent = mTransparent; |
85 | mDesc.color = getTint(); |
86 | |
87 | mImageSprite->update(mDesc, (UINT64)_getParentWidget()); |
88 | |
89 | GUIElement::updateRenderElementsInternal(); |
90 | } |
91 | } |