Преглед изворни кода

Moving selection up/down works again

Marko Pintera пре 12 година
родитељ
комит
8776c7feb6

+ 1 - 1
BansheeEngine/Include/BsGUIInputBox.h

@@ -85,7 +85,7 @@ namespace BansheeEngine
 		void showCaret();
 		void hideCaret();
 
-		void showSelection(CM::UINT32 anchorCaretPos, SelectionDir dir);
+		void showSelection(CM::UINT32 anchorCaretPos);
 		void clearSelection();
 
 		void scrollTextToCaret();

+ 1 - 2
BansheeEngine/Include/BsGUIInputSelection.h

@@ -23,7 +23,7 @@ namespace BansheeEngine
 		CM::Rect GUIInputSelection::getSelectionSpriteClipRect(CM::UINT32 spriteIdx) const;
 		void updateSprite();
 
-		void showSelection(CM::UINT32 anchorCaretPos, SelectionDir dir);
+		void showSelection(CM::UINT32 anchorCaretPos);
 		void clearSelection();
 
 		void moveSelectionToCaret(CM::UINT32 caretPos);
@@ -48,6 +48,5 @@ namespace BansheeEngine
 
 		CM::UINT32 caretPosToSelectionChar(CM::UINT32 caretPos, SelectionDir dir) const;
 		CM::Vector<CM::Rect>::type getSelectionRects() const;
-		bool isNewlineChar(CM::UINT32 charIdx) const;
 	};
 }

+ 11 - 0
BansheeEngine/Include/BsGUIInputTool.h

@@ -33,6 +33,15 @@ namespace BansheeEngine
 
 		void updateText(const TEXT_SPRITE_DESC& textDesc, const CM::Int2& offset, const CM::Int2 clipOffset);
 
+		/**
+		 * @note	"Input index" represents the empty areas between the characters.
+		 */
+		bool isNewlineBefore(CM::UINT32 inputIdx);
+
+		/**
+		 * @note	"Input index" represents the empty areas between the characters.
+		 */
+		bool isNewlineAfter(CM::UINT32 inputIdx);
 	protected:
 		CM::Vector2* mQuads;
 		CM::UINT32 mNumQuads;
@@ -57,5 +66,7 @@ namespace BansheeEngine
 		 * @note	This can return an out of range character index, in case the input index is specified after the last character.
 		 */
 		CM::UINT32 getCharIdxAtInputIdx(CM::UINT32 inputIdx) const;
+
+		bool isNewlineChar(CM::UINT32 charIdx) const;
 	};
 }

+ 16 - 20
BansheeEngine/Source/BsGUIInputBox.cpp

@@ -376,7 +376,7 @@ namespace BansheeEngine
 			mDragInProgress = true;
 
 			UINT32 caretPos = mInputCaret->getCaretPos();
-			showSelection(caretPos, SelectionDir::Left);
+			showSelection(caretPos);
 			mInputSelection->selectionDragStart(caretPos);
 
 			return true;
@@ -549,15 +549,13 @@ namespace BansheeEngine
 			{
 				if(ev.isShiftDown())
 				{
-					//if(!mSelectionShown)
-					//{
-					//	if(isNewlineChar(caretPosToSelectionChar(mInputCaret->getCaretPos(), SelectionDir::Right)))
-					//	{
-					//		mInputCaret->moveCaretLeft();
-					//	}
+					if(!mSelectionShown)
+					{
+						if(mInputCaret->isNewlineBefore(mInputCaret->getCaretPos()))
+							mInputCaret->moveCaretLeft();
 
-					//	showSelection(mInputCaret->getCaretPos(), SelectionDir::Left);
-					//}
+						showSelection(mInputCaret->getCaretPos());
+					}
 				}
 				else
 				{
@@ -580,15 +578,13 @@ namespace BansheeEngine
 			{
 				if(ev.isShiftDown())
 				{
-					//if(!mSelectionShown)
-					//{
-					//	if(isNewlineChar(caretPosToSelectionChar(mInputCaret->getCaretPos(), SelectionDir::Left)))
-					//	{
-					//		mInputCaret->moveCaretRight();
-					//	}
+					if(!mSelectionShown)
+					{
+						if(mInputCaret->isNewlineAfter(mInputCaret->getCaretPos()))
+							mInputCaret->moveCaretRight();
 
-					//	showSelection(mInputCaret->getCaretPos(), SelectionDir::Left);
-					//}
+						showSelection(mInputCaret->getCaretPos());
+					}
 				}
 				else
 				{
@@ -627,7 +623,7 @@ namespace BansheeEngine
 
 			if(ev.getKey() == BC_A && ev.isCtrlDown())
 			{
-				showSelection(0, SelectionDir::Left);
+				showSelection(0);
 				mInputSelection->selectAll();
 
 				markAsDirty();
@@ -677,9 +673,9 @@ namespace BansheeEngine
 		markAsDirty();
 	}
 
-	void GUIInputBox::showSelection(CM::UINT32 anchorCaretPos, SelectionDir dir)
+	void GUIInputBox::showSelection(CM::UINT32 anchorCaretPos)
 	{
-		mInputSelection->showSelection(anchorCaretPos, dir);
+		mInputSelection->showSelection(anchorCaretPos);
 		mSelectionShown = true;
 		markAsDirty();
 	}

+ 3 - 11
BansheeEngine/Source/BsGUIInputSelection.cpp

@@ -153,9 +153,9 @@ namespace BansheeEngine
 		return selectionRects;
 	}
 
-	void GUIInputSelection::showSelection(CM::UINT32 anchorCaretPos, SelectionDir dir)
+	void GUIInputSelection::showSelection(CM::UINT32 anchorCaretPos)
 	{
-		UINT32 charIdx = caretPosToSelectionChar(anchorCaretPos, dir);
+		UINT32 charIdx = caretPosToSelectionChar(anchorCaretPos, SelectionDir::Left);
 
 		mSelectionStart = charIdx;
 		mSelectionEnd = charIdx;
@@ -184,7 +184,7 @@ namespace BansheeEngine
 	{
 		clearSelection();
 
-		showSelection(caretPos, SelectionDir::Left); 
+		showSelection(caretPos); 
 		mSelectionDragAnchor = caretPos;
 	}
 
@@ -248,12 +248,4 @@ namespace BansheeEngine
 	{
 		return mSelectionStart == mSelectionEnd;
 	}
-
-	bool GUIInputSelection::isNewlineChar(CM::UINT32 charIdx) const
-	{
-		if(mTextDesc.text[charIdx] == '\n')
-			return true;
-
-		return false;
-	}
 }

+ 22 - 0
BansheeEngine/Source/BsGUIInputTool.cpp

@@ -213,6 +213,28 @@ namespace BansheeEngine
 		return 0;
 	}
 
+	bool GUIInputTool::isNewlineBefore(CM::UINT32 inputIdx)
+	{
+		UINT32 charIdx = getCharIdxAtInputIdx(inputIdx);
+		charIdx = (UINT32)std::max(0, (INT32)(charIdx - 1));
+
+		return isNewlineChar(charIdx);
+	}
+
+	bool GUIInputTool::isNewlineAfter(CM::UINT32 inputIdx)
+	{
+		UINT32 charIdx = getCharIdxAtInputIdx(inputIdx);
+		return isNewlineChar(charIdx);
+	}
+
+	bool GUIInputTool::isNewlineChar(CM::UINT32 charIdx) const
+	{
+		if(mTextDesc.text[charIdx] == '\n')
+			return true;
+
+		return false;
+	}
+
 	GUIInputLineDesc::GUIInputLineDesc(CM::UINT32 startChar, CM::UINT32 endChar, CM::UINT32 lineHeight, CM::INT32 lineYStart, bool includesNewline)
 		:mStartChar(startChar), mEndChar(endChar), mLineHeight(lineHeight), mLineYStart(lineYStart), mIncludesNewline(includesNewline)
 	{