瀏覽代碼

Fixed input caret rendering
Fixed an issue with rendering multiple elements with the same depth

Marko Pintera 12 年之前
父節點
當前提交
aa5418956e
共有 4 個文件被更改,包括 28 次插入16 次删除
  1. 14 8
      BansheeEngine/Source/BsGUIInputBox.cpp
  2. 10 6
      BansheeEngine/Source/BsGUIManager.cpp
  3. 2 2
      BansheeEngine/Source/BsTextSprite.cpp
  4. 2 0
      TODO.txt

+ 14 - 8
BansheeEngine/Source/BsGUIInputBox.cpp

@@ -84,8 +84,9 @@ namespace BansheeEngine
 		UINT32 numElements = mImageSprite->getNumRenderElements();
 		UINT32 numElements = mImageSprite->getNumRenderElements();
 		numElements += mTextSprite->getNumRenderElements();
 		numElements += mTextSprite->getNumRenderElements();
 
 
-		if(mCaretShown && GUIManager::instance().getCaretBlinkState())
-			numElements += mTextSprite->getNumRenderElements();
+		/*if(mCaretShown && GUIManager::instance().getCaretBlinkState())*/
+		if(mCaretShown)
+			numElements += mCaretSprite->getNumRenderElements();
 
 
 		if(mSelectionShown)
 		if(mSelectionShown)
 		{
 		{
@@ -127,7 +128,8 @@ namespace BansheeEngine
 		TEXT_SPRITE_DESC textDesc = getTextDesc();
 		TEXT_SPRITE_DESC textDesc = getTextDesc();
 		mTextSprite->update(textDesc);
 		mTextSprite->update(textDesc);
 
 
-		if(mCaretShown && GUIManager::instance().getCaretBlinkState())
+		/*if(mCaretShown && GUIManager::instance().getCaretBlinkState())*/
+		if(mCaretShown)
 		{
 		{
 			IMAGE_SPRITE_DESC mCaretDesc;
 			IMAGE_SPRITE_DESC mCaretDesc;
 			mCaretDesc.offset = getCaretPosition();
 			mCaretDesc.offset = getCaretPosition();
@@ -196,15 +198,16 @@ namespace BansheeEngine
 			return mImageSprite;
 			return mImageSprite;
 		}
 		}
 
 
-		if(mCaretShown && GUIManager::instance().getCaretBlinkState())
+		/*if(mCaretShown && GUIManager::instance().getCaretBlinkState())*/
+		if(mCaretShown)
 		{
 		{
 			oldNumElements = newNumElements;
 			oldNumElements = newNumElements;
-			newNumElements += mImageSprite->getNumRenderElements();
+			newNumElements += mCaretSprite->getNumRenderElements();
 
 
 			if(renderElemIdx < newNumElements)
 			if(renderElemIdx < newNumElements)
 			{
 			{
 				localRenderElemIdx = renderElemIdx - oldNumElements;
 				localRenderElemIdx = renderElemIdx - oldNumElements;
-				return mImageSprite;
+				return mCaretSprite;
 			}
 			}
 		}
 		}
 
 
@@ -255,9 +258,9 @@ namespace BansheeEngine
 		if(sprite == mImageSprite)
 		if(sprite == mImageSprite)
 			return _getDepth();
 			return _getDepth();
 		else if(sprite == mTextSprite || sprite == mCaretSprite)
 		else if(sprite == mTextSprite || sprite == mCaretSprite)
-			return _getDepth() + 2;
+			return _getDepth() - 2;
 		else // Selection sprites
 		else // Selection sprites
-			return _getDepth() + 1;
+			return _getDepth() - 1;
 	}
 	}
 
 
 	void GUIInputBox::fillBuffer(UINT8* vertices, UINT8* uv, UINT32* indices, UINT32 startingQuad, UINT32 maxNumQuads, 
 	void GUIInputBox::fillBuffer(UINT8* vertices, UINT8* uv, UINT32* indices, UINT32 startingQuad, UINT32 maxNumQuads, 
@@ -364,7 +367,10 @@ namespace BansheeEngine
 					else
 					else
 					{
 					{
 						if(mCaretPos > 0)
 						if(mCaretPos > 0)
+						{
 							mText.erase(mCaretPos - 1);
 							mText.erase(mCaretPos - 1);
+							mCaretPos--;
+						}
 					}
 					}
 
 
 					markAsDirty();
 					markAsDirty();

+ 10 - 6
BansheeEngine/Source/BsGUIManager.cpp

@@ -244,7 +244,9 @@ namespace BansheeEngine
 
 
 				// Compare pointers just to differentiate between two elements with the same depth, their order doesn't really matter, but std::set
 				// Compare pointers just to differentiate between two elements with the same depth, their order doesn't really matter, but std::set
 				// requires all elements to be unique
 				// requires all elements to be unique
-				return aDepth > bDepth || (aDepth ==bDepth && a.element > b.element); 
+				return (aDepth > bDepth) || 
+					(aDepth == bDepth && a.element > b.element) || 
+					(aDepth == bDepth && a.element == b.element && a.renderElement > b.renderElement); 
 			};
 			};
 
 
 			Set<GUIGroupElement, std::function<bool(const GUIGroupElement&, const GUIGroupElement&)>>::type allElements(elemComp);
 			Set<GUIGroupElement, std::function<bool(const GUIGroupElement&, const GUIGroupElement&)>>::type allElements(elemComp);
@@ -539,14 +541,16 @@ namespace BansheeEngine
 				mActiveMouseButton = guiButton;
 				mActiveMouseButton = guiButton;
 			}
 			}
 
 
-			if(mKeyboardFocusElement != nullptr && mMouseOverElement != mKeyboardFocusElement)
-				mKeyboardFocusElement->_setFocus(false);
-
 			if(mMouseOverElement != nullptr)
 			if(mMouseOverElement != nullptr)
+			{
+				if(mKeyboardFocusElement != nullptr && mMouseOverElement != mKeyboardFocusElement)
+					mKeyboardFocusElement->_setFocus(false);
+
 				mMouseOverElement->_setFocus(true);
 				mMouseOverElement->_setFocus(true);
 
 
-			mKeyboardFocusElement = mMouseOverElement;
-			mKeyboardFocusWidget = mMouseOverWidget;
+				mKeyboardFocusElement = mMouseOverElement;
+				mKeyboardFocusWidget = mMouseOverWidget;
+			}
 		}
 		}
 		
 		
 		event.markAsUsed();
 		event.markAsUsed();

+ 2 - 2
BansheeEngine/Source/BsTextSprite.cpp

@@ -171,7 +171,7 @@ namespace BansheeEngine
 			lineDesc.startChar = curCharIdx;
 			lineDesc.startChar = curCharIdx;
 			lineDesc.endChar = curCharIdx + line.getNumChars();
 			lineDesc.endChar = curCharIdx + line.getNumChars();
 			lineDesc.lineHeight = line.getYOffset();
 			lineDesc.lineHeight = line.getYOffset();
-			lineDesc.lineYStart = vertOffset + curY + desc.offset.y;
+			lineDesc.lineYStart = vertOffset + cachedLineY + desc.offset.y;
 
 
 			mLineDescs.push_back(lineDesc);
 			mLineDescs.push_back(lineDesc);
 
 
@@ -189,7 +189,7 @@ namespace BansheeEngine
 		{
 		{
 			if(charIdx >= idx && charIdx < renderElem.numQuads)
 			if(charIdx >= idx && charIdx < renderElem.numQuads)
 			{
 			{
-				UINT32 localIdx = charIdx - idx;
+				UINT32 localIdx = (charIdx - idx) * 4;
 
 
 				Rect charRect;
 				Rect charRect;
 				charRect.x = Math::RoundToInt(renderElem.vertices[localIdx + 0].x);
 				charRect.x = Math::RoundToInt(renderElem.vertices[localIdx + 0].x);

+ 2 - 0
TODO.txt

@@ -26,6 +26,8 @@ IMMEDIATE:
 	- SpriteTexture keeps a static reference to DUmmyTexture which I need to release before shutdown
 	- SpriteTexture keeps a static reference to DUmmyTexture which I need to release before shutdown
 
 
 TextBox needed elements:
 TextBox needed elements:
+ - Space doesn't register as a character which means I won't be able to place input caret if the last character is a space
+   - Make spaces inivisble characters?
  - Render element: background texture and a text sprite
  - Render element: background texture and a text sprite
  - Keyboard focus: Mouse click gives focus, tabbing between elements gives focus (TODO: explore how will tabbing work)
  - Keyboard focus: Mouse click gives focus, tabbing between elements gives focus (TODO: explore how will tabbing work)
  - Input: All characters get forwarded to element with focus
  - Input: All characters get forwarded to element with focus