Marko Pintera 12 years ago
parent
commit
daadca5313

+ 3 - 0
BansheeEngine/Include/BsGUIInputBox.h

@@ -88,6 +88,9 @@ namespace BansheeEngine
 		void showSelection(CM::UINT32 anchorCaretPos);
 		void showSelection(CM::UINT32 anchorCaretPos);
 		void clearSelection();
 		void clearSelection();
 
 
+		void moveSelectionLeft(bool skipNewline);
+		void moveSelectionRight(bool skipNewline);
+
 		void scrollTextToCaret();
 		void scrollTextToCaret();
 
 
 		CM::Int2 getTextOffset() const;
 		CM::Int2 getTextOffset() const;

+ 1 - 0
BansheeEngine/Include/BsGUIInputSelection.h

@@ -36,6 +36,7 @@ namespace BansheeEngine
 
 
 		CM::UINT32 getSelectionStart() const { return mSelectionStart; }
 		CM::UINT32 getSelectionStart() const { return mSelectionStart; }
 		CM::UINT32 getSelectionEnd() const { return mSelectionEnd; }
 		CM::UINT32 getSelectionEnd() const { return mSelectionEnd; }
+		bool isAnchorAtStart() const { return mSelectionStart == mSelectionAnchor; }
 
 
 	private:
 	private:
 		CM::UINT32 mSelectionStart;
 		CM::UINT32 mSelectionStart;

+ 4 - 2
BansheeEngine/Include/BsGUIInputTool.h

@@ -36,12 +36,14 @@ namespace BansheeEngine
 		/**
 		/**
 		 * @note	"Input index" represents the empty areas between the characters.
 		 * @note	"Input index" represents the empty areas between the characters.
 		 */
 		 */
-		bool isNewlineBefore(CM::UINT32 inputIdx);
+		bool isNewlineBefore(CM::UINT32 inputIdx) const;
 
 
 		/**
 		/**
 		 * @note	"Input index" represents the empty areas between the characters.
 		 * @note	"Input index" represents the empty areas between the characters.
 		 */
 		 */
-		bool isNewlineAfter(CM::UINT32 inputIdx);
+		bool isNewlineAfter(CM::UINT32 inputIdx) const;
+
+		bool isNewline(CM::UINT32 inputIdx) const;
 	protected:
 	protected:
 		CM::Vector2* mQuads;
 		CM::Vector2* mQuads;
 		CM::UINT32 mNumQuads;
 		CM::UINT32 mNumQuads;

+ 96 - 122
BansheeEngine/Source/BsGUIInputBox.cpp

@@ -483,23 +483,23 @@ namespace BansheeEngine
 			{
 			{
 				if(ev.isShiftDown())
 				if(ev.isShiftDown())
 				{
 				{
-					//bool caretMovedDueToNewline = false;
-					//if(!mSelectionShown)
-					//{
-					//	if(isNewlineChar(caretPosToSelectionChar(mInputCaret->getCaretPos(), SelectionDir::Right)))
-					//	{
-					//		mInputCaret->moveCaretLeft();
-					//		caretMovedDueToNewline = true;
-					//	}
-
-					//	showSelection(mInputCaret->getCaretPos(), SelectionDir::Left);
-					//}
-
-					//moveSelectionLeft(caretMovedDueToNewline);
-					//scrollTextToCaret();
-
-					//markAsDirty();
-					//return true;
+					bool caretMovedDueToNewline = false;
+					if(!mSelectionShown)
+					{
+						if(mInputCaret->isNewlineBefore(mInputCaret->getCaretPos()))
+						{
+							mInputCaret->moveCaretLeft();
+							caretMovedDueToNewline = true;
+						}
+
+						showSelection(mInputCaret->getCaretPos());
+					}
+
+					moveSelectionLeft(caretMovedDueToNewline);
+					scrollTextToCaret();
+
+					markAsDirty();
+					return true;
 				}
 				}
 				else
 				else
 				{
 				{
@@ -516,23 +516,23 @@ namespace BansheeEngine
 			{
 			{
 				if(ev.isShiftDown())
 				if(ev.isShiftDown())
 				{
 				{
-					//bool caretMovedDueToNewline = false;
-					//if(!mSelectionShown)
-					//{
-					//	if(isNewlineChar(caretPosToSelectionChar(mInputCaret->getCaretPos(), SelectionDir::Left)))
-					//	{
-					//		mInputCaret->moveCaretRight();
-					//		caretMovedDueToNewline = true;
-					//	}
-
-					//	showSelection(mInputCaret->getCaretPos(), SelectionDir::Left);
-					//}
-					//	
-					//moveSelectionRight(caretMovedDueToNewline);
-					//scrollTextToCaret();
-
-					//markAsDirty();
-					//return true;
+					bool caretMovedDueToNewline = false;
+					if(!mSelectionShown)
+					{
+						if(mInputCaret->isNewlineAfter(mInputCaret->getCaretPos()))
+						{
+							mInputCaret->moveCaretRight();
+							caretMovedDueToNewline = true;
+						}
+
+						showSelection(mInputCaret->getCaretPos());
+					}
+						
+					moveSelectionRight(caretMovedDueToNewline);
+					scrollTextToCaret();
+
+					markAsDirty();
+					return true;
 				}
 				}
 				else
 				else
 				{
 				{
@@ -779,94 +779,68 @@ namespace BansheeEngine
 		clearSelection();
 		clearSelection();
 	}
 	}
 
 
-	//void GUIInputBox::moveSelectionLeft(bool skipNewline) 
-	//{
-	//	SelectionDir newlineTestSelectionDir;
-	//	if(mSelectionAnchor == mSelectionEnd)
-	//		newlineTestSelectionDir = SelectionDir::Left;
-	//	else
-	//		newlineTestSelectionDir = SelectionDir::Right;
-
-	//	if(mInputCaret->getCaretPos() > 0)
-	//	{
-	//		mInputCaret->moveCaretLeft();
-
-	//		if(!skipNewline) // Move one more if we moved to a new line (we can't select newline char so we skip it)
-	//		{
-	//			if (isNewlineChar(caretPosToSelectionChar(mInputCaret->getCaretPos(), newlineTestSelectionDir)) && mInputCaret->getCaretPos() > 0)
-	//			{
-	//				mInputCaret->moveCaretLeft();
-
-	//				// Reverse caret movement if previous char was a newline, and this one is as well.
-	//				// Otherwise we skip an entire line which is not what we want.
-	//				if (isNewlineChar(caretPosToSelectionChar(mInputCaret->getCaretPos(), newlineTestSelectionDir))) 
-	//					mInputCaret->moveCaretRight();
-	//			} 
-	//		}
-	//		else
-	//		{
-	//			// Reverse caret movement if previous char was a newline, and this one is as well
-	//			// so we don't skip a line
-	//			if (isNewlineChar(caretPosToSelectionChar(mInputCaret->getCaretPos(), newlineTestSelectionDir))) 
-	//				mInputCaret->moveCaretRight();
-	//		}
-	//	}
-
-	//	UINT32 charIdx = caretPosToSelectionChar(mInputCaret->getCaretPos(), SelectionDir::Left);
-	//	
-	//	if(mSelectionAnchor == mSelectionEnd)
-	//		mSelectionStart = std::min(mSelectionEnd, charIdx); 
-	//	else
-	//		mSelectionEnd = std::max(mSelectionStart, charIdx);
-
-	//	if(mSelectionStart == mSelectionEnd)
-	//		clearSelection();
-	//}
-
-	//void GUIInputBox::moveSelectionRight(bool skipNewline) 
-	//{
-	//	SelectionDir newlineTestSelectionDir;
-	//	if(mSelectionAnchor == mSelectionStart)
-	//		newlineTestSelectionDir = SelectionDir::Right;
-	//	else
-	//		newlineTestSelectionDir = SelectionDir::Left;
-
-	//	UINT32 maxCaretPos = mInputCaret->getMaxCaretPos();
-	//	if(mInputCaret->getCaretPos() < maxCaretPos)
-	//	{
-	//		mInputCaret->moveCaretRight();
-
-	//		if(!skipNewline) // Move one more if we moved to a new line (we can't select newline char so we skip it)
-	//		{
-	//			if (isNewlineChar(caretPosToSelectionChar(mInputCaret->getCaretPos(), newlineTestSelectionDir)) && mInputCaret->getCaretPos() < maxCaretPos)
-	//			{
-	//				mInputCaret->moveCaretRight();
-
-	//				// Reverse caret movement if previous char was a newline, and this one is as well.
-	//				// Otherwise we skip an entire line which is not what we want.
-	//				if (isNewlineChar(caretPosToSelectionChar(mInputCaret->getCaretPos(), newlineTestSelectionDir))) 
-	//					mInputCaret->moveCaretLeft();
-	//			} 
-	//		}
-	//		else
-	//		{
-	//			// Reverse caret movement if previous char was a newline, and this one is as well.
-	//			// Otherwise we skip an entire line which is not what we want.
-	//			if (isNewlineChar(caretPosToSelectionChar(mInputCaret->getCaretPos(), newlineTestSelectionDir))) 
-	//				mInputCaret->moveCaretLeft();
-	//		}
-	//	}
-
-	//	UINT32 charIdx = caretPosToSelectionChar(mInputCaret->getCaretPos(), SelectionDir::Left);
-
-	//	if(mSelectionAnchor == mSelectionStart)
-	//		mSelectionEnd = std::max(mSelectionStart, charIdx);
-	//	else
-	//		mSelectionStart = std::min(mSelectionEnd, charIdx);
-
-	//	if(mSelectionStart == mSelectionEnd)
-	//		clearSelection();
-	//}
+	void GUIInputBox::moveSelectionLeft(bool skipNewline) 
+	{
+		if(mInputCaret->getCaretPos() > 0)
+		{
+			mInputCaret->moveCaretLeft();
+
+			// Skip newline character if this is one
+			if(!skipNewline) // Move one more if we moved to a new line (we can't select newline char so we skip it)
+			{
+				if (mInputCaret->isCaretAtNewline() && mInputCaret->getCaretPos() > 0)
+				{
+					mInputCaret->moveCaretLeft();
+
+					// Reverse caret movement if previous char was a newline, and this one is as well.
+					// Otherwise we skip an entire line which is not what we want.
+					if (mInputCaret->isCaretAtNewline()) 
+						mInputCaret->moveCaretRight();
+				} 
+			}
+			else
+			{
+				// Reverse caret movement if previous char was a newline, and this one is as well
+				// so we don't skip a line
+				if (mInputCaret->isCaretAtNewline()) 
+					mInputCaret->moveCaretRight();
+			}
+		}
+
+		mInputSelection->moveSelectionToCaret(mInputCaret->getCaretPos());
+	}
+
+	void GUIInputBox::moveSelectionRight(bool skipNewline) 
+	{
+		UINT32 maxCaretPos = mInputCaret->getMaxCaretPos();
+		if(mInputCaret->getCaretPos() < maxCaretPos)
+		{
+			mInputCaret->moveCaretRight();
+
+			// Skip newline character if this is one
+			if(!skipNewline) // Move one more if we moved to a new line (we can't select newline char so we skip it)
+			{
+				if (mInputCaret->isCaretAtNewline() && mInputCaret->getCaretPos() < maxCaretPos)
+				{
+					mInputCaret->moveCaretRight();
+
+					// Reverse caret movement if previous char was a newline, and this one is as well.
+					// Otherwise we skip an entire line which is not what we want.
+					if (mInputCaret->isCaretAtNewline()) 
+						mInputCaret->moveCaretLeft();
+				} 
+			}
+			else
+			{
+				// Reverse caret movement if previous char was a newline, and this one is as well
+				// so we don't skip a line
+				if (mInputCaret->isCaretAtNewline()) 
+					mInputCaret->moveCaretLeft();
+			}
+		}
+
+		mInputSelection->moveSelectionToCaret(mInputCaret->getCaretPos());
+	}
 
 
 	CM::Int2 GUIInputBox::getTextOffset() const
 	CM::Int2 GUIInputBox::getTextOffset() const
 	{
 	{

+ 1 - 17
BansheeEngine/Source/BsGUIInputCaret.cpp

@@ -272,23 +272,7 @@ namespace BansheeEngine
 
 
 	bool GUIInputCaret::isCaretAtNewline() const
 	bool GUIInputCaret::isCaretAtNewline() const
 	{
 	{
-		if(mTextDesc.text.size() == 0)
-			return true;
-
-		UINT32 numLines = getNumLines();
-		UINT32 curPos = 0;
-		for(UINT32 i = 0; i < numLines; i++)
-		{
-			const GUIInputLineDesc& lineDesc = getLineDesc(i);
-
-			if(curPos == mCaretPos)
-				return true;
-
-			UINT32 numChars = lineDesc.getEndChar(false) - lineDesc.getStartChar();
-			curPos += numChars;
-		}
-
-		return false;
+		return isNewline(mCaretPos);
 	}
 	}
 
 
 	UINT32 GUIInputCaret::getMaxCaretPos() const
 	UINT32 GUIInputCaret::getMaxCaretPos() const

+ 24 - 3
BansheeEngine/Source/BsGUIInputTool.cpp

@@ -212,8 +212,8 @@ namespace BansheeEngine
 
 
 		return 0;
 		return 0;
 	}
 	}
-
-	bool GUIInputTool::isNewlineBefore(CM::UINT32 inputIdx)
+	 
+	bool GUIInputTool::isNewlineBefore(CM::UINT32 inputIdx) const
 	{
 	{
 		UINT32 charIdx = getCharIdxAtInputIdx(inputIdx);
 		UINT32 charIdx = getCharIdxAtInputIdx(inputIdx);
 		charIdx = (UINT32)std::max(0, (INT32)(charIdx - 1));
 		charIdx = (UINT32)std::max(0, (INT32)(charIdx - 1));
@@ -221,12 +221,33 @@ namespace BansheeEngine
 		return isNewlineChar(charIdx);
 		return isNewlineChar(charIdx);
 	}
 	}
 
 
-	bool GUIInputTool::isNewlineAfter(CM::UINT32 inputIdx)
+	bool GUIInputTool::isNewlineAfter(CM::UINT32 inputIdx) const
 	{
 	{
 		UINT32 charIdx = getCharIdxAtInputIdx(inputIdx);
 		UINT32 charIdx = getCharIdxAtInputIdx(inputIdx);
 		return isNewlineChar(charIdx);
 		return isNewlineChar(charIdx);
 	}
 	}
 
 
+	bool GUIInputTool::isNewline(CM::UINT32 inputIdx) const
+	{
+		if(mTextDesc.text.size() == 0)
+			return true;
+
+		UINT32 numLines = getNumLines();
+		UINT32 curPos = 0;
+		for(UINT32 i = 0; i < numLines; i++)
+		{
+			const GUIInputLineDesc& lineDesc = getLineDesc(i);
+
+			if(curPos == inputIdx)
+				return true;
+
+			UINT32 numChars = lineDesc.getEndChar(false) - lineDesc.getStartChar();
+			curPos += numChars;
+		}
+
+		return false;
+	}
+
 	bool GUIInputTool::isNewlineChar(CM::UINT32 charIdx) const
 	bool GUIInputTool::isNewlineChar(CM::UINT32 charIdx) const
 	{
 	{
 		if(mTextDesc.text[charIdx] == '\n')
 		if(mTextDesc.text[charIdx] == '\n')