Просмотр исходного кода

Better handling of focus changed events

Marko Pintera 12 лет назад
Родитель
Сommit
0f201050b2

+ 5 - 5
CamelotCore/Include/CmInput.h

@@ -34,11 +34,6 @@ namespace CamelotFramework
 		 */
 		void capture();
 
-		/**
-		 * @brief	Should be called any time window in focus changes. Should only be called by Application.
-		 */
-		void inputWindowChanged(const RenderWindow& win);
-
 		/**
 		 * @brief	Returns smoothed mouse/joystick input in the horizontal axis.
 		 *
@@ -95,6 +90,11 @@ namespace CamelotFramework
 		 */
 		void updateSmoothInput();
 
+		/**
+		 * @brief	Called when window in focus changes, as reported by the OS.
+		 */
+		void inputWindowChanged(RenderWindow& win);
+
 		/************************************************************************/
 		/* 								STATICS		                      		*/
 		/************************************************************************/

+ 2 - 2
CamelotCore/Source/CmApplication.cpp

@@ -48,7 +48,6 @@ namespace CamelotFramework
 		MemStack::setupHeap(HID_Main);
 
 		Time::startUp(cm_new<Time>());
-		Input::startUp(cm_new<Input>());
 		DynLibManager::startUp(cm_new<DynLibManager>());
 		CoreGpuObjectManager::startUp(cm_new<CoreGpuObjectManager>());
 		Resources::startUp(cm_new<Resources>(desc.resourceCacheDirectory));
@@ -58,6 +57,7 @@ namespace CamelotFramework
 
 		mPrimaryWindow = RenderSystemManager::instance().initialize(desc.renderSystem, desc.primaryWindowDesc);
 
+		Input::startUp(cm_new<Input>());
 		RendererManager::startUp(cm_new<RendererManager>());
 
 		loadPlugin(desc.renderer);
@@ -159,11 +159,11 @@ namespace CamelotFramework
 
 		RendererManager::shutDown();
 		RenderSystem::shutDown();
+		Input::shutDown();
 
 		HighLevelGpuProgramManager::shutDown();
 		Resources::shutDown();
 		CoreGpuObjectManager::shutDown(); // Must shut down before DynLibManager to ensure all objects are destroyed before unloading their libraries
-		Input::shutDown();
 		DynLibManager::shutDown();
 		Time::shutDown();
 	}

+ 4 - 1
CamelotCore/Source/CmInput.cpp

@@ -3,6 +3,7 @@
 #include "CmMath.h"
 #include "CmRect.h"
 #include "CmDebug.h"
+#include "CmRenderWindowManager.h"
 
 #include <boost/bind.hpp>
 
@@ -32,6 +33,8 @@ namespace CamelotFramework
 
 		mOSInputHandler->onCharInput.connect(boost::bind(&Input::charInput, this, _1));
 		mOSInputHandler->onMouseMoved.connect(boost::bind(&Input::mouseMoved, this, _1));
+
+		RenderWindowManager::instance().onFocusGained.connect(boost::bind(&Input::inputWindowChanged, this, _1));
 	}
 
 	Input::~Input()
@@ -78,7 +81,7 @@ namespace CamelotFramework
 		updateSmoothInput();
 	}
 
-	void Input::inputWindowChanged(const RenderWindow& win)
+	void Input::inputWindowChanged(RenderWindow& win)
 	{
 		if(mRawInputHandler != nullptr)
 			mRawInputHandler->inputWindowChanged(win);

+ 0 - 2
CamelotCore/Source/CmWindowEventUtilities.cpp

@@ -141,8 +141,6 @@ LRESULT CALLBACK WindowEventUtilities::_WndProc(HWND hWnd, UINT uMsg, WPARAM wPa
 
 			if(!win->hasFocus())
 				win->_setHasFocus(true);
-
-			gInput().inputWindowChanged(*win);
         }
         else
         {

+ 3 - 6
CamelotOISInput/Source/CmInputHandlerOIS.cpp

@@ -66,12 +66,9 @@ namespace CamelotFramework
 		unsigned long long hWnd;
 		win.getCustomAttribute("WINDOW", &hWnd);
 
-		if(hWnd != 0) // DEBUG ONLY
-		{
-			std::string normalString = toString((unsigned long)hWnd).c_str();
-			mKeyboard->setCaptureContext(normalString);
-			mMouse->setCaptureContext(normalString);
-		}
+		std::string normalString = toString((unsigned long)hWnd).c_str();
+		mKeyboard->setCaptureContext(normalString);
+		mMouse->setCaptureContext(normalString);
 	}
 
 	bool InputHandlerOIS::keyPressed(const OIS::KeyEvent &arg)

+ 0 - 3
TODO.txt

@@ -23,9 +23,6 @@ GUIWidget::updateMeshes leaks. If I leave the game running I can see memory cont
 
 /************** INPUT REFACTOR *********************/
 
-AT THE END DONT FORGET:
- Compile new OIS for all other build types (also update libs and includes)
-
 DO LATER:
  - Modifiyng Input focusChange so it gets called from WindowManager
   - After I do remove the HWND == 0 check from Input