Procházet zdrojové kódy

Non-functional refactoring of wheel handling.

Eugene Kozlov před 8 roky
rodič
revize
06864f5d54

+ 3 - 0
Source/Urho3D/UI/ScrollView.h

@@ -54,6 +54,9 @@ public:
     /// React to resize.
     virtual void OnResize(const IntVector2& newSize, const IntVector2& delta) override;
 
+    /// Return whether the element could handle wheel input.
+    virtual bool IsWheelHandler() const { return true; }
+
     /// Set content element.
     void SetContentElement(UIElement* element);
     /// Set view offset from the top-left corner.

+ 1 - 1
Source/Urho3D/UI/Text.cpp

@@ -238,7 +238,7 @@ void Text::GetBatches(PODVector<UIBatch>& batches, PODVector<float>& vertexData,
                         if (x > -thickness && x < thickness &&
                             y > -thickness && y < thickness)
                             continue;
-    
+
                         ConstructBatch(pageBatch, pageGlyphLocation, x, y, &effectColor_, effectDepthBias_);
                     }
                 }

+ 1 - 1
Source/Urho3D/UI/Text.h

@@ -218,7 +218,7 @@ protected:
     void ValidateSelection();
     /// Return row start X position.
     int GetRowStartPosition(unsigned rowIndex) const;
-    /// Contruct batch.
+    /// Construct batch.
     void ConstructBatch
         (UIBatch& pageBatch, const PODVector<GlyphLocation>& pageGlyphLocation, float dx = 0, float dy = 0, Color* color = nullptr,
             float depthBias = 0.0f);

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

@@ -497,7 +497,7 @@ void UI::Render(bool renderUICommand)
         // Render modal batches
         Render(vertexBuffer_, batches_, nonModalBatchSize_, batches_.Size());
     }
-    
+
     // Render to UIComponent textures. This is skipped when called from the RENDERUI command
     if (!renderUICommand)
     {
@@ -508,7 +508,7 @@ void UI::Render(bool renderUICommand)
             {
                 SetVertexData(component->vertexBuffer_, component->vertexData_);
                 SetVertexData(component->debugVertexBuffer_, component->debugVertexData_);
-                
+
                 RenderSurface* surface = component->GetTexture()->GetRenderSurface();
                 graphics_->SetRenderTarget(0, surface);
                 graphics_->SetViewport(IntRect(0, 0, surface->GetWidth(), surface->GetHeight()));
@@ -1746,23 +1746,19 @@ void UI::HandleMouseWheel(StringHash eventType, VariantMap& eventData)
     bool cursorVisible;
     GetCursorPositionAndVisible(cursorPos, cursorVisible);
 
-    UIElement* element;
-    if (!nonFocusedMouseWheel_ && (element = focusElement_))
-        element->OnWheel(delta, mouseButtons_, qualifiers_);
+    if (!nonFocusedMouseWheel_ && focusElement_)
+        focusElement_->OnWheel(delta, mouseButtons_, qualifiers_);
     else
     {
         // If no element has actual focus or in non-focused mode, get the element at cursor
         if (cursorVisible)
         {
-            element = GetElementAt(cursorPos);
+            UIElement* element = GetElementAt(cursorPos);
             if (nonFocusedMouseWheel_)
             {
                 // Going up the hierarchy chain to find element that could handle mouse wheel
-                while (element)
+                while (element && !element->IsWheelHandler())
                 {
-                    if (element->GetType() == ListView::GetTypeStatic() ||
-                        element->GetType() == ScrollView::GetTypeStatic())
-                        break;
                     element = element->GetParent();
                 }
             }

+ 3 - 0
Source/Urho3D/UI/UIElement.h

@@ -197,6 +197,9 @@ public:
     /// Convert element coordinates to screen coordinates.
     virtual IntVector2 ElementToScreen(const IntVector2& position);
 
+    /// Return whether the element could handle wheel input.
+    virtual bool IsWheelHandler() const { return false; }
+
     /// Load from an XML file. Return true if successful.
     bool LoadXML(Deserializer& source);
     /// Save to an XML file. Return true if successful.