Преглед на файлове

Input bugfixes. Enabled mouse move also in non-confined mode and removed the EVENT_MOUSEPOS event.

Lasse Öörni преди 15 години
родител
ревизия
962c4ec9a7
променени са 4 файла, в които са добавени 33 реда и са изтрити 42 реда
  1. 23 25
      Engine/Input/Input.cpp
  2. 3 3
      Engine/Input/Input.h
  3. 3 9
      Engine/Input/InputEvents.h
  4. 4 5
      Engine/UI/UI.cpp

+ 23 - 25
Engine/Input/Input.cpp

@@ -95,31 +95,17 @@ void Input::update()
         
         
         if (mMouseMove != IntVector2::sZero)
         if (mMouseMove != IntVector2::sZero)
         {
         {
-            if (mClipCursor)
-            {
-                using namespace MouseMove;
-                
-                VariantMap eventData;
-                eventData[P_X] = mMouseMove.mX;
-                eventData[P_Y] = mMouseMove.mY;
-                eventData[P_BUTTONS] = mMouseButtonDown;
-                eventData[P_QUALIFIERS] = getQualifiers();
-                sendEvent(EVENT_MOUSEMOVE, eventData);
-            }
-            else
-            {
-                // Set movement as zero and send only the absolute position
-                mMouseMove = IntVector2::sZero;
-                
-                using namespace MousePos;
-                
-                VariantMap eventData;
-                eventData[P_X] = mousePos.mX;
-                eventData[P_Y] = mousePos.mY;
-                eventData[P_BUTTONS] = mMouseButtonDown;
-                eventData[P_QUALIFIERS] = getQualifiers();
-                sendEvent(EVENT_MOUSEPOS, eventData);
-            }
+            using namespace MouseMove;
+            
+            VariantMap eventData;
+            eventData[P_X] = mMouseMove.mX;
+            eventData[P_Y] = mMouseMove.mY;
+            eventData[P_POSX] = mousePos.mX;
+            eventData[P_POSY] = mousePos.mY;
+            eventData[P_BUTTONS] = mMouseButtonDown;
+            eventData[P_QUALIFIERS] = getQualifiers();
+            eventData[P_CLIPCURSOR] = mClipCursor;
+            sendEvent(EVENT_MOUSEMOVE, eventData);
         }
         }
         if (mMouseMoveWheel)
         if (mMouseMoveWheel)
         {
         {
@@ -401,7 +387,10 @@ void Input::makeInactive()
     }
     }
     
     
     if (mActive)
     if (mActive)
+    {
         ShowCursor(TRUE);
         ShowCursor(TRUE);
+        ReleaseCapture();
+    }
     
     
     ClipCursor(0);
     ClipCursor(0);
     
     
@@ -448,6 +437,15 @@ void Input::mouseButtonChange(int button, bool newState)
     eventData[P_BUTTONS] = mMouseButtonDown;
     eventData[P_BUTTONS] = mMouseButtonDown;
     eventData[P_QUALIFIERS] = getQualifiers();
     eventData[P_QUALIFIERS] = getQualifiers();
     sendEvent(newState ? EVENT_MOUSEBUTTONDOWN : EVENT_MOUSEBUTTONUP, eventData);
     sendEvent(newState ? EVENT_MOUSEBUTTONDOWN : EVENT_MOUSEBUTTONUP, eventData);
+    
+    // In non-confined mode, while any of the mouse buttons are down, capture the mouse so that we get the button release reliably
+    if ((mRenderer) && (!mClipCursor))
+    {
+        if (mMouseButtonDown)
+            SetCapture((HWND)mRenderer->getWindowHandle());
+        else
+            ReleaseCapture();
+    }
 }
 }
 
 
 void Input::keyChange(int key, bool newState)
 void Input::keyChange(int key, bool newState)

+ 3 - 3
Engine/Input/Input.h

@@ -70,11 +70,11 @@ public:
     int getQualifiers() const;
     int getQualifiers() const;
     //! Return absolute mouse cursor position within the window. Only useful when the cursor is not confined
     //! Return absolute mouse cursor position within the window. Only useful when the cursor is not confined
     IntVector2 getMousePosition() const;
     IntVector2 getMousePosition() const;
-    //! Return mouse movement since last frame. When mouse is not confined, returns always zero
+    //! Return mouse movement since last frame
     const IntVector2& getMouseMove() const { return mMouseMove; }
     const IntVector2& getMouseMove() const { return mMouseMove; }
-    //! Return horizontal mouse movement since last frame. When mouse is not confined, returns always zero
+    //! Return horizontal mouse movement since last frame
     int getMouseMoveX() const { return mMouseMove.mX; }
     int getMouseMoveX() const { return mMouseMove.mX; }
-    //! Return vertical mouse movement since last frame. When mouse is not confined, returns always zero
+    //! Return vertical mouse movement since last frame
     int getMouseMoveY() const { return mMouseMove.mY; }
     int getMouseMoveY() const { return mMouseMove.mY; }
     //! Return mouse wheel movement since last frame
     //! Return mouse wheel movement since last frame
     int getMouseMoveWheel() const { return mMouseMoveWheel; }
     int getMouseMoveWheel() const { return mMouseMoveWheel; }

+ 3 - 9
Engine/Input/InputEvents.h

@@ -47,17 +47,11 @@ DEFINE_EVENT(EVENT_MOUSEMOVE, MouseMove)
 {
 {
     EVENT_PARAM(P_X, X);                        // int
     EVENT_PARAM(P_X, X);                        // int
     EVENT_PARAM(P_Y, Y);                        // int
     EVENT_PARAM(P_Y, Y);                        // int
+    EVENT_PARAM(P_POSX, PosX);                  // int
+    EVENT_PARAM(P_POSY, PosY);                  // int
     EVENT_PARAM(P_BUTTONS, Buttons);            // int
     EVENT_PARAM(P_BUTTONS, Buttons);            // int
     EVENT_PARAM(P_QUALIFIERS, Qualifiers);      // int
     EVENT_PARAM(P_QUALIFIERS, Qualifiers);      // int
-}
-
-//! Mouse moved when in non-confined mode
-DEFINE_EVENT(EVENT_MOUSEPOS, MousePos)
-{
-    EVENT_PARAM(P_X, X);                        // int
-    EVENT_PARAM(P_Y, Y);                        // int
-    EVENT_PARAM(P_BUTTONS, Buttons);            // int
-    EVENT_PARAM(P_QUALIFIERS, Qualifiers);      // int
+    EVENT_PARAM(P_CLIPCURSOR, ClipCursor);      // bool
 }
 }
 
 
 //! Mouse wheel moved
 //! Mouse wheel moved

+ 4 - 5
Engine/UI/UI.cpp

@@ -66,7 +66,6 @@ UI::UI(Renderer* renderer, ResourceCache* cache) :
     mRootElement->setSize(mRenderer->getWidth(), mRenderer->getHeight());
     mRootElement->setSize(mRenderer->getWidth(), mRenderer->getHeight());
     subscribeToEvent(EVENT_WINDOWRESIZED, EVENT_HANDLER(UI, handleWindowResized));
     subscribeToEvent(EVENT_WINDOWRESIZED, EVENT_HANDLER(UI, handleWindowResized));
     subscribeToEvent(EVENT_MOUSEMOVE, EVENT_HANDLER(UI, handleMouseMove));
     subscribeToEvent(EVENT_MOUSEMOVE, EVENT_HANDLER(UI, handleMouseMove));
-    subscribeToEvent(EVENT_MOUSEPOS, EVENT_HANDLER(UI, handleMouseMove));
     subscribeToEvent(EVENT_MOUSEBUTTONDOWN, EVENT_HANDLER(UI, handleMouseButtonDown));
     subscribeToEvent(EVENT_MOUSEBUTTONDOWN, EVENT_HANDLER(UI, handleMouseButtonDown));
     subscribeToEvent(EVENT_MOUSEBUTTONUP, EVENT_HANDLER(UI, handleMouseButtonUp));
     subscribeToEvent(EVENT_MOUSEBUTTONUP, EVENT_HANDLER(UI, handleMouseButtonUp));
     subscribeToEvent(EVENT_MOUSEWHEEL, EVENT_HANDLER(UI, handleMouseWheel));
     subscribeToEvent(EVENT_MOUSEWHEEL, EVENT_HANDLER(UI, handleMouseWheel));
@@ -472,9 +471,9 @@ void UI::handleMouseMove(StringHash eventType, VariantMap& eventData)
     
     
     if (mCursor)
     if (mCursor)
     {
     {
-        if (eventType == EVENT_MOUSEMOVE)
+        if (eventData[P_CLIPCURSOR].getBool())
         {
         {
-            // When deltas are sent, move the cursor only when visible
+            // When in confined cursor mode, move cursor only when visible
             if (mCursor->isVisible())
             if (mCursor->isVisible())
             {
             {
                 IntVector2 pos = mCursor->getPosition();
                 IntVector2 pos = mCursor->getPosition();
@@ -488,8 +487,8 @@ void UI::handleMouseMove(StringHash eventType, VariantMap& eventData)
         }
         }
         else
         else
         {
         {
-            // When absolute positions are sent, the cursor is not confined, so do not clamp the on-screen cursor's position
-            mCursor->setPosition(eventData[P_X].getInt(), eventData[P_Y].getInt());
+            // When in non-confined mode, move cursor always to ensure accurate position, and do not clamp
+            mCursor->setPosition(eventData[P_POSX].getInt(), eventData[P_POSY].getInt());
         }
         }
         
         
         if ((mMouseDragElement) && (mMouseButtons))
         if ((mMouseDragElement) && (mMouseButtons))