Explorar el Código

Caret up/down works

Marko Pintera hace 12 años
padre
commit
3e8e1e5d62
Se han modificado 2 ficheros con 54 adiciones y 36 borrados
  1. 30 34
      BansheeEngine/Source/BsGUIInputBox.cpp
  2. 24 2
      BansheeEngine/Source/BsGUIInputCaret.cpp

+ 30 - 34
BansheeEngine/Source/BsGUIInputBox.cpp

@@ -462,44 +462,40 @@ namespace BansheeEngine
 
 
 			if(ev.getKey() == BC_UP)
 			if(ev.getKey() == BC_UP)
 			{
 			{
-				//Int2 caretCoords = getCaretPosition();
-				//UINT32 curLine = 0; mTextSprite->getLineForChar(mCaretPos);
-
-				//if(mCaretPos > 0)
-				//	curLine = 0; mTextSprite->getLineForChar(mCaretPos - 1);
-
-				//if(curLine > 0)
-				//{
-				//	if(ev.isShiftDown())
-				//	{
-				//		if(!mSelectionShown)
-				//			showSelection(mCaretPos, mCaretPos);
-
-				//		// TODO
-				//		//if(mSelectionAnchor == mSelectionEnd)
-				//		//	mSelectionStart = (UINT32)std::max(0, (INT32)mSelectionStart - 1);
-				//		//else
-				//		//	mSelectionEnd = (UINT32)std::max(0, (INT32)mSelectionEnd - 1);
-
-				//		markAsDirty();
-				//		return true;
-				//	}
-				//	else
-				//	{
-				//		clearSelection();
-
-				//		const SpriteLineDesc& lineDesc = mTextSprite->getLineDesc(curLine);
-				//		Int2 newCaretCoords = caretCoords;
-				//		newCaretCoords.y -= lineDesc.lineHeight / 2;
-
-				//		showCaretAtPos(newCaretCoords);
-				//	}
-				//}
+				if(ev.isShiftDown())
+				{
+					// TODO
+
+					markAsDirty();
+					return true;
+				}
+				else
+				{
+					clearSelection();
+					mInputCaret->moveCaretUp();
+
+					markAsDirty();
+					return true;
+				}
 			}
 			}
 
 
 			if(ev.getKey() == BC_DOWN)
 			if(ev.getKey() == BC_DOWN)
 			{
 			{
-				// TODO
+				if(ev.isShiftDown())
+				{
+					// TODO
+
+					markAsDirty();
+					return true;
+				}
+				else
+				{
+					clearSelection();
+					mInputCaret->moveCaretDown();
+
+					markAsDirty();
+					return true;
+				}
 			}
 			}
 
 
 			if(ev.getKey() == BC_RETURN)
 			if(ev.getKey() == BC_RETURN)

+ 24 - 2
BansheeEngine/Source/BsGUIInputCaret.cpp

@@ -60,12 +60,34 @@ namespace BansheeEngine
 
 
 	void GUIInputCaret::moveCaretUp()
 	void GUIInputCaret::moveCaretUp()
 	{
 	{
-		// TODO
+		UINT32 charIdx = getCharIdxAtCaretPos();
+		if(charIdx > 0)
+			charIdx -= 1;	
+
+		UINT32 lineIdx = mTextSprite->getLineForChar(charIdx);
+		if(lineIdx == 0)
+			return;
+
+		Int2 caretCoords = getCaretPosition(mTextDesc.offset);
+		caretCoords.y -= getCaretHeight();
+
+		moveCaretToPos(caretCoords);
 	}
 	}
 
 
 	void GUIInputCaret::moveCaretDown()
 	void GUIInputCaret::moveCaretDown()
 	{
 	{
-		// TODO
+		UINT32 charIdx = getCharIdxAtCaretPos();
+		if(charIdx > 0)
+			charIdx -= 1;	
+
+		UINT32 lineIdx = mTextSprite->getLineForChar(charIdx);
+		if(lineIdx == (mTextSprite->getNumLines() - 1))
+			return;
+
+		Int2 caretCoords = getCaretPosition(mTextDesc.offset);
+		caretCoords.y += getCaretHeight();
+
+		moveCaretToPos(caretCoords);
 	}
 	}
 
 
 	void GUIInputCaret::moveCaretToPos(const CM::Int2& pos)
 	void GUIInputCaret::moveCaretToPos(const CM::Int2& pos)