Browse Source

Added proper parameter forwarding via std::forward to cm_new and SceneObject::addComponent

Marko Pintera 12 years ago
parent
commit
872cc892ed

+ 1 - 1
BansheeEngine/Source/BsGUIContextMenu.cpp

@@ -22,7 +22,7 @@ namespace BansheeEngine
 		GUIDropDownAreaPlacement placement = GUIDropDownAreaPlacement::aroundPosition(position);
 
 		GameObjectHandle<GUIDropDownBox> dropDownBox = GUIDropDownBoxManager::instance().openDropDownBox(widget.getTarget(), widget.getOwnerWindow(), 
-			placement, getDropDownData(), widget.getSkin(), GUIDropDownType::MenuBar, boost::bind(&GUIContextMenu::onMenuClosed, this));
+			placement, getDropDownData(), widget.getSkin(), GUIDropDownType::ContextMenu, boost::bind(&GUIContextMenu::onMenuClosed, this));
 
 		GUIManager::instance().enableSelectiveInput(boost::bind(&GUIContextMenu::close, this));
 		GUIManager::instance().addSelectiveInputWidget(dropDownBox.get());

+ 23 - 1
BansheeEngine/Source/BsGUIDropDownBox.cpp

@@ -206,7 +206,9 @@ namespace BansheeEngine
 		// Background frame
 		mBackgroundArea = GUIArea::create(*mOwner, x, y, width, height);
 		mBackgroundArea->setDepth(102);
-		mBackgroundArea->getLayout().addElement(GUITexture::create(*mOwner, GUIImageScaleMode::ScaleToFit, mOwner->mBackgroundStyle));
+
+		mBackgroundFrame = GUITexture::create(*mOwner, GUIImageScaleMode::ScaleToFit, mOwner->mBackgroundStyle);
+		mBackgroundArea->getLayout().addElement(mBackgroundFrame);
 
 		updateGUIElements();
 	}
@@ -214,6 +216,26 @@ namespace BansheeEngine
 	GUIDropDownBox::DropDownSubMenu::~DropDownSubMenu()
 	{
 		closeSubMenu();
+
+		for(auto& elem : mCachedSeparators)
+			GUIElement::destroy(elem);
+
+		for(auto& elem : mCachedEntryBtns)
+			GUIElement::destroy(elem);
+
+		for(auto& elem : mCachedExpEntryBtns)
+			GUIElement::destroy(elem);
+
+		if(mScrollUpBtn != nullptr)
+			GUIElement::destroy(mScrollUpBtn);
+
+		if(mScrollDownBtn != nullptr)
+			GUIElement::destroy(mScrollDownBtn);
+
+		GUIElement::destroy(mBackgroundFrame);
+
+		GUIArea::destroy(mBackgroundArea);
+		GUIArea::destroy(mContentArea);
 	}
 
 	void GUIDropDownBox::DropDownSubMenu::updateGUIElements()

+ 5 - 1
CamelotCore/Include/CmSceneObject.h

@@ -233,7 +233,7 @@ namespace CamelotFramework
 				"Specified type is not a valid Component.");										\
 																									\
 			GameObjectHandle<Type> newComponent = GameObjectHandle<Type>(							\
-				new (cm_alloc<Type, PoolAlloc>()) Type(mThisHandle, BOOST_PP_ENUM_PARAMS (n, t)),	\
+				new (cm_alloc<Type, PoolAlloc>()) Type(mThisHandle, std::forward<T0>(t0) BOOST_PP_REPEAT_FROM_TO(1, n, FORWARD_T, ~)),	\
 				&cm_delete<PoolAlloc, GameObject>);													\
 																									\
 			mComponents.push_back(newComponent);													\
@@ -243,8 +243,12 @@ namespace CamelotFramework
 			return newComponent;																	\
 		}
 
+#define FORWARD_T(z, i, unused) \
+		, std::forward<BOOST_PP_CAT(T, i)>(BOOST_PP_CAT(t, i))
+
 		BOOST_PP_REPEAT_FROM_TO(1, 15, MAKE_ADD_COMPONENT, ~)
 
+#undef FORWARD_T
 #undef MAKE_ADD_COMPONENT
 
 		/**

+ 10 - 2
CamelotUtility/Include/CmMemoryAllocator.h

@@ -95,11 +95,15 @@ namespace CamelotFramework
 #define MAKE_CM_NEW(z, n, unused)                                     \
 	template<class Type, class Alloc BOOST_PP_ENUM_TRAILING_PARAMS(n, class T)>     \
 	Type* cm_new(BOOST_PP_ENUM_BINARY_PARAMS(n, T, &&t) ) { \
-		return new (cm_alloc<Alloc>(sizeof(Type))) Type(BOOST_PP_ENUM_PARAMS (n, t));     \
+		return new (cm_alloc<Alloc>(sizeof(Type))) Type(std::forward<T0>(t0) BOOST_PP_REPEAT_FROM_TO(1, n, FORWARD_T, ~));     \
 	}
 
+#define FORWARD_T(z, i, unused) \
+	, std::forward<BOOST_PP_CAT(T, i)>(BOOST_PP_CAT(t, i))
+
 	BOOST_PP_REPEAT_FROM_TO(1, 15, MAKE_CM_NEW, ~)
 
+#undef FORWARD_T
 #undef MAKE_CM_NEW
 
 	// Create a new object with the specified allocator without any parameters
@@ -181,11 +185,15 @@ namespace CamelotFramework
 #define MAKE_CM_NEW(z, n, unused)                                     \
 	template<class Type BOOST_PP_ENUM_TRAILING_PARAMS(n, class T)>     \
 	Type* cm_new(BOOST_PP_ENUM_BINARY_PARAMS(n, T, &&t) ) { \
-	return new (cm_alloc<GenAlloc>(sizeof(Type))) Type(BOOST_PP_ENUM_PARAMS (n, t));     \
+	return new (cm_alloc<GenAlloc>(sizeof(Type))) Type(std::forward<T0>(t0) BOOST_PP_REPEAT_FROM_TO(1, n, FORWARD_T, ~));     \
 	}
 
+#define FORWARD_T(z, i, unused) \
+	, std::forward<BOOST_PP_CAT(T, i)>(BOOST_PP_CAT(t, i))
+
 	BOOST_PP_REPEAT_FROM_TO(1, 15, MAKE_CM_NEW, ~)
 
+#undef FORWARD_T
 #undef MAKE_CM_NEW
 
 	// Create a new object with the general allocator without any parameters

+ 2 - 6
DropDown.txt

@@ -1,11 +1,7 @@
 GUI ignores image in GUIContent for most elements.
 
-Doesn't belong here but as an additional reminder: Remove Component::initialize and instead make multi paramter addComponent
- - There's an exception that happens where mStyle of a GUIButtonBase is not initialized
- - Track down other uses of initialize() and remove them (GUIWidget has one, probably Camera and similar as well)
-
-Test context
- - There are issues when dealing with the context menu. Hover doesn't seem to close menus, and hovering for a few seconds seems to cause an exception.
+Context menu appears at the wrong coordinates
+Menus lack proper frame
 
 Test scrollUp/scrollDown