Browse Source

Selection up/down working

Marko Pintera 12 years ago
parent
commit
df595f3d8b

+ 4 - 0
BansheeEngine/Include/BsGUIInputBox.h

@@ -91,8 +91,12 @@ namespace BansheeEngine
 
 		void showSelection(CM::UINT32 startChar);
 		void clearSelection();
+
 		void moveSelectionLeft(bool skipNewline);
 		void moveSelectionRight(bool skipnewLine);
+		void moveSelectionUp();
+		void moveSelectionDown();
+
 		CM::UINT32 getCaretSelectionCharIdx(SelectionDir dir) const;
 		bool isNewlineChar(CM::UINT32 charIdx) const;
 		CM::Vector<CM::Rect>::type getSelectionRects() const;

+ 1 - 0
BansheeEngine/Include/BsGUIInputCaret.h

@@ -22,6 +22,7 @@ namespace BansheeEngine
 		void updateSprite(const CM::Int2& offset);
 
 		void moveCaretToStart();
+		void moveCaretToEnd();
 		void moveCaretLeft();
 		void moveCaretRight();
 		void moveCaretUp();

+ 106 - 2
BansheeEngine/Source/BsGUIInputBox.cpp

@@ -503,7 +503,18 @@ namespace BansheeEngine
 			{
 				if(ev.isShiftDown())
 				{
-					// TODO
+					if(!mSelectionShown)
+					{
+						if(isNewlineChar(getCaretSelectionCharIdx(SelectionDir::Right)))
+						{
+							mInputCaret->moveCaretLeft();
+						}
+
+						showSelection(getCaretSelectionCharIdx(SelectionDir::Left));
+					}
+
+					moveSelectionUp();
+					scrollTextToCaret();
 
 					markAsDirty();
 					return true;
@@ -523,7 +534,18 @@ namespace BansheeEngine
 			{
 				if(ev.isShiftDown())
 				{
-					// TODO
+					if(!mSelectionShown)
+					{
+						if(isNewlineChar(getCaretSelectionCharIdx(SelectionDir::Left)))
+						{
+							mInputCaret->moveCaretRight();
+						}
+
+						showSelection(getCaretSelectionCharIdx(SelectionDir::Left));
+					}
+
+					moveSelectionDown();
+					scrollTextToCaret();
 
 					markAsDirty();
 					return true;
@@ -790,6 +812,88 @@ namespace BansheeEngine
 			clearSelection();
 	}
 
+	void GUIInputBox::moveSelectionUp()
+	{
+		UINT32 charIdx = mInputCaret->getCharIdxAtCaretPos();
+		if(charIdx > 0)
+			charIdx--;
+
+		UINT32 lineIdx = mTextSprite->getLineForChar(charIdx);
+		// Newline chars should count on the second line, but that not how the sprite reports them, so fix that
+		if(lineIdx < (mTextSprite->getNumLines() - 1))
+		{
+			if(charIdx == (mTextSprite->getLineDesc(lineIdx).endChar - 1)) 
+				lineIdx++;
+		}
+
+		if(lineIdx == 0)
+		{
+			mInputCaret->moveCaretToStart();
+			mSelectionStart = 0; 
+			mSelectionEnd = mSelectionAnchor;
+		}
+		else
+		{
+			mInputCaret->moveCaretUp();
+			UINT32 charIdx = getCaretSelectionCharIdx(SelectionDir::Left);
+
+			if(charIdx > mSelectionAnchor)
+			{
+				mSelectionStart = mSelectionAnchor;
+				mSelectionEnd = charIdx;
+			}
+			else
+			{
+				mSelectionStart = charIdx;
+				mSelectionEnd = mSelectionAnchor;
+			}
+		}
+
+		if(mSelectionStart == mSelectionEnd)
+			clearSelection();
+	}
+
+	void GUIInputBox::moveSelectionDown()
+	{
+		UINT32 charIdx = mInputCaret->getCharIdxAtCaretPos();
+		if(charIdx > 0)
+			charIdx--;
+
+		UINT32 lineIdx = mTextSprite->getLineForChar(charIdx);
+		// Newline chars should count on the second line, but that not how the sprite reports them, so fix that
+		if(lineIdx < (mTextSprite->getNumLines() - 1))
+		{
+			if(charIdx == (mTextSprite->getLineDesc(lineIdx).endChar - 1)) 
+				lineIdx++;
+		}
+
+		if(lineIdx == (mTextSprite->getNumLines() - 1))
+		{
+			mInputCaret->moveCaretToEnd();
+			mSelectionStart = mSelectionAnchor;
+			mSelectionEnd = (UINT32)mText.size();
+		}
+		else
+		{
+			mInputCaret->moveCaretDown();
+			UINT32 charIdx = getCaretSelectionCharIdx(SelectionDir::Left);
+
+			if(charIdx > mSelectionAnchor)
+			{
+				mSelectionStart = mSelectionAnchor;
+				mSelectionEnd = charIdx;
+			}
+			else
+			{
+				mSelectionStart = charIdx;
+				mSelectionEnd = mSelectionAnchor;
+			}
+		}
+
+		if(mSelectionStart == mSelectionEnd)
+			clearSelection();
+	}
+
 	Vector<Rect>::type GUIInputBox::getSelectionRects() const
 	{
 		Vector<Rect>::type selectionRects;

+ 5 - 0
BansheeEngine/Source/BsGUIInputCaret.cpp

@@ -49,6 +49,11 @@ namespace BansheeEngine
 		mCaretPos = 0;
 	}
 
+	void GUIInputCaret::moveCaretToEnd()
+	{
+		mCaretPos = getMaxCaretPos();
+	}
+
 	void GUIInputCaret::moveCaretLeft()
 	{
 		mCaretPos = (UINT32)std::max(0, (INT32)mCaretPos - 1);