Browse Source

Added global event callbacks to GUIManager, so that outside systems can receive GUI events

Marko Pintera 12 years ago
parent
commit
62b7f992e6

+ 5 - 0
BansheeEngine/Include/BsGUIManager.h

@@ -59,6 +59,8 @@ namespace BansheeEngine
 		GUIInputCaret* getInputCaretTool() const { return mInputCaret; }
 		GUIInputSelection* getInputSelectionTool() const { return mInputSelection; }
 
+		boost::signal<void(GUIWidget*, GUIElement*, const GUIMouseEvent&)> mouseEventFilter;
+		boost::signal<void(GUIWidget*, GUIElement*, const GUIKeyEvent&)> keyEventFilter;
 	private:
 		CM::Vector<WidgetInfo>::type mWidgets;
 		CM::UnorderedMap<const CM::Viewport*, GUIRenderData>::type mCachedGUIData;
@@ -123,6 +125,9 @@ namespace BansheeEngine
 
 		GUIMouseButton buttonToMouseButton(CM::ButtonCode code) const;
 		CM::Int2 getWidgetRelativePos(const GUIWidget& widget, const CM::Int2& screenPos) const;
+
+		bool sendMouseEvent(GUIWidget* widget, GUIElement* element, const GUIMouseEvent& event);
+		bool sendKeyEvent(GUIWidget* widget, GUIElement* element, const GUIKeyEvent& event);
 	};
 
 	BS_EXPORT GUIManager& gGUIManager();

+ 30 - 14
BansheeEngine/Source/BsGUIManager.cpp

@@ -520,7 +520,7 @@ namespace BansheeEngine
 				mKeyEvent = GUIKeyEvent(shiftDown, ctrlDown, altDown);
 
 				mKeyEvent.setKeyDownData(event.buttonCode);
-				if(mKeyboardFocusWidget->_keyEvent(mKeyboardFocusElement, mKeyEvent))
+				if(sendKeyEvent(mKeyboardFocusWidget, mKeyboardFocusElement, mKeyEvent))
 					event.markAsUsed();
 			}
 		}
@@ -553,13 +553,13 @@ namespace BansheeEngine
 				Int2 localPos = getWidgetRelativePos(*mMouseOverWidget, gInput().getMousePosition());
 
 				mMouseEvent.setMouseDownData(mMouseOverElement, localPos, guiButton);
-				if(mMouseOverWidget->_mouseEvent(mMouseOverElement, mMouseEvent))
+				if(sendMouseEvent(mMouseOverWidget, mMouseOverElement, mMouseEvent))
 					event.markAsUsed();
 
 				// DragStart is for all intents and purposes same as mouse down but since I need a DragEnd event, I feel a separate DragStart
 				// event was also needed to make things clearer.
 				mMouseEvent.setMouseDragStartData(mMouseOverElement, localPos);
-				if(mMouseOverWidget->_mouseEvent(mMouseOverElement, mMouseEvent))
+				if(sendMouseEvent(mMouseOverWidget, mMouseOverElement, mMouseEvent))
 					event.markAsUsed();
 
 				mActiveElement = mMouseOverElement;
@@ -598,7 +598,7 @@ namespace BansheeEngine
 				mKeyEvent = GUIKeyEvent(shiftDown, ctrlDown, altDown);
 
 				mKeyEvent.setKeyUpData(event.buttonCode);
-				if(mKeyboardFocusWidget->_keyEvent(mKeyboardFocusElement, mKeyEvent))
+				if(sendKeyEvent(mKeyboardFocusWidget, mKeyboardFocusElement, mKeyEvent))
 					event.markAsUsed();
 			}
 		}
@@ -625,7 +625,7 @@ namespace BansheeEngine
 				if(mMouseOverElement != nullptr)
 				{
 					mMouseEvent.setDragAndDropDroppedData(mMouseOverElement, localPos, DragAndDropManager::instance().getDragTypeId(), DragAndDropManager::instance().getDragData());
-					bool processed = mMouseOverWidget->_mouseEvent(mMouseOverElement, mMouseEvent);
+					bool processed = sendMouseEvent(mMouseOverWidget, mMouseOverElement, mMouseEvent);
 
 					DragAndDropManager::instance()._endDrag(processed);
 
@@ -641,7 +641,7 @@ namespace BansheeEngine
 			{
 				mMouseEvent.setMouseUpData(mMouseOverElement, localPos, guiButton);
 				
-				if(mMouseOverWidget->_mouseEvent(mMouseOverElement, mMouseEvent))
+				if(sendMouseEvent(mMouseOverWidget, mMouseOverElement, mMouseEvent))
 					event.markAsUsed();
 			}
 
@@ -650,7 +650,7 @@ namespace BansheeEngine
 			if(acceptEndDrag)
 			{
 				mMouseEvent.setMouseDragEndData(mMouseOverElement, localPos);
-				if(mActiveWidget->_mouseEvent(mActiveElement, mMouseEvent))
+				if(sendMouseEvent(mActiveWidget, mActiveElement, mMouseEvent))
 					event.markAsUsed();
 
 				mActiveElement = nullptr;
@@ -763,7 +763,7 @@ namespace BansheeEngine
 					Int2 curLocalPos = getWidgetRelativePos(*mMouseOverWidget, event.screenPos);
 
 					mMouseEvent.setMouseOutData(topMostElement, curLocalPos);
-					if(mMouseOverWidget->_mouseEvent(mMouseOverElement, mMouseEvent))
+					if(sendMouseEvent(mMouseOverWidget, mMouseOverElement, mMouseEvent))
 						event.markAsUsed();
 				}
 			}
@@ -774,7 +774,7 @@ namespace BansheeEngine
 				if(mActiveElement == nullptr || topMostElement == mActiveElement)
 				{
 					mMouseEvent.setMouseOverData(topMostElement, localPos);
-					if(widgetInFocus->_mouseEvent(topMostElement, mMouseEvent))
+					if(sendMouseEvent(widgetInFocus, topMostElement, mMouseEvent))
 						event.markAsUsed();
 				}
 			}
@@ -788,7 +788,7 @@ namespace BansheeEngine
 			if(mLastCursorLocalPos != curLocalPos)
 			{
 				mMouseEvent.setMouseDragData(topMostElement, curLocalPos, curLocalPos - mLastCursorLocalPos);
-				if(mActiveWidget->_mouseEvent(mActiveElement, mMouseEvent))
+				if(sendMouseEvent(mActiveWidget, mActiveElement, mMouseEvent))
 					event.markAsUsed();
 
 				mLastCursorLocalPos = curLocalPos;
@@ -800,7 +800,7 @@ namespace BansheeEngine
 				if(topMostElement != nullptr)
 				{
 					mMouseEvent.setDragAndDropDraggedData(topMostElement, localPos, DragAndDropManager::instance().getDragTypeId(), DragAndDropManager::instance().getDragData());
-					if(widgetInFocus->_mouseEvent(topMostElement, mMouseEvent))
+					if(sendMouseEvent(widgetInFocus, topMostElement, mMouseEvent))
 						event.markAsUsed();
 				}
 			}
@@ -813,7 +813,7 @@ namespace BansheeEngine
 				if(mLastCursorLocalPos != localPos)
 				{
 					mMouseEvent.setMouseMoveData(topMostElement, localPos);
-					if(widgetInFocus->_mouseEvent(topMostElement, mMouseEvent))
+					if(sendMouseEvent(widgetInFocus, topMostElement, mMouseEvent))
 						event.markAsUsed();
 
 					mLastCursorLocalPos = localPos;
@@ -822,7 +822,7 @@ namespace BansheeEngine
 				if(Math::Abs(event.mouseWheelScrollAmount) > 0.00001f)
 				{
 					mMouseEvent.setMouseWheelScrollData(topMostElement, event.mouseWheelScrollAmount);
-					if(widgetInFocus->_mouseEvent(topMostElement, mMouseEvent))
+					if(sendMouseEvent(widgetInFocus, topMostElement, mMouseEvent))
 						event.markAsUsed();
 				}
 			}
@@ -846,7 +846,7 @@ namespace BansheeEngine
 			mKeyEvent = GUIKeyEvent(shiftDown, ctrlDown, altDown);
 
 			mKeyEvent.setTextInputData(event.textChar);
-			if(mKeyboardFocusWidget->_keyEvent(mKeyboardFocusElement, mKeyEvent))
+			if(sendKeyEvent(mKeyboardFocusWidget, mKeyboardFocusElement, mKeyEvent))
 				event.markAsUsed();
 		}
 	}
@@ -932,6 +932,22 @@ namespace BansheeEngine
 		return curLocalPos;
 	}
 
+	bool GUIManager::sendMouseEvent(GUIWidget* widget, GUIElement* element, const GUIMouseEvent& event)
+	{
+		if(!mouseEventFilter.empty())
+			mouseEventFilter(widget, element, event);
+
+		return widget->_mouseEvent(element, event);
+	}
+
+	bool GUIManager::sendKeyEvent(GUIWidget* widget, GUIElement* element, const GUIKeyEvent& event)
+	{
+		if(!keyEventFilter.empty())
+			keyEventFilter(widget, element, event);
+
+		return widget->_keyEvent(element, event);
+	}
+
 	GUIManager& gGUIManager()
 	{
 		return GUIManager::instance();

+ 3 - 0
CamelotClient/Include/BsDockManager.h

@@ -49,6 +49,9 @@ namespace BansheeEditor
 		void setArea(CM::INT32 x, CM::INT32 y, CM::UINT32 width, CM::UINT32 height);
 
 	private:
+		static const CM::Color TINT_COLOR;
+		static const CM::Color HIGHLIGHT_COLOR;
+
 		BS::GUIWidget* mParent;
 		DockContainer mRootContainer;
 

+ 4 - 2
CamelotClient/Source/BsDockManager.cpp

@@ -19,6 +19,8 @@ using namespace BansheeEngine;
 namespace BansheeEditor
 {
 	const CM::UINT32 DockManager::DockContainer::SliderSize = 4;
+	const CM::Color DockManager::TINT_COLOR = Color(0.44f, 0.44f, 0.44f, 0.22f);
+	const CM::Color DockManager::HIGHLIGHT_COLOR = Color(0.44f, 0.44f, 0.44f, 0.42f);
 
 	DockManager::DockContainer::DockContainer()
 		:mIsLeaf(false), mWidgets(nullptr), mX(0), mY(0), mWidth(0), mHeight(0), mSplitPosition(0.5f),
@@ -185,8 +187,8 @@ namespace BansheeEditor
 		mDropOverlayMat->setFloat("invViewportWidth", invViewportWidth);
 		mDropOverlayMat->setFloat("invViewportHeight", invViewportHeight);
 
-		mDropOverlayMat->setColor("tintColor", Color::White);
-		mDropOverlayMat->setColor("highlightColor", Color::Green);
+		mDropOverlayMat->setColor("tintColor", TINT_COLOR);
+		mDropOverlayMat->setColor("highlightColor", HIGHLIGHT_COLOR);
 		mDropOverlayMat->setColor("highlightActive", Color(0.0f, 0.0f, 0.0f, 0.0f));
 
 		renderQueue.add(mDropOverlayMat, mDropOverlayMesh->getSubMeshData(), Vector3::ZERO);