Browse Source

Refactored pointer up/down function

rsredsq 10 years ago
parent
commit
5173b0d0b8

+ 1 - 2
Source/Atomic/UI/UIListView.cpp

@@ -252,8 +252,7 @@ ListViewItemWidget::ListViewItemWidget(ListViewItem *item, ListViewItemSource *s
     SetLayoutDistribution(LAYOUT_DISTRIBUTION_GRAVITY);
     SetLayoutDistribution(LAYOUT_DISTRIBUTION_GRAVITY);
     SetLayoutDistributionPosition(LAYOUT_DISTRIBUTION_POSITION_LEFT_TOP);
     SetLayoutDistributionPosition(LAYOUT_DISTRIBUTION_POSITION_LEFT_TOP);
     SetPaintOverflowFadeout(false);
     SetPaintOverflowFadeout(false);
-    SetCapturing(false);
-
+    
     item_->widget_ = this;
     item_->widget_ = this;
 
 
     for (int i = 0; i < item->depth_; i++)
     for (int i = 0; i < item->depth_; i++)

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

@@ -238,6 +238,13 @@ bool UISelectList::OnEvent(const tb::TBWidgetEvent &ev)
     {
     {
         GetTBSelectList()->SetFocus(WIDGET_FOCUS_REASON_POINTER);
         GetTBSelectList()->SetFocus(WIDGET_FOCUS_REASON_POINTER);
     }
     }
+    if (ev.type == EVENT_TYPE_POINTER_MOVE)
+    {
+        UIDragDrop* dragDrop = GetSubsystem<UIDragDrop>();
+        //if return true, then scroll event will be controlled by that widget itself
+        if (dragDrop->GetDraggingObject())
+            return true;
+    }
     return UIWidget::OnEvent(ev);
     return UIWidget::OnEvent(ev);
 }
 }
 
 

+ 0 - 4
Source/AtomicEditor/Editors/ResourceEditor.cpp

@@ -61,10 +61,6 @@ public:
 
 
     bool OnEvent(const TBWidgetEvent &ev)
     bool OnEvent(const TBWidgetEvent &ev)
     {
     {
-        // Don't process pointer down, we only respond to click events
-        if (ev.type == EVENT_TYPE_POINTER_DOWN)
-            return true;
-
         if (ev.type == EVENT_TYPE_CLICK)
         if (ev.type == EVENT_TYPE_CLICK)
         {
         {
             if (ev.target->GetID() == TBIDC("unsaved_modifications_dialog"))
             if (ev.target->GetID() == TBIDC("unsaved_modifications_dialog"))

+ 50 - 18
Source/ThirdParty/TurboBadger/tb_widgets.cpp

@@ -1336,15 +1336,35 @@ void TBWidget::InvokePointerDown(int x, int y, int click_count, MODIFIER_KEYS mo
             focus_target = focus_target->m_parent;
             focus_target = focus_target->m_parent;
         }
         }
     }
     }
-    if (down_widget)
+    //save x and y to restore it later
+    int ox = x;
+    int oy = y;
+    //check only for captured_widget
+    if (captured_widget)
+    {
+        captured_widget->SetTouchId(touchId);
+        //converts x, y
+        captured_widget->ConvertFromRoot(x, y);
+        pointer_move_widget_x = pointer_down_widget_x = x;
+        pointer_move_widget_y = pointer_down_widget_y = y;
+        TBWidgetEvent ev(EVENT_TYPE_POINTER_DOWN, x, y, touch, modifierkeys);
+        ev.count = click_count;
+        captured_widget->InvokeEvent(ev);
+    }
+    //restore x and y coords, to use with down_widget
+    x = ox;
+    y = oy;
+    //if down_widget is captured and it's not a captured_widget 
+    //then send an event, otherwise don't send it because POINTER_DOWN event will be sent twice
+    if (down_widget && down_widget != captured_widget)
     {
     {
+        //the same things that's done with captured_widget
         down_widget->Invalidate();
         down_widget->Invalidate();
         down_widget->InvalidateSkinStates();
         down_widget->InvalidateSkinStates();
         down_widget->OnCaptureChanged(true);
         down_widget->OnCaptureChanged(true);
         down_widget->SetTouchId(touchId);
         down_widget->SetTouchId(touchId);
+        //convert x, y
         down_widget->ConvertFromRoot(x, y);
         down_widget->ConvertFromRoot(x, y);
-        pointer_move_widget_x = pointer_down_widget_x = x;
-        pointer_move_widget_y = pointer_down_widget_y = y;
         TBWidgetEvent ev(EVENT_TYPE_POINTER_DOWN, x, y, touch, modifierkeys);
         TBWidgetEvent ev(EVENT_TYPE_POINTER_DOWN, x, y, touch, modifierkeys);
         ev.count = click_count;
         ev.count = click_count;
         down_widget->InvokeEvent(ev);
         down_widget->InvokeEvent(ev);
@@ -1353,30 +1373,42 @@ void TBWidget::InvokePointerDown(int x, int y, int click_count, MODIFIER_KEYS mo
 
 
 void TBWidget::InvokePointerUp(int x, int y, MODIFIER_KEYS modifierkeys, bool touch, int touchId)
 void TBWidget::InvokePointerUp(int x, int y, MODIFIER_KEYS modifierkeys, bool touch, int touchId)
 {
 {
-    TBWidget* down_widget = GetWidgetAt(x, y, true);
-    if ((down_widget && down_widget->touchId_ == touchId) || captured_widget)
+    //save x and y to restore it later
+    int ox = x;
+    int oy = y;
+    //save old_capture for later check, because captured_widget can be nullptr after releasing capture
+    TBWidget *old_capture = captured_widget;
+    if (captured_widget && captured_widget->touchId_ == touchId)
     {
     {
+        captured_widget->ConvertFromRoot(x, y);
         TBWidgetEvent ev_up(EVENT_TYPE_POINTER_UP, x, y, touch, modifierkeys);
         TBWidgetEvent ev_up(EVENT_TYPE_POINTER_UP, x, y, touch, modifierkeys);
         TBWidgetEvent ev_click(EVENT_TYPE_CLICK, x, y, touch, modifierkeys);
         TBWidgetEvent ev_click(EVENT_TYPE_CLICK, x, y, touch, modifierkeys);
-        down_widget->Invalidate();
-        down_widget->InvalidateSkinStates();
-        down_widget->OnCaptureChanged(false);
+        captured_widget->InvokeEvent(ev_up);
+        if (!cancel_click && captured_widget->GetHitStatus(x, y))
+        {
+            captured_widget->InvokeEvent(ev_click);
+        }
+        captured_widget->ReleaseCapture();
+    }
+    //restore x and y coords, to use with down_widget
+    x = ox;
+    y = oy;
+    TBWidget* down_widget = GetWidgetAt(x, y, true);
+    //make sure that down_widget is not captured_widget to don't sent event twice
+    if (down_widget && down_widget->touchId_ == touchId && old_capture != down_widget)
+    {
         down_widget->ConvertFromRoot(x, y);
         down_widget->ConvertFromRoot(x, y);
+        TBWidgetEvent ev_up(EVENT_TYPE_POINTER_UP, x, y, touch, modifierkeys);
+        TBWidgetEvent ev_click(EVENT_TYPE_CLICK, x, y, touch, modifierkeys);
         down_widget->InvokeEvent(ev_up);
         down_widget->InvokeEvent(ev_up);
         if (!cancel_click && down_widget->GetHitStatus(x, y))
         if (!cancel_click && down_widget->GetHitStatus(x, y))
         {
         {
             down_widget->InvokeEvent(ev_click);
             down_widget->InvokeEvent(ev_click);
         }
         }
-        if (captured_widget)
-        {
-            captured_widget->ConvertFromRoot(x, y);
-            if (!cancel_click && captured_widget->GetHitStatus(x, y))
-            {
-                captured_widget->InvokeEvent(ev_click);
-            }
-            captured_widget->InvokeEvent(ev_up);
-            captured_widget->ReleaseCapture();
-        }
+        //ReleaseCapture
+        down_widget->Invalidate();
+        down_widget->InvalidateSkinStates();
+        down_widget->OnCaptureChanged(false);
     }
     }
 }
 }