Просмотр исходного кода

Moved input caret & selection on GUIManager

Marko Pintera 12 лет назад
Родитель
Сommit
5c3a22457a

+ 0 - 4
BansheeEngine/Include/BsGUIInputBox.h

@@ -4,8 +4,6 @@
 #include "BsGUIElement.h"
 #include "BsImageSprite.h"
 #include "BsTextSprite.h"
-#include "BsGUIInputCaret.h"
-#include "BsGUIInputSelection.h"
 
 namespace BansheeEngine
 {
@@ -54,8 +52,6 @@ namespace BansheeEngine
 		// Sprites
 		ImageSprite* mImageSprite;
 		TextSprite* mTextSprite;
-		GUIInputCaret* mInputCaret;
-		GUIInputSelection* mInputSelection;
 		bool mIsMultiline;
 		CM::Int2 mTextOffset;
 

+ 1 - 1
BansheeEngine/Include/BsGUIInputCaret.h

@@ -15,7 +15,7 @@ namespace BansheeEngine
 	class BS_EXPORT GUIInputCaret : public GUIInputTool
 	{
 	public:
-		GUIInputCaret(const TEXT_SPRITE_DESC& textDesc, const CM::Int2& offset, const CM::Int2 clipOffset);
+		GUIInputCaret();
 		~GUIInputCaret();
 
 		ImageSprite* getSprite() const { return mCaretSprite; }

+ 1 - 1
BansheeEngine/Include/BsGUIInputSelection.h

@@ -9,7 +9,7 @@ namespace BansheeEngine
 	class BS_EXPORT GUIInputSelection : public GUIInputTool
 	{
 	public:
-		GUIInputSelection(const TEXT_SPRITE_DESC& textDesc, const CM::Int2& offset, const CM::Int2 clipOffset);
+		GUIInputSelection();
 		~GUIInputSelection();
 
 		const CM::Vector<ImageSprite*>::type& getSprites() const { return mSprites; }

+ 1 - 1
BansheeEngine/Include/BsGUIInputTool.h

@@ -28,7 +28,7 @@ namespace BansheeEngine
 	class BS_EXPORT GUIInputTool
 	{
 	public:
-		GUIInputTool(const TEXT_SPRITE_DESC& textDesc, const CM::Int2& offset, const CM::Int2 clipOffset);
+		GUIInputTool();
 		~GUIInputTool();
 
 		void updateText(const TEXT_SPRITE_DESC& textDesc, const CM::Int2& offset, const CM::Int2 clipOffset);

+ 8 - 0
BansheeEngine/Include/BsGUIManager.h

@@ -45,6 +45,9 @@ namespace BansheeEngine
 		const SpriteTexturePtr& getTextSelectionTexture() const { return mTextSelectionTexture; }
 		bool getCaretBlinkState() const { return mIsCaretOn; }
 
+		GUIInputCaret* getInputCaretTool() const { return mInputCaret; }
+		GUIInputSelection* getInputSelectionTool() const { return mInputSelection; }
+
 	private:
 		CM::Vector<GUIWidget*>::type mWidgets;
 		CM::UnorderedMap<const CM::Viewport*, GUIRenderData>::type mCachedGUIData;
@@ -62,6 +65,9 @@ namespace BansheeEngine
 		GUIWidget* mKeyboardFocusWidget;
 		GUIElement* mKeyboardFocusElement;
 
+		GUIInputCaret* mInputCaret;
+		GUIInputSelection* mInputSelection;
+
 		bool mSeparateMeshesByWidget;
 		CM::Int2 mLastCursorLocalPos;
 
@@ -106,4 +112,6 @@ namespace BansheeEngine
 		GUIMouseButton buttonToMouseButton(CM::ButtonCode code) const;
 		CM::Int2 getWidgetRelativePos(const GUIWidget& widget, const CM::Int2& screenPos) const;
 	};
+
+	BS_EXPORT GUIManager& gGUIManager();
 }

+ 2 - 0
BansheeEngine/Include/BsPrerequisites.h

@@ -47,6 +47,8 @@ namespace BansheeEngine
 	class GUILayoutY;
 	class GUIFixedSpace;
 	class GUIFlexibleSpace;
+	class GUIInputCaret;
+	class GUIInputSelection;
 	struct GUILayoutOptions;
 
 	// 2D

+ 71 - 74
BansheeEngine/Source/BsGUIInputBox.cpp

@@ -13,6 +13,8 @@
 #include "CmTextUtility.h"
 #include "CmTexture.h"
 #include "CmCursor.h"
+#include "BsGUIInputCaret.h"
+#include "BsGUIInputSelection.h"
 
 using namespace CamelotFramework;
 
@@ -26,12 +28,10 @@ namespace BansheeEngine
 
 	GUIInputBox::GUIInputBox(GUIWidget& parent, const GUIElementStyle* style, const GUILayoutOptions& layoutOptions, bool multiline)
 		:GUIElement(parent, style, layoutOptions), mInputCursorSet(false), mDragInProgress(false),
-		mInputCaret(nullptr), mInputSelection(nullptr), mCaretShown(false), mSelectionShown(false), mIsMultiline(multiline)
+		mCaretShown(false), mSelectionShown(false), mIsMultiline(multiline)
 	{
 		mImageSprite = cm_new<ImageSprite, PoolAlloc>();
 		mTextSprite = cm_new<TextSprite, PoolAlloc>();
-		mInputCaret = cm_new<GUIInputCaret, PoolAlloc>(getTextDesc(), getTextOffset(), mTextOffset);
-		mInputSelection = cm_new<GUIInputSelection, PoolAlloc>(getTextDesc(), getTextOffset(), mTextOffset);
 
 		mImageDesc.texture = mStyle->normal.texture;
 
@@ -51,9 +51,6 @@ namespace BansheeEngine
 	{
 		cm_delete<PoolAlloc>(mTextSprite);
 		cm_delete<PoolAlloc>(mImageSprite);
-
-		cm_delete<PoolAlloc>(mInputCaret);
-		cm_delete<PoolAlloc>(mInputSelection);
 	}
 
 	GUIInputBox* GUIInputBox::create(GUIWidget& parent, bool multiline, const GUIElementStyle* style)
@@ -83,12 +80,12 @@ namespace BansheeEngine
 		UINT32 numElements = mImageSprite->getNumRenderElements();
 		numElements += mTextSprite->getNumRenderElements();
 
-		if(mCaretShown && GUIManager::instance().getCaretBlinkState())
-			numElements += mInputCaret->getSprite()->getNumRenderElements();
+		if(mCaretShown && gGUIManager().getCaretBlinkState())
+			numElements += gGUIManager().getInputCaretTool()->getSprite()->getNumRenderElements();
 
 		if(mSelectionShown)
 		{
-			const Vector<ImageSprite*>::type& sprites = mInputSelection->getSprites();
+			const Vector<ImageSprite*>::type& sprites = gGUIManager().getInputSelectionTool()->getSprites();
 			for(auto& selectionSprite : sprites)
 			{
 				numElements += selectionSprite->getNumRenderElements();
@@ -125,16 +122,16 @@ namespace BansheeEngine
 		TEXT_SPRITE_DESC textDesc = getTextDesc();
 		mTextSprite->update(textDesc);
 
-		if(mCaretShown && GUIManager::instance().getCaretBlinkState())
+		if(mCaretShown && gGUIManager().getCaretBlinkState())
 		{
-			mInputCaret->updateText(textDesc, getTextOffset(), mTextOffset); // TODO - These shouldn't be here. Only call this when one of these parameters changes.
-			mInputCaret->updateSprite();
+			gGUIManager().getInputCaretTool()->updateText(textDesc, getTextOffset(), mTextOffset); // TODO - These shouldn't be here. Only call this when one of these parameters changes.
+			gGUIManager().getInputCaretTool()->updateSprite();
 		}
 
 		if(mSelectionShown)
 		{
-			mInputSelection->updateText(textDesc, getTextOffset(), mTextOffset); // TODO - These shouldn't be here. Only call this when one of these parameters changes.
-			mInputSelection->updateSprite();
+			gGUIManager().getInputSelectionTool()->updateText(textDesc, getTextOffset(), mTextOffset); // TODO - These shouldn't be here. Only call this when one of these parameters changes.
+			gGUIManager().getInputSelectionTool()->updateSprite();
 		}
 	}
 
@@ -157,21 +154,21 @@ namespace BansheeEngine
 			return mImageSprite;
 		}
 
-		if(mCaretShown && GUIManager::instance().getCaretBlinkState())
+		if(mCaretShown && gGUIManager().getCaretBlinkState())
 		{
 			oldNumElements = newNumElements;
-			newNumElements += mInputCaret->getSprite()->getNumRenderElements();
+			newNumElements += gGUIManager().getInputCaretTool()->getSprite()->getNumRenderElements();
 
 			if(renderElemIdx < newNumElements)
 			{
 				localRenderElemIdx = renderElemIdx - oldNumElements;
-				return mInputCaret->getSprite();
+				return gGUIManager().getInputCaretTool()->getSprite();
 			}
 		}
 
 		if(mSelectionShown)
 		{
-			const Vector<ImageSprite*>::type& sprites = mInputSelection->getSprites();
+			const Vector<ImageSprite*>::type& sprites = gGUIManager().getInputSelectionTool()->getSprites();
 			for(auto& selectionSprite : sprites)
 			{
 				oldNumElements = newNumElements;
@@ -202,26 +199,26 @@ namespace BansheeEngine
 		if(renderElemIdx < newNumElements)
 			return mOffset;
 
-		if(mCaretShown && GUIManager::instance().getCaretBlinkState())
+		if(mCaretShown && gGUIManager().getCaretBlinkState())
 		{
 			oldNumElements = newNumElements;
-			newNumElements += mInputCaret->getSprite()->getNumRenderElements();
+			newNumElements += gGUIManager().getInputCaretTool()->getSprite()->getNumRenderElements();
 
 			if(renderElemIdx < newNumElements)
-				return mInputCaret->getSpriteOffset();
+				return gGUIManager().getInputCaretTool()->getSpriteOffset();
 		}
 
 		if(mSelectionShown)
 		{
 			UINT32 spriteIdx = 0;
-			const Vector<ImageSprite*>::type& sprites = mInputSelection->getSprites();
+			const Vector<ImageSprite*>::type& sprites = gGUIManager().getInputSelectionTool()->getSprites();
 			for(auto& selectionSprite : sprites)
 			{
 				oldNumElements = newNumElements;
 				newNumElements += selectionSprite->getNumRenderElements();
 
 				if(renderElemIdx < newNumElements)
-					return mInputSelection->getSelectionSpriteOffset(spriteIdx);
+					return gGUIManager().getInputSelectionTool()->getSelectionSpriteOffset(spriteIdx);
 
 				spriteIdx++;
 			}
@@ -243,26 +240,26 @@ namespace BansheeEngine
 		if(renderElemIdx < newNumElements)
 			return mClipRect;
 
-		if(mCaretShown && GUIManager::instance().getCaretBlinkState())
+		if(mCaretShown && gGUIManager().getCaretBlinkState())
 		{
 			oldNumElements = newNumElements;
-			newNumElements += mInputCaret->getSprite()->getNumRenderElements();
+			newNumElements += gGUIManager().getInputCaretTool()->getSprite()->getNumRenderElements();
 
 			if(renderElemIdx < newNumElements)
-				return mInputCaret->getSpriteClipRect();
+				return gGUIManager().getInputCaretTool()->getSpriteClipRect();
 		}
 
 		if(mSelectionShown)
 		{
 			UINT32 spriteIdx = 0;
-			const Vector<ImageSprite*>::type& sprites = mInputSelection->getSprites();
+			const Vector<ImageSprite*>::type& sprites = gGUIManager().getInputSelectionTool()->getSprites();
 			for(auto& selectionSprite : sprites)
 			{
 				oldNumElements = newNumElements;
 				newNumElements += selectionSprite->getNumRenderElements();
 
 				if(renderElemIdx < newNumElements)
-					return mInputSelection->getSelectionSpriteClipRect(spriteIdx);
+					return gGUIManager().getInputSelectionTool()->getSelectionSpriteClipRect(spriteIdx);
 
 				spriteIdx++;
 			}
@@ -300,7 +297,7 @@ namespace BansheeEngine
 			return _getDepth();
 		else if(sprite == mTextSprite)
 			return _getDepth() - 2;
-		else if(sprite == mInputCaret->getSprite())
+		else if(sprite == gGUIManager().getInputCaretTool()->getSprite())
 			return _getDepth() - 3;
 		else // Selection sprites
 			return _getDepth() - 1;
@@ -352,9 +349,9 @@ namespace BansheeEngine
 			showCaret();
 
 			if(mText.size() > 0)
-				mInputCaret->moveCaretToPos(ev.getPosition());
+				gGUIManager().getInputCaretTool()->moveCaretToPos(ev.getPosition());
 			else
-				mInputCaret->moveCaretToStart();
+				gGUIManager().getInputCaretTool()->moveCaretToStart();
 
 			scrollTextToCaret();
 
@@ -375,9 +372,9 @@ namespace BansheeEngine
 		{
 			mDragInProgress = true;
 
-			UINT32 caretPos = mInputCaret->getCaretPos();
+			UINT32 caretPos = gGUIManager().getInputCaretTool()->getCaretPos();
 			showSelection(caretPos);
-			mInputSelection->selectionDragStart(caretPos);
+			gGUIManager().getInputSelectionTool()->selectionDragStart(caretPos);
 
 			return true;
 		}
@@ -391,7 +388,7 @@ namespace BansheeEngine
 				mInputCursorSet = false;
 			}
 
-			mInputSelection->selectionDragEnd();
+			gGUIManager().getInputSelectionTool()->selectionDragEnd();
 
 			return true;
 		}
@@ -399,11 +396,11 @@ namespace BansheeEngine
 		{
 			Rect bounds = getTextBounds();
 			if(mText.size() > 0)
-				mInputCaret->moveCaretToPos(ev.getPosition());
+				gGUIManager().getInputCaretTool()->moveCaretToPos(ev.getPosition());
 			else
-				mInputCaret->moveCaretToStart();
+				gGUIManager().getInputCaretTool()->moveCaretToStart();
 
-			mInputSelection->selectionDragUpdate(mInputCaret->getCaretPos());
+			gGUIManager().getInputSelectionTool()->selectionDragUpdate(gGUIManager().getInputCaretTool()->getCaretPos());
 
 			scrollTextToCaret();
 
@@ -428,7 +425,7 @@ namespace BansheeEngine
 					}
 					else
 					{
-						UINT32 charIdx = mInputCaret->getCharIdxAtCaretPos() - 1;
+						UINT32 charIdx = gGUIManager().getInputCaretTool()->getCharIdxAtCaretPos() - 1;
 
 						if(charIdx < (UINT32)mText.size())
 						{
@@ -437,7 +434,7 @@ namespace BansheeEngine
 							if(charIdx > 0)
 								charIdx--;
 
-							mInputCaret->moveCaretToChar(charIdx, CARET_AFTER);
+							gGUIManager().getInputCaretTool()->moveCaretToChar(charIdx, CARET_AFTER);
 
 							scrollTextToCaret();
 						}
@@ -459,7 +456,7 @@ namespace BansheeEngine
 					}
 					else
 					{
-						UINT32 charIdx = mInputCaret->getCharIdxAtCaretPos();
+						UINT32 charIdx = gGUIManager().getInputCaretTool()->getCharIdxAtCaretPos();
 						if(charIdx < (UINT32)mText.size())
 						{
 							eraseChar(charIdx);
@@ -467,7 +464,7 @@ namespace BansheeEngine
 							if(charIdx > 0)
 								charIdx--;
 
-							mInputCaret->moveCaretToChar(charIdx, CARET_AFTER);
+							gGUIManager().getInputCaretTool()->moveCaretToChar(charIdx, CARET_AFTER);
 
 							scrollTextToCaret();
 						}
@@ -484,15 +481,15 @@ namespace BansheeEngine
 				if(ev.isShiftDown())
 				{
 					if(!mSelectionShown)
-						showSelection(mInputCaret->getCaretPos());
+						showSelection(gGUIManager().getInputCaretTool()->getCaretPos());
 				}
 				else
 					clearSelection();
 
-				mInputCaret->moveCaretLeft();
+				gGUIManager().getInputCaretTool()->moveCaretLeft();
 
 				if(ev.isShiftDown())
-					mInputSelection->moveSelectionToCaret(mInputCaret->getCaretPos());
+					gGUIManager().getInputSelectionTool()->moveSelectionToCaret(gGUIManager().getInputCaretTool()->getCaretPos());
 
 				scrollTextToCaret();
 				markAsDirty();
@@ -504,15 +501,15 @@ namespace BansheeEngine
 				if(ev.isShiftDown())
 				{
 					if(!mSelectionShown)
-						showSelection(mInputCaret->getCaretPos());
+						showSelection(gGUIManager().getInputCaretTool()->getCaretPos());
 				}
 				else
 					clearSelection();
 
-				mInputCaret->moveCaretRight();
+				gGUIManager().getInputCaretTool()->moveCaretRight();
 
 				if(ev.isShiftDown())
-					mInputSelection->moveSelectionToCaret(mInputCaret->getCaretPos());
+					gGUIManager().getInputSelectionTool()->moveSelectionToCaret(gGUIManager().getInputCaretTool()->getCaretPos());
 
 				scrollTextToCaret();
 				markAsDirty();
@@ -524,15 +521,15 @@ namespace BansheeEngine
 				if(ev.isShiftDown())
 				{
 					if(!mSelectionShown)
-						showSelection(mInputCaret->getCaretPos());
+						showSelection(gGUIManager().getInputCaretTool()->getCaretPos());
 				}
 				else
 					clearSelection();
 
-				mInputCaret->moveCaretUp();
+				gGUIManager().getInputCaretTool()->moveCaretUp();
 				
 				if(ev.isShiftDown())
-					mInputSelection->moveSelectionToCaret(mInputCaret->getCaretPos());
+					gGUIManager().getInputSelectionTool()->moveSelectionToCaret(gGUIManager().getInputCaretTool()->getCaretPos());
 
 				scrollTextToCaret();
 				markAsDirty();
@@ -544,15 +541,15 @@ namespace BansheeEngine
 				if(ev.isShiftDown())
 				{
 					if(!mSelectionShown)
-						showSelection(mInputCaret->getCaretPos());
+						showSelection(gGUIManager().getInputCaretTool()->getCaretPos());
 				}
 				else
 					clearSelection();
 
-				mInputCaret->moveCaretDown();
+				gGUIManager().getInputCaretTool()->moveCaretDown();
 				
 				if(ev.isShiftDown())
-					mInputSelection->moveSelectionToCaret(mInputCaret->getCaretPos());
+					gGUIManager().getInputSelectionTool()->moveSelectionToCaret(gGUIManager().getInputCaretTool()->getCaretPos());
 
 				scrollTextToCaret();
 				markAsDirty();
@@ -566,9 +563,9 @@ namespace BansheeEngine
 					if(mSelectionShown)
 						deleteSelectedText();
 
-					insertChar(mInputCaret->getCharIdxAtCaretPos(), '\n');
+					insertChar(gGUIManager().getInputCaretTool()->getCharIdxAtCaretPos(), '\n');
 
-					mInputCaret->moveCaretRight();
+					gGUIManager().getInputCaretTool()->moveCaretRight();
 					scrollTextToCaret();
 
 					markAsDirty();
@@ -580,7 +577,7 @@ namespace BansheeEngine
 			if(ev.getKey() == BC_A && ev.isCtrlDown())
 			{
 				showSelection(0);
-				mInputSelection->selectAll();
+				gGUIManager().getInputSelectionTool()->selectAll();
 
 				markAsDirty();
 				return true;
@@ -591,10 +588,10 @@ namespace BansheeEngine
 			if(mSelectionShown)
 				deleteSelectedText();
 
-			UINT32 charIdx = mInputCaret->getCharIdxAtCaretPos();
+			UINT32 charIdx = gGUIManager().getInputCaretTool()->getCharIdxAtCaretPos();
 			insertChar(charIdx, ev.getInputChar());
 
-			mInputCaret->moveCaretToChar(charIdx, CARET_AFTER);
+			gGUIManager().getInputCaretTool()->moveCaretToChar(charIdx, CARET_AFTER);
 
 			scrollTextToCaret();
 
@@ -631,14 +628,14 @@ namespace BansheeEngine
 
 	void GUIInputBox::showSelection(CM::UINT32 anchorCaretPos)
 	{
-		mInputSelection->showSelection(anchorCaretPos);
+		gGUIManager().getInputSelectionTool()->showSelection(anchorCaretPos);
 		mSelectionShown = true;
 		markAsDirty();
 	}
 
 	void GUIInputBox::clearSelection()
 	{
-		mInputSelection->clearSelection();
+		gGUIManager().getInputSelectionTool()->clearSelection();
 		mSelectionShown = false;
 		markAsDirty();
 	}
@@ -648,8 +645,8 @@ namespace BansheeEngine
 		TEXT_SPRITE_DESC textDesc = getTextDesc();
 
 		Int2 textOffset = getTextOffset();
-		Int2 caretPos = mInputCaret->getCaretPosition(textOffset);
-		UINT32 caretHeight = mInputCaret->getCaretHeight();
+		Int2 caretPos = gGUIManager().getInputCaretTool()->getCaretPosition(textOffset);
+		UINT32 caretHeight = gGUIManager().getInputCaretTool()->getCaretHeight();
 		UINT32 caretWidth = 1;
 		INT32 caretRight = caretPos.x + (INT32)caretWidth;
 		INT32 caretBottom = caretPos.y + (INT32)caretHeight;
@@ -683,8 +680,8 @@ namespace BansheeEngine
 		mTextOffset += offset;
 
 		Int2 newOffset = getTextOffset();
-		mInputCaret->updateText(textDesc, newOffset, mTextOffset);
-		mInputSelection->updateText(textDesc, newOffset, mTextOffset);
+		gGUIManager().getInputCaretTool()->updateText(textDesc, newOffset, mTextOffset);
+		gGUIManager().getInputSelectionTool()->updateText(textDesc, newOffset, mTextOffset);
 
 		markAsDirty();
 	}
@@ -696,8 +693,8 @@ namespace BansheeEngine
 		TEXT_SPRITE_DESC textDesc = getTextDesc();
 		Int2 offset = getTextOffset();
 
-		mInputCaret->updateText(textDesc, offset, mTextOffset);
-		mInputSelection->updateText(textDesc, offset, mTextOffset);
+		gGUIManager().getInputCaretTool()->updateText(textDesc, offset, mTextOffset);
+		gGUIManager().getInputSelectionTool()->updateText(textDesc, offset, mTextOffset);
 	}
 
 	void GUIInputBox::eraseChar(CM::UINT32 charIdx)
@@ -707,28 +704,28 @@ namespace BansheeEngine
 		TEXT_SPRITE_DESC textDesc = getTextDesc();
 		Int2 offset = getTextOffset();
 
-		mInputCaret->updateText(textDesc, offset, mTextOffset);
-		mInputSelection->updateText(textDesc, offset, mTextOffset);
+		gGUIManager().getInputCaretTool()->updateText(textDesc, offset, mTextOffset);
+		gGUIManager().getInputSelectionTool()->updateText(textDesc, offset, mTextOffset);
 	}
 
 	void GUIInputBox::deleteSelectedText()
 	{
-		UINT32 selStart = mInputSelection->getSelectionStart();
-		mText.erase(mText.begin() + selStart, mText.begin() + mInputSelection->getSelectionEnd());
+		UINT32 selStart = gGUIManager().getInputSelectionTool()->getSelectionStart();
+		mText.erase(mText.begin() + selStart, mText.begin() + gGUIManager().getInputSelectionTool()->getSelectionEnd());
 
 		TEXT_SPRITE_DESC textDesc = getTextDesc();
 		Int2 offset = getTextOffset();
-		mInputCaret->updateText(textDesc, offset, mTextOffset);
-		mInputSelection->updateText(textDesc, offset, mTextOffset);
+		gGUIManager().getInputCaretTool()->updateText(textDesc, offset, mTextOffset);
+		gGUIManager().getInputSelectionTool()->updateText(textDesc, offset, mTextOffset);
 
 		if(selStart > 0)
 		{
 			UINT32 newCaretPos = selStart - 1;
-			mInputCaret->moveCaretToChar(newCaretPos, CARET_AFTER);
+			gGUIManager().getInputCaretTool()->moveCaretToChar(newCaretPos, CARET_AFTER);
 		}
 		else
 		{
-			mInputCaret->moveCaretToChar(0, CARET_BEFORE);
+			gGUIManager().getInputCaretTool()->moveCaretToChar(0, CARET_BEFORE);
 		}
 
 		scrollTextToCaret();

+ 2 - 4
BansheeEngine/Source/BsGUIInputCaret.cpp

@@ -7,12 +7,10 @@ using namespace CamelotFramework;
 
 namespace BansheeEngine
 {
-	GUIInputCaret::GUIInputCaret(const TEXT_SPRITE_DESC& textDesc, const Int2& offset, const Int2 clipOffset)
-		:GUIInputTool(textDesc, offset, clipOffset), mCaretPos(0)
+	GUIInputCaret::GUIInputCaret()
+		:mCaretPos(0)
 	{
 		mCaretSprite = cm_new<ImageSprite, PoolAlloc>();
-
-		updateText(textDesc, offset, clipOffset);
 	}
 
 	GUIInputCaret::~GUIInputCaret()

+ 2 - 2
BansheeEngine/Source/BsGUIInputSelection.cpp

@@ -6,8 +6,8 @@ using namespace CamelotFramework;
 
 namespace BansheeEngine
 {
-	GUIInputSelection::GUIInputSelection(const TEXT_SPRITE_DESC& textDesc, const CM::Int2& offset, const CM::Int2 clipOffset)
-		:GUIInputTool(textDesc, offset, clipOffset), mSelectionStart(0), mSelectionEnd(0), mSelectionAnchor(0), mSelectionDragAnchor(0)
+	GUIInputSelection::GUIInputSelection()
+		:mSelectionStart(0), mSelectionEnd(0), mSelectionAnchor(0), mSelectionDragAnchor(0)
 	{ }
 
 	GUIInputSelection::~GUIInputSelection()

+ 3 - 5
BansheeEngine/Source/BsGUIInputTool.cpp

@@ -7,11 +7,9 @@ using namespace CamelotFramework;
 
 namespace BansheeEngine
 {
-	GUIInputTool::GUIInputTool(const TEXT_SPRITE_DESC& textDesc, const Int2& offset, const Int2 clipOffset)
-		:mTextDesc(textDesc), mTextOffset(offset), mClipOffset(clipOffset), mQuads(nullptr), mNumQuads(0)
-	{
-		updateText(textDesc, offset, clipOffset);
-	}
+	GUIInputTool::GUIInputTool()
+		:mQuads(nullptr), mNumQuads(0)
+	{ }
 
 	GUIInputTool::~GUIInputTool()
 	{ }

+ 14 - 1
BansheeEngine/Source/BsGUIManager.cpp

@@ -17,6 +17,8 @@
 #include "CmInput.h"
 #include "CmPass.h"
 #include "CmDebug.h"
+#include "BsGUIInputCaret.h"
+#include "BsGUIInputSelection.h"
 
 using namespace CamelotFramework;
 namespace BansheeEngine
@@ -47,7 +49,7 @@ namespace BansheeEngine
 		:mMouseOverElement(nullptr), mMouseOverWidget(nullptr), mSeparateMeshesByWidget(true), mActiveElement(nullptr), 
 		mActiveWidget(nullptr), mActiveMouseButton(GUIMouseButton::Left), mKeyboardFocusElement(nullptr), mKeyboardFocusWidget(nullptr),
 		mCaretTexture(nullptr), mCaretBlinkInterval(0.5f), mCaretLastBlinkTime(0.0f), mCaretColor(1.0f, 0.6588f, 0.0f), mIsCaretOn(false),
-		mTextSelectionColor(1.0f, 0.6588f, 0.0f)
+		mTextSelectionColor(1.0f, 0.6588f, 0.0f), mInputCaret(nullptr), mInputSelection(nullptr)
 	{
 		mOnButtonDownConn = gInput().onButtonDown.connect(boost::bind(&GUIManager::onButtonDown, this, _1));
 		mOnButtonUpConn = gInput().onButtonUp.connect(boost::bind(&GUIManager::onButtonUp, this, _1));
@@ -58,6 +60,9 @@ namespace BansheeEngine
 		mWindowLostFocusConn = RenderWindowManager::instance().onFocusLost.connect(boost::bind(&GUIManager::onWindowFocusLost, this, _1));
 		mWindowMovedOrResizedConn = RenderWindowManager::instance().onMovedOrResized.connect(boost::bind(&GUIManager::onWindowMovedOrResized, this, _1));
 
+		mInputCaret = cm_new<GUIInputCaret, PoolAlloc>();
+		mInputSelection = cm_new<GUIInputSelection, PoolAlloc>();
+
 		// Need to defer this call because I want to make sure all managers are initialized first
 		deferredCall(std::bind(&GUIManager::updateCaretTexture, this));
 		deferredCall(std::bind(&GUIManager::updateTextSelectionTexture, this));
@@ -79,6 +84,9 @@ namespace BansheeEngine
 		mWindowGainedFocusConn.disconnect();
 		mWindowLostFocusConn.disconnect();
 		mWindowMovedOrResizedConn.disconnect();
+
+		cm_delete<PoolAlloc>(mInputCaret);
+		cm_delete<PoolAlloc>(mInputSelection);
 	}
 
 	void GUIManager::registerWidget(GUIWidget* widget)
@@ -840,4 +848,9 @@ namespace BansheeEngine
 
 		return curLocalPos;
 	}
+
+	GUIManager& gGUIManager()
+	{
+		return GUIManager::instance();
+	}
 }

+ 2 - 6
TODO.txt

@@ -31,8 +31,6 @@ TextBox needed elements:
  - Cut/Copy/Paste
  - All classes dealing with text (Button, Toggle, Label, InputBox) determine text field size based on mBounds which is calculated from 
     clipped mImageSprite coordinates. Which is wrong because text word wrap will change depending how clipped the sprite is.
- - Re-enable selection
- - Add GUIInputTextBase which is a parent to both caret and selection
  - Don't forget to make the classes input/selection singletons
  - Elements need TWO different dirty flags. Right now setting dirty causes both content update and fillBuffer update.
    - But I'd like only fillBuffer update when element is moved, or clipped as content update may be expensive
@@ -41,10 +39,8 @@ TextBox needed elements:
  - LATER
   - TAB between input elements
   - Context menu with copy/cut/paste
-  - Sprites. Perform clipping when fillbuffer is called? (Also deal with offset?)
-    This way I can change clip rect without recreating the entire sprite. 
-	Which is important for text, especially when I'll be scrolling it. 
-	Plus its important for all other elements that will be inside scroll areas.
+  - Remove updateText calls from updateRenderElementsInternal and instead call it whenever offsets change
+  - I might consider not rendering caret from within input sprite to avoid redrawing it while, and draw it directly from GUIManager
 
 GUIDragManager
  - GUI system sends startdrag/enddrag/drag events to all elements