Jelajahi Sumber

Finished up input selection (for now)

Marko Pintera 12 tahun lalu
induk
melakukan
62637a6704

+ 0 - 8
BansheeEngine/Include/BsGUIInputSelection.h

@@ -6,12 +6,6 @@
 
 namespace BansheeEngine
 {
-	enum class SelectionDir
-	{
-		Left,
-		Right
-	};
-
 	class BS_EXPORT GUIInputSelection : public GUIInputTool
 	{
 	public:
@@ -36,7 +30,6 @@ namespace BansheeEngine
 
 		CM::UINT32 getSelectionStart() const { return mSelectionStart; }
 		CM::UINT32 getSelectionEnd() const { return mSelectionEnd; }
-		bool isAnchorAtStart() const { return mSelectionStart == mSelectionAnchor; }
 
 	private:
 		CM::UINT32 mSelectionStart;
@@ -47,7 +40,6 @@ namespace BansheeEngine
 		CM::Vector<CM::Rect>::type mSelectionRects;
 		CM::Vector<ImageSprite*>::type mSprites;
 
-		CM::UINT32 caretPosToSelectionChar(CM::UINT32 caretPos, SelectionDir dir) const;
 		CM::Vector<CM::Rect>::type getSelectionRects() const;
 	};
 }

+ 1 - 12
BansheeEngine/Include/BsGUIInputTool.h

@@ -32,18 +32,6 @@ namespace BansheeEngine
 		~GUIInputTool();
 
 		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) const;
-
-		/**
-		 * @note	"Input index" represents the empty areas between the characters.
-		 */
-		bool isNewlineAfter(CM::UINT32 inputIdx) const;
-
-		bool isNewline(CM::UINT32 inputIdx) const;
 	protected:
 		CM::Vector2* mQuads;
 		CM::UINT32 mNumQuads;
@@ -70,5 +58,6 @@ namespace BansheeEngine
 		CM::UINT32 getCharIdxAtInputIdx(CM::UINT32 inputIdx) const;
 
 		bool isNewlineChar(CM::UINT32 charIdx) const;
+		bool isNewline(CM::UINT32 inputIdx) const;
 	};
 }

+ 20 - 127
BansheeEngine/Source/BsGUIInputBox.cpp

@@ -483,66 +483,40 @@ namespace BansheeEngine
 			{
 				if(ev.isShiftDown())
 				{
-					bool caretMovedDueToNewline = false;
 					if(!mSelectionShown)
-					{
-						if(mInputCaret->isNewlineBefore(mInputCaret->getCaretPos()))
-						{
-							mInputCaret->moveCaretLeft();
-							caretMovedDueToNewline = true;
-						}
-
 						showSelection(mInputCaret->getCaretPos());
-					}
-
-					moveSelectionLeft(caretMovedDueToNewline);
-					scrollTextToCaret();
-
-					markAsDirty();
-					return true;
 				}
 				else
-				{
 					clearSelection();
-					mInputCaret->moveCaretLeft();
-					scrollTextToCaret();
 
-					markAsDirty();
-					return true;
-				}
+				mInputCaret->moveCaretLeft();
+
+				if(ev.isShiftDown())
+					mInputSelection->moveSelectionToCaret(mInputCaret->getCaretPos());
+
+				scrollTextToCaret();
+				markAsDirty();
+				return true;
 			}
 
 			if(ev.getKey() == BC_RIGHT)
 			{
 				if(ev.isShiftDown())
 				{
-					bool caretMovedDueToNewline = false;
 					if(!mSelectionShown)
-					{
-						if(mInputCaret->isNewlineAfter(mInputCaret->getCaretPos()))
-						{
-							mInputCaret->moveCaretRight();
-							caretMovedDueToNewline = true;
-						}
-
 						showSelection(mInputCaret->getCaretPos());
-					}
-						
-					moveSelectionRight(caretMovedDueToNewline);
-					scrollTextToCaret();
-
-					markAsDirty();
-					return true;
 				}
 				else
-				{
 					clearSelection();
-					mInputCaret->moveCaretRight();
-					scrollTextToCaret();
 
-					markAsDirty();
-					return true;
-				}
+				mInputCaret->moveCaretRight();
+
+				if(ev.isShiftDown())
+					mInputSelection->moveSelectionToCaret(mInputCaret->getCaretPos());
+
+				scrollTextToCaret();
+				markAsDirty();
+				return true;
 			}
 
 			if(ev.getKey() == BC_UP)
@@ -550,26 +524,17 @@ namespace BansheeEngine
 				if(ev.isShiftDown())
 				{
 					if(!mSelectionShown)
-					{
-						if(mInputCaret->isNewlineBefore(mInputCaret->getCaretPos()))
-							mInputCaret->moveCaretLeft();
-
 						showSelection(mInputCaret->getCaretPos());
-					}
 				}
 				else
-				{
 					clearSelection();
-				}
 
 				mInputCaret->moveCaretUp();
-				scrollTextToCaret();
-
+				
 				if(ev.isShiftDown())
-				{
 					mInputSelection->moveSelectionToCaret(mInputCaret->getCaretPos());
-				}
 
+				scrollTextToCaret();
 				markAsDirty();
 				return true;
 			}
@@ -579,26 +544,17 @@ namespace BansheeEngine
 				if(ev.isShiftDown())
 				{
 					if(!mSelectionShown)
-					{
-						if(mInputCaret->isNewlineAfter(mInputCaret->getCaretPos()))
-							mInputCaret->moveCaretRight();
-
 						showSelection(mInputCaret->getCaretPos());
-					}
 				}
 				else
-				{
 					clearSelection();
-				}
 
 				mInputCaret->moveCaretDown();
-				scrollTextToCaret();
-
+				
 				if(ev.isShiftDown())
-				{
 					mInputSelection->moveSelectionToCaret(mInputCaret->getCaretPos());
-				}
 
+				scrollTextToCaret();
 				markAsDirty();
 				return true;
 			}
@@ -779,69 +735,6 @@ namespace BansheeEngine
 		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
 	{
 		Rect textBounds = getTextBounds();

+ 2 - 12
BansheeEngine/Source/BsGUIInputSelection.cpp

@@ -155,7 +155,7 @@ namespace BansheeEngine
 
 	void GUIInputSelection::showSelection(CM::UINT32 anchorCaretPos)
 	{
-		UINT32 charIdx = caretPosToSelectionChar(anchorCaretPos, SelectionDir::Left);
+		UINT32 charIdx = getCharIdxAtInputIdx(anchorCaretPos);
 
 		mSelectionStart = charIdx;
 		mSelectionEnd = charIdx;
@@ -170,16 +170,6 @@ namespace BansheeEngine
 		mSprites.clear();
 	}
 
-	UINT32 GUIInputSelection::caretPosToSelectionChar(UINT32 caretPos, SelectionDir dir) const
-	{
-		UINT32 charIdx = getCharIdxAtInputIdx(caretPos);
-
-		if(dir == SelectionDir::Right)
-			charIdx = (UINT32)std::max(0, (INT32)(charIdx - 1));
-
-		return charIdx;
-	}
-
 	void GUIInputSelection::selectionDragStart(UINT32 caretPos)
 	{
 		clearSelection();
@@ -221,7 +211,7 @@ namespace BansheeEngine
 
 	void GUIInputSelection::moveSelectionToCaret(UINT32 caretPos)
 	{
-		UINT32 charIdx = caretPosToSelectionChar(caretPos, SelectionDir::Left);
+		UINT32 charIdx = getCharIdxAtInputIdx(caretPos);
 
 		if(charIdx > mSelectionAnchor)
 		{

+ 0 - 14
BansheeEngine/Source/BsGUIInputTool.cpp

@@ -212,20 +212,6 @@ namespace BansheeEngine
 
 		return 0;
 	}
-	 
-	bool GUIInputTool::isNewlineBefore(CM::UINT32 inputIdx) const
-	{
-		UINT32 charIdx = getCharIdxAtInputIdx(inputIdx);
-		charIdx = (UINT32)std::max(0, (INT32)(charIdx - 1));
-
-		return isNewlineChar(charIdx);
-	}
-
-	bool GUIInputTool::isNewlineAfter(CM::UINT32 inputIdx) const
-	{
-		UINT32 charIdx = getCharIdxAtInputIdx(inputIdx);
-		return isNewlineChar(charIdx);
-	}
 
 	bool GUIInputTool::isNewline(CM::UINT32 inputIdx) const
 	{