浏览代码

Working selection areas with the new method

Marko Pintera 12 年之前
父节点
当前提交
48ca203776

+ 1 - 0
BansheeEngine/Include/BsGUIInputTool.h

@@ -48,6 +48,7 @@ namespace BansheeEngine
 		const GUIInputLineDesc& getLineDesc(CM::UINT32 lineIdx) const { return mLineDescs.at(lineIdx); }
 		CM::UINT32 getLineForChar(CM::UINT32 charIdx, bool newlineCountsOnNextLine = false) const;
 		CM::Rect getCharRect(CM::UINT32 charIdx) const;
+		CM::Rect getLocalCharRect(CM::UINT32 charIdx) const;
 		CM::INT32 getCharIdxAtPos(const CM::Int2& pos) const;
 
 		/**

+ 19 - 19
BansheeEngine/Source/BsGUIInputSelection.cpp

@@ -59,24 +59,24 @@ namespace BansheeEngine
 
 	Rect GUIInputSelection::getSelectionSpriteClipRect(UINT32 spriteIdx, const CM::Rect& parentClipRect) const
 	{
-		return parentClipRect;
-		//Rect clipRect(-(mElement->_getTextInputOffset().x + mSelectionRects[spriteIdx].x) + mElement->_getTextInputRect().x, 
-		//	-mSelectionRects[spriteIdx].y - mElement->_getTextInputOffset().y - mElement->_getTextInputRect().y, 
-		//	mTextDesc.width, mTextDesc.height);
+		Int2 selectionOffset(mSelectionRects[spriteIdx].x, mSelectionRects[spriteIdx].y);
+		Int2 clipOffset = selectionOffset + mElement->_getTextInputOffset();
 
-		//Rect localParentCliprect = parentClipRect;
+		Rect clipRect(-clipOffset.x, -clipOffset.y, mTextDesc.width, mTextDesc.height);
 
-		//// Move parent rect to our space
-		//localParentCliprect.x += clipRect.x;
-		//localParentCliprect.y += clipRect.y;
+		Rect localParentCliprect = parentClipRect;
 
-		//// Clip our rectangle so its not larger then the parent
-		//clipRect.clip(localParentCliprect);
+		// Move parent rect to our space
+		localParentCliprect.x += mElement->_getTextInputOffset().x + clipRect.x;
+		localParentCliprect.y += mElement->_getTextInputOffset().y + clipRect.y;
 
-		//// Increase clip size by 1, so we can fit the caret in case it is fully at the end of the text
-		//clipRect.width += 1;
+		// Clip our rectangle so its not larger then the parent
+		clipRect.clip(localParentCliprect);
 
-		//return clipRect;
+		// Increase clip size by 1, so we can fit the caret in case it is fully at the end of the text
+		clipRect.width += 1;
+
+		return clipRect;
 	}
 
 	Vector<Rect>::type GUIInputSelection::getSelectionRects() const
@@ -107,8 +107,8 @@ namespace BansheeEngine
 
 			if(!isNewlineChar(startCharIdx) && !isNewlineChar(endCharIdx))
 			{
-				Rect startChar = getCharRect(startCharIdx);
-				Rect endChar = getCharRect(endCharIdx);
+				Rect startChar = getLocalCharRect(startCharIdx);
+				Rect endChar = getLocalCharRect(endCharIdx);
 
 				Rect selectionRect;
 				selectionRect.x = startChar.x;
@@ -130,8 +130,8 @@ namespace BansheeEngine
 			if(endCharIdx > 0)
 				endCharIdx = endCharIdx - 1;
 
-			Rect startChar = getCharRect(lineDesc.getStartChar());
-			Rect endChar = getCharRect(endCharIdx);
+			Rect startChar = getLocalCharRect(lineDesc.getStartChar());
+			Rect endChar = getLocalCharRect(endCharIdx);
 
 			Rect selectionRect;
 			selectionRect.x = startChar.x;
@@ -152,8 +152,8 @@ namespace BansheeEngine
 
 				if(!isNewlineChar(endCharIdx))
 				{
-					Rect startChar = getCharRect(lineDesc.getStartChar());
-					Rect endChar = getCharRect(endCharIdx);
+					Rect startChar = getLocalCharRect(lineDesc.getStartChar());
+					Rect endChar = getLocalCharRect(endCharIdx);
 
 					Rect selectionRect;
 					selectionRect.x = startChar.x;

+ 16 - 7
BansheeEngine/Source/BsGUIInputTool.cpp

@@ -74,7 +74,18 @@ namespace BansheeEngine
 		return mElement->_getOffset() + mElement->_getTextInputOffset() + Int2(mElement->_getTextInputRect().x, mElement->_getTextInputRect().y);
 	}
 
-	CM::Rect GUIInputTool::getCharRect(UINT32 charIdx) const
+	Rect GUIInputTool::getCharRect(UINT32 charIdx) const
+	{
+		Rect charRect = getLocalCharRect(charIdx);
+		Int2 textOffset = getTextOffset();
+
+		charRect.x += textOffset.x;
+		charRect.y += textOffset.y;
+
+		return charRect;
+	}
+
+	Rect GUIInputTool::getLocalCharRect(UINT32 charIdx) const
 	{
 		UINT32 lineIdx = getLineForChar(charIdx);
 
@@ -87,18 +98,16 @@ namespace BansheeEngine
 		for(UINT32 i = 0; i < lineIdx; i++)
 			numNewlineChars += (getLineDesc(i).hasNewlineChar() ? 1 : 0);
 
-		Int2 textOffset = getTextOffset();
-
 		UINT32 quadIdx = charIdx - numNewlineChars;
 		if(quadIdx >= 0 && quadIdx < mNumQuads)
 		{
 			UINT32 vertIdx = quadIdx * 4;
 
 			Rect charRect;
-			charRect.x = Math::RoundToInt(mQuads[vertIdx + 0].x) + textOffset.x;
-			charRect.y = Math::RoundToInt(mQuads[vertIdx + 0].y) + textOffset.y;
-			charRect.width = Math::RoundToInt((mQuads[vertIdx + 3].x + textOffset.x) - charRect.x);
-			charRect.height = Math::RoundToInt((mQuads[vertIdx + 3].y + textOffset.y) - charRect.y);
+			charRect.x = Math::RoundToInt(mQuads[vertIdx + 0].x);
+			charRect.y = Math::RoundToInt(mQuads[vertIdx + 0].y);
+			charRect.width = Math::RoundToInt(mQuads[vertIdx + 3].x - charRect.x);
+			charRect.height = Math::RoundToInt(mQuads[vertIdx + 3].y - charRect.y);
 
 			return charRect;
 		}

+ 1 - 0
TODO.txt

@@ -36,6 +36,7 @@ IMMEDIATE:
 - Scrolling the window shouldn't remove text selection
  - In general focus shouldn't be lost at all
 - Hover colors of the scroll bar are wrong
+- Input caret gets removed when I resize the window
 
 TextBox needed elements:
  - Key-repeat? Pressing left/right/up/down arrows doesn't repeat the keys (also delete/backspace)