Lasse Öörni пре 14 година
родитељ
комит
7819e4644b
3 измењених фајлова са 29 додато и 20 уклоњено
  1. 24 17
      Engine/Input/Input.cpp
  2. 2 0
      Engine/Input/Input.h
  3. 3 3
      ThirdParty/GLFW/src/cocoa_window.m

+ 24 - 17
Engine/Input/Input.cpp

@@ -98,6 +98,7 @@ Input::Input(Context* context) :
     minimized_(false),
     activated_(false),
     suppressNextChar_(false),
+    suppressNextMouseMove_(false),
     initialized_(false)
 {
     // Zero the initial state
@@ -144,20 +145,12 @@ void Input::Update()
     // Pump GLFW events
     glfwPollEvents();
 
-    // Check activation state
-    if (glfwGetWindowParam(graphics_->GetWindowHandle(), GLFW_ACTIVE))
-    {
-        if (!active_)
-            activated_ = true;
-    }
-    else
-    {
-        if (active_)
-            MakeInactive();
-    }    
+    // Check for input inactivation
+    if (active_ && !glfwGetWindowParam(graphics_->GetWindowHandle(), GLFW_ACTIVE))
+        MakeInactive();
     #endif
     
-    // Activate application now if necessary
+    // Activate input now if necessary
     if (activated_)
         MakeActive();
     
@@ -183,6 +176,12 @@ void Input::Update()
         lastCursorPosition_ = mousePos;
         #endif
         
+        if (mouseMove_ != IntVector2::ZERO && suppressNextMouseMove_)
+        {
+            mouseMove_ = IntVector2::ZERO;
+            suppressNextMouseMove_ = false;
+        }
+        
         if (mouseMove_ != IntVector2::ZERO)
         {
             using namespace MouseMove;
@@ -272,8 +271,7 @@ void Input::Initialize()
     graphics_ = graphics;
     
     // Set the initial activation
-    MakeActive();
-    
+    activated_ = true;
     initialized_ = true;
     
     LOGINFO("Initialized input");
@@ -294,9 +292,9 @@ void Input::MakeActive()
     SetClipCursor(true);
     SetCursorVisible(false);
     #else
-    // Get the current mouse position as a base for movement calculations
     glfwSetInputMode(graphics_->GetWindowHandle(), GLFW_CURSOR_MODE, GLFW_CURSOR_CAPTURED);
     lastCursorPosition_ = GetCursorPosition();
+    suppressNextMouseMove_ = true;
     #endif
     
     using namespace Activation;
@@ -352,6 +350,15 @@ void Input::ResetState()
 
 void Input::SetMouseButton(int button, bool newState)
 {
+    // In GLFW mode, activate by a left-click inside the window
+    #ifdef USE_OPENGL
+    if (graphics_ && initialized_)
+    {
+        if (glfwGetWindowParam(graphics_->GetWindowHandle(), GLFW_ACTIVE) && !active_ && newState && button == MOUSEB_LEFT)
+            activated_ = true;
+    }
+    #endif    
+        
     // If we are not active yet, do not react to the mouse button down
     if (newState && !active_)
         return;
@@ -546,7 +553,7 @@ void Input::HandleWindowMessage(StringHash eventType, VariantMap& eventData)
             MakeInactive();
         else
         {
-            if (!minimized_)
+            if (!minimized_ && graphics_->GetFullscreen())
                activated_ = true;
         }
         eventData[P_HANDLED] = true;
@@ -679,13 +686,13 @@ void Input::HandleScreenMode(StringHash eventType, VariantMap& eventData)
     #else
     // Re-enable GLFW callbacks each time the window has been recreated
     GLFWwindow window = graphics_->GetWindowHandle();
-    glfwSetInputMode(window, GLFW_CURSOR_MODE, GLFW_CURSOR_CAPTURED);
     glfwSetInputMode(window, GLFW_KEY_REPEAT, GL_TRUE);
     glfwSetKeyCallback(&KeyCallback);
     glfwSetCharCallback(&CharCallback);
     glfwSetMouseButtonCallback(&MouseButtonCallback);
     glfwSetScrollCallback(&MouseScrollCallback);
     lastCursorPosition_ = GetCursorPosition();
+    activated_ = true;
     #endif
 }
 

+ 2 - 0
Engine/Input/Input.h

@@ -143,6 +143,8 @@ private:
     bool activated_;
     /// Next char message suppress flag.
     bool suppressNextChar_;
+    /// Next mouse move suppress flag.
+    bool suppressNextMouseMove_;
     /// Initialized flag.
     bool initialized_;
 };

+ 3 - 3
ThirdParty/GLFW/src/cocoa_window.m

@@ -901,9 +901,6 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window,
 
         [[window->NS.window contentView] enterFullScreenMode:[NSScreen mainScreen]
                                                  withOptions:nil];
-            
-        // Urho3D: assume initial input activation for fullscreen
-        _glfwInputWindowFocus(window, GL_TRUE);
     }
     else 
     {
@@ -920,6 +917,9 @@ int _glfwPlatformOpenWindow(_GLFWwindow* window,
 
     window->resizable = wndconfig->resizable;
 
+    // Urho3D: assume initial input activation
+    _glfwInputWindowFocus(window, GL_TRUE);
+        
     return GL_TRUE;
 }