Browse Source

When dragging object and mouse is at top/bottom of scroll list, scroll list

Josh Engebretson 10 years ago
parent
commit
4391bb6749

+ 2 - 0
Source/Atomic/UI/UI.cpp

@@ -508,6 +508,8 @@ void UI::HandleUpdate(StringHash eventType, VariantMap& eventData)
         exitRequested_ = false;
         exitRequested_ = false;
         return;
         return;
     }
     }
+
+    SendEvent(E_UIUPDATE);
     TBMessageHandler::ProcessMessages();
     TBMessageHandler::ProcessMessages();
 }
 }
 
 

+ 3 - 0
Source/Atomic/UI/UIDragDrop.h

@@ -48,6 +48,9 @@ public:
     void FileDragAddFile(const String& filename);
     void FileDragAddFile(const String& filename);
     void FileDragConclude();
     void FileDragConclude();
 
 
+    /// Returns true when dragging an object
+    bool GetDraggingObject() { return dragObject_.NotNull(); }
+
 private:
 private:
 
 
     void HandleMouseDown(StringHash eventType, VariantMap& eventData);
     void HandleMouseDown(StringHash eventType, VariantMap& eventData);

+ 6 - 0
Source/Atomic/UI/UIEvents.h

@@ -27,6 +27,12 @@
 namespace Atomic
 namespace Atomic
 {
 {
 
 
+// UIUpdate event
+EVENT(E_UIUPDATE, UIUpdate)
+{
+
+}
+
 EVENT(E_WIDGETEVENT, WidgetEvent)
 EVENT(E_WIDGETEVENT, WidgetEvent)
 {
 {
     PARAM(P_HANDLER, Handler);           // UIWidget pointer of widget's OnEvent we are in
     PARAM(P_HANDLER, Handler);           // UIWidget pointer of widget's OnEvent we are in

+ 53 - 0
Source/Atomic/UI/UISelectList.cpp

@@ -22,8 +22,12 @@
 
 
 #include <TurboBadger/tb_select.h>
 #include <TurboBadger/tb_select.h>
 
 
+#include "../Atomic/IO/Log.h"
+#include "../Atomic/Input/Input.h"
+
 #include "UI.h"
 #include "UI.h"
 #include "UIEvents.h"
 #include "UIEvents.h"
+#include "UIDragDrop.h"
 #include "UISelectList.h"
 #include "UISelectList.h"
 
 
 using namespace tb;
 using namespace tb;
@@ -39,6 +43,8 @@ UISelectList::UISelectList(Context* context, bool createWidget) : UIWidget(conte
         widget_->SetDelegate(this);
         widget_->SetDelegate(this);
         GetSubsystem<UI>()->WrapWidget(this, widget_);
         GetSubsystem<UI>()->WrapWidget(this, widget_);
     }
     }
+
+    SubscribeToEvent(E_UIUPDATE, HANDLER(UISelectList, HandleUIUpdate));
 }
 }
 
 
 UISelectList::~UISelectList()
 UISelectList::~UISelectList()
@@ -139,6 +145,53 @@ void UISelectList::ScrollToSelectedItem()
 
 
 }
 }
 
 
+void UISelectList::HandleUIUpdate(StringHash eventType, VariantMap& eventData)
+{
+    TBSelectList* select = (TBSelectList*) widget_;
+
+    if (!select)
+        return;
+
+    // if we have a drag and drop item, auto scroll if top/bottom
+
+    UIDragDrop* dragDrop = GetSubsystem<UIDragDrop>();
+
+    if (dragDrop->GetDraggingObject())
+    {
+        Input* input = GetSubsystem<Input>();
+        IntVector2 pos = input->GetMousePosition();
+        select->ConvertFromRoot(pos.x_, pos.y_);
+
+        if ((select->GetHitStatus(pos.x_, pos.y_) != WIDGET_HIT_STATUS_NO_HIT))
+        {
+
+            // Adjust speed based on pixel distance from top and bottom
+            int value = pos.y_;
+
+            if (value > 16)
+                value = select->GetRect().h - pos.y_;
+
+            if (value > 16)
+                return;
+
+            int speed = 0;
+
+            if (value <= 16)
+                speed = 2;
+            if (value < 8)
+                speed = 4;
+
+            if (pos.y_ <= 12)
+                speed = -speed;
+
+            select->GetScrollContainer()->ScrollBy(0, speed);
+
+        }
+
+    }
+
+}
+
 bool UISelectList::OnEvent(const tb::TBWidgetEvent &ev)
 bool UISelectList::OnEvent(const tb::TBWidgetEvent &ev)
 {
 {
     return UIWidget::OnEvent(ev);
     return UIWidget::OnEvent(ev);

+ 2 - 0
Source/Atomic/UI/UISelectList.h

@@ -59,6 +59,8 @@ public:
 
 
 protected:
 protected:
 
 
+    void HandleUIUpdate(StringHash eventType, VariantMap& eventData);
+
     virtual bool OnEvent(const tb::TBWidgetEvent &ev);
     virtual bool OnEvent(const tb::TBWidgetEvent &ev);
 
 
 private:
 private:

+ 2 - 1
Source/ThirdParty/TurboBadger/tb_select.cpp

@@ -316,7 +316,8 @@ bool TBSelectList::OnEvent(const TBWidgetEvent &ev)
 		if (GetScrollContainer()->OnEvent(ev))
 		if (GetScrollContainer()->OnEvent(ev))
 			return true;
 			return true;
 	}
 	}
-	return false;
+
+    return TBWidget::OnEvent(ev);
 }
 }
 
 
 bool TBSelectList::ChangeValue(SPECIAL_KEY key)
 bool TBSelectList::ChangeValue(SPECIAL_KEY key)