Browse Source

Move the UI update event to engine post update, cleanups

Josh Engebretson 8 years ago
parent
commit
4396507fa5

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

@@ -380,6 +380,9 @@ void UI::Render(bool resetRenderTargets)
 
 void UI::HandlePostUpdate(StringHash eventType, VariantMap& eventData)
 {
+    SendEvent(E_UIUPDATE);
+
+    TBMessageHandler::ProcessMessages();
     TBAnimationManager::Update();
 
     rootWidget_->InvokeProcessStates();
@@ -507,8 +510,6 @@ void UI::HandleUpdate(StringHash eventType, VariantMap& eventData)
         if (tooltip_) tooltip_->Close();
     }
 
-    SendEvent(E_UIUPDATE);
-    TBMessageHandler::ProcessMessages();
 }
 
 UIWidget* UI::GetHoveredWidget()

+ 7 - 8
Source/Atomic/UI/UIDragDrop.cpp

@@ -52,9 +52,9 @@ namespace Atomic
 
 UIDragDrop::UIDragDrop(Context* context) : Object(context)
 {
+    SubscribeToEvent(E_UIUPDATE, ATOMIC_HANDLER(UIDragDrop, HandleUIUpdate));
     SubscribeToEvent(E_MOUSEMOVE, ATOMIC_HANDLER(UIDragDrop,HandleMouseMove));
-    SubscribeToEvent(E_MOUSEBUTTONUP, ATOMIC_HANDLER(UIDragDrop,HandleMouseUp));
-    SubscribeToEvent(E_MOUSEBUTTONDOWN, ATOMIC_HANDLER(UIDragDrop,HandleMouseDown));
+    SubscribeToEvent(E_MOUSEBUTTONUP, ATOMIC_HANDLER(UIDragDrop,HandleMouseUp));    
 
     SharedPtr<UIFontDescription> fd(new UIFontDescription(context));
     fd->SetId("Vera");
@@ -107,16 +107,16 @@ void UIDragDrop::DragEnd()
     currentTargetWidget->SendEvent(E_DRAGENDED, dropData);
 }
 
-void UIDragDrop::HandleMouseDown(StringHash eventType, VariantMap& eventData)
+void UIDragDrop::HandleUIUpdate(StringHash eventType, VariantMap& eventData)
 {
-    using namespace MouseButtonDown;
-
     Input* input = GetSubsystem<Input>();
 
-    if (!input->IsMouseVisible())
+    if (dragSourceWidget_.NotNull() || !input->IsMouseVisible() || !input->GetMouseButtonDown(MOUSEB_LEFT))
+    {
         return;
+    }
 
-    if ((eventData[P_BUTTONS].GetUInt() & MOUSEB_LEFT) && TBWidget::hovered_widget)
+    if (TBWidget::hovered_widget)
     {
         // see if we have a widget with a drag object
 
@@ -252,7 +252,6 @@ void UIDragDrop::HandleMouseMove(StringHash eventType, VariantMap& eventData)
 void UIDragDrop::FileDragEntered()
 {
     dragObject_ = new UIDragObject(context_);
-    //dragObject_->SetText("Files...");
 }
 
 void UIDragDrop::FileDragAddFile(const String& filename)

+ 1 - 1
Source/Atomic/UI/UIDragDrop.h

@@ -53,7 +53,7 @@ public:
 
 private:
 
-    void HandleMouseDown(StringHash eventType, VariantMap& eventData);
+    void HandleUIUpdate(StringHash eventType, VariantMap& eventData);
     void HandleMouseUp(StringHash eventType, VariantMap& eventData);
     void HandleMouseMove(StringHash eventType, VariantMap& eventData);
 

+ 1 - 1
Source/Atomic/UI/UIEvents.h

@@ -27,7 +27,7 @@
 namespace Atomic
 {
 
-// UIUpdate event
+// UIUpdate event which is sent post engine update, ensuring all input events have been processed
 ATOMIC_EVENT(E_UIUPDATE, UIUpdate)
 {