Selaa lähdekoodia

Fixed SDL build on Windows.
Improved mouse move logic.

Lasse Öörni 14 vuotta sitten
vanhempi
sitoutus
9f6ca174f8

+ 0 - 1
Engine/IO/FileSystem.cpp

@@ -331,7 +331,6 @@ String FileSystem::GetProgramDir()
     #ifdef __APPLE__
     unsigned size = MAX_PATH;
     _NSGetExecutablePath(exeName, &size);
-    printf("NSGetExecutablePath: %s\n", exeName);
     #endif
     #ifdef __linux__
     unsigned pid = getpid();

+ 17 - 0
Engine/Input/Input.cpp

@@ -121,6 +121,8 @@ void Input::Update()
     // Finally send mouse move event
     if (active_)
     {
+        // Recenter the mouse cursor manually if cursor clipping is in effect
+        #ifndef USE_SDL
         IntVector2 mousePos = GetMousePosition();
         mouseMove_ = mousePos - lastMousePosition_;
         
@@ -132,6 +134,14 @@ void Input::Update()
         }
         else
             lastMousePosition_ = mousePos;
+        #else
+        if ((clipCursor_) && (mouseMove_ != IntVector2::ZERO))
+        {
+            IntVector2 center(graphics_->GetWidth() / 2, graphics_->GetHeight() / 2);
+            SetMousePosition(center);
+            lastMousePosition_ = GetMousePosition();
+        }
+        #endif
         
         if (mouseMove_ != IntVector2::ZERO)
         {
@@ -665,6 +675,13 @@ void Input::HandleSDLEvent(void* sdlEvent)
         SetMouseButton(1 << (evt.button.button - 1), false);
         break;
         
+    case SDL_MOUSEMOTION:
+        mouseMove_.x_ += evt.motion.xrel;
+        mouseMove_.y_ += evt.motion.yrel;
+        lastMousePosition_.x_ = evt.motion.x;
+        lastMousePosition_.y_ = evt.motion.y;
+        break;
+        
     case SDL_MOUSEWHEEL:
         SetMouseWheel(evt.wheel.y);
         break;

+ 2 - 2
ThirdParty/SDL/CMakeLists.txt

@@ -22,10 +22,10 @@ endif ()
 
 file (GLOB H_FILES include/*.h)
 
+set_source_files_properties (${C_FILES} PROPERTIES LANGUAGE C)
+set_source_files_properties (${SYS_FILES} PROPERTIES LANGUAGE C)
 set (SOURCE_FILES ${C_FILES} ${SYS_C_FILES} ${H_FILES})
 
-set_source_files_properties (${SOURCE_FILES} PROPERTIES LANGUAGE C)
-
 # Define target & libraries to link
 add_library (${TARGET_NAME} STATIC ${SOURCE_FILES})
 

+ 0 - 3
ThirdParty/SDL/include/SDL_config_windows.h

@@ -144,9 +144,6 @@ typedef unsigned int uintptr_t;
 #define HAVE_STDDEF_H	1
 #endif
 
-#define SDL_HAPTIC_DISABLED 1
-#define SDL_JOYSTICK_DISABLED 1
-
 /* Allow disabling of core subsystems */
 #define SDL_JOYSTICK_DISABLED 1
 #define SDL_HAPTIC_DISABLED 1

+ 3 - 1
ThirdParty/SDL/src/events/SDL_mouse.c

@@ -299,9 +299,11 @@ SDL_WarpMouseInWindow(SDL_Window * window, int x, int y)
     SDL_Mouse *mouse = SDL_GetMouse();
 
     if (mouse->WarpMouse) {
-        // Urho3D: make sure to update the internal position when the mouse is warped
+        // Urho3D: update the internal position and the relative movement origin when the mouse is warped
         mouse->x = x;
         mouse->y = y;
+        mouse->last_x = x;
+        mouse->last_y = y;
         mouse->WarpMouse(window, x, y);
     } else {
         SDL_SendMouseMotion(window, 0, x, y);