Browse Source

Minor changes.

Eugene Kozlov 8 years ago
parent
commit
8bb8aa28e8
3 changed files with 20 additions and 18 deletions
  1. 12 10
      Source/Urho3D/UI/UI.cpp
  2. 6 7
      Source/Urho3D/UI/UIComponent.cpp
  3. 2 1
      Source/Urho3D/UI/UIComponent.h

+ 12 - 10
Source/Urho3D/UI/UI.cpp

@@ -445,8 +445,12 @@ void UI::RenderUpdate()
     {
     {
         RenderToTextureData& data = it->second_;
         RenderToTextureData& data = it->second_;
         if (data.rootElement_.Expired())
         if (data.rootElement_.Expired())
+        {
             it = renderToTexture_.Erase(it);
             it = renderToTexture_.Erase(it);
-        else if (data.rootElement_->IsEnabled())
+            continue;
+        }
+
+        if (data.rootElement_->IsEnabled())
         {
         {
             data.batches_.Clear();
             data.batches_.Clear();
             data.vertexData_.Clear();
             data.vertexData_.Clear();
@@ -465,10 +469,8 @@ void UI::RenderUpdate()
                 batch.AddQuad(scissor.left_, scissor.top_, scissor.right_, scissor.bottom_, 0, 0);
                 batch.AddQuad(scissor.left_, scissor.top_, scissor.right_, scissor.bottom_, 0, 0);
                 data.batches_.Push(batch);
                 data.batches_.Push(batch);
             }
             }
-            ++it;
         }
         }
-        else
-            ++it;
+        ++it;
     }
     }
 }
 }
 
 
@@ -503,9 +505,9 @@ void UI::Render(bool renderUICommand)
     // Render to UIComponent textures. This is skipped when called from the RENDERUI command
     // Render to UIComponent textures. This is skipped when called from the RENDERUI command
     if (!renderUICommand)
     if (!renderUICommand)
     {
     {
-        for (auto it = renderToTexture_.Begin(); it != renderToTexture_.End(); it++)
+        for (auto& item : renderToTexture_)
         {
         {
-            RenderToTextureData& data = it->second_;
+            RenderToTextureData& data = item.second_;
             if (data.rootElement_->IsEnabled())
             if (data.rootElement_->IsEnabled())
             {
             {
                 SetVertexData(data.vertexBuffer_, data.vertexData_);
                 SetVertexData(data.vertexBuffer_, data.vertexData_);
@@ -548,9 +550,9 @@ void UI::DebugDraw(UIElement* element)
             element->GetDebugDrawBatches(debugDrawBatches_, debugVertexData_, scissor);
             element->GetDebugDrawBatches(debugDrawBatches_, debugVertexData_, scissor);
         else
         else
         {
         {
-            for (auto it = renderToTexture_.Begin(); it != renderToTexture_.End(); it++)
+            for (auto& item : renderToTexture_)
             {
             {
-                RenderToTextureData& data = it->second_;
+                RenderToTextureData& data = item.second_;
                 if (!data.rootElement_.Expired() && data.rootElement_ == root && data.rootElement_->IsEnabled())
                 if (!data.rootElement_.Expired() && data.rootElement_ == root && data.rootElement_->IsEnabled())
                 {
                 {
                     element->GetDebugDrawBatches(data.debugDrawBatches_, data.debugVertexData_, scissor);
                     element->GetDebugDrawBatches(data.debugDrawBatches_, data.debugVertexData_, scissor);
@@ -770,9 +772,9 @@ UIElement* UI::GetElementAt(const IntVector2& position, bool enabledOnly, IntVec
     // Mouse was not hovering UI element. Check elements rendered on 3D objects.
     // Mouse was not hovering UI element. Check elements rendered on 3D objects.
     if (!result && renderToTexture_.Size())
     if (!result && renderToTexture_.Size())
     {
     {
-        for (auto it = renderToTexture_.Begin(); it != renderToTexture_.End(); it++)
+        for (auto& item : renderToTexture_)
         {
         {
-            RenderToTextureData& data = it->second_;
+            RenderToTextureData& data = item.second_;
             if (data.rootElement_.Expired() || !data.rootElement_->IsEnabled())
             if (data.rootElement_.Expired() || !data.rootElement_->IsEnabled())
                 continue;
                 continue;
 
 

+ 6 - 7
Source/Urho3D/UI/UIComponent.cpp

@@ -38,6 +38,7 @@
 #include "../UI/UIComponent.h"
 #include "../UI/UIComponent.h"
 #include "../UI/UIEvents.h"
 #include "../UI/UIEvents.h"
 
 
+#include "../DebugNew.h"
 
 
 namespace Urho3D
 namespace Urho3D
 {
 {
@@ -46,7 +47,6 @@ static int const UICOMPONENT_DEFAULT_TEXTURE_SIZE = 512;
 static int const UICOMPONENT_MIN_TEXTURE_SIZE = 64;
 static int const UICOMPONENT_MIN_TEXTURE_SIZE = 64;
 static int const UICOMPONENT_MAX_TEXTURE_SIZE = 4096;
 static int const UICOMPONENT_MAX_TEXTURE_SIZE = 4096;
 
 
-
 class UIElement3D : public UIElement
 class UIElement3D : public UIElement
 {
 {
     URHO3D_OBJECT(UIElement3D, UIElement);
     URHO3D_OBJECT(UIElement3D, UIElement);
@@ -196,21 +196,20 @@ Texture2D* UIComponent::GetTexture() const
 
 
 void UIComponent::OnNodeSet(Node* node)
 void UIComponent::OnNodeSet(Node* node)
 {
 {
-    UIElement3D* rootElement = static_cast<UIElement3D*>(rootElement_.Get());
-    rootElement->SetNode(node);
+    rootElement_->SetNode(node);
     if (node)
     if (node)
     {
     {
         Renderer* renderer = GetSubsystem<Renderer>();
         Renderer* renderer = GetSubsystem<Renderer>();
         StaticModel* model = node->GetComponent<StaticModel>();
         StaticModel* model = node->GetComponent<StaticModel>();
-        rootElement->SetViewport(renderer->GetViewportForScene(GetScene(), viewportIndex_));
+        rootElement_->SetViewport(renderer->GetViewportForScene(GetScene(), viewportIndex_));
         if (model == nullptr)
         if (model == nullptr)
             model_ = model = node->CreateComponent<StaticModel>();
             model_ = model = node->CreateComponent<StaticModel>();
         model->SetMaterial(material_);
         model->SetMaterial(material_);
-        rootElement->SetRenderTexture(texture_);
+        rootElement_->SetRenderTexture(texture_);
     }
     }
     else
     else
     {
     {
-        rootElement->SetRenderTexture(nullptr);
+        rootElement_->SetRenderTexture(nullptr);
         if (model_.NotNull())
         if (model_.NotNull())
         {
         {
             model_->Remove();
             model_->Remove();
@@ -245,7 +244,7 @@ void UIComponent::SetViewportIndex(unsigned int index)
     {
     {
         Renderer* renderer = GetSubsystem<Renderer>();
         Renderer* renderer = GetSubsystem<Renderer>();
         Viewport* viewport = renderer->GetViewportForScene(scene, index);
         Viewport* viewport = renderer->GetViewportForScene(scene, index);
-        static_cast<UIElement3D*>(rootElement_.Get())->SetViewport(viewport);
+        rootElement_->SetViewport(viewport);
     }
     }
 }
 }
 
 

+ 2 - 1
Source/Urho3D/UI/UIComponent.h

@@ -34,6 +34,7 @@ class Viewport;
 class UIElement;
 class UIElement;
 class UIBatch;
 class UIBatch;
 class VertexBuffer;
 class VertexBuffer;
+class UIElement3D;
 
 
 class URHO3D_API UIComponent : public Component
 class URHO3D_API UIComponent : public Component
 {
 {
@@ -69,7 +70,7 @@ protected:
     /// Model created by this component. If node already has StaticModel then this will be null.
     /// Model created by this component. If node already has StaticModel then this will be null.
     SharedPtr<StaticModel> model_;
     SharedPtr<StaticModel> model_;
     /// UIElement to be rendered into texture. It also handles screen to UI coordinate translation.
     /// UIElement to be rendered into texture. It also handles screen to UI coordinate translation.
-    SharedPtr<UIElement> rootElement_;
+    SharedPtr<UIElement3D> rootElement_;
     /// Viewport index to be set when component is added to a node.
     /// Viewport index to be set when component is added to a node.
     unsigned viewportIndex_;
     unsigned viewportIndex_;
 };
 };