소스 검색

Proper caret clipping
Caret move up/down works even if caret is on new line start

Marko Pintera 12 년 전
부모
커밋
79aaf71515
2개의 변경된 파일9개의 추가작업 그리고 9개의 파일을 삭제
  1. 9 1
      BansheeEngine/Source/BsGUIInputCaret.cpp
  2. 0 8
      CamelotCore/Source/CmTextUtility.cpp

+ 9 - 1
BansheeEngine/Source/BsGUIInputCaret.cpp

@@ -35,7 +35,8 @@ namespace BansheeEngine
 		mCaretDesc.offset = getCaretPosition(mTextDesc.offset);
 		mCaretDesc.offset = getCaretPosition(mTextDesc.offset);
 		mCaretDesc.width = 1;
 		mCaretDesc.width = 1;
 		mCaretDesc.height = getCaretHeight();
 		mCaretDesc.height = getCaretHeight();
-		mCaretDesc.clipRect = Rect(0, 0, mTextDesc.width, mTextDesc.height);
+		mCaretDesc.clipRect = Rect(-mCaretDesc.offset.x + mTextDesc.offset.x, -mCaretDesc.offset.y + mTextDesc.offset.y, 
+			mTextDesc.width, mTextDesc.height);
 		mCaretDesc.texture = GUIManager::instance().getCaretTexture();
 		mCaretDesc.texture = GUIManager::instance().getCaretTexture();
 
 
 		mCaretSprite->update(mCaretDesc);
 		mCaretSprite->update(mCaretDesc);
@@ -65,6 +66,13 @@ namespace BansheeEngine
 			charIdx -= 1;	
 			charIdx -= 1;	
 
 
 		UINT32 lineIdx = mTextSprite->getLineForChar(charIdx);
 		UINT32 lineIdx = mTextSprite->getLineForChar(charIdx);
+		const SpriteLineDesc& desc = mTextSprite->getLineDesc(lineIdx);
+		if(lineIdx != (mTextSprite->getNumLines() - 1)) // If not the last line
+		{
+			if(charIdx == (desc.endChar - 1)) // If char is a newline, I want that to count as being on the next line because that's
+				lineIdx++;					  // how user sees it
+		}
+
 		if(lineIdx == 0)
 		if(lineIdx == 0)
 			return;
 			return;
 
 

+ 0 - 8
CamelotCore/Source/CmTextUtility.cpp

@@ -339,7 +339,6 @@ namespace CamelotFramework
 			LOGWRN("Unable to find font with specified size (" + toString(fontSize) + "). Using nearest available size: " + toString(fontData->size));
 			LOGWRN("Unable to find font with specified size (" + toString(fontSize) + "). Using nearest available size: " + toString(fontData->size));
 		}
 		}
 
 
-		bool heightIsLimited = height > 0;
 		bool widthIsLimited = width > 0;
 		bool widthIsLimited = width > 0;
 
 
 		std::shared_ptr<TextUtility::TextData> textData = cm_shared_ptr<TextData, PoolAlloc>();
 		std::shared_ptr<TextUtility::TextData> textData = cm_shared_ptr<TextData, PoolAlloc>();
@@ -359,9 +358,6 @@ namespace CamelotFramework
 
 
 			if(text[charIdx] == '\n')
 			if(text[charIdx] == '\n')
 			{
 			{
-				if(heightIsLimited && (curHeight + fontData->fontDesc.lineHeight * 2) > height)
-					break; // Max height reached
-
 				textData->mLines.push_back(TextLine(fontData->fontDesc.baselineOffset, fontData->fontDesc.lineHeight, fontData->fontDesc.spaceWidth));
 				textData->mLines.push_back(TextLine(fontData->fontDesc.baselineOffset, fontData->fontDesc.lineHeight, fontData->fontDesc.spaceWidth));
 				curLine = &textData->mLines.back();
 				curLine = &textData->mLines.back();
 
 
@@ -390,10 +386,6 @@ namespace CamelotFramework
 					if(lastWord.isSpacer())
 					if(lastWord.isSpacer())
 						curLine->addWord(lastWord); // Spaces can stay on previous line even if they don't technically fit
 						curLine->addWord(lastWord); // Spaces can stay on previous line even if they don't technically fit
 
 
-					// No more lines fit vertically so we're done
-					if(heightIsLimited && curHeight > height)
-						break;
-
 					textData->mLines.push_back(TextLine(fontData->fontDesc.baselineOffset, fontData->fontDesc.lineHeight, fontData->fontDesc.spaceWidth));
 					textData->mLines.push_back(TextLine(fontData->fontDesc.baselineOffset, fontData->fontDesc.lineHeight, fontData->fontDesc.spaceWidth));
 					curLine = &textData->mLines.back();
 					curLine = &textData->mLines.back();