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

Hooked up custom OIS
GUIManager now uses OIS mouse position

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

+ 2 - 0
BansheeEngine.sln

@@ -102,6 +102,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "BansheeOctreeSM", "BansheeO
 		{07B0C186-5173-46F2-BE26-7E4148BD0CCA} = {07B0C186-5173-46F2-BE26-7E4148BD0CCA}
 		{07B0C186-5173-46F2-BE26-7E4148BD0CCA} = {07B0C186-5173-46F2-BE26-7E4148BD0CCA}
 	EndProjectSection
 	EndProjectSection
 EndProject
 EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Plugins", "Plugins", "{32E4E2B7-1B4D-4B06-AD87-57CEE00BC247}"
+EndProject
 Global
 Global
 	GlobalSection(SubversionScc) = preSolution
 	GlobalSection(SubversionScc) = preSolution
 		Svn-Managed = True
 		Svn-Managed = True

+ 1 - 1
BansheeEngine/Include/BsGUIManager.h

@@ -76,6 +76,6 @@ namespace BansheeEngine
 		void onMouseDown(const CM::MouseEvent& event, CM::MouseButton buttonID);
 		void onMouseDown(const CM::MouseEvent& event, CM::MouseButton buttonID);
 		void onMouseUp(const CM::MouseEvent& event, CM::MouseButton buttonID);
 		void onMouseUp(const CM::MouseEvent& event, CM::MouseButton buttonID);
 
 
-		CM::Int2 getWidgetRelativeCursorPos(const GUIWidget& widget);
+		CM::Int2 getWidgetRelativePos(const GUIWidget& widget, const CM::Int2& screenPos);
 	};
 	};
 }
 }

+ 8 - 23
BansheeEngine/Source/BsGUIManager.cpp

@@ -472,8 +472,7 @@ namespace BansheeEngine
 		{
 		{
 			const RenderWindow* window = widgetInFocus->getOwnerWindow();
 			const RenderWindow* window = widgetInFocus->getOwnerWindow();
 
 
-			// TODO - Use position provided by mouse event
-			screenPos = Cursor::getWindowPosition(*window);
+			Int2 screenPos = window->screenToWindowPos(event.coords);
 			Vector4 vecScreenPos((float)screenPos.x, (float)screenPos.y, 0.0f, 1.0f);
 			Vector4 vecScreenPos((float)screenPos.x, (float)screenPos.y, 0.0f, 1.0f);
 
 
 			UINT32 topMostDepth = std::numeric_limits<UINT32>::max();
 			UINT32 topMostDepth = std::numeric_limits<UINT32>::max();
@@ -519,7 +518,7 @@ namespace BansheeEngine
 				// Send MouseOut event
 				// Send MouseOut event
 				if(mActiveElement == nullptr || mMouseOverElement == mActiveElement)
 				if(mActiveElement == nullptr || mMouseOverElement == mActiveElement)
 				{
 				{
-					Int2 curLocalPos = getWidgetRelativeCursorPos(*mMouseOverWidget);
+					Int2 curLocalPos = getWidgetRelativePos(*mMouseOverWidget, event.coords);
 
 
 					mMouseEvent.setMouseOutData(topMostElement, curLocalPos);
 					mMouseEvent.setMouseOutData(topMostElement, curLocalPos);
 					mMouseOverWidget->_mouseEvent(mMouseOverElement, mMouseEvent);
 					mMouseOverWidget->_mouseEvent(mMouseOverElement, mMouseEvent);
@@ -540,7 +539,7 @@ namespace BansheeEngine
 		// If mouse is being held down send MouseDrag events
 		// If mouse is being held down send MouseDrag events
 		if(mActiveElement != nullptr)
 		if(mActiveElement != nullptr)
 		{
 		{
-			Int2 curLocalPos = getWidgetRelativeCursorPos(*mActiveWidget);
+			Int2 curLocalPos = getWidgetRelativePos(*mActiveWidget, event.coords);
 
 
 			if(mLastCursorLocalPos != curLocalPos)
 			if(mLastCursorLocalPos != curLocalPos)
 			{
 			{
@@ -582,14 +581,7 @@ namespace BansheeEngine
 		bool acceptMouseDown = mActiveElement == nullptr && mMouseOverElement != nullptr;
 		bool acceptMouseDown = mActiveElement == nullptr && mMouseOverElement != nullptr;
 		if(acceptMouseDown)
 		if(acceptMouseDown)
 		{
 		{
-			// TODO - Use position provided by mouse event
-			Int2 screenPos = Cursor::getWindowPosition(*mMouseOverWidget->getOwnerWindow());
-			Vector4 vecScreenPos((float)screenPos.x, (float)screenPos.y, 0.0f, 1.0f);
-
-			const Matrix4& worldTfrm = mMouseOverWidget->SO()->getWorldTfrm();
-
-			Vector4 vecLocalPos = worldTfrm.inverse() * vecScreenPos;
-			Int2 localPos = Int2(Math::RoundToInt(vecLocalPos.x), Math::RoundToInt(vecLocalPos.y));
+			Int2 localPos = getWidgetRelativePos(*mMouseOverWidget, event.coords);
 
 
 			mMouseEvent.setMouseDownData(mMouseOverElement, localPos, buttonID);
 			mMouseEvent.setMouseDownData(mMouseOverElement, localPos, buttonID);
 			mMouseOverWidget->_mouseEvent(mMouseOverElement, mMouseEvent);
 			mMouseOverWidget->_mouseEvent(mMouseOverElement, mMouseEvent);
@@ -623,17 +615,10 @@ namespace BansheeEngine
 
 
 		mMouseEvent = GUIMouseEvent(buttonStates);
 		mMouseEvent = GUIMouseEvent(buttonStates);
 
 
-		// TODO - Use position provided by mouse event
 		Int2 localPos;
 		Int2 localPos;
 		if(mMouseOverWidget != nullptr)
 		if(mMouseOverWidget != nullptr)
 		{
 		{
-			Int2 screenPos = Cursor::getWindowPosition(*mMouseOverWidget->getOwnerWindow());
-			Vector4 vecScreenPos((float)screenPos.x, (float)screenPos.y, 0.0f, 1.0f);
-
-			const Matrix4& worldTfrm = mMouseOverWidget->SO()->getWorldTfrm();
-
-			Vector4 vecLocalPos = worldTfrm.inverse() * vecScreenPos;
-			localPos = Int2(Math::RoundToInt(vecLocalPos.x), Math::RoundToInt(vecLocalPos.y));
+			localPos = getWidgetRelativePos(*mMouseOverWidget, event.coords);
 		}
 		}
 
 
 		// Send MouseUp event only if we are over the active element (we don't want to accidentally trigger other elements).
 		// Send MouseUp event only if we are over the active element (we don't want to accidentally trigger other elements).
@@ -658,14 +643,14 @@ namespace BansheeEngine
 		}	
 		}	
 	}
 	}
 
 
-	Int2 GUIManager::getWidgetRelativeCursorPos(const GUIWidget& widget)
+	Int2 GUIManager::getWidgetRelativePos(const GUIWidget& widget, const Int2& screenPos)
 	{
 	{
 		const RenderWindow* window = widget.getOwnerWindow();
 		const RenderWindow* window = widget.getOwnerWindow();
-		Int2 screenPos = Cursor::getWindowPosition(*window);
+		Int2 windowPos = window->screenToWindowPos(screenPos);
 
 
 		const Matrix4& worldTfrm = widget.SO()->getWorldTfrm();
 		const Matrix4& worldTfrm = widget.SO()->getWorldTfrm();
 
 
-		Vector4 vecLocalPos = worldTfrm.inverse() * Vector4((float)screenPos.x, (float)screenPos.y, 0.0f, 1.0f);
+		Vector4 vecLocalPos = worldTfrm.inverse() * Vector4((float)windowPos.x, (float)windowPos.y, 0.0f, 1.0f);
 		Int2 curLocalPos(Math::RoundToInt(vecLocalPos.x), Math::RoundToInt(vecLocalPos.y));
 		Int2 curLocalPos(Math::RoundToInt(vecLocalPos.x), Math::RoundToInt(vecLocalPos.y));
 
 
 		return curLocalPos;
 		return curLocalPos;

+ 1 - 1
CamelotClient/CmEditorWindow.cpp

@@ -105,7 +105,7 @@ namespace BansheeEditor
 
 
 	void EditorWindow::update()
 	void EditorWindow::update()
 	{
 	{
-		Int2 cursorPos = Cursor::getWindowPosition(*mRenderWindow);
+		//Int2 cursorPos = Cursor::getWindowPosition(*mRenderWindow);
 		
 		
 		//mDbgLabel->setText("Position: " + toString(cursorPos.x) + ", " + toString(cursorPos.y));
 		//mDbgLabel->setText("Position: " + toString(cursorPos.x) + ", " + toString(cursorPos.y));
 		
 		

+ 0 - 3
CamelotCore/Include/Win32/CmCursorImpl.h

@@ -29,9 +29,6 @@ namespace CamelotFramework
 		static Int2 getScreenPosition();
 		static Int2 getScreenPosition();
 		static void setScreenPosition(const Int2& pos);
 		static void setScreenPosition(const Int2& pos);
 
 
-		static Int2 getWindowPosition(const RenderWindow& window);
-		static void setWindowPosition(const RenderWindow& window, const Int2& pos);
-
 		static void clipToWindow(const RenderWindow& window);
 		static void clipToWindow(const RenderWindow& window);
 		static void clipToRect(const Rect& screenRect);
 		static void clipToRect(const Rect& screenRect);
 		static void clipDisable();
 		static void clipDisable();

+ 0 - 29
CamelotCore/Source/Win32/CmCursorImpl.cpp

@@ -26,35 +26,6 @@ namespace CamelotFramework
 	NativeCursorData Cursor::mCursor;
 	NativeCursorData Cursor::mCursor;
 	bool Cursor::mUsingCustom = false;
 	bool Cursor::mUsingCustom = false;
 
 
-	Int2 Cursor::getWindowPosition(const RenderWindow& window)
-	{
-		POINT screenPos;
-		GetCursorPos(&screenPos);
-
-		HWND hwnd;
-		window.getCustomAttribute("WINDOW", &hwnd);
-
-		ScreenToClient(hwnd, &screenPos);
-
-		return Int2(screenPos.x, screenPos.y);
-	}
-
-	void Cursor::setWindowPosition(const RenderWindow& window, const Int2& pos)
-	{
-		POINT screenPos;
-
-		// Convert client coordinates to screen coordinates
-		screenPos.x = pos.x;
-		screenPos.y = pos.y;
-
-		HWND hwnd;
-		window.getCustomAttribute("WINDOW", &hwnd);
-
-		ClientToScreen(hwnd, &screenPos);
-
-		SetCursorPos(screenPos.x, screenPos.y);
-	}
-
 	Int2 Cursor::getScreenPosition()
 	Int2 Cursor::getScreenPosition()
 	{
 	{
 		POINT screenPos;
 		POINT screenPos;

+ 1 - 1
CamelotD3D11RenderSystem/Source/CmD3D11RenderWindow.cpp

@@ -544,7 +544,7 @@ namespace CamelotFramework
 		pos.x = screenPos.x;
 		pos.x = screenPos.x;
 		pos.y = screenPos.y;
 		pos.y = screenPos.y;
 
 
-		ClientToScreen(mHWnd, &pos);
+		ScreenToClient(mHWnd, &pos);
 		return Int2(pos.x, pos.y);
 		return Int2(pos.x, pos.y);
 	}
 	}
 
 

+ 1 - 1
CamelotD3D9Renderer/Source/CmD3D9RenderWindow.cpp

@@ -754,7 +754,7 @@ namespace CamelotFramework
 		pos.x = screenPos.x;
 		pos.x = screenPos.x;
 		pos.y = screenPos.y;
 		pos.y = screenPos.y;
 
 
-		ClientToScreen(mHWnd, &pos);
+		ScreenToClient(mHWnd, &pos);
 		return Int2(pos.x, pos.y);
 		return Int2(pos.x, pos.y);
 	}
 	}
 
 

+ 1 - 1
CamelotGLRenderer/Source/CmWin32Window.cpp

@@ -684,7 +684,7 @@ namespace CamelotFramework {
 		pos.x = screenPos.x;
 		pos.x = screenPos.x;
 		pos.y = screenPos.y;
 		pos.y = screenPos.y;
 
 
-		ClientToScreen(mHWnd, &pos);
+		ScreenToClient(mHWnd, &pos);
 		return Int2(pos.x, pos.y);
 		return Int2(pos.x, pos.y);
 	}
 	}
 
 

+ 1 - 1
CamelotOISInput/CamelotOISInput.vcxproj

@@ -107,7 +107,7 @@
     <Link>
     <Link>
       <GenerateDebugInformation>true</GenerateDebugInformation>
       <GenerateDebugInformation>true</GenerateDebugInformation>
       <AdditionalLibraryDirectories>../lib/$(Platform)/$(Configuration);../Dependencies/lib/x64/Debug;./Dependencies/lib/x64/Debug</AdditionalLibraryDirectories>
       <AdditionalLibraryDirectories>../lib/$(Platform)/$(Configuration);../Dependencies/lib/x64/Debug;./Dependencies/lib/x64/Debug</AdditionalLibraryDirectories>
-      <AdditionalDependencies>CamelotCore.lib;CamelotUtility.lib;OIS.lib;%(AdditionalDependencies)</AdditionalDependencies>
+      <AdditionalDependencies>CamelotCore.lib;CamelotUtility.lib;CamelotOIS.lib;%(AdditionalDependencies)</AdditionalDependencies>
       <ImportLibrary>..\lib\$(Platform)\$(Configuration)\$(TargetName).lib</ImportLibrary>
       <ImportLibrary>..\lib\$(Platform)\$(Configuration)\$(TargetName).lib</ImportLibrary>
     </Link>
     </Link>
   </ItemDefinitionGroup>
   </ItemDefinitionGroup>

+ 4 - 62
Dependencies.txt

@@ -27,73 +27,15 @@ CamelotFontImporter (optional) relies on:
   - IMPORTANT NOTE: When compiling as static library make sure to define "FREETYPE2_STATIC". It is not defined by default
   - IMPORTANT NOTE: When compiling as static library make sure to define "FREETYPE2_STATIC". It is not defined by default
     in provided Visual Studio projects, which can cause a headache.
     in provided Visual Studio projects, which can cause a headache.
 
 
+CamelotOISInput relies on:
+ - CamelotOIS - Slightly modified version of OIS 1.3 specifically for Camelot
+  - Supplied with Camelot source code but compiled as a separate project into a dependency
+
 Place plug-in specific dependency files in:
 Place plug-in specific dependency files in:
  - Library include files in (BansheeRootDir)/(PluginDir)/Dependencies/Include
  - Library include files in (BansheeRootDir)/(PluginDir)/Dependencies/Include
  - Static library files in (BansheeRootDir)/(PluginDir)/Dependencies/lib/(Platform)/(Configuration)
  - Static library files in (BansheeRootDir)/(PluginDir)/Dependencies/lib/(Platform)/(Configuration)
  - Dynamic library files in (BansheeRootDir)/bin/(Platform)/(Configuration)
  - Dynamic library files in (BansheeRootDir)/bin/(Platform)/(Configuration)
 
 
- ----------------------------------------------------------------------------------
-
- Banshee editor dependencies:
-  - Qt Toolkit
-    - http://qt-project.org/downloads
-
-Qt setup instructions:
- 1. Make sure to install Qt 5.0.1 (earlier or later versions might possibly work fine)
- 2. Set up CamelotEditor project so it is pre-processed by Qt MOC before compilation. Each header with CmQt* prefix needs to be preproceesed
-     by MOC, and its files output in GeneratedFiles folder.
- 2. Add Qt include files to CamelotEditor/Dependencies/Include
- 3. Add Qt libraries to CamelotEditor/Dependencies/lib/Debug, CamelotEditor/Dependencies/lib/Release, CamelotEditor/Dependencies/lib/x64/Debug and CamelotEditor/Dependencies/lib/x64/Release
-   - You may download pre-compiled 32bit versions of the libraries for some compilers from the Qt web
-   - For other cases you will need to compile them yourself
- 4. Add dynamic Qt libraries in (BansheeRootDir)/bin/(Platform)/(Configuration)
- 5. Only some Qt libraries are used, so you don't need to add them all. We use:
-   - Qt5Core
-   - Qt5Gui
-   - Qt5Widgets
- 6. Add Qt platform plugins:
-   - copy qtbase/plugins/platform/ contents from compiled Qt binaries to (BansheeRootDir)/bin/(Platform)/(Configuration)/qtplugins/platform/
-     - this folder contains platform-specific libraries (e.g. qwindows.dll for Windows)
-   - Create conf.qt file in (BansheeRootDir)/bin/(Platform)/(Configuration) containing:
-      [Paths]
-      Plugins = qtplugins
-
-   - This tells Qt where the plugins are located (i.e. in the "plugins" subfolder of the current folder)
-
-Compiling Qt using MSVC2012 compiler:
- - At the moment there are no provided precompiled libraries for 2012 version of MSVC so
-   you will need to compile them yourself. Qt also doesn't officially provide 64bit
-   versions of their libraries, so this short guide will cover that as well.
- 1. Get Qt 5.0.1. source from http://qt-project.org/downloads
- 2. Extract source to qt-everywhere-opensource-src-5.0.1
- 3. Install:
-   - ActivePerl 5.16.1.1601 (for x64): http://www.activestate.com/activeperl/downloads
-   - Python 2.7.3 (for x64): http://www.python.org/download/
- 4. To compile run Visual Studio 2012 Native Tools Command Prompt 
-    (x64 or x86 version, depending which platform you want to compile for)
- 5. Go to qt-everywhere-opensource-src-5.0.1 in the command prompt
- 6. Run: configure -prefix %CD%\qtbase -opensource -nomake tests -nomake examples -opengl desktop -debug-and-release -platform win32-msvc2012
- 7. Run: nmake
-    OR
- 8. Download and run jom. jom is faster than nmake because it will use multiple CPU cores
-   - Download jom from: http://qt-project.org/wiki/jom
-   - Place it in qt-everywhere-opensource-src-5.0.1 dir
-   - Run: jom -j N 
-   - (N is the number of cores you want to use)
- 9. Wait some time (About 10 minutes on my PC, but I've seen people report waiting for hours)
-
- MOC preproces:
-  1. Each header starting with CmQt* (or, more generally, each file containing Q_OBJECT) needs to be
-     preprocessed by MOC, and MOC output needs to be compiled with the project
-  2. Example command line for preprocessing a single file: 
-    "$(QTDIR)\bin\moc.exe"  ".\Include\CmQtEditor.h" -o ".\GeneratedFiles\moc_CmQtEditor.cpp"  
-	-DUNICODE -DWIN32 -DQT_NO_KEYWORDS -DQT_LARGEFILE_SUPPORT -DQT_DLL  "-I.\GeneratedFiles" "-I.\Include" "-I.\Dependencies\Include"
-	"-I.\..\CamelotCore\Include" "-I.\..\CamelotUtility\Include" "-I.\..\Dependencies\Include"
-  3. (Optional step) With Visual Studio you can set up a custom build set so this is done automatically
-  4. (Optional step) Qt also provides a Visual Studio Add-In that handles MOC for your, although it is currently very buggy with VS2012 so I do not use it.
-
- ----------------------------------------------------------------------------------
-
  Legend:
  Legend:
   (BansheeRootDir) - Path to BansheeEngine folder
   (BansheeRootDir) - Path to BansheeEngine folder
   (Platform) - Platform you're compiling for, e.g. Win32, x64, etc.
   (Platform) - Platform you're compiling for, e.g. Win32, x64, etc.

+ 1 - 0
TODO.txt

@@ -22,6 +22,7 @@ I call waitUntilLoaded too many times. Sometimes 5-6 times in a single function.
 GUIWidget::updateMeshes leaks. If I leave the game running I can see memory continously going up
 GUIWidget::updateMeshes leaks. If I leave the game running I can see memory continously going up
 
 
 IMMEDIATE:
 IMMEDIATE:
+ - OIS provides me only with main window cursor coordinates, while I need screen coordinates. Modify OIS project and correct that. Merging it with my plugin is probably a bad idea.
  - Add window-management command to DeferredRenderContext - I already have resource management commands
  - Add window-management command to DeferredRenderContext - I already have resource management commands
    there, few window related ones won't hurt. I can always split the class if needed.
    there, few window related ones won't hurt. I can always split the class if needed.
      - Possibly add guards to render target classes so they aren't accidentaly accessed from the render thread (similar to how Texture is handled)
      - Possibly add guards to render target classes so they aren't accidentaly accessed from the render thread (similar to how Texture is handled)