Browse Source

Merge pull request #419 from AtomicGameEngine/JME-ATOMIC-418

Hierarchy frame select list improvements
JoshEngebretson 10 years ago
parent
commit
1fe03bef72

+ 0 - 1
Script/AtomicEditor/ui/frames/HierarchyFrame.ts

@@ -137,7 +137,6 @@ class HierarchyFrame extends Atomic.UIWidget {
         var childItemID = this.recursiveAddNode(parentID, node);
 
         this.nodeIDToItemID[node.id] = childItemID;
-
     }
 
     handleNodeRemoved(ev: Atomic.NodeRemovedEvent) {

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

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

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

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

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

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

+ 9 - 0
Source/Atomic/UI/UIListView.cpp

@@ -230,6 +230,7 @@ ListViewItemWidget::ListViewItemWidget(ListViewItem *item, ListViewItemSource *s
     SetLayoutDistribution(LAYOUT_DISTRIBUTION_GRAVITY);
     SetLayoutDistributionPosition(LAYOUT_DISTRIBUTION_POSITION_LEFT_TOP);
     SetPaintOverflowFadeout(false);
+    SetCapturing(false);
 
     item_->widget_ = this;
 
@@ -542,5 +543,13 @@ void UIListView::SelectItemByID(const String& id)
     }
 }
 
+void UIListView::ScrollToSelectedItem()
+{
+    if (rootList_.Null())
+        return;
+
+    rootList_->ScrollToSelectedItem();
+}
+
 
 }

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

@@ -52,6 +52,8 @@ public:
     void SetItemIcon(const String& id, const String& icon);
     void DeleteItemByID(const String& id);
 
+    void ScrollToSelectedItem();
+
     void SetExpanded(unsigned itemID, bool value);
 
     void DeleteAllItems();

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

@@ -22,8 +22,12 @@
 
 #include <TurboBadger/tb_select.h>
 
+#include "../Atomic/IO/Log.h"
+#include "../Atomic/Input/Input.h"
+
 #include "UI.h"
 #include "UIEvents.h"
+#include "UIDragDrop.h"
 #include "UISelectList.h"
 
 using namespace tb;
@@ -39,6 +43,8 @@ UISelectList::UISelectList(Context* context, bool createWidget) : UIWidget(conte
         widget_->SetDelegate(this);
         GetSubsystem<UI>()->WrapWidget(this, widget_);
     }
+
+    SubscribeToEvent(E_UIUPDATE, HANDLER(UISelectList, HandleUIUpdate));
 }
 
 UISelectList::~UISelectList()
@@ -130,6 +136,62 @@ void UISelectList::SetSource(UISelectItemSource* source)
     ((TBSelectList*)widget_)->SetSource(source ? source->GetTBItemSource() : NULL);
 }
 
+void UISelectList::ScrollToSelectedItem()
+{
+    if (!widget_)
+        return;
+
+    ((TBSelectList*)widget_)->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)
 {
     return UIWidget::OnEvent(ev);

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

@@ -53,10 +53,14 @@ public:
     String GetHoverItemID();
     String GetSelectedItemID();
 
+    void ScrollToSelectedItem();
+
     tb::TBSelectList* GetTBSelectList();
 
 protected:
 
+    void HandleUIUpdate(StringHash eventType, VariantMap& eventData);
+
     virtual bool OnEvent(const tb::TBWidgetEvent &ev);
 
 private:

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

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