Bläddra i källkod

Ensure cursor is rendered on top of all other UI elements. Removed the SetTempVisible() hack from UIElement.

Lasse Öörni 12 år sedan
förälder
incheckning
6095d2ac11
5 ändrade filer med 20 tillägg och 27 borttagningar
  1. 0 3
      Engine/UI/Cursor.cpp
  2. 19 16
      Engine/UI/UI.cpp
  3. 1 1
      Engine/UI/UI.h
  4. 0 5
      Engine/UI/UIElement.cpp
  5. 0 2
      Engine/UI/UIElement.h

+ 0 - 3
Engine/UI/Cursor.cpp

@@ -70,9 +70,6 @@ Cursor::Cursor(Context* context) :
     shape_(CS_NORMAL),
     useSystemShapes_(false)
 {
-    // Show on top of all other UI elements
-    priority_ = M_MAX_INT;
-    
     // Subscribe to OS mouse cursor visibility changes to be able to reapply the cursor shape
     SubscribeToEvent(E_MOUSEVISIBLECHANGED, HANDLER(Cursor, HandleMouseVisibleChanged));
 }

+ 19 - 16
Engine/UI/UI.cpp

@@ -339,13 +339,7 @@ void UI::RenderUpdate()
 
     // If the OS cursor is visible, do not render the UI's own cursor
     bool osCursorVisible = GetSubsystem<Input>()->IsMouseVisible();
-    bool uiCursorVisible = false;
-    if (osCursorVisible && cursor_)
-    {
-        uiCursorVisible = cursor_->IsVisible();
-        cursor_->SetTempVisible(false);
-    }
-
+    
     // Get rendering batches from the non-modal UI elements
     batches_.Clear();
     vertexData_.Clear();
@@ -359,9 +353,13 @@ void UI::RenderUpdate()
     // Get rendering batches from the modal UI elements
     GetBatches(rootModalElement_, currentScissor);
 
-    // Restore UI cursor visibility state
-    if (osCursorVisible && cursor_)
-        cursor_->SetTempVisible(uiCursorVisible);
+    // Get batches from the cursor (and its possible children) last to draw it on top of everything
+    if (cursor_ && cursor_->IsVisible() && !osCursorVisible)
+    {
+        currentScissor = IntRect(0, 0, rootSize.x_, rootSize.y_);
+        cursor_->GetBatches(batches_, vertexData_, currentScissor);
+        GetBatches(cursor_, currentScissor);
+    }
 }
 
 void UI::Render()
@@ -643,6 +641,8 @@ void UI::Render(VertexBuffer* buffer, const PODVector<UIBatch>& batches, unsigne
 
 void UI::GetBatches(UIElement* element, IntRect currentScissor)
 {
+    UIElement* cursorElement = cursor_;
+    
     // Set clipping scissor for child elements. No need to draw if zero size
     element->AdjustScissor(currentScissor);
     if (currentScissor.left_ == currentScissor.right_ || currentScissor.top_ == currentScissor.bottom_)
@@ -664,14 +664,14 @@ void UI::GetBatches(UIElement* element, IntRect currentScissor)
             int currentPriority = (*i)->GetPriority();
             while (j != children.End() && (*j)->GetPriority() == currentPriority)
             {
-                if ((*j)->IsWithinScissor(currentScissor))
+                if ((*j)->IsWithinScissor(currentScissor) && (*j) != cursorElement)
                     (*j)->GetBatches(batches_, vertexData_, currentScissor);
                 ++j;
             }
             // Now recurse into the children
             while (i != j)
             {
-                if ((*i)->IsVisible())
+                if ((*i)->IsVisible() && (*i) != cursorElement)
                     GetBatches(*i, currentScissor);
                 ++i;
             }
@@ -682,10 +682,13 @@ void UI::GetBatches(UIElement* element, IntRect currentScissor)
     {
         while (i != children.End())
         {
-            if ((*i)->IsWithinScissor(currentScissor))
-                (*i)->GetBatches(batches_, vertexData_, currentScissor);
-            if ((*i)->IsVisible())
-                GetBatches(*i, currentScissor);
+            if ((*i) != cursorElement)
+            {
+                if ((*i)->IsWithinScissor(currentScissor))
+                    (*i)->GetBatches(batches_, vertexData_, currentScissor);
+                if ((*i)->IsVisible())
+                    GetBatches(*i, currentScissor);
+            }
             ++i;
         }
     }

+ 1 - 1
Engine/UI/UI.h

@@ -115,7 +115,7 @@ private:
     void SetVertexData(VertexBuffer* dest, const PODVector<float>& vertexData);
     /// Render UI batches. Geometry must have been uploaded first.
     void Render(VertexBuffer* buffer, const PODVector<UIBatch>& batches, unsigned batchStart, unsigned batchEnd);
-    /// Generate batches from an UI element recursively.
+    /// Generate batches from an UI element recursively. Skip the cursor element.
     void GetBatches(UIElement* element, IntRect currentScissor);
     /// Return UI element at screen position recursively.
     void GetElementAt(UIElement*& result, UIElement* current, const IntVector2& position, bool enabledOnly);

+ 0 - 5
Engine/UI/UIElement.cpp

@@ -1522,11 +1522,6 @@ void UIElement::SetHovering(bool enable)
     hovering_ = enable;
 }
 
-void UIElement::SetTempVisible(bool enable)
-{
-    visible_ = enable;
-}
-
 void UIElement::AdjustScissor(IntRect& currentScissor)
 {
     if (clipChildren_)

+ 0 - 2
Engine/UI/UIElement.h

@@ -442,8 +442,6 @@ public:
     void SetChildOffset(const IntVector2& offset);
     /// Set hovering state.
     void SetHovering(bool enable);
-    /// Set temporary visibility status without updating layout or sending events. Used internally.
-    void SetTempVisible(bool enable);
     /// Adjust scissor for rendering.
     void AdjustScissor(IntRect& currentScissor);
     /// Get UI rendering batches with a specified offset. Also recurses to child elements.