Kaynağa Gözat

Emit public drag start/move/end events. Adapted from patch contributed by Chris Friesen.

Lasse Öörni 12 yıl önce
ebeveyn
işleme
e5d4a3939b
5 değiştirilmiş dosya ile 73 ekleme ve 10 silme
  1. 3 0
      Docs/Urho3D.dox
  2. 33 6
      Engine/UI/UI.cpp
  3. 3 1
      Engine/UI/UI.h
  4. 30 0
      Engine/UI/UIEvents.h
  5. 4 3
      Readme.txt

+ 3 - 0
Docs/Urho3D.dox

@@ -53,6 +53,7 @@ Urho3D development, contributions and bugfixes by:
 - Colin Barrett
 - Erik Beran
 - Carlo Carollo
+- Chris Friesen
 - Alex Fuller
 - Mika Heinonen
 - Aster Jian
@@ -88,6 +89,7 @@ Urho3D uses the following third-party libraries:
 - jo_jpeg 1.52 (http://www.jonolick.com/uploads/7/9/2/1/7921194/jo_jpeg.cpp)
 - kNet (https://github.com/juj/kNet)
 - libcpuid 0.2.0 (http://libcpuid.sourceforge.net/)
+- Lua 5.1 (http://www.lua.org)
 - MojoShader (http://icculus.org/mojoshader/)
 - Open Asset Import Library (http://assimp.sourceforge.net/)
 - pugixml 1.0 (http://pugixml.org/)
@@ -96,6 +98,7 @@ Urho3D uses the following third-party libraries:
 - StanHull (http://codesuppository.blogspot.com/2006/03/john-ratcliffs-code-suppository-blog.html)
 - stb_image 1.29 (http://nothings.org/)
 - stb_vorbis 0.99996 (http://nothings.org/)
+- tolua++ 1.0.93 (http://www.codenix.com/~tolua)
 
 DXT / ETC1 / PVRTC decompression code based on the Squish library and the Oolong %Engine.
 

+ 33 - 6
Engine/UI/UI.cpp

@@ -784,6 +784,25 @@ void UI::SetCursorShape(CursorShape shape)
         cursor_->SetShape(shape);
 }
 
+void UI::SendDragEvent(StringHash eventType, UIElement* element, const IntVector2& screenPos)
+{
+    if (!element)
+        return;
+    
+    IntVector2 relativePos = element->ScreenToElement(screenPos);
+    
+    using namespace DragBegin;
+    
+    VariantMap eventData;
+    eventData[P_ELEMENT] = (void*)element;
+    eventData[P_X] = screenPos.x_;
+    eventData[P_Y] = screenPos.y_;
+    eventData[P_ELEMENTX] = relativePos.x_;
+    eventData[P_ELEMENTY] = relativePos.y_;
+    
+    element->SendEvent(eventType, eventData);
+}
+
 void UI::HandleScreenMode(StringHash eventType, VariantMap& eventData)
 {
     using namespace ScreenMode;
@@ -829,6 +848,7 @@ void UI::HandleMouseButtonDown(StringHash eventType, VariantMap& eventData)
             {
                 dragElement_ = element;
                 element->OnDragBegin(element->ScreenToElement(cursorPos), cursorPos, mouseButtons_, qualifiers_, cursor_);
+                SendDragEvent(E_DRAGBEGIN, element, cursorPos);
             }
         }
         else
@@ -837,8 +857,6 @@ void UI::HandleMouseButtonDown(StringHash eventType, VariantMap& eventData)
             SetFocusElement(0);
         }
 
-        using namespace UIMouseClick;
-
         VariantMap eventData;
         eventData[UIMouseClick::P_ELEMENT] = (void*)element.Get();
         eventData[UIMouseClick::P_X] = cursorPos.x_;
@@ -868,7 +886,8 @@ void UI::HandleMouseButtonUp(StringHash eventType, VariantMap& eventData)
             if (dragElement_->IsEnabled() && dragElement_->IsVisible())
             {
                 dragElement_->OnDragEnd(dragElement_->ScreenToElement(cursorPos), cursorPos, cursor_);
-
+                SendDragEvent(E_DRAGEND, dragElement_, cursorPos);
+                
                 // Drag and drop finish
                 bool dragSource = dragElement_ && (dragElement_->GetDragDropMode() & DD_SOURCE) != 0;
                 if (dragSource)
@@ -940,10 +959,14 @@ void UI::HandleMouseMove(StringHash eventType, VariantMap& eventData)
     if (cursorVisible && dragElement_ && mouseButtons_)
     {
         if (dragElement_->IsEnabled() && dragElement_->IsVisible())
+        {
             dragElement_->OnDragMove(dragElement_->ScreenToElement(cursorPos), cursorPos, mouseButtons_, qualifiers_, cursor_);
+            SendDragEvent(E_DRAGMOVE, dragElement_, cursorPos);
+        }
         else
         {
             dragElement_->OnDragEnd(dragElement_->ScreenToElement(cursorPos), cursorPos, cursor_);
+            SendDragEvent(E_DRAGEND, dragElement_, cursorPos);
             dragElement_.Reset();
         }
     }
@@ -1013,6 +1036,7 @@ void UI::HandleTouchBegin(StringHash eventType, VariantMap& eventData)
         {
             dragElement_ = element;
             element->OnDragBegin(element->ScreenToElement(pos), pos, MOUSEB_LEFT, 0, 0);
+            SendDragEvent(E_DRAGBEGIN, element, pos);
         }
     }
     else
@@ -1021,8 +1045,6 @@ void UI::HandleTouchBegin(StringHash eventType, VariantMap& eventData)
         SetFocusElement(0);
     }
 
-    using namespace UIMouseClick;
-
     VariantMap clickEventData;
     clickEventData[UIMouseClick::P_ELEMENT] = (void*)element.Get();
     clickEventData[UIMouseClick::P_X] = pos.x_;
@@ -1049,7 +1071,8 @@ void UI::HandleTouchEnd(StringHash eventType, VariantMap& eventData)
         if (dragElement_->IsEnabled() && dragElement_->IsVisible())
         {
             dragElement_->OnDragEnd(dragElement_->ScreenToElement(pos), pos, cursor_);
-
+            SendDragEvent(E_DRAGEND, dragElement_, pos);
+            
             // Drag and drop finish
             bool dragSource = dragElement_ && (dragElement_->GetDragDropMode() & DD_SOURCE) != 0;
             if (dragSource)
@@ -1090,10 +1113,14 @@ void UI::HandleTouchMove(StringHash eventType, VariantMap& eventData)
     if (dragElement_)
     {
         if (dragElement_->IsEnabled() && dragElement_->IsVisible())
+        {
             dragElement_->OnDragMove(dragElement_->ScreenToElement(pos), pos, MOUSEB_LEFT, 0, 0);
+            SendDragEvent(E_DRAGMOVE, dragElement_, pos);
+        }
         else
         {
             dragElement_->OnDragEnd(dragElement_->ScreenToElement(pos), pos, 0);
+            SendDragEvent(E_DRAGEND, dragElement_, pos);
             dragElement_.Reset();
         }
     }

+ 3 - 1
Engine/UI/UI.h

@@ -121,6 +121,8 @@ private:
     void GetCursorPositionAndVisible(IntVector2& pos, bool& visible);
     /// Set cursor shape if it exists.
     void SetCursorShape(CursorShape shape);
+    /// Send a UI element drag event.
+    void SendDragEvent(StringHash eventType, UIElement* element, const IntVector2& screenPos);
     /// Handle screen mode event.
     void HandleScreenMode(StringHash eventType, VariantMap& eventData);
     /// Handle mouse button down event.
@@ -145,7 +147,7 @@ private:
     void HandlePostUpdate(StringHash eventType, VariantMap& eventData);
     /// Handle render update event.
     void HandleRenderUpdate(StringHash eventType, VariantMap& eventData);
-
+    
     /// Graphics subsystem.
     WeakPtr<Graphics> graphics_;
     /// Vertex shader for no texture.

+ 30 - 0
Engine/UI/UIEvents.h

@@ -244,4 +244,34 @@ EVENT(E_ELEMENTREMOVED, ElementRemoved)
     PARAM(P_ELEMENT, Element);              // UIElement pointer
 }
 
+/// Drag behavior of a UI Element has started
+EVENT(E_DRAGBEGIN, DragBegin)
+{
+    PARAM(P_ELEMENT, Element);              // UIElement pointer
+    PARAM(P_X, X);                          // int
+    PARAM(P_Y, Y);                          // int
+    PARAM(P_ELEMENTX, ElementX);            // int
+    PARAM(P_ELEMENTY, ElementY);            // int
+}
+
+/// Drag behavior of a UI Element when the input device has moved
+EVENT(E_DRAGMOVE, DragMove)
+{
+    PARAM(P_ELEMENT, Element);              // UIElement pointer
+    PARAM(P_X, X);                          // int
+    PARAM(P_Y, Y);                          // int
+    PARAM(P_ELEMENTX, ElementX);            // int
+    PARAM(P_ELEMENTY, ElementY);            // int
+}
+
+/// Drag behavior of a UI Element has finished
+EVENT(E_DRAGEND, DragEnd)
+{
+    PARAM(P_ELEMENT, Element);              // UIElement pointer
+    PARAM(P_X, X);                          // int
+    PARAM(P_Y, Y);                          // int
+    PARAM(P_ELEMENTX, ElementX);            // int
+    PARAM(P_ELEMENTY, ElementY);            // int
+}
+
 }

+ 4 - 3
Readme.txt

@@ -15,6 +15,7 @@ Urho3D development, contributions and bugfixes by:
 - Colin Barrett
 - Erik Beran
 - Carlo Carollo
+- Chris Friesen
 - Alex Fuller
 - Mika Heinonen
 - Aster Jian
@@ -57,8 +58,10 @@ Urho3D uses the following third-party libraries:
 - Bullet 2.81 (http://www.bulletphysics.org/)
 - FreeType 2.3.12 (http://www.freetype.org/)
 - GLEW 1.9.0 (http://glew.sourceforge.net/)
+- jo_jpeg 1.52 (http://www.jonolick.com/uploads/7/9/2/1/7921194/jo_jpeg.cpp)
 - kNet (https://github.com/juj/kNet)
 - libcpuid 0.2.0 (http://libcpuid.sourceforge.net/)
+- Lua 5.1 (http://www.lua.org)
 - MojoShader (http://icculus.org/mojoshader/)
 - Open Asset Import Library (http://assimp.sourceforge.net/)
 - pugixml 1.0 (http://pugixml.org/)
@@ -68,8 +71,6 @@ Urho3D uses the following third-party libraries:
   john-ratcliffs-code-suppository-blog.html)
 - stb_image 1.29 (http://nothings.org/)
 - stb_vorbis 0.99996 (http://nothings.org/)
-- jo_jpeg 1.52 (http://www.jonolick.com/uploads/7/9/2/1/7921194/jo_jpeg.cpp)
-- Lua 5.1 (http://www.lua.org)
 - tolua++ 1.0.93 (http://www.codenix.com/~tolua)
 
 DXT / ETC1 / PVRTC decompression code based on the Squish library and the Oolong
@@ -361,4 +362,4 @@ V1.1    - Object and scene model refactoring.
         - Added OpenGL and cross-platform support.
         - Switched to kNet library for networking.
 
-V1.0    - Original release.
+V1.0    - Original release.