Browse Source

Merge remote-tracking branch 'rokups/feature/move-ui-root-element'

Lasse Öörni 8 years ago
parent
commit
2e19e8a28f
1 changed files with 32 additions and 12 deletions
  1. 32 12
      Source/Urho3D/UI/UI.cpp

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

@@ -154,8 +154,9 @@ void UI::SetCursor(Cursor* cursor)
 
         IntVector2 pos = cursor_->GetPosition();
         const IntVector2& rootSize = rootElement_->GetSize();
-        pos.x_ = Clamp(pos.x_, 0, rootSize.x_ - 1);
-        pos.y_ = Clamp(pos.y_, 0, rootSize.y_ - 1);
+        const IntVector2& rootPos = rootElement_->GetPosition();
+        pos.x_ = Clamp(pos.x_, rootPos.x_, rootPos.x_ + rootSize.x_ - 1);
+        pos.y_ = Clamp(pos.y_, rootPos.y_, rootPos.y_ + rootSize.y_ - 1);
         cursor_->SetPosition(pos);
     }
 }
@@ -410,8 +411,9 @@ void UI::RenderUpdate()
     batches_.Clear();
     vertexData_.Clear();
     const IntVector2& rootSize = rootElement_->GetSize();
+    const IntVector2& rootPos = rootElement_->GetPosition();
     // Note: the scissors operate on unscaled coordinates. Scissor scaling is only performed during render
-    IntRect currentScissor = IntRect(0, 0, rootSize.x_, rootSize.y_);
+    IntRect currentScissor = IntRect(rootPos.x_, rootPos.y_, rootPos.x_ + rootSize.x_, rootPos.y_ + rootSize.y_);
     if (rootElement_->IsVisible())
         GetBatches(rootElement_, currentScissor);
 
@@ -465,7 +467,10 @@ void UI::DebugDraw(UIElement* element)
     if (element)
     {
         const IntVector2& rootSize = rootElement_->GetSize();
-        element->GetDebugDrawBatches(debugDrawBatches_, debugVertexData_, IntRect(0, 0, rootSize.x_, rootSize.y_));
+        const IntVector2& rootPos = rootElement_->GetPosition();
+        element->GetDebugDrawBatches(debugDrawBatches_, debugVertexData_, IntRect(rootPos.x_, rootPos.y_,
+                                                                                  rootPos.x_ + rootSize.x_,
+                                                                                  rootPos.y_ + rootSize.y_));
     }
 }
 
@@ -639,14 +644,22 @@ UIElement* UI::GetElementAt(const IntVector2& position, bool enabledOnly)
 {
     IntVector2 positionCopy(position);
     const IntVector2& rootSize = rootElement_->GetSize();
+    const IntVector2& rootPos = rootElement_->GetPosition();
+
+    // If position is out of bounds of root element return null.
+    if (position.x_ < rootPos.x_ || position.x_ > rootPos.x_ + rootSize.x_)
+        return 0;
+
+    if (position.y_ < rootPos.y_ || position.y_ > rootPos.y_ + rootSize.y_)
+        return 0;
 
     // If UI is smaller than the screen, wrap if necessary
     if (rootSize.x_ > 0 && rootSize.y_ > 0)
     {
-        if (positionCopy.x_ >= rootSize.x_)
-            positionCopy.x_ %= rootSize.x_;
-        if (positionCopy.y_ >= rootSize.y_)
-            positionCopy.y_ %= rootSize.y_;
+        if (positionCopy.x_ >= rootPos.x_ + rootSize.x_)
+            positionCopy.x_ = rootPos.x_ + ((positionCopy.x_ - rootPos.x_) % rootSize.x_);
+        if (positionCopy.y_ >= rootPos.y_ + rootSize.y_)
+            positionCopy.y_ = rootPos.y_ + ((positionCopy.y_ - rootPos.y_) % rootSize.y_);
     }
 
     UIElement* result = 0;
@@ -996,12 +1009,18 @@ void UI::GetElementAt(UIElement*& result, UIElement* current, const IntVector2&
                     }
                     else if (parentLayoutMode == LM_HORIZONTAL)
                     {
-                        if (element->GetScreenPosition().x_ >= rootElement_->GetSize().x_)
+                        if (element->GetScreenPosition().x_ < rootElement_->GetPosition().x_)
+                            break;
+
+                        if (element->GetScreenPosition().x_ >= rootElement_->GetPosition().x_ + rootElement_->GetSize().x_)
                             break;
                     }
                     else if (parentLayoutMode == LM_VERTICAL)
                     {
-                        if (element->GetScreenPosition().y_ >= rootElement_->GetSize().y_)
+                        if (element->GetScreenPosition().y_ < rootElement_->GetPosition().y_)
+                            break;
+
+                        if (element->GetScreenPosition().y_ >= rootElement_->GetPosition().y_ + rootElement_->GetSize().y_)
                             break;
                     }
                 }
@@ -1490,6 +1509,7 @@ void UI::HandleMouseMove(StringHash eventType, VariantMap& eventData)
 
     Input* input = GetSubsystem<Input>();
     const IntVector2& rootSize = rootElement_->GetSize();
+    const IntVector2& rootPos = rootElement_->GetPosition();
 
     IntVector2 DeltaP = IntVector2(eventData[P_DX].GetInt(), eventData[P_DY].GetInt());
 
@@ -1505,8 +1525,8 @@ void UI::HandleMouseMove(StringHash eventType, VariantMap& eventData)
                 IntVector2 pos = cursor_->GetPosition();
                 pos.x_ += eventData[P_DX].GetInt();
                 pos.y_ += eventData[P_DY].GetInt();
-                pos.x_ = Clamp(pos.x_, 0, rootSize.x_ - 1);
-                pos.y_ = Clamp(pos.y_, 0, rootSize.y_ - 1);
+                pos.x_ = Clamp(pos.x_, rootPos.x_, rootPos.x_ + rootSize.x_ - 1);
+                pos.y_ = Clamp(pos.y_, rootPos.y_, rootPos.y_ + rootSize.y_ - 1);
                 cursor_->SetPosition(pos);
             }
         }