Browse Source

Hooked up shortcuts and context menus for input box cut/copy/paste
Drag is only possible with left mouse button click

Marko Pintera 12 years ago
parent
commit
e8f22bddc5

+ 2 - 0
BansheeEngine/Include/BsGUIInputBox.h

@@ -84,9 +84,11 @@ namespace BansheeEngine
 		CM::Int2 renderElemToOffset(CM::UINT32 renderElemIdx) const;
 		CM::Rect renderElemToClipRect(CM::UINT32 renderElemIdx) const;
 
+		void insertString(CM::UINT32 charIdx, const CM::WString& string);
 		void insertChar(CM::UINT32 charIdx, CM::UINT32 charCode);
 		void eraseChar(CM::UINT32 charIdx);
 		void deleteSelectedText();
+		CM::WString getSelectedText();
 
 		void showCaret();
 		void hideCaret();

+ 3 - 0
BansheeEngine/Source/BsGUIDropDownBox.cpp

@@ -7,6 +7,7 @@
 #include "BsGUISkin.h"
 #include "CmViewport.h"
 #include "BsGUIListBox.h"
+#include "BsGUIDropDownBoxManager.h"
 #include "CmSceneObject.h"
 
 using namespace CamelotFramework;
@@ -479,6 +480,8 @@ namespace BansheeEngine
 		closeSubMenu();
 
 		mElements[idx].getCallback()();
+
+		GUIDropDownBoxManager::instance().closeDropDownBox();
 	}
 
 	void GUIDropDownBox::DropDownSubMenu::openSubMenu(GUIButton* source, UINT32 idx)

+ 59 - 13
BansheeEngine/Source/BsGUIInputBox.cpp

@@ -338,8 +338,6 @@ namespace BansheeEngine
 
 	bool GUIInputBox::mouseEvent(const GUIMouseEvent& ev)
 	{
-		static UINT32 dbg = 0;
-
 		if(ev.getType() == GUIMouseEventType::MouseOver)
 		{
 			if(!mHasFocus)
@@ -372,7 +370,7 @@ namespace BansheeEngine
 
 			return true;
 		}
-		else if(ev.getType() == GUIMouseEventType::MouseDown)
+		else if(ev.getType() == GUIMouseEventType::MouseDown && ev.getButton() == GUIMouseButton::Left)
 		{
 			if(mHasFocus)
 			{
@@ -631,6 +629,29 @@ namespace BansheeEngine
 				markContentAsDirty();
 				return true;
 			}
+
+			if(ev.getKey() == BC_X && ev.isCtrlDown())
+			{
+				cutText();
+
+				markContentAsDirty();
+				return true;
+			}
+
+			if(ev.getKey() == BC_C && ev.isCtrlDown())
+			{
+				copyText();
+
+				return true;
+			}
+
+			if(ev.getKey() == BC_V && ev.isCtrlDown())
+			{
+				pasteText();
+
+				markContentAsDirty();
+				return true;
+			}
 		}
 		else if(ev.getType() == GUIKeyEventType::TextInput)
 		{
@@ -743,6 +764,17 @@ namespace BansheeEngine
 		markContentAsDirty();
 	}
 
+	void GUIInputBox::insertString(CM::UINT32 charIdx, const WString& string)
+	{
+		mText.insert(mText.begin() + charIdx, string.begin(), string.end());
+
+		TEXT_SPRITE_DESC textDesc = getTextDesc();
+		Int2 offset = getTextOffset();
+
+		gGUIManager().getInputCaretTool()->updateText(this, textDesc);
+		gGUIManager().getInputSelectionTool()->updateText(this, textDesc);
+	}
+
 	void GUIInputBox::insertChar(CM::UINT32 charIdx, CM::UINT32 charCode)
 	{
 		mText.insert(mText.begin() + charIdx, charCode);
@@ -789,6 +821,16 @@ namespace BansheeEngine
 		clearSelection();
 	}
 
+	WString GUIInputBox::getSelectedText()
+	{
+		UINT32 selStart = gGUIManager().getInputSelectionTool()->getSelectionStart();
+		UINT32 selEnd = gGUIManager().getInputSelectionTool()->getSelectionEnd();
+
+		return mText.substr(selStart, selEnd - selStart);
+
+		mText.erase(mText.begin() + selStart, mText.begin() + gGUIManager().getInputSelectionTool()->getSelectionEnd());
+	}
+
 	CM::Int2 GUIInputBox::getTextOffset() const
 	{
 		Rect textBounds = getContentBounds();
@@ -847,13 +889,6 @@ namespace BansheeEngine
 			mContextMenu.addMenuItem(L"Copy", boost::bind(&GUIInputBox::copyText, const_cast<GUIInputBox*>(this)));
 			mContextMenu.addMenuItem(L"Paste", boost::bind(&GUIInputBox::pasteText, const_cast<GUIInputBox*>(this)));
 
-			// DEBUG ONLY
-			
-			mContextMenu.addSeparator(L"");
-			mContextMenu.addMenuItem(L"DebugBox/Test1", boost::bind(&GUIInputBox::pasteText, const_cast<GUIInputBox*>(this)));
-			mContextMenu.addMenuItem(L"DebugBox/Test2", boost::bind(&GUIInputBox::pasteText, const_cast<GUIInputBox*>(this)));
-			mContextMenu.addMenuItem(L"Zzzz/Test1", boost::bind(&GUIInputBox::pasteText, const_cast<GUIInputBox*>(this)));
-
 			initialized = true;
 		}
 
@@ -862,16 +897,27 @@ namespace BansheeEngine
 
 	void GUIInputBox::cutText()
 	{
-		// TODO
+		copyText();
+		deleteSelectedText();
 	}
 
 	void GUIInputBox::copyText()
 	{
-		// TODO
+		Platform::copyToClipboard(getSelectedText());
 	}
 
 	void GUIInputBox::pasteText()
 	{
-		// TODO
+		WString textInClipboard = Platform::copyFromClipboard();
+
+		UINT32 charIdx = gGUIManager().getInputCaretTool()->getCharIdxAtCaretPos();
+		insertString(charIdx, textInClipboard);
+
+		if(textInClipboard.size() > 0)
+			gGUIManager().getInputCaretTool()->moveCaretToChar(charIdx + ((UINT32)textInClipboard.size() - 1), CARET_AFTER);
+
+		scrollTextToCaret();
+
+		markContentAsDirty();
 	}
 }

+ 13 - 9
BansheeEngine/Source/BsGUIManager.cpp

@@ -586,11 +586,12 @@ namespace BansheeEngine
 				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(sendMouseEvent(mMouseOverWidget, mMouseOverElement, mMouseEvent))
-					event.markAsUsed();
+				if(guiButton == GUIMouseButton::Left)
+				{
+					mMouseEvent.setMouseDragStartData(mMouseOverElement, localPos);
+					if(sendMouseEvent(mMouseOverWidget, mMouseOverElement, mMouseEvent))
+						event.markAsUsed();
+				}
 
 				mActiveElement = mMouseOverElement;
 				mActiveWidget = mMouseOverWidget;
@@ -680,9 +681,12 @@ namespace BansheeEngine
 			bool acceptEndDrag = mActiveMouseButton == guiButton && mActiveElement != nullptr;
 			if(acceptEndDrag)
 			{
-				mMouseEvent.setMouseDragEndData(mMouseOverElement, localPos);
-				if(sendMouseEvent(mActiveWidget, mActiveElement, mMouseEvent))
-					event.markAsUsed();
+				if(guiButton == GUIMouseButton::Left)
+				{
+					mMouseEvent.setMouseDragEndData(mMouseOverElement, localPos);
+					if(sendMouseEvent(mActiveWidget, mActiveElement, mMouseEvent))
+						event.markAsUsed();
+				}
 
 				mActiveElement = nullptr;
 				mActiveWidget = nullptr;
@@ -888,7 +892,7 @@ namespace BansheeEngine
 		}
 
 		// If mouse is being held down send MouseDrag events
-		if(mActiveElement != nullptr)
+		if(mActiveElement != nullptr && mActiveMouseButton == GUIMouseButton::Left)
 		{
 			Int2 curLocalPos = getWidgetRelativePos(*mActiveWidget, screenMousePos);
 

+ 1 - 1
CamelotCore/Include/Win32/CmPlatformImpl.h

@@ -43,7 +43,7 @@ namespace CamelotFramework
 	};
 
 	/**
-	 * @brief	Provides access for version Windows operating system functions, including
+	 * @brief	Provides access to various Windows operating system functions, including
 	 * 			the main message pump.
 	 */
 	class CM_EXPORT Platform